diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/jni/android/graphics/Graphics.cpp | 6 | ||||
-rw-r--r-- | core/jni/android/graphics/GraphicsJNI.h | 3 | ||||
-rw-r--r-- | core/jni/android_graphics_Canvas.cpp | 24 | ||||
-rw-r--r-- | core/jni/android_view_GraphicBuffer.cpp | 22 | ||||
-rw-r--r-- | core/jni/android_view_Surface.cpp | 23 | ||||
-rw-r--r-- | core/jni/android_view_TextureView.cpp | 22 |
6 files changed, 35 insertions, 65 deletions
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp index 0747969..44037dd 100644 --- a/core/jni/android/graphics/Graphics.cpp +++ b/core/jni/android/graphics/Graphics.cpp @@ -358,7 +358,7 @@ SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig) return legacyBitmapConfigToColorType(c); } -SkCanvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) { +android::Canvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) { SkASSERT(env); SkASSERT(canvas); SkASSERT(env->IsInstanceOf(canvas, gCanvas_class)); @@ -366,9 +366,7 @@ SkCanvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) { if (!canvasHandle) { return NULL; } - SkCanvas* c = reinterpret_cast<android::Canvas*>(canvasHandle)->asSkCanvas(); - SkASSERT(c); - return c; + return reinterpret_cast<android::Canvas*>(canvasHandle); } SkRegion* GraphicsJNI::getNativeRegion(JNIEnv* env, jobject region) diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h index 422d3f1..d73507e 100644 --- a/core/jni/android/graphics/GraphicsJNI.h +++ b/core/jni/android/graphics/GraphicsJNI.h @@ -8,6 +8,7 @@ #include "SkPoint.h" #include "SkRect.h" #include "SkImageDecoder.h" +#include <Canvas.h> #include <jni.h> class SkBitmapRegionDecoder; @@ -47,7 +48,7 @@ public: static SkPoint* jpointf_to_point(JNIEnv*, jobject jpointf, SkPoint* point); static void point_to_jpointf(const SkPoint& point, JNIEnv*, jobject jpointf); - static SkCanvas* getNativeCanvas(JNIEnv*, jobject canvas); + static android::Canvas* getNativeCanvas(JNIEnv*, jobject canvas); static SkBitmap* getSkBitmap(JNIEnv*, jobject bitmap); static SkRegion* getNativeRegion(JNIEnv*, jobject region); diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index a2c1609..3ae829b 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -39,17 +39,23 @@ static void finalizer(JNIEnv* env, jobject clazz, jlong canvasHandle) { } // Native wrapper constructor used by Canvas(Bitmap) -static jlong initRaster(JNIEnv* env, jobject, jlong bitmapHandle) { - SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); - return reinterpret_cast<jlong>(Canvas::create_canvas(bitmap)); +static jlong initRaster(JNIEnv* env, jobject, jobject jbitmap) { + SkBitmap* bitmap = nullptr; + if (jbitmap != NULL) { + bitmap = GraphicsJNI::getSkBitmap(env, jbitmap); + } + return reinterpret_cast<jlong>(Canvas::create_canvas( + bitmap ? *bitmap : SkBitmap())); } // Set the given bitmap as the new draw target (wrapped in a new SkCanvas), // optionally copying canvas matrix & clip state. -static void setBitmap(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, - jboolean copyState) { - SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); - get_canvas(canvasHandle)->setBitmap(bitmap, copyState); +static void setBitmap(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap) { + SkBitmap* bitmap = nullptr; + if (jbitmap != NULL) { + bitmap = GraphicsJNI::getSkBitmap(env, jbitmap); + } + get_canvas(canvasHandle)->setBitmap(bitmap ? *bitmap : SkBitmap()); } static jboolean isOpaque(JNIEnv*, jobject, jlong canvasHandle) { @@ -658,8 +664,8 @@ static void freeTextLayoutCaches(JNIEnv* env, jobject) { static JNINativeMethod gMethods[] = { {"finalizer", "(J)V", (void*) CanvasJNI::finalizer}, - {"initRaster", "(J)J", (void*) CanvasJNI::initRaster}, - {"native_setBitmap", "(JJZ)V", (void*) CanvasJNI::setBitmap}, + {"initRaster", "(Landroid/graphics/Bitmap;)J", (void*) CanvasJNI::initRaster}, + {"native_setBitmap", "(JLandroid/graphics/Bitmap;)V", (void*) CanvasJNI::setBitmap}, {"native_isOpaque","(J)Z", (void*) CanvasJNI::isOpaque}, {"native_getWidth","(J)I", (void*) CanvasJNI::getWidth}, {"native_getHeight","(J)I", (void*) CanvasJNI::getHeight}, diff --git a/core/jni/android_view_GraphicBuffer.cpp b/core/jni/android_view_GraphicBuffer.cpp index a12629f..aa79d70 100644 --- a/core/jni/android_view_GraphicBuffer.cpp +++ b/core/jni/android_view_GraphicBuffer.cpp @@ -67,11 +67,6 @@ static struct { jfieldID bottom; } gRectClassInfo; -static struct { - jfieldID mSurfaceFormat; - jmethodID setNativeBitmap; -} gCanvasClassInfo; - #define GET_INT(object, field) \ env->GetIntField(object, field) @@ -196,13 +191,9 @@ static jboolean android_view_GraphicBuffer_lockCanvas(JNIEnv* env, jobject, bitmap.setPixels(NULL); } - SET_INT(canvas, gCanvasClassInfo.mSurfaceFormat, buffer->getPixelFormat()); - INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, reinterpret_cast<jlong>(&bitmap)); - - SkRect clipRect; - clipRect.set(rect.left, rect.top, rect.right, rect.bottom); - SkCanvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas); - nativeCanvas->clipRect(clipRect); + Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas); + nativeCanvas->setBitmap(bitmap); + nativeCanvas->clipRect(rect.left, rect.top, rect.right, rect.bottom); if (dirtyRect) { INVOKEV(dirtyRect, gRectClassInfo.set, @@ -217,7 +208,8 @@ static jboolean android_view_GraphicBuffer_unlockCanvasAndPost(JNIEnv* env, jobj GraphicBufferWrapper* wrapper = reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle); - INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, (jlong)0); + Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas); + nativeCanvas->setBitmap(SkBitmap()); if (wrapper) { status_t status = wrapper->buffer->unlock(); @@ -302,10 +294,6 @@ int register_android_view_GraphicBuffer(JNIEnv* env) { gRectClassInfo.right = GetFieldIDOrDie(env, clazz, "right", "I"); gRectClassInfo.bottom = GetFieldIDOrDie(env, clazz, "bottom", "I"); - clazz = FindClassOrDie(env, "android/graphics/Canvas"); - gCanvasClassInfo.mSurfaceFormat = GetFieldIDOrDie(env, clazz, "mSurfaceFormat", "I"); - gCanvasClassInfo.setNativeBitmap = GetMethodIDOrDie(env, clazz, "setNativeBitmap", "(J)V"); - return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index 4fcb361..c4cd7ff 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -73,11 +73,6 @@ static struct { jfieldID bottom; } gRectClassInfo; -static struct { - jfieldID mSurfaceFormat; - jmethodID setNativeBitmap; -} gCanvasClassInfo; - // ---------------------------------------------------------------------------- // this is just a pointer we use to pass to inc/decStrong @@ -318,9 +313,6 @@ static jlong nativeLockCanvas(JNIEnv* env, jclass clazz, return 0; } - // Associate a SkCanvas object to this surface - env->SetIntField(canvasObj, gCanvasClassInfo.mSurfaceFormat, outBuffer.format); - SkImageInfo info = SkImageInfo::Make(outBuffer.width, outBuffer.height, convertPixelFormat(outBuffer.format), kPremul_SkAlphaType); @@ -338,12 +330,12 @@ static jlong nativeLockCanvas(JNIEnv* env, jclass clazz, bitmap.setPixels(NULL); } - env->CallVoidMethod(canvasObj, gCanvasClassInfo.setNativeBitmap, - reinterpret_cast<jlong>(&bitmap)); + Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvasObj); + nativeCanvas->setBitmap(bitmap); if (dirtyRectPtr) { - SkCanvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvasObj); - nativeCanvas->clipRect( SkRect::Make(reinterpret_cast<const SkIRect&>(dirtyRect)) ); + nativeCanvas->clipRect(dirtyRect.left, dirtyRect.top, + dirtyRect.right, dirtyRect.bottom); } if (dirtyRectObj) { @@ -369,7 +361,8 @@ static void nativeUnlockCanvasAndPost(JNIEnv* env, jclass clazz, } // detach the canvas from the surface - env->CallVoidMethod(canvasObj, gCanvasClassInfo.setNativeBitmap, (jlong)0); + Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvasObj); + nativeCanvas->setBitmap(SkBitmap()); // unlock surface status_t err = surface->unlockAndPost(); @@ -564,10 +557,6 @@ int register_android_view_Surface(JNIEnv* env) gSurfaceClassInfo.clazz, "mLock", "Ljava/lang/Object;"); gSurfaceClassInfo.ctor = GetMethodIDOrDie(env, gSurfaceClassInfo.clazz, "<init>", "(J)V"); - clazz = FindClassOrDie(env, "android/graphics/Canvas"); - gCanvasClassInfo.mSurfaceFormat = GetFieldIDOrDie(env, clazz, "mSurfaceFormat", "I"); - gCanvasClassInfo.setNativeBitmap = GetMethodIDOrDie(env, clazz, "setNativeBitmap", "(J)V"); - clazz = FindClassOrDie(env, "android/graphics/Rect"); gRectClassInfo.left = GetFieldIDOrDie(env, clazz, "left", "I"); gRectClassInfo.top = GetFieldIDOrDie(env, clazz, "top", "I"); diff --git a/core/jni/android_view_TextureView.cpp b/core/jni/android_view_TextureView.cpp index c2bd0b3..7e05793 100644 --- a/core/jni/android_view_TextureView.cpp +++ b/core/jni/android_view_TextureView.cpp @@ -48,11 +48,6 @@ static struct { } gRectClassInfo; static struct { - jfieldID mSurfaceFormat; - jmethodID setNativeBitmap; -} gCanvasClassInfo; - -static struct { jfieldID nativeWindow; } gTextureViewClassInfo; @@ -172,13 +167,9 @@ static jboolean android_view_TextureView_lockCanvas(JNIEnv* env, jobject, bitmap.setPixels(NULL); } - SET_INT(canvas, gCanvasClassInfo.mSurfaceFormat, buffer.format); - INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, reinterpret_cast<jlong>(&bitmap)); - - SkRect clipRect; - clipRect.set(rect.left, rect.top, rect.right, rect.bottom); - SkCanvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas); - nativeCanvas->clipRect(clipRect); + Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas); + nativeCanvas->setBitmap(bitmap); + nativeCanvas->clipRect(rect.left, rect.top, rect.right, rect.bottom); if (dirtyRect) { INVOKEV(dirtyRect, gRectClassInfo.set, @@ -191,7 +182,8 @@ static jboolean android_view_TextureView_lockCanvas(JNIEnv* env, jobject, static void android_view_TextureView_unlockCanvasAndPost(JNIEnv* env, jobject, jlong nativeWindow, jobject canvas) { - INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, (jlong)0); + Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas); + nativeCanvas->setBitmap(SkBitmap()); if (nativeWindow) { sp<ANativeWindow> window((ANativeWindow*) nativeWindow); @@ -225,10 +217,6 @@ int register_android_view_TextureView(JNIEnv* env) { gRectClassInfo.right = GetFieldIDOrDie(env, clazz, "right", "I"); gRectClassInfo.bottom = GetFieldIDOrDie(env, clazz, "bottom", "I"); - clazz = FindClassOrDie(env, "android/graphics/Canvas"); - gCanvasClassInfo.mSurfaceFormat = GetFieldIDOrDie(env, clazz, "mSurfaceFormat", "I"); - gCanvasClassInfo.setNativeBitmap = GetMethodIDOrDie(env, clazz, "setNativeBitmap", "(J)V"); - clazz = FindClassOrDie(env, "android/view/TextureView"); gTextureViewClassInfo.nativeWindow = GetFieldIDOrDie(env, clazz, "mNativeWindow", "J"); |