Skip to content

Most visited

Recently visited

navigation

HardwareBuffer

public final class HardwareBuffer
extends Object implements Parcelable

java.lang.Object
   ↳ android.hardware.HardwareBuffer


HardwareBuffer wraps a native AHardwareBuffer object, which is a low-level object representing a memory buffer accessible by various hardware units. HardwareBuffer allows sharing buffers across different application processes. In particular, HardwareBuffers may be mappable to memory accessibly to various hardware systems, such as the GPU, a sensor or context hub, or other auxiliary processing units. For more information, see the NDK documentation for AHardwareBuffer.

Summary

Constants

int BLOB

Format: opaque format used for raw data transfer; must have a height of 1

int RGBA_1010102

Format: 10 bits each red, green, blue, 2 bits alpha

int RGBA_8888

Format: 8 bits each red, green, blue, alpha

int RGBA_FP16

Format: 16 bits each red, green, blue, alpha

int RGBX_8888

Format: 8 bits each red, green, blue, alpha, alpha is always 0xFF

int RGB_565

Format: 5 bits each red and blue, 6 bits green, no alpha

int RGB_888

Format: 8 bits each red, green, blue, no alpha

long USAGE0_CPU_READ

Usage0: the buffer will sometimes be read by the CPU

long USAGE0_CPU_READ_OFTEN

Usage0: the buffer will often be read by the CPU

long USAGE0_CPU_WRITE

Usage0: the buffer will sometimes be written to by the CPU

long USAGE0_CPU_WRITE_OFTEN

Usage0: the buffer will often be written to by the CPU

long USAGE0_GPU_COLOR_OUTPUT

Usage0: the buffer will be written to by the GPU

long USAGE0_GPU_CUBEMAP

Usage0: the buffer will be used as a cubemap texture

long USAGE0_GPU_DATA_BUFFER

Usage0: the buffer will be used as a shader storage or uniform buffer object

long USAGE0_GPU_SAMPLED_IMAGE

Usage0: the buffer will be read from by the GPU

long USAGE0_GPU_STORAGE_IMAGE

Usage0: the buffer will be read from and written to by the GPU

long USAGE0_PROTECTED_CONTENT

Usage0: the buffer must not be used outside of a protected hardware path

long USAGE0_SENSOR_DIRECT_DATA

Usage0: the buffer will be used for sensor direct data

long USAGE0_VIDEO_ENCODE

Usage0: the buffer will be read by a hardware video encoder

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<HardwareBuffer> CREATOR

Public methods

static HardwareBuffer create(int width, int height, int format, int layers, long usage)

Creates a new HardwareBuffer instance.

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

void destroy()

Destroys this buffer immediately.

int getFormat()

Returns the format of this buffer, one of RGBA_8888, RGBA_FP16, RGBX_8888, RGB_565, RGB_888, RGBA_1010102, BLOB.

int getHeight()

Returns the height of this buffer in pixels.

int getLayers()

Returns the number of layers in this buffer.

long getUsage()

Returns the usage flags of the usage hints set on this buffer.

int getWidth()

Returns the width of this buffer in pixels.

boolean isDestroyed()

Indicates whether this buffer has been destroyed.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Constants

BLOB

int BLOB

Format: opaque format used for raw data transfer; must have a height of 1

Constant Value: 33 (0x00000021)

RGBA_1010102

int RGBA_1010102

Format: 10 bits each red, green, blue, 2 bits alpha

Constant Value: 43 (0x0000002b)

RGBA_8888

int RGBA_8888

Format: 8 bits each red, green, blue, alpha

Constant Value: 1 (0x00000001)

RGBA_FP16

int RGBA_FP16

Format: 16 bits each red, green, blue, alpha

Constant Value: 22 (0x00000016)

RGBX_8888

int RGBX_8888

Format: 8 bits each red, green, blue, alpha, alpha is always 0xFF

Constant Value: 2 (0x00000002)

RGB_565

int RGB_565

Format: 5 bits each red and blue, 6 bits green, no alpha

Constant Value: 4 (0x00000004)

RGB_888

int RGB_888

Format: 8 bits each red, green, blue, no alpha

Constant Value: 3 (0x00000003)

USAGE0_CPU_READ

long USAGE0_CPU_READ

Usage0: the buffer will sometimes be read by the CPU

Constant Value: 2 (0x0000000000000002)

USAGE0_CPU_READ_OFTEN

long USAGE0_CPU_READ_OFTEN

Usage0: the buffer will often be read by the CPU

Constant Value: 6 (0x0000000000000006)

USAGE0_CPU_WRITE

long USAGE0_CPU_WRITE

Usage0: the buffer will sometimes be written to by the CPU

Constant Value: 32 (0x0000000000000020)

USAGE0_CPU_WRITE_OFTEN

long USAGE0_CPU_WRITE_OFTEN

Usage0: the buffer will often be written to by the CPU

Constant Value: 96 (0x0000000000000060)

USAGE0_GPU_COLOR_OUTPUT

long USAGE0_GPU_COLOR_OUTPUT

Usage0: the buffer will be written to by the GPU

Constant Value: 2048 (0x0000000000000800)

USAGE0_GPU_CUBEMAP

long USAGE0_GPU_CUBEMAP

Usage0: the buffer will be used as a cubemap texture

Constant Value: 8192 (0x0000000000002000)

USAGE0_GPU_DATA_BUFFER

long USAGE0_GPU_DATA_BUFFER

Usage0: the buffer will be used as a shader storage or uniform buffer object

Constant Value: 16384 (0x0000000000004000)

USAGE0_GPU_SAMPLED_IMAGE

long USAGE0_GPU_SAMPLED_IMAGE

Usage0: the buffer will be read from by the GPU

Constant Value: 1024 (0x0000000000000400)

USAGE0_GPU_STORAGE_IMAGE

long USAGE0_GPU_STORAGE_IMAGE

Usage0: the buffer will be read from and written to by the GPU

Constant Value: 3072 (0x0000000000000c00)

USAGE0_PROTECTED_CONTENT

long USAGE0_PROTECTED_CONTENT

Usage0: the buffer must not be used outside of a protected hardware path

Constant Value: 262144 (0x0000000000040000)

USAGE0_SENSOR_DIRECT_DATA

long USAGE0_SENSOR_DIRECT_DATA

Usage0: the buffer will be used for sensor direct data

Constant Value: 536870912 (0x0000000020000000)

USAGE0_VIDEO_ENCODE

long USAGE0_VIDEO_ENCODE

Usage0: the buffer will be read by a hardware video encoder

Constant Value: 2097152 (0x0000000000200000)

Fields

Public methods

create

HardwareBuffer create (int width, 
                int height, 
                int format, 
                int layers, 
                long usage)

Creates a new HardwareBuffer instance.

Calling this method will throw an IllegalStateException if format is not a supported Format type.

Parameters
width int: The width in pixels of the buffer
height int: The height in pixels of the buffer
format int: The format of each pixel, one of RGBA_8888, RGBA_FP16, RGBX_8888, RGB_565, RGB_888, RGBA_1010102, BLOB
layers int: The number of layers in the buffer
usage long: Flags describing how the buffer will be used, one of USAGE0_CPU_READ, USAGE0_CPU_READ_OFTEN, USAGE0_CPU_WRITE, USAGE0_CPU_WRITE_OFTEN, USAGE0_GPU_SAMPLED_IMAGE, USAGE0_GPU_COLOR_OUTPUT,USAGE0_GPU_STORAGE_IMAGE, USAGE0_GPU_CUBEMAP, USAGE0_GPU_DATA_BUFFER, USAGE0_PROTECTED_CONTENT, USAGE0_SENSOR_DIRECT_DATA, USAGE0_VIDEO_ENCODE
Returns
HardwareBuffer A HardwareBuffer instance if successful, or throws an IllegalArgumentException if the dimensions passed are invalid (either zero, negative, or too large to allocate), if the format is not supported, if the requested number of layers is less than one or not supported, or if the passed usage flags are not a supported set.

describeContents

int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

destroy

void destroy ()

Destroys this buffer immediately. Calling this method frees up any underlying native resources. After calling this method, this buffer must not be used in any way.

See also:

getFormat

int getFormat ()

Returns the format of this buffer, one of RGBA_8888, RGBA_FP16, RGBX_8888, RGB_565, RGB_888, RGBA_1010102, BLOB.

Returns
int

getHeight

int getHeight ()

Returns the height of this buffer in pixels.

Returns
int

getLayers

int getLayers ()

Returns the number of layers in this buffer.

Returns
int

getUsage

long getUsage ()

Returns the usage flags of the usage hints set on this buffer.

Returns
long

getWidth

int getWidth ()

Returns the width of this buffer in pixels.

Returns
int

isDestroyed

boolean isDestroyed ()

Indicates whether this buffer has been destroyed. A destroyed buffer cannot be used in any way: the buffer cannot be written to a parcel, etc.

Returns
boolean True if this HardwareBuffer is in a destroyed state, false otherwise.

See also:

writeToParcel

void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Calling this method will throw an IllegalStateException if destroy() has been previously called.

Parameters
dest Parcel: The Parcel in which the object should be written.
flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.