Skip to main content
Version: 20 Mar 2024

AHardwareBuffer

NameSpace: NativeWindow

Inherits from:
INullablePointer,
IDisposable

Public Fields

description


public Description description { get; set; }


Public Methods

void Acquire

public void Acquire()

void Dispose

public void Dispose()

bool IsSupported

public static bool IsSupported(
Description description
)

Parameters

TypeNameDescription
Descriptiondescription

bool TryAllocate

public static bool TryAllocate(
Description description,
out AHardwareBuffer buffer
)

Parameters

TypeNameDescription
Descriptiondescription
out AHardwareBufferbuffer

unsafe bool TryLockData

public unsafe bool TryLockData(
Usage usageFlags,
out void * outAddress
)

Parameters

TypeNameDescription
UsageusageFlags
out void *outAddress

bool TryLockPlaneData

public bool TryLockPlaneData(
Usage usageFlags,
out Planes planes
)

Parameters

TypeNameDescription
UsageusageFlags
out Planesplanes

bool TryUnlockData

public bool TryUnlockData()

Public Attributes

IsNull


public bool IsNull => value == IntPtr.Zero;


Public Enums

Format

EnumeratorValueDescription
R8G8B8A8UNorm1Corresponding formats: Vulkan: VK_FORMAT_R8G8B8A8_UNORM OpenGL ES: GL_RGBA8
R8G8B8X8UNorm232 bits per pixel, 8 bits per channel format where alpha values are ignored (always opaque). Corresponding formats: Vulkan: VK_FORMAT_R8G8B8A8_UNORM OpenGL ES: GL_RGB8
R8G8B8UNorm3Corresponding formats: Vulkan: VK_FORMAT_R8G8B8_UNORM OpenGL ES: GL_RGB8
R5G6B5UNorm4Corresponding formats: Vulkan: VK_FORMAT_R5G6B5_UNORM_PACK16 OpenGL ES: GL_RGB565
R16G16B16A16Float0x16Corresponding formats: Vulkan: VK_FORMAT_R16G16B16A16_SFLOAT OpenGL ES: GL_RGBA16F
R10G10B10A2UNorm0x2bCorresponding formats: Vulkan: VK_FORMAT_A2B10G10R10_UNORM_PACK32 OpenGL ES: GL_RGB10_A2
Blob0x21Opaque binary blob format. Must have height 1 and one layer, with width equal to the buffer size in bytes. Corresponds to Vulkan buffers and OpenGL buffer objects. Can be bound to the latter using GL_EXT_external_buffer.
D16UNorm0x30Corresponding formats: Vulkan: VK_FORMAT_D16_UNORM OpenGL ES: GL_DEPTH_COMPONENT16
D24UNorm0x31Corresponding formats: Vulkan: VK_FORMAT_X8_D24_UNORM_PACK32 OpenGL ES: GL_DEPTH_COMPONENT24
D24UNormS8UInt0x32Corresponding formats: Vulkan: VK_FORMAT_D24_UNORM_S8_UINT OpenGL ES: GL_DEPTH24_STENCIL8
D32Float0x33Corresponding formats: Vulkan: VK_FORMAT_D32_SFLOAT OpenGL ES: GL_DEPTH_COMPONENT32F
D32FloatS8UInt0x34Corresponding formats: Vulkan: VK_FORMAT_D32_SFLOAT_S8_UINT OpenGL ES: GL_DEPTH32F_STENCIL8
S8UInt0x35Corresponding formats: Vulkan: VK_FORMAT_S8_UINT OpenGL ES: GL_STENCIL_INDEX8
Y8Cb8Cr8_4200x23YUV 420 888 format. Must have an even width and height. Can be accessed in OpenGL shaders through an external sampler. Does not support mip-maps cube-maps or multi-layered textures.
YCbCrP0100x36YUV P010 format. Must have an even width and height. Can be accessed in OpenGL shaders through an external sampler. Does not support mip-maps cube-maps or multi-layered textures.
R8UNorm0x38Corresponding formats: Vulkan: VK_FORMAT_R8_UNORM OpenGL ES: GR_GL_R8

Usage

EnumeratorValueDescription
CpuReadNever0ULThe buffer will never be locked for direct CPU reads using the AHardwareBuffer_lock() function. Note that reading the buffer using OpenGL or Vulkan functions or memory mappings is still allowed.
CpuReadRarely2ULThe buffer will sometimes be locked for direct CPU reads using the AHardwareBuffer_lock() function. Note that reading the buffer using OpenGL or Vulkan functions or memory mappings does not require the presence of this flag.
CpuReadOften3ULThe buffer will often be locked for direct CPU reads using the AHardwareBuffer_lock() function. Note that reading the buffer using OpenGL or Vulkan functions or memory mappings does not require the presence of this flag.
CpuReadMask0xFULCPU read value mask.
CpuWriteNever0UL << 4The buffer will never be locked for direct CPU writes using the AHardwareBuffer_lock() function. Note that writing the buffer using OpenGL or Vulkan functions or memory mappings is still allowed.
CpuWriteRarely2UL << 4The buffer will sometimes be locked for direct CPU writes using the AHardwareBuffer_lock() function. Note that writing the buffer using OpenGL or Vulkan functions or memory mappings does not require the presence of this flag.
CpuWriteOften3UL << 4The buffer will often be locked for direct CPU writes using the AHardwareBuffer_lock() function. Note that writing the buffer using OpenGL or Vulkan functions or memory mappings does not require the presence of this flag.
CpuWriteMask0xFUL << 4CPU write value mask.
GpuSampledImage1UL << 8The buffer will be read from by the GPU as a texture.
GpuFramebuffer1UL << 9The buffer will be written to by the GPU as a framebuffer attachment.
GpuColorOutputGpuFramebufferThe buffer will be written to by the GPU as a framebuffer attachment. Note that the name of this flag is somewhat misleading: it does not imply that the buffer contains a color format. A buffer with depth or stencil format that will be used as a framebuffer attachment should also have this flag. Use the equivalent flag AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER to avoid this confusion.
ComposerOverlay1UL << 11The buffer will be used as a composer HAL overlay layer. This flag is currently only needed when using ASurfaceTransaction_setBuffer to set a buffer. In all other cases, the framework adds this flag internally to buffers that could be presented in a composer overlay. ASurfaceTransaction_setBuffer is special because it uses buffers allocated directly through AHardwareBuffer_allocate instead of buffers allocated by the framework.
ProtectedContent1UL << 14The buffer is protected from direct CPU access or being read by non-secure hardware, such as video encoders. This flag is incompatible with CPU read and write flags. It is mainly used when handling DRM video. Refer to the EGL extension EGL_EXT_protected_content and GL extension GL_EXT_protected_textures for more information on how these buffers are expected to behave.
VideoEncode1UL << 16The buffer will be read by a hardware video encoder.
SensorDirectData1UL << 23The buffer will be used for direct writes from sensors. When this flag is present, the format must be AHARDWAREBUFFER_FORMAT_BLOB.
GpuDataBuffer1UL << 24The buffer will be used as a shader storage or uniform buffer object. When this flag is present, the format must be AHARDWAREBUFFER_FORMAT_BLOB.
GpuCubeMap1UL << 25The buffer will be used as a cube map texture. When this flag is present, the buffer must have a layer count that is a multiple of 6. Note that buffers with this flag must be bound to OpenGL textures using the extension GL_EXT_EGL_image_storage instead of GL_KHR_EGL_image.
GpuMipmapComplete1UL << 26The buffer contains a complete mipmap hierarchy. Note that buffers with this flag must be bound to OpenGL textures using the extension GL_EXT_EGL_image_storage instead of GL_KHR_EGL_image.
Vendor01UL << 28
Vendor11UL << 29
Vendor21UL << 30
Vendor31UL << 31
Vendor41UL << 48
Vendor51UL << 49
Vendor61UL << 50
Vendor71UL << 51
Vendor81UL << 52
Vendor91UL << 53
Vendor101UL << 54
Vendor111UL << 55
Vendor121UL << 56
Vendor131UL << 57
Vendor141UL << 58
Vendor151UL << 59
Vendor161UL << 60
Vendor171UL << 61
Vendor181UL << 62
Vendor191UL << 63