summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/api/current.txt1
-rw-r--r--core/java/android/hardware/HardwareBuffer.java77
-rw-r--r--core/jni/android_hardware_HardwareBuffer.cpp20
-rw-r--r--core/jni/include/android_runtime/android_hardware_HardwareBuffer.h4
4 files changed, 31 insertions, 71 deletions
diff --git a/core/api/current.txt b/core/api/current.txt
index 1578839f183f..77b350088f40 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -16888,6 +16888,7 @@ package android.hardware {
method public int describeContents();
method public int getFormat();
method public int getHeight();
+ method public long getId();
method public int getLayers();
method public long getUsage();
method public int getWidth();
diff --git a/core/java/android/hardware/HardwareBuffer.java b/core/java/android/hardware/HardwareBuffer.java
index 1e4c95013205..11892fea20f2 100644
--- a/core/java/android/hardware/HardwareBuffer.java
+++ b/core/java/android/hardware/HardwareBuffer.java
@@ -188,9 +188,6 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
public static HardwareBuffer create(
@IntRange(from = 1) int width, @IntRange(from = 1) int height,
@Format int format, @IntRange(from = 1) int layers, @Usage long usage) {
- if (!HardwareBuffer.isSupportedFormat(format)) {
- throw new IllegalArgumentException("Invalid pixel format " + format);
- }
if (width <= 0) {
throw new IllegalArgumentException("Invalid width " + width);
}
@@ -226,9 +223,6 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
*/
public static boolean isSupported(@IntRange(from = 1) int width, @IntRange(from = 1) int height,
@Format int format, @IntRange(from = 1) int layers, @Usage long usage) {
- if (!HardwareBuffer.isSupportedFormat(format)) {
- throw new IllegalArgumentException("Invalid pixel format " + format);
- }
if (width <= 0) {
throw new IllegalArgumentException("Invalid width " + width);
}
@@ -286,10 +280,7 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
* Returns the width of this buffer in pixels.
*/
public int getWidth() {
- if (isClosed()) {
- throw new IllegalStateException("This HardwareBuffer has been closed and its width "
- + "cannot be obtained.");
- }
+ checkClosed("width");
return nGetWidth(mNativeObject);
}
@@ -297,10 +288,7 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
* Returns the height of this buffer in pixels.
*/
public int getHeight() {
- if (isClosed()) {
- throw new IllegalStateException("This HardwareBuffer has been closed and its height "
- + "cannot be obtained.");
- }
+ checkClosed("height");
return nGetHeight(mNativeObject);
}
@@ -309,10 +297,7 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
*/
@Format
public int getFormat() {
- if (isClosed()) {
- throw new IllegalStateException("This HardwareBuffer has been closed and its format "
- + "cannot be obtained.");
- }
+ checkClosed("format");
return nGetFormat(mNativeObject);
}
@@ -320,10 +305,7 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
* Returns the number of layers in this buffer.
*/
public int getLayers() {
- if (isClosed()) {
- throw new IllegalStateException("This HardwareBuffer has been closed and its layer "
- + "count cannot be obtained.");
- }
+ checkClosed("layer count");
return nGetLayers(mNativeObject);
}
@@ -331,11 +313,24 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
* Returns the usage flags of the usage hints set on this buffer.
*/
public long getUsage() {
+ checkClosed("usage");
+ return nGetUsage(mNativeObject);
+ }
+
+ /**
+ * Returns the system-wide unique id for this buffer
+ *
+ */
+ public long getId() {
+ checkClosed("id");
+ return nGetId(mNativeObject);
+ }
+
+ private void checkClosed(String name) {
if (isClosed()) {
- throw new IllegalStateException("This HardwareBuffer has been closed and its usage "
- + "cannot be obtained.");
+ throw new IllegalStateException("This HardwareBuffer has been closed and its "
+ + name + " cannot be obtained.");
}
- return nGetUsage(mNativeObject);
}
/**
@@ -407,36 +402,6 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
}
};
- /**
- * Validates whether a particular format is supported by HardwareBuffer.
- *
- * @param format The format to validate.
- *
- * @return True if <code>format</code> is a supported format. false otherwise.
- * See {@link #create(int, int, int, int, long)}.
- */
- private static boolean isSupportedFormat(@Format int format) {
- switch(format) {
- case RGBA_8888:
- case RGBA_FP16:
- case RGBA_1010102:
- case RGBX_8888:
- case RGB_565:
- case RGB_888:
- case BLOB:
- case YCBCR_420_888:
- case D_16:
- case D_24:
- case DS_24UI8:
- case D_FP32:
- case DS_FP32UI8:
- case S_UI8:
- case YCBCR_P010:
- return true;
- }
- return false;
- }
-
private static native long nCreateHardwareBuffer(int width, int height, int format, int layers,
long usage);
private static native long nCreateFromGraphicBuffer(GraphicBuffer graphicBuffer);
@@ -457,4 +422,6 @@ public final class HardwareBuffer implements Parcelable, AutoCloseable {
long usage);
@CriticalNative
private static native long nEstimateSize(long nativeObject);
+ @CriticalNative
+ private static native long nGetId(long nativeObject);
}
diff --git a/core/jni/android_hardware_HardwareBuffer.cpp b/core/jni/android_hardware_HardwareBuffer.cpp
index f462523c6ce4..5fcc46ee1499 100644
--- a/core/jni/android_hardware_HardwareBuffer.cpp
+++ b/core/jni/android_hardware_HardwareBuffer.cpp
@@ -163,7 +163,7 @@ static jint android_hardware_HardwareBuffer_getLayers(JNIEnv* env,
static jlong android_hardware_HardwareBuffer_getUsage(JNIEnv* env,
jobject clazz, jlong nativeObject) {
GraphicBuffer* buffer = GraphicBufferWrapper_to_GraphicBuffer(nativeObject);
- return AHardwareBuffer_convertFromGrallocUsageBits(buffer->getUsage());
+ return static_cast<jlong>(AHardwareBuffer_convertFromGrallocUsageBits(buffer->getUsage()));
}
static jlong android_hardware_HardwareBuffer_estimateSize(jlong nativeObject) {
@@ -177,7 +177,12 @@ static jlong android_hardware_HardwareBuffer_estimateSize(jlong nativeObject) {
const uint32_t bufferStride =
buffer->getStride() > 0 ? buffer->getStride() : buffer->getWidth();
- return static_cast<jlong>(buffer->getHeight() * bufferStride * bpp);
+ return static_cast<jlong>(static_cast<uint64_t>(buffer->getHeight() * bufferStride * bpp));
+}
+
+static jlong android_hardware_HardwareBuffer_getId(jlong nativeObject) {
+ GraphicBuffer* buffer = GraphicBufferWrapper_to_GraphicBuffer(nativeObject);
+ return static_cast<jlong>(buffer->getId());
}
// ----------------------------------------------------------------------------
@@ -223,16 +228,6 @@ AHardwareBuffer* android_hardware_HardwareBuffer_getNativeHardwareBuffer(
}
}
-GraphicBuffer* android_hardware_HardwareBuffer_getNativeGraphicBuffer(
- JNIEnv* env, jobject hardwareBufferObj) {
- if (env->IsInstanceOf(hardwareBufferObj, gHardwareBufferClassInfo.clazz)) {
- return GraphicBufferWrapper_to_GraphicBuffer(
- env->GetLongField(hardwareBufferObj, gHardwareBufferClassInfo.mNativeObject));
- } else {
- return nullptr;
- }
-}
-
jobject android_hardware_HardwareBuffer_createFromAHardwareBuffer(
JNIEnv* env, AHardwareBuffer* hardwareBuffer) {
GraphicBuffer* buffer = AHardwareBuffer_to_GraphicBuffer(hardwareBuffer);
@@ -295,6 +290,7 @@ static const JNINativeMethod gMethods[] = {
// --------------- @CriticalNative ----------------------
{ "nEstimateSize", "(J)J", (void*) android_hardware_HardwareBuffer_estimateSize },
+ { "nGetId", "(J)J", (void*) android_hardware_HardwareBuffer_getId },
};
// clang-format on
diff --git a/core/jni/include/android_runtime/android_hardware_HardwareBuffer.h b/core/jni/include/android_runtime/android_hardware_HardwareBuffer.h
index dfd80359e169..964c28f0a49f 100644
--- a/core/jni/include/android_runtime/android_hardware_HardwareBuffer.h
+++ b/core/jni/include/android_runtime/android_hardware_HardwareBuffer.h
@@ -28,10 +28,6 @@ namespace android {
extern AHardwareBuffer* android_hardware_HardwareBuffer_getNativeHardwareBuffer(
JNIEnv* env, jobject hardwareBufferObj);
-/* Gets the underlying GraphicBuffer for a HardwareBuffer. */
-extern GraphicBuffer* android_hardware_HardwareBuffer_getNativeGraphicBuffer(
- JNIEnv* env, jobject hardwareBufferObj);
-
/* Returns a HardwareBuffer wrapper for the underlying AHardwareBuffer. */
extern jobject android_hardware_HardwareBuffer_createFromAHardwareBuffer(
JNIEnv* env, AHardwareBuffer* hardwareBuffer);