Merge "GraphicsJNI Canvas cleanup"
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -47,11 +47,6 @@ static struct {
|
||||
jfieldID bottom;
|
||||
} 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");
|
||||
|
||||
|
||||
@@ -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,20 +219,13 @@ public class Canvas {
|
||||
}
|
||||
throwIfCannotDraw(bitmap);
|
||||
|
||||
native_setBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), true);
|
||||
native_setBitmap(mNativeCanvasWrapper, bitmap);
|
||||
mDensity = bitmap.mDensity;
|
||||
}
|
||||
|
||||
mBitmap = bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -46,41 +46,10 @@ namespace android {
|
||||
// This timeout is defined in nanoseconds (see EGL_KHR_fence_sync extension)
|
||||
#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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user