Loading api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -14070,6 +14070,7 @@ package android.graphics { method public android.graphics.Bitmap.Config getConfig(); method public int getDensity(); method public int getGenerationId(); method @NonNull public android.hardware.HardwareBuffer getHardwareBuffer(); method public int getHeight(); method public byte[] getNinePatchChunk(); method @ColorInt public int getPixel(int, int); graphics/java/android/graphics/Bitmap.java +23 −5 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import dalvik.annotation.optimization.CriticalNative; import libcore.util.NativeAllocationRegistry; import java.io.OutputStream; import java.lang.ref.WeakReference; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.IntBuffer; Loading Loading @@ -85,6 +86,7 @@ public final class Bitmap implements Parcelable { private int mWidth; @UnsupportedAppUsage private int mHeight; private WeakReference<HardwareBuffer> mHardwareBuffer; private boolean mRecycled; private ColorSpace mColorSpace; Loading Loading @@ -366,6 +368,7 @@ public final class Bitmap implements Parcelable { nativeRecycle(mNativePtr); mNinePatchChunk = null; mRecycled = true; mHardwareBuffer = null; } } Loading Loading @@ -748,7 +751,12 @@ public final class Bitmap implements Parcelable { if (colorSpace == null) { colorSpace = ColorSpace.get(ColorSpace.Named.SRGB); } return nativeWrapHardwareBufferBitmap(hardwareBuffer, colorSpace.getNativeInstance()); Bitmap bitmap = nativeWrapHardwareBufferBitmap(hardwareBuffer, colorSpace.getNativeInstance()); if (bitmap != null) { bitmap.mHardwareBuffer = new WeakReference<HardwareBuffer>(hardwareBuffer); } return bitmap; } /** Loading Loading @@ -2244,12 +2252,22 @@ public final class Bitmap implements Parcelable { * * Note: the HardwareBuffer does *not* have an associated {@link ColorSpace}. * To render this object the same as its rendered with this Bitmap, you * should also call {@link getColorSpace}. * should also call {@link #getColorSpace()}.</p> * * @hide * Must not be modified while a wrapped Bitmap is accessing it. Doing so will * result in undefined behavior.</p> * * @throws IllegalStateException if the bitmap's config is not {@link Config#HARDWARE} * or if the bitmap has been recycled. */ public HardwareBuffer getHardwareBuffer() { return nativeGetHardwareBuffer(mNativePtr); public @NonNull HardwareBuffer getHardwareBuffer() { checkRecycled("Can't getHardwareBuffer from a recycled bitmap"); HardwareBuffer hardwareBuffer = mHardwareBuffer == null ? null : mHardwareBuffer.get(); if (hardwareBuffer == null) { hardwareBuffer = nativeGetHardwareBuffer(mNativePtr); mHardwareBuffer = new WeakReference<HardwareBuffer>(hardwareBuffer); } return hardwareBuffer; } //////////// native methods Loading libs/hwui/jni/Bitmap.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -1196,13 +1196,16 @@ static jobject Bitmap_wrapHardwareBufferBitmap(JNIEnv* env, jobject, jobject har static jobject Bitmap_getHardwareBuffer(JNIEnv* env, jobject, jlong bitmapPtr) { #ifdef __ANDROID__ // Layoutlib does not support graphic buffer LocalScopedBitmap bitmapHandle(bitmapPtr); LOG_ALWAYS_FATAL_IF(!bitmapHandle->isHardware(), if (!bitmapHandle->isHardware()) { jniThrowException(env, "java/lang/IllegalStateException", "Hardware config is only supported config in Bitmap_getHardwareBuffer"); return nullptr; } Bitmap& bitmap = bitmapHandle->bitmap(); return AHardwareBuffer_toHardwareBuffer(env, bitmap.hardwareBuffer()); #else return NULL; return nullptr; #endif } Loading Loading
api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -14070,6 +14070,7 @@ package android.graphics { method public android.graphics.Bitmap.Config getConfig(); method public int getDensity(); method public int getGenerationId(); method @NonNull public android.hardware.HardwareBuffer getHardwareBuffer(); method public int getHeight(); method public byte[] getNinePatchChunk(); method @ColorInt public int getPixel(int, int);
graphics/java/android/graphics/Bitmap.java +23 −5 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import dalvik.annotation.optimization.CriticalNative; import libcore.util.NativeAllocationRegistry; import java.io.OutputStream; import java.lang.ref.WeakReference; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.IntBuffer; Loading Loading @@ -85,6 +86,7 @@ public final class Bitmap implements Parcelable { private int mWidth; @UnsupportedAppUsage private int mHeight; private WeakReference<HardwareBuffer> mHardwareBuffer; private boolean mRecycled; private ColorSpace mColorSpace; Loading Loading @@ -366,6 +368,7 @@ public final class Bitmap implements Parcelable { nativeRecycle(mNativePtr); mNinePatchChunk = null; mRecycled = true; mHardwareBuffer = null; } } Loading Loading @@ -748,7 +751,12 @@ public final class Bitmap implements Parcelable { if (colorSpace == null) { colorSpace = ColorSpace.get(ColorSpace.Named.SRGB); } return nativeWrapHardwareBufferBitmap(hardwareBuffer, colorSpace.getNativeInstance()); Bitmap bitmap = nativeWrapHardwareBufferBitmap(hardwareBuffer, colorSpace.getNativeInstance()); if (bitmap != null) { bitmap.mHardwareBuffer = new WeakReference<HardwareBuffer>(hardwareBuffer); } return bitmap; } /** Loading Loading @@ -2244,12 +2252,22 @@ public final class Bitmap implements Parcelable { * * Note: the HardwareBuffer does *not* have an associated {@link ColorSpace}. * To render this object the same as its rendered with this Bitmap, you * should also call {@link getColorSpace}. * should also call {@link #getColorSpace()}.</p> * * @hide * Must not be modified while a wrapped Bitmap is accessing it. Doing so will * result in undefined behavior.</p> * * @throws IllegalStateException if the bitmap's config is not {@link Config#HARDWARE} * or if the bitmap has been recycled. */ public HardwareBuffer getHardwareBuffer() { return nativeGetHardwareBuffer(mNativePtr); public @NonNull HardwareBuffer getHardwareBuffer() { checkRecycled("Can't getHardwareBuffer from a recycled bitmap"); HardwareBuffer hardwareBuffer = mHardwareBuffer == null ? null : mHardwareBuffer.get(); if (hardwareBuffer == null) { hardwareBuffer = nativeGetHardwareBuffer(mNativePtr); mHardwareBuffer = new WeakReference<HardwareBuffer>(hardwareBuffer); } return hardwareBuffer; } //////////// native methods Loading
libs/hwui/jni/Bitmap.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -1196,13 +1196,16 @@ static jobject Bitmap_wrapHardwareBufferBitmap(JNIEnv* env, jobject, jobject har static jobject Bitmap_getHardwareBuffer(JNIEnv* env, jobject, jlong bitmapPtr) { #ifdef __ANDROID__ // Layoutlib does not support graphic buffer LocalScopedBitmap bitmapHandle(bitmapPtr); LOG_ALWAYS_FATAL_IF(!bitmapHandle->isHardware(), if (!bitmapHandle->isHardware()) { jniThrowException(env, "java/lang/IllegalStateException", "Hardware config is only supported config in Bitmap_getHardwareBuffer"); return nullptr; } Bitmap& bitmap = bitmapHandle->bitmap(); return AHardwareBuffer_toHardwareBuffer(env, bitmap.hardwareBuffer()); #else return NULL; return nullptr; #endif } Loading