diff options
-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 | ||||
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 24 | ||||
-rw-r--r-- | libs/hwui/Canvas.h | 7 | ||||
-rw-r--r-- | libs/hwui/DisplayListCanvas.h | 2 | ||||
-rw-r--r-- | libs/hwui/SkiaCanvas.cpp | 28 | ||||
-rw-r--r-- | media/jni/Android.mk | 3 | ||||
-rw-r--r-- | native/graphics/jni/Android.mk | 3 | ||||
-rw-r--r-- | rs/jni/Android.mk | 1 | ||||
-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 | 54 |
16 files changed, 75 insertions, 178 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"); diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 48afcbf..2acb8ba 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -81,10 +81,6 @@ public class Canvas { */ protected int mScreenDensity = Bitmap.DENSITY_NONE; - // Used by native code - @SuppressWarnings("UnusedDeclaration") - private int mSurfaceFormat; - /** * Flag for drawTextRun indicating left-to-right run direction. * @hide @@ -137,7 +133,7 @@ public class Canvas { public Canvas() { if (!isHardwareAccelerated()) { // 0 means no native bitmap - mNativeCanvasWrapper = initRaster(0); + mNativeCanvasWrapper = initRaster(null); mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper); } else { mFinalizer = null; @@ -158,7 +154,7 @@ public class Canvas { throw new IllegalStateException("Immutable bitmap passed to Canvas constructor"); } throwIfCannotDraw(bitmap); - mNativeCanvasWrapper = initRaster(bitmap.getSkBitmap()); + mNativeCanvasWrapper = initRaster(bitmap); mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper); mBitmap = bitmap; mDensity = bitmap.mDensity; @@ -215,7 +211,7 @@ public class Canvas { } if (bitmap == null) { - native_setBitmap(mNativeCanvasWrapper, 0, false); + native_setBitmap(mNativeCanvasWrapper, null); mDensity = Bitmap.DENSITY_NONE; } else { if (!bitmap.isMutable()) { @@ -223,7 +219,7 @@ public class Canvas { } throwIfCannotDraw(bitmap); - native_setBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), true); + native_setBitmap(mNativeCanvasWrapper, bitmap); mDensity = bitmap.mDensity; } @@ -231,13 +227,6 @@ public class Canvas { } /** - * setBitmap() variant for native callers with a raw bitmap handle. - */ - private void setNativeBitmap(long bitmapHandle) { - native_setBitmap(mNativeCanvasWrapper, bitmapHandle, false); - } - - /** * Set the viewport dimensions if this canvas is GL based. If it is not, * this method is ignored and no exception is thrown. * @@ -1976,10 +1965,9 @@ public class Canvas { */ public static native void freeTextLayoutCaches(); - private static native long initRaster(long nativeBitmapOrZero); + private static native long initRaster(Bitmap bitmap); private static native void native_setBitmap(long canvasHandle, - long bitmapHandle, - boolean copyState); + Bitmap bitmap); private static native boolean native_isOpaque(long canvasHandle); private static native int native_getWidth(long canvasHandle); private static native int native_getHeight(long canvasHandle); diff --git a/libs/hwui/Canvas.h b/libs/hwui/Canvas.h index 7ad0683..aa24673 100644 --- a/libs/hwui/Canvas.h +++ b/libs/hwui/Canvas.h @@ -29,7 +29,7 @@ class ANDROID_API Canvas { public: virtual ~Canvas() {}; - static Canvas* create_canvas(SkBitmap* bitmap); + static Canvas* create_canvas(const SkBitmap& bitmap); /** * Create a new Canvas object which delegates to an SkCanvas. @@ -52,7 +52,7 @@ public: */ virtual SkCanvas* asSkCanvas() = 0; - virtual void setBitmap(SkBitmap* bitmap, bool copyState) = 0; + virtual void setBitmap(const SkBitmap& bitmap) = 0; virtual bool isOpaque() = 0; virtual int width() = 0; @@ -87,7 +87,8 @@ public: virtual bool quickRejectRect(float left, float top, float right, float bottom) const = 0; virtual bool quickRejectPath(const SkPath& path) const = 0; - virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) = 0; + virtual bool clipRect(float left, float top, float right, float bottom, + SkRegion::Op op = SkRegion::kIntersect_Op) = 0; virtual bool clipPath(const SkPath* path, SkRegion::Op op) = 0; virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) = 0; diff --git a/libs/hwui/DisplayListCanvas.h b/libs/hwui/DisplayListCanvas.h index a9ac57d..2b0b6b2 100644 --- a/libs/hwui/DisplayListCanvas.h +++ b/libs/hwui/DisplayListCanvas.h @@ -136,7 +136,7 @@ public: // ---------------------------------------------------------------------------- virtual SkCanvas* asSkCanvas() override; - virtual void setBitmap(SkBitmap* bitmap, bool copyState) override { + virtual void setBitmap(const SkBitmap& bitmap) override { LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap."); } diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index 8b11757..a323065 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -31,7 +31,7 @@ namespace android { // Holds an SkCanvas reference plus additional native data. class SkiaCanvas : public Canvas { public: - explicit SkiaCanvas(SkBitmap* bitmap); + explicit SkiaCanvas(const SkBitmap& bitmap); /** * Create a new SkiaCanvas. @@ -49,7 +49,7 @@ public: return mCanvas.get(); } - virtual void setBitmap(SkBitmap* bitmap, bool copyState) override; + virtual void setBitmap(const SkBitmap& bitmap) override; virtual bool isOpaque() override; virtual int width() override; @@ -145,19 +145,7 @@ private: SkAutoTDelete<SkDeque> mSaveStack; // lazily allocated, tracks partial saves. }; -// Construct an SkCanvas from the bitmap. -static SkCanvas* createCanvas(SkBitmap* bitmap) { - if (bitmap) { - return SkNEW_ARGS(SkCanvas, (*bitmap)); - } - - // Create an empty bitmap device to prevent callers from crashing - // if they attempt to draw into this canvas. - SkBitmap emptyBitmap; - return new SkCanvas(emptyBitmap); -} - -Canvas* Canvas::create_canvas(SkBitmap* bitmap) { +Canvas* Canvas::create_canvas(const SkBitmap& bitmap) { return new SkiaCanvas(bitmap); } @@ -165,8 +153,8 @@ Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) { return new SkiaCanvas(skiaCanvas); } -SkiaCanvas::SkiaCanvas(SkBitmap* bitmap) { - mCanvas.reset(createCanvas(bitmap)); +SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) { + mCanvas.reset(new SkCanvas(bitmap)); } // ---------------------------------------------------------------------------- @@ -191,11 +179,11 @@ private: SkCanvas* m_dstCanvas; }; -void SkiaCanvas::setBitmap(SkBitmap* bitmap, bool copyState) { - SkCanvas* newCanvas = createCanvas(bitmap); +void SkiaCanvas::setBitmap(const SkBitmap& bitmap) { + SkCanvas* newCanvas = new SkCanvas(bitmap); SkASSERT(newCanvas); - if (copyState) { + if (!bitmap.isNull()) { // Copy the canvas matrix & clip state. newCanvas->setMatrix(mCanvas->getTotalMatrix()); if (NULL != mCanvas->getDevice() && NULL != newCanvas->getDevice()) { diff --git a/media/jni/Android.mk b/media/jni/Android.mk index 8cf9874..c8464c7 100644 --- a/media/jni/Android.mk +++ b/media/jni/Android.mk @@ -43,7 +43,7 @@ LOCAL_SHARED_LIBRARIES := \ libusbhost \ libjhead \ libexif \ - libstagefright_amrnb_common \ + libstagefright_amrnb_common LOCAL_REQUIRED_MODULES := \ libjhead_jni @@ -55,6 +55,7 @@ LOCAL_C_INCLUDES += \ external/libexif/ \ external/tremor/Tremor \ frameworks/base/core/jni \ + frameworks/base/libs/hwui \ frameworks/av/media/libmedia \ frameworks/av/media/libstagefright \ frameworks/av/media/libstagefright/codecs/amrnb/enc/src \ diff --git a/native/graphics/jni/Android.mk b/native/graphics/jni/Android.mk index 91c9ac6..f89a5af 100644 --- a/native/graphics/jni/Android.mk +++ b/native/graphics/jni/Android.mk @@ -24,7 +24,8 @@ LOCAL_SHARED_LIBRARIES := \ LOCAL_C_INCLUDES += \ frameworks/base/native/include \ - frameworks/base/core/jni/android/graphics + frameworks/base/core/jni/android/graphics \ + frameworks/base/libs/hwui LOCAL_MODULE:= libjnigraphics diff --git a/rs/jni/Android.mk b/rs/jni/Android.mk index 94f0859..0658620 100644 --- a/rs/jni/Android.mk +++ b/rs/jni/Android.mk @@ -25,6 +25,7 @@ LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE) \ frameworks/rs \ frameworks/base/core/jni \ + frameworks/base/libs/hwui \ $(rs_generated_include_dir) LOCAL_CFLAGS += -Wno-unused-parameter -std=c++11 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 19ca2b4..a5546cf 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..ad1d0f5 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,11 @@ 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); + 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 +157,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 +204,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)); } |