summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2015-04-17 20:45:40 +0000
committerJohn Reck <jreck@google.com>2015-04-17 20:47:27 +0000
commit9d4efdf2802f06ccf7031610891f75af70ea5538 (patch)
treea86a7a833af6b45b466a391c5ff72fbffcdca329
parent7809f835cae637c12eebdc92103ad88890228d97 (diff)
downloadframeworks_base-9d4efdf2802f06ccf7031610891f75af70ea5538.zip
frameworks_base-9d4efdf2802f06ccf7031610891f75af70ea5538.tar.gz
frameworks_base-9d4efdf2802f06ccf7031610891f75af70ea5538.tar.bz2
Revert "A bunch more cleanups"
This reverts commit c294d128d03bc9a9982b273a82516c04583438cc. Change-Id: Id1ebb236950f7c36c6d86e1dd95566d3a200748d
-rw-r--r--core/java/android/view/ThreadedRenderer.java4
-rw-r--r--core/jni/android/graphics/Graphics.cpp6
-rw-r--r--core/jni/android/graphics/GraphicsJNI.h3
-rw-r--r--core/jni/android/graphics/Shader.cpp9
-rw-r--r--core/jni/android_graphics_Canvas.cpp21
-rw-r--r--core/jni/android_view_GraphicBuffer.cpp22
-rw-r--r--core/jni/android_view_Surface.cpp23
-rw-r--r--core/jni/android_view_TextureView.cpp22
-rw-r--r--core/jni/android_view_ThreadedRenderer.cpp8
-rw-r--r--graphics/java/android/graphics/BitmapShader.java5
-rw-r--r--graphics/java/android/graphics/Canvas.java24
-rw-r--r--libs/hwui/Canvas.h7
-rw-r--r--libs/hwui/DisplayListRenderer.h2
-rw-r--r--libs/hwui/SkiaCanvas.cpp28
-rw-r--r--libs/hwui/renderthread/RenderProxy.cpp4
-rw-r--r--libs/hwui/renderthread/RenderProxy.h2
-rw-r--r--media/jni/Android.mk3
-rw-r--r--native/graphics/jni/Android.mk3
-rw-r--r--rs/jni/Android.mk1
-rw-r--r--services/core/java/com/android/server/AssetAtlasService.java30
-rw-r--r--services/core/jni/Android.mk1
-rw-r--r--services/core/jni/com_android_server_AssetAtlasService.cpp55
22 files changed, 192 insertions, 91 deletions
diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java
index 5017a38..87d5d9a 100644
--- a/core/java/android/view/ThreadedRenderer.java
+++ b/core/java/android/view/ThreadedRenderer.java
@@ -360,7 +360,7 @@ public class ThreadedRenderer extends HardwareRenderer {
@Override
boolean copyLayerInto(final HardwareLayer layer, final Bitmap bitmap) {
return nCopyLayerInto(mNativeProxy,
- layer.getDeferredLayerUpdater(), bitmap);
+ layer.getDeferredLayerUpdater(), bitmap.getSkBitmap());
}
@Override
@@ -531,7 +531,7 @@ public class ThreadedRenderer extends HardwareRenderer {
private static native long nCreateTextureLayer(long nativeProxy);
private static native void nBuildLayer(long nativeProxy, long node);
- private static native boolean nCopyLayerInto(long nativeProxy, long layer, Bitmap bitmap);
+ private static native boolean nCopyLayerInto(long nativeProxy, long layer, long bitmap);
private static native void nPushLayerUpdate(long nativeProxy, long layer);
private static native void nCancelLayerUpdate(long nativeProxy, long layer);
private static native void nDetachSurfaceTexture(long nativeProxy, long layer);
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index f0bd8d1..f0bd5dd 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -373,7 +373,7 @@ SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig)
return legacyBitmapConfigToColorType(c);
}
-android::Canvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) {
+SkCanvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) {
SkASSERT(env);
SkASSERT(canvas);
SkASSERT(env->IsInstanceOf(canvas, gCanvas_class));
@@ -381,7 +381,9 @@ android::Canvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) {
if (!canvasHandle) {
return NULL;
}
- return reinterpret_cast<android::Canvas*>(canvasHandle);
+ SkCanvas* c = reinterpret_cast<android::Canvas*>(canvasHandle)->asSkCanvas();
+ SkASSERT(c);
+ return c;
}
SkRegion* GraphicsJNI::getNativeRegion(JNIEnv* env, jobject region)
diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h
index 8eb43f8..49def13 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -8,7 +8,6 @@
#include "SkPoint.h"
#include "SkRect.h"
#include "SkImageDecoder.h"
-#include <Canvas.h>
#include <jni.h>
class SkBitmapRegionDecoder;
@@ -48,7 +47,7 @@ public:
static SkPoint* jpointf_to_point(JNIEnv*, jobject jpointf, SkPoint* point);
static void point_to_jpointf(const SkPoint& point, JNIEnv*, jobject jpointf);
- static android::Canvas* getNativeCanvas(JNIEnv*, jobject canvas);
+ static SkCanvas* getNativeCanvas(JNIEnv*, jobject canvas);
static SkBitmap* getSkBitmapDeprecated(JNIEnv*, jobject bitmap);
static void getSkBitmap(JNIEnv*, jobject bitmap, SkBitmap* outBitmap);
static SkPixelRef* getSkPixelRef(JNIEnv*, jobject bitmap);
diff --git a/core/jni/android/graphics/Shader.cpp b/core/jni/android/graphics/Shader.cpp
index d0f7591..6591d29 100644
--- a/core/jni/android/graphics/Shader.cpp
+++ b/core/jni/android/graphics/Shader.cpp
@@ -80,12 +80,11 @@ static jlong Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle, j
///////////////////////////////////////////////////////////////////////////////////////////////
-static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jobject jbitmap,
+static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong bitmapHandle,
jint tileModeX, jint tileModeY)
{
- SkBitmap bitmap;
- GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
- SkShader* s = SkShader::CreateBitmapShader(bitmap,
+ const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+ SkShader* s = SkShader::CreateBitmapShader(*bitmap,
(SkShader::TileMode)tileModeX,
(SkShader::TileMode)tileModeY);
@@ -250,7 +249,7 @@ static JNINativeMethod gShaderMethods[] = {
};
static JNINativeMethod gBitmapShaderMethods[] = {
- { "nativeCreate", "(Landroid/graphics/Bitmap;II)J", (void*)BitmapShader_constructor },
+ { "nativeCreate", "(JII)J", (void*)BitmapShader_constructor },
};
static JNINativeMethod gLinearGradientMethods[] = {
diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp
index 50a1069..a2c1609 100644
--- a/core/jni/android_graphics_Canvas.cpp
+++ b/core/jni/android_graphics_Canvas.cpp
@@ -39,22 +39,17 @@ static void finalizer(JNIEnv* env, jobject clazz, jlong canvasHandle) {
}
// Native wrapper constructor used by Canvas(Bitmap)
-static jlong initRaster(JNIEnv* env, jobject, jobject jbitmap) {
- SkBitmap bitmap;
- if (jbitmap != NULL) {
- GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
- }
+static jlong initRaster(JNIEnv* env, jobject, jlong bitmapHandle) {
+ SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
return reinterpret_cast<jlong>(Canvas::create_canvas(bitmap));
}
// 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, jobject jbitmap) {
- SkBitmap bitmap;
- if (jbitmap != NULL) {
- GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
- }
- get_canvas(canvasHandle)->setBitmap(bitmap);
+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 jboolean isOpaque(JNIEnv*, jobject, jlong canvasHandle) {
@@ -663,8 +658,8 @@ static void freeTextLayoutCaches(JNIEnv* env, jobject) {
static JNINativeMethod gMethods[] = {
{"finalizer", "(J)V", (void*) CanvasJNI::finalizer},
- {"initRaster", "(Landroid/graphics/Bitmap;)J", (void*) CanvasJNI::initRaster},
- {"native_setBitmap", "(JLandroid/graphics/Bitmap;)V", (void*) CanvasJNI::setBitmap},
+ {"initRaster", "(J)J", (void*) CanvasJNI::initRaster},
+ {"native_setBitmap", "(JJZ)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 aa79d70..a12629f 100644
--- a/core/jni/android_view_GraphicBuffer.cpp
+++ b/core/jni/android_view_GraphicBuffer.cpp
@@ -67,6 +67,11 @@ static struct {
jfieldID bottom;
} gRectClassInfo;
+static struct {
+ jfieldID mSurfaceFormat;
+ jmethodID setNativeBitmap;
+} gCanvasClassInfo;
+
#define GET_INT(object, field) \
env->GetIntField(object, field)
@@ -191,9 +196,13 @@ static jboolean android_view_GraphicBuffer_lockCanvas(JNIEnv* env, jobject,
bitmap.setPixels(NULL);
}
- Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas);
- nativeCanvas->setBitmap(bitmap);
- nativeCanvas->clipRect(rect.left, rect.top, rect.right, rect.bottom);
+ 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);
if (dirtyRect) {
INVOKEV(dirtyRect, gRectClassInfo.set,
@@ -208,8 +217,7 @@ static jboolean android_view_GraphicBuffer_unlockCanvasAndPost(JNIEnv* env, jobj
GraphicBufferWrapper* wrapper =
reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle);
- Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas);
- nativeCanvas->setBitmap(SkBitmap());
+ INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, (jlong)0);
if (wrapper) {
status_t status = wrapper->buffer->unlock();
@@ -294,6 +302,10 @@ 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 06d1e85..f1c90ea 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -74,6 +74,11 @@ static struct {
jfieldID bottom;
} gRectClassInfo;
+static struct {
+ jfieldID mSurfaceFormat;
+ jmethodID setNativeBitmap;
+} gCanvasClassInfo;
+
// ----------------------------------------------------------------------------
// this is just a pointer we use to pass to inc/decStrong
@@ -314,6 +319,9 @@ 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);
@@ -331,12 +339,12 @@ static jlong nativeLockCanvas(JNIEnv* env, jclass clazz,
bitmap.setPixels(NULL);
}
- Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvasObj);
- nativeCanvas->setBitmap(bitmap);
+ env->CallVoidMethod(canvasObj, gCanvasClassInfo.setNativeBitmap,
+ reinterpret_cast<jlong>(&bitmap));
if (dirtyRectPtr) {
- nativeCanvas->clipRect(dirtyRect.left, dirtyRect.top,
- dirtyRect.right, dirtyRect.bottom);
+ SkCanvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvasObj);
+ nativeCanvas->clipRect( SkRect::Make(reinterpret_cast<const SkIRect&>(dirtyRect)) );
}
if (dirtyRectObj) {
@@ -362,8 +370,7 @@ static void nativeUnlockCanvasAndPost(JNIEnv* env, jclass clazz,
}
// detach the canvas from the surface
- Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvasObj);
- nativeCanvas->setBitmap(SkBitmap());
+ env->CallVoidMethod(canvasObj, gCanvasClassInfo.setNativeBitmap, (jlong)0);
// unlock surface
status_t err = surface->unlockAndPost();
@@ -558,6 +565,10 @@ 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 7e05793..c2bd0b3 100644
--- a/core/jni/android_view_TextureView.cpp
+++ b/core/jni/android_view_TextureView.cpp
@@ -48,6 +48,11 @@ static struct {
} gRectClassInfo;
static struct {
+ jfieldID mSurfaceFormat;
+ jmethodID setNativeBitmap;
+} gCanvasClassInfo;
+
+static struct {
jfieldID nativeWindow;
} gTextureViewClassInfo;
@@ -167,9 +172,13 @@ static jboolean android_view_TextureView_lockCanvas(JNIEnv* env, jobject,
bitmap.setPixels(NULL);
}
- Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas);
- nativeCanvas->setBitmap(bitmap);
- nativeCanvas->clipRect(rect.left, rect.top, rect.right, rect.bottom);
+ 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);
if (dirtyRect) {
INVOKEV(dirtyRect, gRectClassInfo.set,
@@ -182,8 +191,7 @@ static jboolean android_view_TextureView_lockCanvas(JNIEnv* env, jobject,
static void android_view_TextureView_unlockCanvasAndPost(JNIEnv* env, jobject,
jlong nativeWindow, jobject canvas) {
- Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvas);
- nativeCanvas->setBitmap(SkBitmap());
+ INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, (jlong)0);
if (nativeWindow) {
sp<ANativeWindow> window((ANativeWindow*) nativeWindow);
@@ -217,6 +225,10 @@ 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/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp
index 4ccbb41..11b3805 100644
--- a/core/jni/android_view_ThreadedRenderer.cpp
+++ b/core/jni/android_view_ThreadedRenderer.cpp
@@ -21,7 +21,6 @@
#include "jni.h"
#include <nativehelper/JNIHelp.h>
#include "core_jni_helpers.h"
-#include <GraphicsJNI.h>
#include <ScopedPrimitiveArray.h>
#include <EGL/egl.h>
@@ -348,11 +347,10 @@ static void android_view_ThreadedRenderer_buildLayer(JNIEnv* env, jobject clazz,
}
static jboolean android_view_ThreadedRenderer_copyLayerInto(JNIEnv* env, jobject clazz,
- jlong proxyPtr, jlong layerPtr, jobject jbitmap) {
+ jlong proxyPtr, jlong layerPtr, jlong bitmapPtr) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr);
- SkBitmap bitmap;
- GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
+ SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr);
return proxy->copyLayerInto(layer, bitmap);
}
@@ -460,7 +458,7 @@ static JNINativeMethod gMethods[] = {
{ "nInvokeFunctor", "(JZ)V", (void*) android_view_ThreadedRenderer_invokeFunctor },
{ "nCreateTextureLayer", "(J)J", (void*) android_view_ThreadedRenderer_createTextureLayer },
{ "nBuildLayer", "(JJ)V", (void*) android_view_ThreadedRenderer_buildLayer },
- { "nCopyLayerInto", "(JJLandroid/graphics/Bitmap;)Z", (void*) android_view_ThreadedRenderer_copyLayerInto },
+ { "nCopyLayerInto", "(JJJ)Z", (void*) android_view_ThreadedRenderer_copyLayerInto },
{ "nPushLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_pushLayerUpdate },
{ "nCancelLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_cancelLayerUpdate },
{ "nDetachSurfaceTexture", "(JJ)V", (void*) android_view_ThreadedRenderer_detachSurfaceTexture },
diff --git a/graphics/java/android/graphics/BitmapShader.java b/graphics/java/android/graphics/BitmapShader.java
index bd74bc8..f2f890e 100644
--- a/graphics/java/android/graphics/BitmapShader.java
+++ b/graphics/java/android/graphics/BitmapShader.java
@@ -42,7 +42,8 @@ public class BitmapShader extends Shader {
mBitmap = bitmap;
mTileX = tileX;
mTileY = tileY;
- init(nativeCreate(bitmap, tileX.nativeInt, tileY.nativeInt));
+ final long b = bitmap.getSkBitmap();
+ init(nativeCreate(b, tileX.nativeInt, tileY.nativeInt));
}
/**
@@ -55,6 +56,6 @@ public class BitmapShader extends Shader {
return copy;
}
- private static native long nativeCreate(Bitmap bitmap, int shaderTileModeX,
+ private static native long nativeCreate(long native_bitmap, int shaderTileModeX,
int shaderTileModeY);
}
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index 2acb8ba..48afcbf 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -81,6 +81,10 @@ 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
@@ -133,7 +137,7 @@ public class Canvas {
public Canvas() {
if (!isHardwareAccelerated()) {
// 0 means no native bitmap
- mNativeCanvasWrapper = initRaster(null);
+ mNativeCanvasWrapper = initRaster(0);
mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper);
} else {
mFinalizer = null;
@@ -154,7 +158,7 @@ public class Canvas {
throw new IllegalStateException("Immutable bitmap passed to Canvas constructor");
}
throwIfCannotDraw(bitmap);
- mNativeCanvasWrapper = initRaster(bitmap);
+ mNativeCanvasWrapper = initRaster(bitmap.getSkBitmap());
mFinalizer = new CanvasFinalizer(mNativeCanvasWrapper);
mBitmap = bitmap;
mDensity = bitmap.mDensity;
@@ -211,7 +215,7 @@ public class Canvas {
}
if (bitmap == null) {
- native_setBitmap(mNativeCanvasWrapper, null);
+ native_setBitmap(mNativeCanvasWrapper, 0, false);
mDensity = Bitmap.DENSITY_NONE;
} else {
if (!bitmap.isMutable()) {
@@ -219,7 +223,7 @@ public class Canvas {
}
throwIfCannotDraw(bitmap);
- native_setBitmap(mNativeCanvasWrapper, bitmap);
+ native_setBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), true);
mDensity = bitmap.mDensity;
}
@@ -227,6 +231,13 @@ 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.
*
@@ -1965,9 +1976,10 @@ public class Canvas {
*/
public static native void freeTextLayoutCaches();
- private static native long initRaster(Bitmap bitmap);
+ private static native long initRaster(long nativeBitmapOrZero);
private static native void native_setBitmap(long canvasHandle,
- Bitmap bitmap);
+ long bitmapHandle,
+ boolean copyState);
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 aa24673..7ad0683 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(const SkBitmap& bitmap);
+ static Canvas* create_canvas(SkBitmap* bitmap);
/**
* Create a new Canvas object which delegates to an SkCanvas.
@@ -52,7 +52,7 @@ public:
*/
virtual SkCanvas* asSkCanvas() = 0;
- virtual void setBitmap(const SkBitmap& bitmap) = 0;
+ virtual void setBitmap(SkBitmap* bitmap, bool copyState) = 0;
virtual bool isOpaque() = 0;
virtual int width() = 0;
@@ -87,8 +87,7 @@ 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 = SkRegion::kIntersect_Op) = 0;
+ virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op 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/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index ff698f5..53fd1ad 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -138,7 +138,7 @@ public:
// ----------------------------------------------------------------------------
virtual SkCanvas* asSkCanvas() override;
- virtual void setBitmap(const SkBitmap& bitmap) override {
+ virtual void setBitmap(SkBitmap* bitmap, bool copyState) override {
LOG_ALWAYS_FATAL("DisplayListRenderer is not backed by a bitmap.");
}
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index a323065..8b11757 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(const SkBitmap& bitmap);
+ explicit SkiaCanvas(SkBitmap* bitmap);
/**
* Create a new SkiaCanvas.
@@ -49,7 +49,7 @@ public:
return mCanvas.get();
}
- virtual void setBitmap(const SkBitmap& bitmap) override;
+ virtual void setBitmap(SkBitmap* bitmap, bool copyState) override;
virtual bool isOpaque() override;
virtual int width() override;
@@ -145,7 +145,19 @@ private:
SkAutoTDelete<SkDeque> mSaveStack; // lazily allocated, tracks partial saves.
};
-Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
+// 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) {
return new SkiaCanvas(bitmap);
}
@@ -153,8 +165,8 @@ Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) {
return new SkiaCanvas(skiaCanvas);
}
-SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) {
- mCanvas.reset(new SkCanvas(bitmap));
+SkiaCanvas::SkiaCanvas(SkBitmap* bitmap) {
+ mCanvas.reset(createCanvas(bitmap));
}
// ----------------------------------------------------------------------------
@@ -179,11 +191,11 @@ private:
SkCanvas* m_dstCanvas;
};
-void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
- SkCanvas* newCanvas = new SkCanvas(bitmap);
+void SkiaCanvas::setBitmap(SkBitmap* bitmap, bool copyState) {
+ SkCanvas* newCanvas = createCanvas(bitmap);
SkASSERT(newCanvas);
- if (!bitmap.isNull()) {
+ if (copyState) {
// Copy the canvas matrix & clip state.
newCanvas->setMatrix(mCanvas->getTotalMatrix());
if (NULL != mCanvas->getDevice() && NULL != newCanvas->getDevice()) {
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index d15fa39..cc87241 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -293,11 +293,11 @@ CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* laye
return (void*) success;
}
-bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) {
+bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) {
SETUP_TASK(copyLayerInto);
args->context = mContext;
args->layer = layer;
- args->bitmap = &bitmap;
+ args->bitmap = bitmap;
return (bool) postAndWait(task);
}
diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h
index cc475fa..29c6f08 100644
--- a/libs/hwui/renderthread/RenderProxy.h
+++ b/libs/hwui/renderthread/RenderProxy.h
@@ -83,7 +83,7 @@ public:
ANDROID_API DeferredLayerUpdater* createTextureLayer();
ANDROID_API void buildLayer(RenderNode* node);
- ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
+ ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer);
ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer);
ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer);
diff --git a/media/jni/Android.mk b/media/jni/Android.mk
index c8464c7..8cf9874 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,7 +55,6 @@ 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 f89a5af..91c9ac6 100644
--- a/native/graphics/jni/Android.mk
+++ b/native/graphics/jni/Android.mk
@@ -24,8 +24,7 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_C_INCLUDES += \
frameworks/base/native/include \
- frameworks/base/core/jni/android/graphics \
- frameworks/base/libs/hwui
+ frameworks/base/core/jni/android/graphics
LOCAL_MODULE:= libjnigraphics
diff --git a/rs/jni/Android.mk b/rs/jni/Android.mk
index 0658620..94f0859 100644
--- a/rs/jni/Android.mk
+++ b/rs/jni/Android.mk
@@ -25,7 +25,6 @@ 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 9e28b64..66cc29a 100644
--- a/services/core/java/com/android/server/AssetAtlasService.java
+++ b/services/core/java/com/android/server/AssetAtlasService.java
@@ -199,6 +199,9 @@ 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) {
@@ -296,7 +299,9 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
}
final long endRender = System.nanoTime();
- result = nUploadAtlas(buffer, mAtlasBitmap);
+ if (mNativeBitmap != 0) {
+ result = nUploadAtlas(buffer, mNativeBitmap);
+ }
final long endUpload = System.nanoTime();
if (DEBUG_ATLAS) {
@@ -321,8 +326,14 @@ public class AssetAtlasService extends IAssetAtlas.Stub {
* @param height
*/
private Canvas acquireCanvas(int width, int height) {
- mAtlasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- return new Canvas(mAtlasBitmap);
+ 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;
+ }
}
/**
@@ -332,8 +343,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");
@@ -347,13 +358,18 @@ 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 boolean nUploadAtlas(GraphicBuffer buffer, Bitmap bitmap);
+ 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);
@Override
public boolean isCompatible(int ppid) {
diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk
index a5546cf..19ca2b4 100644
--- a/services/core/jni/Android.mk
+++ b/services/core/jni/Android.mk
@@ -33,7 +33,6 @@ 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 8f4fb51..e4f242e 100644
--- a/services/core/jni/com_android_server_AssetAtlasService.cpp
+++ b/services/core/jni/com_android_server_AssetAtlasService.cpp
@@ -47,9 +47,40 @@ 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); \
@@ -62,12 +93,9 @@ namespace android {
return result;
static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject,
- jobject graphicBuffer, jobject bitmapHandle) {
-
- SkBitmap bitmap;
- GraphicsJNI::getSkBitmap(env, bitmapHandle, &bitmap);
- SkAutoLockPixels alp(bitmap);
+ jobject graphicBuffer, jlong bitmapHandle) {
+ 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));
@@ -158,9 +186,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);
@@ -205,11 +233,20 @@ static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject
const char* const kClassPathName = "com/android/server/AssetAtlasService";
static JNINativeMethod gMethods[] = {
- { "nUploadAtlas", "(Landroid/view/GraphicBuffer;Landroid/graphics/Bitmap;)Z",
+ { "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",
(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));
}