Merge "Add support for BLOB format to HardwareBuffer."
This commit is contained in:
committed by
Android (Google) Code Review
commit
d20a0fd3df
@@ -14203,9 +14203,10 @@ package android.hardware {
|
||||
method public int getWidth();
|
||||
method public boolean isDestroyed();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final int BLOB = 33; // 0x21
|
||||
field public static final android.os.Parcelable.Creator<android.hardware.HardwareBuffer> CREATOR;
|
||||
field public static final int RGBA_8888 = 1; // 0x1
|
||||
field public static final int RGBA_FP16 = 5; // 0x5
|
||||
field public static final int RGBA_FP16 = 22; // 0x16
|
||||
field public static final int RGBX_8888 = 2; // 0x2
|
||||
field public static final int RGB_565 = 4; // 0x4
|
||||
field public static final int RGB_888 = 3; // 0x3
|
||||
|
||||
@@ -14761,9 +14761,10 @@ package android.hardware {
|
||||
method public int getWidth();
|
||||
method public boolean isDestroyed();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final int BLOB = 33; // 0x21
|
||||
field public static final android.os.Parcelable.Creator<android.hardware.HardwareBuffer> CREATOR;
|
||||
field public static final int RGBA_8888 = 1; // 0x1
|
||||
field public static final int RGBA_FP16 = 5; // 0x5
|
||||
field public static final int RGBA_FP16 = 22; // 0x16
|
||||
field public static final int RGBX_8888 = 2; // 0x2
|
||||
field public static final int RGB_565 = 4; // 0x4
|
||||
field public static final int RGB_888 = 3; // 0x3
|
||||
|
||||
@@ -14235,9 +14235,10 @@ package android.hardware {
|
||||
method public int getWidth();
|
||||
method public boolean isDestroyed();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final int BLOB = 33; // 0x21
|
||||
field public static final android.os.Parcelable.Creator<android.hardware.HardwareBuffer> CREATOR;
|
||||
field public static final int RGBA_8888 = 1; // 0x1
|
||||
field public static final int RGBA_FP16 = 5; // 0x5
|
||||
field public static final int RGBA_FP16 = 22; // 0x16
|
||||
field public static final int RGBX_8888 = 2; // 0x2
|
||||
field public static final int RGB_565 = 4; // 0x4
|
||||
field public static final int RGB_888 = 3; // 0x3
|
||||
|
||||
@@ -40,7 +40,7 @@ import libcore.util.NativeAllocationRegistry;
|
||||
public final class HardwareBuffer implements Parcelable {
|
||||
/** @hide */
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({RGBA_8888, RGBA_FP16, RGBX_8888, RGB_888, RGB_565})
|
||||
@IntDef({RGBA_8888, RGBA_FP16, RGBX_8888, RGB_888, RGB_565, BLOB})
|
||||
public @interface Format {};
|
||||
|
||||
/** Format: 8 bits each red, green, blue, alpha */
|
||||
@@ -52,7 +52,9 @@ public final class HardwareBuffer implements Parcelable {
|
||||
/** Format: 5 bits each red and blue, 6 bits green, no alpha */
|
||||
public static final int RGB_565 = 4;
|
||||
/** Format: 16 bits each red, green, blue, alpha */
|
||||
public static final int RGBA_FP16 = 5;
|
||||
public static final int RGBA_FP16 = 0x16;
|
||||
/** Format: opaque format used for raw data transfer; must have a height of 1 */
|
||||
public static final int BLOB = 0x21;
|
||||
|
||||
// Note: do not rename, this field is used by native code
|
||||
private long mNativeObject;
|
||||
@@ -135,6 +137,9 @@ public final class HardwareBuffer implements Parcelable {
|
||||
if (layers <= 0) {
|
||||
throw new IllegalArgumentException("Invalid layer count " + layers);
|
||||
}
|
||||
if (format == BLOB && height != 1) {
|
||||
throw new IllegalArgumentException("Height must be 1 when using the BLOB format");
|
||||
}
|
||||
long nativeObject = nCreateHardwareBuffer(width, height, format, layers, usage);
|
||||
if (nativeObject == 0) {
|
||||
throw new IllegalArgumentException("Unable to create a HardwareBuffer, either the " +
|
||||
@@ -295,6 +300,7 @@ public final class HardwareBuffer implements Parcelable {
|
||||
case RGBX_8888:
|
||||
case RGB_565:
|
||||
case RGB_888:
|
||||
case BLOB:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -223,16 +223,18 @@ jobject android_hardware_HardwareBuffer_createFromAHardwareBuffer(
|
||||
|
||||
uint32_t android_hardware_HardwareBuffer_convertFromPixelFormat(uint32_t format) {
|
||||
switch (format) {
|
||||
case PIXEL_FORMAT_RGBA_8888:
|
||||
case HAL_PIXEL_FORMAT_RGBA_8888:
|
||||
return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
|
||||
case PIXEL_FORMAT_RGBX_8888:
|
||||
case HAL_PIXEL_FORMAT_RGBX_8888:
|
||||
return AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
|
||||
case PIXEL_FORMAT_RGB_565:
|
||||
case HAL_PIXEL_FORMAT_RGB_565:
|
||||
return AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
|
||||
case PIXEL_FORMAT_RGB_888:
|
||||
case HAL_PIXEL_FORMAT_RGB_888:
|
||||
return AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM;
|
||||
case PIXEL_FORMAT_RGBA_FP16:
|
||||
case HAL_PIXEL_FORMAT_RGBA_FP16:
|
||||
return AHARDWAREBUFFER_FORMAT_R16G16B16A16_SFLOAT;
|
||||
case HAL_PIXEL_FORMAT_BLOB:
|
||||
return AHARDWAREBUFFER_FORMAT_BLOB;
|
||||
default:
|
||||
ALOGE("Unknown pixel format %u", format);
|
||||
return 0;
|
||||
@@ -242,15 +244,17 @@ uint32_t android_hardware_HardwareBuffer_convertFromPixelFormat(uint32_t format)
|
||||
uint32_t android_hardware_HardwareBuffer_convertToPixelFormat(uint32_t format) {
|
||||
switch (format) {
|
||||
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
|
||||
return PIXEL_FORMAT_RGBA_8888;
|
||||
return HAL_PIXEL_FORMAT_RGBA_8888;
|
||||
case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
|
||||
return PIXEL_FORMAT_RGBX_8888;
|
||||
return HAL_PIXEL_FORMAT_RGBX_8888;
|
||||
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
|
||||
return PIXEL_FORMAT_RGB_565;
|
||||
return HAL_PIXEL_FORMAT_RGB_565;
|
||||
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
|
||||
return PIXEL_FORMAT_RGB_888;
|
||||
return HAL_PIXEL_FORMAT_RGB_888;
|
||||
case AHARDWAREBUFFER_FORMAT_R16G16B16A16_SFLOAT:
|
||||
return PIXEL_FORMAT_RGBA_FP16;
|
||||
return HAL_PIXEL_FORMAT_RGBA_FP16;
|
||||
case AHARDWAREBUFFER_FORMAT_BLOB:
|
||||
return HAL_PIXEL_FORMAT_BLOB;
|
||||
default:
|
||||
ALOGE("Unknown AHardwareBuffer format %u", format);
|
||||
return 0;
|
||||
|
||||
@@ -89,6 +89,12 @@ int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc,
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
if (desc->format == AHARDWAREBUFFER_FORMAT_BLOB && desc->height != 1) {
|
||||
ALOGE("Height must be 1 when using the AHARDWAREBUFFER_FORMAT_BLOB "
|
||||
"format");
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
status_t err;
|
||||
uint32_t usage = android_hardware_HardwareBuffer_convertToGrallocUsageBits(
|
||||
desc->usage0, desc->usage1);
|
||||
|
||||
Reference in New Issue
Block a user