diff options
author | John Reck <jreck@google.com> | 2015-04-13 15:20:29 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2015-04-14 15:38:22 -0700 |
commit | c294d128d03bc9a9982b273a82516c04583438cc (patch) | |
tree | fd6c7ae3a6a292caf48160f0c0c8cc82e4729225 /services | |
parent | 4fc266bbef6129b5cefc910f0680eb9d61794faf (diff) | |
download | frameworks_base-c294d128d03bc9a9982b273a82516c04583438cc.zip frameworks_base-c294d128d03bc9a9982b273a82516c04583438cc.tar.gz frameworks_base-c294d128d03bc9a9982b273a82516c04583438cc.tar.bz2 |
A bunch more cleanups
Switch a few places to using android::canvas
instead of SkCanvas as well which eliminated
some JNI
Change-Id: I8f98b56442a06362b82b984cd1bd3a92398d8dbc
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/AssetAtlasService.java | 30 | ||||
-rw-r--r-- | services/core/jni/Android.mk | 1 | ||||
-rw-r--r-- | services/core/jni/com_android_server_AssetAtlasService.cpp | 55 |
3 files changed, 17 insertions, 69 deletions
diff --git a/services/core/java/com/android/server/AssetAtlasService.java b/services/core/java/com/android/server/AssetAtlasService.java index 66cc29a..9e28b64 100644 --- a/services/core/java/com/android/server/AssetAtlasService.java +++ b/services/core/java/com/android/server/AssetAtlasService.java @@ -199,9 +199,6 @@ public class AssetAtlasService extends IAssetAtlas.Stub { private final ArrayList<Bitmap> mBitmaps; private final int mPixelCount; - private long mNativeBitmap; - - // Used for debugging only private Bitmap mAtlasBitmap; Renderer(ArrayList<Bitmap> bitmaps, int pixelCount) { @@ -299,9 +296,7 @@ public class AssetAtlasService extends IAssetAtlas.Stub { } final long endRender = System.nanoTime(); - if (mNativeBitmap != 0) { - result = nUploadAtlas(buffer, mNativeBitmap); - } + result = nUploadAtlas(buffer, mAtlasBitmap); final long endUpload = System.nanoTime(); if (DEBUG_ATLAS) { @@ -326,14 +321,8 @@ public class AssetAtlasService extends IAssetAtlas.Stub { * @param height */ private Canvas acquireCanvas(int width, int height) { - if (DEBUG_ATLAS_TEXTURE) { - mAtlasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - return new Canvas(mAtlasBitmap); - } else { - Canvas canvas = new Canvas(); - mNativeBitmap = nAcquireAtlasCanvas(canvas, width, height); - return canvas; - } + mAtlasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + return new Canvas(mAtlasBitmap); } /** @@ -343,8 +332,8 @@ public class AssetAtlasService extends IAssetAtlas.Stub { * to disk in /data/system/atlas.png for debugging. */ private void releaseCanvas(Canvas canvas) { + canvas.setBitmap(null); if (DEBUG_ATLAS_TEXTURE) { - canvas.setBitmap(null); File systemDirectory = new File(Environment.getDataDirectory(), "system"); File dataFile = new File(systemDirectory, "atlas.png"); @@ -358,18 +347,13 @@ public class AssetAtlasService extends IAssetAtlas.Stub { } catch (IOException e) { // Ignore } - - mAtlasBitmap.recycle(); - mAtlasBitmap = null; - } else { - nReleaseAtlasCanvas(canvas, mNativeBitmap); } + mAtlasBitmap.recycle(); + mAtlasBitmap = null; } } - private static native long nAcquireAtlasCanvas(Canvas canvas, int width, int height); - private static native void nReleaseAtlasCanvas(Canvas canvas, long bitmap); - private static native boolean nUploadAtlas(GraphicBuffer buffer, long bitmap); + private static native boolean nUploadAtlas(GraphicBuffer buffer, Bitmap bitmap); @Override public boolean isCompatible(int ppid) { diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk index 6448de2..d26717c 100644 --- a/services/core/jni/Android.mk +++ b/services/core/jni/Android.mk @@ -33,6 +33,7 @@ LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE) \ frameworks/base/services \ frameworks/base/libs \ + frameworks/base/libs/hwui \ frameworks/base/core/jni \ frameworks/native/services \ libcore/include \ diff --git a/services/core/jni/com_android_server_AssetAtlasService.cpp b/services/core/jni/com_android_server_AssetAtlasService.cpp index e4f242e..8f4fb51 100644 --- a/services/core/jni/com_android_server_AssetAtlasService.cpp +++ b/services/core/jni/com_android_server_AssetAtlasService.cpp @@ -47,40 +47,9 @@ namespace android { #define FENCE_TIMEOUT 2000000000 // ---------------------------------------------------------------------------- -// JNI Helpers -// ---------------------------------------------------------------------------- - -static struct { - jmethodID setNativeBitmap; -} gCanvasClassInfo; - -#define INVOKEV(object, method, ...) \ - env->CallVoidMethod(object, method, __VA_ARGS__) - -// ---------------------------------------------------------------------------- // Canvas management // ---------------------------------------------------------------------------- -static jlong com_android_server_AssetAtlasService_acquireCanvas(JNIEnv* env, jobject, - jobject canvas, jint width, jint height) { - - SkBitmap* bitmap = new SkBitmap; - bitmap->allocN32Pixels(width, height); - bitmap->eraseColor(0); - INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, reinterpret_cast<jlong>(bitmap)); - - return reinterpret_cast<jlong>(bitmap); -} - -static void com_android_server_AssetAtlasService_releaseCanvas(JNIEnv* env, jobject, - jobject canvas, jlong bitmapHandle) { - - SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); - INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, (jlong)0); - - delete bitmap; -} - #define CLEANUP_GL_AND_RETURN(result) \ if (fence != EGL_NO_SYNC_KHR) eglDestroySyncKHR(display, fence); \ if (image) eglDestroyImageKHR(display, image); \ @@ -93,9 +62,12 @@ static void com_android_server_AssetAtlasService_releaseCanvas(JNIEnv* env, jobj return result; static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject, - jobject graphicBuffer, jlong bitmapHandle) { + jobject graphicBuffer, jobject bitmapHandle) { + + SkBitmap bitmap; + GraphicsJNI::getSkBitmap(env, bitmapHandle, &bitmap); + SkAutoLockPixels alp(bitmap); - SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); // The goal of this method is to copy the bitmap into the GraphicBuffer // using the GPU to swizzle the texture content sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer)); @@ -186,9 +158,9 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject } // Upload the content of the bitmap in the GraphicBuffer - glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel()); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap->width(), bitmap->height(), - GL_RGBA, GL_UNSIGNED_BYTE, bitmap->getPixels()); + glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap.bytesPerPixel()); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap.width(), bitmap.height(), + GL_RGBA, GL_UNSIGNED_BYTE, bitmap.getPixels()); if (glGetError() != GL_NO_ERROR) { ALOGW("Could not upload to texture"); CLEANUP_GL_AND_RETURN(JNI_FALSE); @@ -233,20 +205,11 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject const char* const kClassPathName = "com/android/server/AssetAtlasService"; static JNINativeMethod gMethods[] = { - { "nAcquireAtlasCanvas", "(Landroid/graphics/Canvas;II)J", - (void*) com_android_server_AssetAtlasService_acquireCanvas }, - { "nReleaseAtlasCanvas", "(Landroid/graphics/Canvas;J)V", - (void*) com_android_server_AssetAtlasService_releaseCanvas }, - { "nUploadAtlas", "(Landroid/view/GraphicBuffer;J)Z", + { "nUploadAtlas", "(Landroid/view/GraphicBuffer;Landroid/graphics/Bitmap;)Z", (void*) com_android_server_AssetAtlasService_upload }, }; int register_android_server_AssetAtlasService(JNIEnv* env) { - jclass clazz; - - FIND_CLASS(clazz, "android/graphics/Canvas"); - GET_METHOD_ID(gCanvasClassInfo.setNativeBitmap, clazz, "setNativeBitmap", "(J)V"); - return jniRegisterNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); } |