chromium/ui/gfx/mojom/native_handle_types.mojom

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module gfx.mojom;

import "mojo/public/mojom/base/shared_memory.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";

// gfx::NativePixmapPlane
[EnableIf=supports_native_pixmap, Stable]
struct NativePixmapPlane {
  uint32 stride;
  uint64 offset;
  uint64 size;

  // A platform-specific handle the underlying memory object.
  handle<platform> buffer_handle;
};

// gfx::NativePixmapHandle
[EnableIf=supports_native_pixmap]
struct NativePixmapHandle {
  array<NativePixmapPlane> planes;

  [EnableIf=is_linux_or_chromeos]
  uint64 modifier;

  [EnableIf=is_linux_or_chromeos]
  bool supports_zero_copy_webgpu_import;

  [EnableIf=is_fuchsia]
  handle<platform> buffer_collection_handle;
  [EnableIf=is_fuchsia]
  uint32 buffer_index;
  [EnableIf=is_fuchsia]
  bool ram_coherency;
};

[EnableIf=is_android]
struct AHardwareBufferHandle {
  // The actual file descriptor used to wrap the AHardwareBuffer object for
  // serialization.
  handle<platform> buffer_handle;

  // A message pipe handle which tracks the lifetime of this
  // AHardwareBufferHandle. The sender may use this to observe the lifetime
  // remotely by watching the other end of this pipe. Useful for retaining a
  // sender-side AHB ref until the receiver deserializes the AHB and acquires
  // its own ref.
  handle<message_pipe> tracking_pipe;
};

// gfx::DXGIHandleToken
// A unique identifier to identify one of the below resources
// (cannot identify the other at the same time):
// - Texture corresponding to the GMB handle. Handles get duplicated and OS
//   provides no other identifier. DXGISharedHandleManager in the GPU services
//   uses this as a key to cache state across calls that reference the same
//   texture via different handles.
// - Fence corresponding to the GPUFenceHandle. Fence handle get duplicated
//   and OS provides no other identifier. D3DImageBacking in the GPU services
//   uses this as a key to reference the same fence via different handles.
[EnableIf=is_win]
struct DXGIHandleToken {
  mojo_base.mojom.UnguessableToken value;
};

[EnableIf=is_win]
struct DXGIHandle {
  // The actual buffer windows handle.
  handle<platform> buffer_handle;

  // A unique identifier for the texture corresponding to this GMB handle. This
  // is needed because there's no other way to uniquely identify the underlying
  // texture. Handles get duplicated and the OS provides no other identifier.
  // DXGISharedHandleManager in the GPU service uses this as a key to cache
  // state across calls that reference the same texture via different handles.
  DXGIHandleToken token;

  // Shared memory copy of all the data. Valid only if requested by the
  // consumer. It is included here because DXGI GMBs are unmappable except in
  // the GPU process. So without it the consumer if a CPU readable frame is
  // needed would resort to request a copy in the shared memory via GPU process.
  mojo_base.mojom.UnsafeSharedMemoryRegion? shared_memory_handle;
};

union GpuMemoryBufferPlatformHandle {
  mojo_base.mojom.UnsafeSharedMemoryRegion shared_memory_handle;

  [EnableIf=supports_native_pixmap]
  NativePixmapHandle native_pixmap_handle;

  [EnableIf=is_apple]
  handle<platform> mach_port;

  [EnableIf=is_win]
  DXGIHandle dxgi_handle;

  [EnableIf=is_android]
  AHardwareBufferHandle android_hardware_buffer_handle;
};