diff options
| -rw-r--r-- | core/jni/Android.mk | 2 | ||||
| -rw-r--r-- | core/jni/AndroidRuntime.cpp | 4 | ||||
| -rwxr-xr-x | core/jni/android/graphics/Bitmap.cpp | 29 | ||||
| -rw-r--r-- | core/jni/android/graphics/GraphicBuffer.cpp (renamed from core/jni/android_view_GraphicBuffer.cpp) | 73 | ||||
| -rw-r--r-- | core/jni/android/graphics/GraphicBuffer.h (renamed from core/jni/android_view_GraphicBuffer.h) | 2 | ||||
| -rw-r--r-- | core/jni/android_view_ThreadedRenderer.cpp | 1 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 22 | ||||
| -rw-r--r-- | graphics/java/android/graphics/GraphicBuffer.aidl (renamed from core/java/android/view/GraphicBuffer.aidl) | 2 | ||||
| -rw-r--r-- | graphics/java/android/graphics/GraphicBuffer.java (renamed from core/java/android/view/GraphicBuffer.java) | 17 |
9 files changed, 92 insertions, 60 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk index 252f168040df..29483c78b9d1 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -60,7 +60,6 @@ LOCAL_SRC_FILES:= \ android_graphics_drawable_VectorDrawable.cpp \ android_view_DisplayEventReceiver.cpp \ android_view_DisplayListCanvas.cpp \ - android_view_GraphicBuffer.cpp \ android_view_HardwareLayer.cpp \ android_view_InputChannel.cpp \ android_view_InputDevice.cpp \ @@ -120,6 +119,7 @@ LOCAL_SRC_FILES:= \ android/graphics/FontFamily.cpp \ android/graphics/CreateJavaOutputStreamAdaptor.cpp \ android/graphics/GIFMovie.cpp \ + android/graphics/GraphicBuffer.cpp \ android/graphics/Graphics.cpp \ android/graphics/HarfBuzzNGFaceSkia.cpp \ android/graphics/Interpolator.cpp \ diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 6c9a764c9be9..c195cfe23bfb 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -57,6 +57,7 @@ extern int register_android_graphics_BitmapFactory(JNIEnv*); extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*); extern int register_android_graphics_Camera(JNIEnv* env); extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env); +extern int register_android_graphics_GraphicBuffer(JNIEnv* env); extern int register_android_graphics_Graphics(JNIEnv* env); extern int register_android_graphics_Interpolator(JNIEnv* env); extern int register_android_graphics_MaskFilter(JNIEnv* env); @@ -134,7 +135,6 @@ extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env); extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env); extern int register_android_view_DisplayEventReceiver(JNIEnv* env); extern int register_android_view_DisplayListCanvas(JNIEnv* env); -extern int register_android_view_GraphicBuffer(JNIEnv* env); extern int register_android_view_HardwareLayer(JNIEnv* env); extern int register_android_view_RenderNode(JNIEnv* env); extern int register_android_view_RenderNodeAnimator(JNIEnv* env); @@ -1296,7 +1296,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_view_DisplayEventReceiver), REG_JNI(register_android_view_RenderNode), REG_JNI(register_android_view_RenderNodeAnimator), - REG_JNI(register_android_view_GraphicBuffer), REG_JNI(register_android_view_DisplayListCanvas), REG_JNI(register_android_view_HardwareLayer), REG_JNI(register_android_view_ThreadedRenderer), @@ -1328,6 +1327,7 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_graphics_ColorFilter), REG_JNI(register_android_graphics_DrawFilter), REG_JNI(register_android_graphics_FontFamily), + REG_JNI(register_android_graphics_GraphicBuffer), REG_JNI(register_android_graphics_Interpolator), REG_JNI(register_android_graphics_MaskFilter), REG_JNI(register_android_graphics_Matrix), diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index 59cbc939890a..2bde9911da8e 100755 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -1,6 +1,7 @@ #define LOG_TAG "Bitmap" #include "Bitmap.h" +#include "GraphicBuffer.h" #include "SkBitmap.h" #include "SkPixelRef.h" #include "SkImageEncoder.h" @@ -1291,7 +1292,7 @@ static jint Bitmap_getAllocationByteCount(JNIEnv* env, jobject, jlong bitmapPtr) return static_cast<jint>(bitmapHandle->getAllocationByteCount()); } -static jobject Bitmap_nativeCopyPreserveInternalConfig(JNIEnv* env, jobject, jlong bitmapPtr) { +static jobject Bitmap_copyPreserveInternalConfig(JNIEnv* env, jobject, jlong bitmapPtr) { LocalScopedBitmap bitmapHandle(bitmapPtr); LOG_ALWAYS_FATAL_IF(!bitmapHandle->isHardware(), "Hardware config is only supported config in Bitmap_nativeCopyPreserveInternalConfig"); @@ -1308,6 +1309,26 @@ static jobject Bitmap_nativeCopyPreserveInternalConfig(JNIEnv* env, jobject, jlo return createBitmap(env, allocator.getStorageObjAndReset(), kBitmapCreateFlag_None); } +static jobject Bitmap_createHardwareBitmap(JNIEnv* env, jobject, jobject graphicBuffer) { + sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer)); + sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer); + if (!bitmap.get()) { + ALOGW("failed to create hardware bitmap from graphic buffer"); + return NULL; + } + return bitmap::createBitmap(env, bitmap.release(), android::bitmap::kBitmapCreateFlag_None); +} + +static jobject Bitmap_createGraphicBufferHandle(JNIEnv* env, jobject, jlong bitmapPtr) { + LocalScopedBitmap bitmapHandle(bitmapPtr); + LOG_ALWAYS_FATAL_IF(!bitmapHandle->isHardware(), + "Hardware config is only supported config in Bitmap_getGraphicBuffer"); + + Bitmap& hwuiBitmap = bitmapHandle->bitmap(); + sp<GraphicBuffer> buffer(hwuiBitmap.graphicBuffer()); + return createJavaGraphicBuffer(env, buffer); +} + /////////////////////////////////////////////////////////////////////////////// static jclass make_globalref(JNIEnv* env, const char classname[]) { @@ -1367,7 +1388,11 @@ static const JNINativeMethod gBitmapMethods[] = { { "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw }, { "nativeGetAllocationByteCount", "(J)I", (void*)Bitmap_getAllocationByteCount }, { "nativeCopyPreserveInternalConfig", "(J)Landroid/graphics/Bitmap;", - (void*)Bitmap_nativeCopyPreserveInternalConfig }, + (void*)Bitmap_copyPreserveInternalConfig }, + { "nativeCreateHardwareBitmap", "(Landroid/graphics/GraphicBuffer;)Landroid/graphics/Bitmap;", + (void*) Bitmap_createHardwareBitmap }, + { "nativeCreateGraphicBufferHandle", "(J)Landroid/graphics/GraphicBuffer;", + (void*) Bitmap_createGraphicBufferHandle } }; int register_android_graphics_Bitmap(JNIEnv* env) diff --git a/core/jni/android_view_GraphicBuffer.cpp b/core/jni/android/graphics/GraphicBuffer.cpp index f18837f2f72a..c61b53e5fa65 100644 --- a/core/jni/android_view_GraphicBuffer.cpp +++ b/core/jni/android/graphics/GraphicBuffer.cpp @@ -20,9 +20,8 @@ #include "JNIHelp.h" #include "android_os_Parcel.h" -#include "android_view_GraphicBuffer.h" -#include "android/graphics/GraphicsJNI.h" -#include "Bitmap.h" +#include "GraphicBuffer.h" +#include "GraphicsJNI.h" #include <android_runtime/AndroidRuntime.h> @@ -59,6 +58,8 @@ static const bool kDebugGraphicBuffer = false; static struct { jfieldID mNativeObject; + jclass mClass; + jmethodID mConstructorMethodID; } gGraphicBufferClassInfo; static struct { @@ -100,7 +101,7 @@ public: // GraphicBuffer lifecycle // ---------------------------------------------------------------------------- -static jlong android_view_GraphiceBuffer_create(JNIEnv* env, jobject clazz, +static jlong android_graphics_GraphicBuffer_create(JNIEnv* env, jobject clazz, jint width, jint height, jint format, jint usage) { sp<ISurfaceComposer> composer(ComposerService::getComposerService()); @@ -125,7 +126,7 @@ static jlong android_view_GraphiceBuffer_create(JNIEnv* env, jobject clazz, return reinterpret_cast<jlong>(wrapper); } -static void android_view_GraphiceBuffer_destroy(JNIEnv* env, jobject clazz, +static void android_graphics_GraphicBuffer_destroy(JNIEnv* env, jobject clazz, jlong wrapperHandle) { GraphicBufferWrapper* wrapper = reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle); @@ -151,7 +152,7 @@ static inline SkColorType convertPixelFormat(int32_t format) { } } -static jboolean android_view_GraphicBuffer_lockCanvas(JNIEnv* env, jobject, +static jboolean android_graphics_GraphicBuffer_lockCanvas(JNIEnv* env, jobject, jlong wrapperHandle, jobject canvas, jobject dirtyRect) { GraphicBufferWrapper* wrapper = @@ -209,7 +210,7 @@ static jboolean android_view_GraphicBuffer_lockCanvas(JNIEnv* env, jobject, return JNI_TRUE; } -static jboolean android_view_GraphicBuffer_unlockCanvasAndPost(JNIEnv* env, jobject, +static jboolean android_graphics_GraphicBuffer_unlockCanvasAndPost(JNIEnv* env, jobject, jlong wrapperHandle, jobject canvas) { GraphicBufferWrapper* wrapper = @@ -229,7 +230,7 @@ static jboolean android_view_GraphicBuffer_unlockCanvasAndPost(JNIEnv* env, jobj // Serialization // ---------------------------------------------------------------------------- -static void android_view_GraphiceBuffer_write(JNIEnv* env, jobject clazz, +static void android_graphics_GraphicBuffer_write(JNIEnv* env, jobject clazz, jlong wrapperHandle, jobject dest) { GraphicBufferWrapper* wrapper = reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle); @@ -239,7 +240,7 @@ static void android_view_GraphiceBuffer_write(JNIEnv* env, jobject clazz, } } -static jlong android_view_GraphiceBuffer_read(JNIEnv* env, jobject clazz, +static jlong android_graphics_GraphicBuffer_read(JNIEnv* env, jobject clazz, jobject in) { Parcel* parcel = parcelForJavaObject(env, in); @@ -252,17 +253,6 @@ static jlong android_view_GraphiceBuffer_read(JNIEnv* env, jobject clazz, return NULL; } -static jobject android_view_GraphicBuffer_createHardwareBitmap(JNIEnv* env, jobject, - jlong wrapperHandle) { - GraphicBufferWrapper* wrapper = reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle); - sk_sp<Bitmap> bitmap = Bitmap::createFrom(wrapper->buffer); - if (!bitmap.get()) { - ALOGW("failed to create hardware bitmap from graphic buffer"); - return NULL; - } - return bitmap::createBitmap(env, bitmap.release(), android::bitmap::kBitmapCreateFlag_None); -} - // ---------------------------------------------------------------------------- // External helpers // ---------------------------------------------------------------------------- @@ -279,35 +269,46 @@ sp<GraphicBuffer> graphicBufferForJavaObject(JNIEnv* env, jobject obj) { return NULL; } +jobject createJavaGraphicBuffer(JNIEnv* env, const sp<GraphicBuffer>& buffer) { + GraphicBufferWrapper* wrapper = new GraphicBufferWrapper(buffer); + jobject obj = env->NewObject(gGraphicBufferClassInfo.mClass, + gGraphicBufferClassInfo.mConstructorMethodID, buffer->getWidth(), buffer->getHeight(), + buffer->getPixelFormat(), buffer->getUsage(), reinterpret_cast<jlong>(wrapper)); + return obj; +} + +}; + +using namespace android; // ---------------------------------------------------------------------------- // JNI Glue // ---------------------------------------------------------------------------- -const char* const kClassPathName = "android/view/GraphicBuffer"; +const char* const kClassPathName = "android/graphics/GraphicBuffer"; static const JNINativeMethod gMethods[] = { - { "nCreateGraphicBuffer", "(IIII)J", (void*) android_view_GraphiceBuffer_create }, - { "nDestroyGraphicBuffer", "(J)V", (void*) android_view_GraphiceBuffer_destroy }, + { "nCreateGraphicBuffer", "(IIII)J", (void*) android_graphics_GraphicBuffer_create }, + { "nDestroyGraphicBuffer", "(J)V", (void*) android_graphics_GraphicBuffer_destroy }, { "nWriteGraphicBufferToParcel", "(JLandroid/os/Parcel;)V", - (void*) android_view_GraphiceBuffer_write }, + (void*) android_graphics_GraphicBuffer_write }, { "nReadGraphicBufferFromParcel", "(Landroid/os/Parcel;)J", - (void*) android_view_GraphiceBuffer_read }, + (void*) android_graphics_GraphicBuffer_read }, { "nLockCanvas", "(JLandroid/graphics/Canvas;Landroid/graphics/Rect;)Z", - (void*) android_view_GraphicBuffer_lockCanvas }, + (void*) android_graphics_GraphicBuffer_lockCanvas }, { "nUnlockCanvasAndPost", "(JLandroid/graphics/Canvas;)Z", - (void*) android_view_GraphicBuffer_unlockCanvasAndPost }, - { "nCreateHardwareBitmap", "(J)Landroid/graphics/Bitmap;", - (void*) android_view_GraphicBuffer_createHardwareBitmap - } + (void*) android_graphics_GraphicBuffer_unlockCanvasAndPost } }; -int register_android_view_GraphicBuffer(JNIEnv* env) { - jclass clazz = FindClassOrDie(env, "android/view/GraphicBuffer"); - gGraphicBufferClassInfo.mNativeObject = GetFieldIDOrDie(env, clazz, "mNativeObject", "J"); +int register_android_graphics_GraphicBuffer(JNIEnv* env) { + gGraphicBufferClassInfo.mClass = MakeGlobalRefOrDie(env, FindClassOrDie(env, kClassPathName)); + gGraphicBufferClassInfo.mNativeObject = GetFieldIDOrDie(env, gGraphicBufferClassInfo.mClass, + "mNativeObject", "J"); + gGraphicBufferClassInfo.mConstructorMethodID = env->GetMethodID(gGraphicBufferClassInfo.mClass, + "<init>", "(IIIIJ)V"); - clazz = FindClassOrDie(env, "android/graphics/Rect"); + jclass clazz = FindClassOrDie(env, "android/graphics/Rect"); gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V"); gRectClassInfo.left = GetFieldIDOrDie(env, clazz, "left", "I"); gRectClassInfo.top = GetFieldIDOrDie(env, clazz, "top", "I"); @@ -315,6 +316,4 @@ int register_android_view_GraphicBuffer(JNIEnv* env) { gRectClassInfo.bottom = GetFieldIDOrDie(env, clazz, "bottom", "I"); return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); -} - -}; +}
\ No newline at end of file diff --git a/core/jni/android_view_GraphicBuffer.h b/core/jni/android/graphics/GraphicBuffer.h index 509587cc4e20..0d7266942748 100644 --- a/core/jni/android_view_GraphicBuffer.h +++ b/core/jni/android/graphics/GraphicBuffer.h @@ -24,4 +24,6 @@ namespace android { // object must be an instance of android.view.GraphicBuffer extern sp<GraphicBuffer> graphicBufferForJavaObject(JNIEnv* env, jobject obj); +jobject createJavaGraphicBuffer(JNIEnv* env, const sp<GraphicBuffer>& buffer); + } diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index 14dcb3febe6f..c00bcd461181 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -36,7 +36,6 @@ #include <android_runtime/android_view_Surface.h> #include <system/window.h> -#include "android_view_GraphicBuffer.h" #include "android_os_MessageQueue.h" #include <Animator.h> diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index a259937c0b73..ba7f05d86fc8 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -655,6 +655,17 @@ public final class Bitmap implements Parcelable { } /** + * Create hardware bitmap backed GraphicBuffer. + * + * @return Bitmap or null if this GraphicBuffer has unsupported PixelFormat. + * currently PIXEL_FORMAT_RGBA_8888 is the only supported format + * @hide + */ + public static Bitmap createHardwareBitmap(GraphicBuffer graphicBuffer) { + return nativeCreateHardwareBitmap(graphicBuffer); + } + + /** * Creates a new bitmap, scaled from an existing bitmap, when possible. If the * specified width and height are the same as the current width and height of * the source bitmap, the source bitmap is returned and no new bitmap is @@ -1735,6 +1746,15 @@ public final class Bitmap implements Parcelable { nativePrepareToDraw(mNativePtr); } + /** + * + * @return {@link GraphicBuffer} which is internally used by hardware bitmap + * @hide + */ + public GraphicBuffer createGraphicBufferHandle() { + return nativeCreateGraphicBufferHandle(mNativePtr); + } + //////////// native methods private static native Bitmap nativeCreate(int[] colors, int offset, @@ -1794,4 +1814,6 @@ public final class Bitmap implements Parcelable { private static native void nativePrepareToDraw(long nativeBitmap); private static native int nativeGetAllocationByteCount(long nativeBitmap); private static native Bitmap nativeCopyPreserveInternalConfig(long nativeBitmap); + private static native Bitmap nativeCreateHardwareBitmap(GraphicBuffer buffer); + private static native GraphicBuffer nativeCreateGraphicBufferHandle(long nativeBitmap); } diff --git a/core/java/android/view/GraphicBuffer.aidl b/graphics/java/android/graphics/GraphicBuffer.aidl index 6dc6bede0dee..134699aa3e0c 100644 --- a/core/java/android/view/GraphicBuffer.aidl +++ b/graphics/java/android/graphics/GraphicBuffer.aidl @@ -14,6 +14,6 @@ * limitations under the License. */ -package android.view; +package android.graphics; parcelable GraphicBuffer; diff --git a/core/java/android/view/GraphicBuffer.java b/graphics/java/android/graphics/GraphicBuffer.java index 64611d0bfd68..3be9216177e9 100644 --- a/core/java/android/view/GraphicBuffer.java +++ b/graphics/java/android/graphics/GraphicBuffer.java @@ -14,12 +14,8 @@ * limitations under the License. */ -package android.view; +package android.graphics; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.PixelFormat; -import android.graphics.Rect; import android.os.Parcel; import android.os.Parcelable; @@ -265,16 +261,6 @@ public class GraphicBuffer implements Parcelable { nWriteGraphicBufferToParcel(mNativeObject, dest); } - /** - * Create hardware bitmap backed by this GraphicBuffer. - * - * @return Bitmap or null if this GraphicBuffer has unsupported PixelFormat. - * currently PIXEL_FORMAT_RGBA_8888 is the only supported format - */ - public Bitmap createHardwareBitmap() { - return nCreateHardwareBitmap(mNativeObject); - } - public static final Parcelable.Creator<GraphicBuffer> CREATOR = new Parcelable.Creator<GraphicBuffer>() { public GraphicBuffer createFromParcel(Parcel in) { @@ -300,5 +286,4 @@ public class GraphicBuffer implements Parcelable { private static native long nReadGraphicBufferFromParcel(Parcel in); private static native boolean nLockCanvas(long nativeObject, Canvas canvas, Rect dirty); private static native boolean nUnlockCanvasAndPost(long nativeObject, Canvas canvas); - private static native Bitmap nCreateHardwareBitmap(long nativeObject); } |