am 05dc201f: Merge "Remove Bitmap#getSkBitmap" into mnc-dev

* commit '05dc201ff64f6324c2726a8841af7021e7071b97':
  Remove Bitmap#getSkBitmap
This commit is contained in:
John Reck
2015-05-04 14:40:45 +00:00
committed by Android Git Automerger
11 changed files with 88 additions and 86 deletions

View File

@@ -271,7 +271,7 @@ public class DisplayListCanvas extends Canvas {
Bitmap bitmap = patch.getBitmap(); Bitmap bitmap = patch.getBitmap();
throwIfCannotDraw(bitmap); throwIfCannotDraw(bitmap);
final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk, nDrawPatch(mNativeCanvasWrapper, bitmap, patch.mNativeChunk,
dst.left, dst.top, dst.right, dst.bottom, nativePaint); dst.left, dst.top, dst.right, dst.bottom, nativePaint);
} }
@@ -281,11 +281,11 @@ public class DisplayListCanvas extends Canvas {
Bitmap bitmap = patch.getBitmap(); Bitmap bitmap = patch.getBitmap();
throwIfCannotDraw(bitmap); throwIfCannotDraw(bitmap);
final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
nDrawPatch(mNativeCanvasWrapper, bitmap.getSkBitmap(), patch.mNativeChunk, nDrawPatch(mNativeCanvasWrapper, bitmap, patch.mNativeChunk,
dst.left, dst.top, dst.right, dst.bottom, nativePaint); dst.left, dst.top, dst.right, dst.bottom, nativePaint);
} }
private static native void nDrawPatch(long renderer, long bitmap, long chunk, private static native void nDrawPatch(long renderer, Bitmap bitmap, long chunk,
float left, float top, float right, float bottom, long paint); float left, float top, float right, float bottom, long paint);
public void drawCircle(CanvasProperty<Float> cx, CanvasProperty<Float> cy, public void drawCircle(CanvasProperty<Float> cx, CanvasProperty<Float> cy,

View File

@@ -64,7 +64,7 @@ public:
return JNI_FALSE; return JNI_FALSE;
} }
static jlong validateNinePatchChunk(JNIEnv* env, jobject, jlong, jbyteArray obj) { static jlong validateNinePatchChunk(JNIEnv* env, jobject, jbyteArray obj) {
size_t chunkSize = env->GetArrayLength(obj); size_t chunkSize = env->GetArrayLength(obj);
if (chunkSize < (int) (sizeof(Res_png_9patch))) { if (chunkSize < (int) (sizeof(Res_png_9patch))) {
jniThrowRuntimeException(env, "Array too small for chunk."); jniThrowRuntimeException(env, "Array too small for chunk.");
@@ -88,13 +88,13 @@ public:
} }
} }
static void draw(JNIEnv* env, SkCanvas* canvas, SkRect& bounds, const SkBitmap* bitmap, static void draw(JNIEnv* env, SkCanvas* canvas, SkRect& bounds, const SkBitmap& bitmap,
Res_png_9patch* chunk, const SkPaint* paint, jint destDensity, jint srcDensity) { Res_png_9patch* chunk, const SkPaint* paint, jint destDensity, jint srcDensity) {
if (destDensity == srcDensity || destDensity == 0 || srcDensity == 0) { if (destDensity == srcDensity || destDensity == 0 || srcDensity == 0) {
ALOGV("Drawing unscaled 9-patch: (%g,%g)-(%g,%g)", ALOGV("Drawing unscaled 9-patch: (%g,%g)-(%g,%g)",
SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop), SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom)); SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom));
NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL); NinePatch_Draw(canvas, bounds, bitmap, *chunk, paint, NULL);
} else { } else {
canvas->save(); canvas->save();
@@ -111,25 +111,25 @@ public:
SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom), SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom),
srcDensity, destDensity); srcDensity, destDensity);
NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL); NinePatch_Draw(canvas, bounds, bitmap, *chunk, paint, NULL);
canvas->restore(); canvas->restore();
} }
} }
static void drawF(JNIEnv* env, jobject, jlong canvasHandle, jobject boundsRectF, static void drawF(JNIEnv* env, jobject, jlong canvasHandle, jobject boundsRectF,
jlong bitmapHandle, jlong chunkHandle, jlong paintHandle, jobject jbitmap, jlong chunkHandle, jlong paintHandle,
jint destDensity, jint srcDensity) { jint destDensity, jint srcDensity) {
SkCanvas* canvas = reinterpret_cast<Canvas*>(canvasHandle)->asSkCanvas(); SkCanvas* canvas = reinterpret_cast<Canvas*>(canvasHandle)->asSkCanvas();
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle); Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
SkASSERT(canvas); SkASSERT(canvas);
SkASSERT(boundsRectF); SkASSERT(boundsRectF);
SkASSERT(bitmap);
SkASSERT(chunk); SkASSERT(chunk);
// paint is optional // paint is optional
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
SkRect bounds; SkRect bounds;
GraphicsJNI::jrectf_to_rect(env, boundsRectF, &bounds); GraphicsJNI::jrectf_to_rect(env, boundsRectF, &bounds);
@@ -137,36 +137,36 @@ public:
} }
static void drawI(JNIEnv* env, jobject, jlong canvasHandle, jobject boundsRect, static void drawI(JNIEnv* env, jobject, jlong canvasHandle, jobject boundsRect,
jlong bitmapHandle, jlong chunkHandle, jlong paintHandle, jobject jbitmap, jlong chunkHandle, jlong paintHandle,
jint destDensity, jint srcDensity) { jint destDensity, jint srcDensity) {
SkCanvas* canvas = reinterpret_cast<Canvas*>(canvasHandle)->asSkCanvas(); SkCanvas* canvas = reinterpret_cast<Canvas*>(canvasHandle)->asSkCanvas();
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle); Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
SkASSERT(canvas); SkASSERT(canvas);
SkASSERT(boundsRect); SkASSERT(boundsRect);
SkASSERT(bitmap);
SkASSERT(chunk); SkASSERT(chunk);
// paint is optional // paint is optional
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
SkRect bounds; SkRect bounds;
GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds); GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds);
draw(env, canvas, bounds, bitmap, chunk, paint, destDensity, srcDensity); draw(env, canvas, bounds, bitmap, chunk, paint, destDensity, srcDensity);
} }
static jlong getTransparentRegion(JNIEnv* env, jobject, jlong bitmapHandle, static jlong getTransparentRegion(JNIEnv* env, jobject, jobject jbitmap,
jlong chunkHandle, jobject boundsRect) { jlong chunkHandle, jobject boundsRect) {
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle); Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle);
SkASSERT(bitmap);
SkASSERT(chunk); SkASSERT(chunk);
SkASSERT(boundsRect); SkASSERT(boundsRect);
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
SkRect bounds; SkRect bounds;
GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds); GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds);
SkRegion* region = NULL; SkRegion* region = NULL;
NinePatch_Draw(NULL, bounds, *bitmap, *chunk, NULL, &region); NinePatch_Draw(NULL, bounds, bitmap, *chunk, NULL, &region);
return reinterpret_cast<jlong>(region); return reinterpret_cast<jlong>(region);
} }
@@ -176,13 +176,16 @@ public:
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
static JNINativeMethod gNinePatchMethods[] = { static JNINativeMethod gNinePatchMethods[] = {
{ "isNinePatchChunk", "([B)Z", (void*) SkNinePatchGlue::isNinePatchChunk }, { "isNinePatchChunk", "([B)Z", (void*) SkNinePatchGlue::isNinePatchChunk },
{ "validateNinePatchChunk", "(J[B)J", (void*) SkNinePatchGlue::validateNinePatchChunk }, { "validateNinePatchChunk", "([B)J",
{ "nativeFinalize", "(J)V", (void*) SkNinePatchGlue::finalize }, (void*) SkNinePatchGlue::validateNinePatchChunk },
{ "nativeDraw", "(JLandroid/graphics/RectF;JJJII)V", (void*) SkNinePatchGlue::drawF }, { "nativeFinalize", "(J)V", (void*) SkNinePatchGlue::finalize },
{ "nativeDraw", "(JLandroid/graphics/Rect;JJJII)V", (void*) SkNinePatchGlue::drawI }, { "nativeDraw", "(JLandroid/graphics/RectF;Landroid/graphics/Bitmap;JJII)V",
{ "nativeGetTransparentRegion", "(JJLandroid/graphics/Rect;)J", (void*) SkNinePatchGlue::drawF },
(void*) SkNinePatchGlue::getTransparentRegion } { "nativeDraw", "(JLandroid/graphics/Rect;Landroid/graphics/Bitmap;JJII)V",
(void*) SkNinePatchGlue::drawI },
{ "nativeGetTransparentRegion", "(Landroid/graphics/Bitmap;JLandroid/graphics/Rect;)J",
(void*) SkNinePatchGlue::getTransparentRegion }
}; };
int register_android_graphics_NinePatch(JNIEnv* env) { int register_android_graphics_NinePatch(JNIEnv* env) {

View File

@@ -318,11 +318,12 @@ static void drawVertices(JNIEnv* env, jobject, jlong canvasHandle,
indices, indexCount, *paint); indices, indexCount, *paint);
} }
static void drawBitmap(JNIEnv* env, jobject jcanvas, jlong canvasHandle, jlong bitmapHandle, static void drawBitmap(JNIEnv* env, jobject jcanvas, jlong canvasHandle, jobject jbitmap,
jfloat left, jfloat top, jlong paintHandle, jint canvasDensity, jfloat left, jfloat top, jlong paintHandle, jint canvasDensity,
jint screenDensity, jint bitmapDensity) { jint screenDensity, jint bitmapDensity) {
Canvas* canvas = get_canvas(canvasHandle); Canvas* canvas = get_canvas(canvasHandle);
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
if (canvasDensity == bitmapDensity || canvasDensity == 0 || bitmapDensity == 0) { if (canvasDensity == bitmapDensity || canvasDensity == 0 || bitmapDensity == 0) {
@@ -332,9 +333,9 @@ static void drawBitmap(JNIEnv* env, jobject jcanvas, jlong canvasHandle, jlong b
filteredPaint = *paint; filteredPaint = *paint;
} }
filteredPaint.setFilterQuality(kLow_SkFilterQuality); filteredPaint.setFilterQuality(kLow_SkFilterQuality);
canvas->drawBitmap(*bitmap, left, top, &filteredPaint); canvas->drawBitmap(bitmap, left, top, &filteredPaint);
} else { } else {
canvas->drawBitmap(*bitmap, left, top, paint); canvas->drawBitmap(bitmap, left, top, paint);
} }
} else { } else {
canvas->save(SkCanvas::kMatrixClip_SaveFlag); canvas->save(SkCanvas::kMatrixClip_SaveFlag);
@@ -348,37 +349,39 @@ static void drawBitmap(JNIEnv* env, jobject jcanvas, jlong canvasHandle, jlong b
} }
filteredPaint.setFilterQuality(kLow_SkFilterQuality); filteredPaint.setFilterQuality(kLow_SkFilterQuality);
canvas->drawBitmap(*bitmap, 0, 0, &filteredPaint); canvas->drawBitmap(bitmap, 0, 0, &filteredPaint);
canvas->restore(); canvas->restore();
} }
} }
static void drawBitmapMatrix(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, static void drawBitmapMatrix(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap,
jlong matrixHandle, jlong paintHandle) { jlong matrixHandle, jlong paintHandle) {
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
get_canvas(canvasHandle)->drawBitmap(*bitmap, *matrix, paint); SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
get_canvas(canvasHandle)->drawBitmap(bitmap, *matrix, paint);
} }
static void drawBitmapRect(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, static void drawBitmapRect(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap,
float srcLeft, float srcTop, float srcRight, float srcBottom, float srcLeft, float srcTop, float srcRight, float srcBottom,
float dstLeft, float dstTop, float dstRight, float dstBottom, float dstLeft, float dstTop, float dstRight, float dstBottom,
jlong paintHandle, jint screenDensity, jint bitmapDensity) { jlong paintHandle, jint screenDensity, jint bitmapDensity) {
Canvas* canvas = get_canvas(canvasHandle); Canvas* canvas = get_canvas(canvasHandle);
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
if (screenDensity != 0 && screenDensity != bitmapDensity) { if (screenDensity != 0 && screenDensity != bitmapDensity) {
Paint filteredPaint; Paint filteredPaint;
if (paint) { if (paint) {
filteredPaint = *paint; filteredPaint = *paint;
} }
filteredPaint.setFilterQuality(kLow_SkFilterQuality); filteredPaint.setFilterQuality(kLow_SkFilterQuality);
canvas->drawBitmap(*bitmap, srcLeft, srcTop, srcRight, srcBottom, canvas->drawBitmap(bitmap, srcLeft, srcTop, srcRight, srcBottom,
dstLeft, dstTop, dstRight, dstBottom, &filteredPaint); dstLeft, dstTop, dstRight, dstBottom, &filteredPaint);
} else { } else {
canvas->drawBitmap(*bitmap, srcLeft, srcTop, srcRight, srcBottom, canvas->drawBitmap(bitmap, srcLeft, srcTop, srcRight, srcBottom,
dstLeft, dstTop, dstRight, dstBottom, paint); dstLeft, dstTop, dstRight, dstBottom, paint);
} }
} }
@@ -406,16 +409,17 @@ static void drawBitmapArray(JNIEnv* env, jobject, jlong canvasHandle,
get_canvas(canvasHandle)->drawBitmap(bitmap, x, y, paint); get_canvas(canvasHandle)->drawBitmap(bitmap, x, y, paint);
} }
static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap,
jint meshWidth, jint meshHeight, jfloatArray jverts, jint meshWidth, jint meshHeight, jfloatArray jverts,
jint vertIndex, jintArray jcolors, jint colorIndex, jlong paintHandle) { jint vertIndex, jintArray jcolors, jint colorIndex, jlong paintHandle) {
const int ptCount = (meshWidth + 1) * (meshHeight + 1); const int ptCount = (meshWidth + 1) * (meshHeight + 1);
AutoJavaFloatArray vertA(env, jverts, vertIndex + (ptCount << 1)); AutoJavaFloatArray vertA(env, jverts, vertIndex + (ptCount << 1));
AutoJavaIntArray colorA(env, jcolors, colorIndex + ptCount); AutoJavaIntArray colorA(env, jcolors, colorIndex + ptCount);
const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
get_canvas(canvasHandle)->drawBitmapMesh(*bitmap, meshWidth, meshHeight, SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
get_canvas(canvasHandle)->drawBitmapMesh(bitmap, meshWidth, meshHeight,
vertA.ptr(), colorA.ptr(), paint); vertA.ptr(), colorA.ptr(), paint);
} }
@@ -700,11 +704,11 @@ static JNINativeMethod gMethods[] = {
{"native_drawArc","(JFFFFFFZJ)V", (void*) CanvasJNI::drawArc}, {"native_drawArc","(JFFFFFFZJ)V", (void*) CanvasJNI::drawArc},
{"native_drawPath","(JJJ)V", (void*) CanvasJNI::drawPath}, {"native_drawPath","(JJJ)V", (void*) CanvasJNI::drawPath},
{"nativeDrawVertices", "(JII[FI[FI[II[SIIJ)V", (void*)CanvasJNI::drawVertices}, {"nativeDrawVertices", "(JII[FI[FI[II[SIIJ)V", (void*)CanvasJNI::drawVertices},
{"native_drawBitmap","(JJFFJIII)V", (void*) CanvasJNI::drawBitmap}, {"native_drawBitmap","(JLandroid/graphics/Bitmap;FFJIII)V", (void*) CanvasJNI::drawBitmap},
{"nativeDrawBitmapMatrix", "(JJJJ)V", (void*)CanvasJNI::drawBitmapMatrix}, {"nativeDrawBitmapMatrix", "(JLandroid/graphics/Bitmap;JJ)V", (void*)CanvasJNI::drawBitmapMatrix},
{"native_drawBitmap","(JJFFFFFFFFJII)V", (void*) CanvasJNI::drawBitmapRect}, {"native_drawBitmap","(JLandroid/graphics/Bitmap;FFFFFFFFJII)V", (void*) CanvasJNI::drawBitmapRect},
{"native_drawBitmap", "(J[IIIFFIIZJ)V", (void*)CanvasJNI::drawBitmapArray}, {"native_drawBitmap", "(J[IIIFFIIZJ)V", (void*)CanvasJNI::drawBitmapArray},
{"nativeDrawBitmapMesh", "(JJII[FI[IIJ)V", (void*)CanvasJNI::drawBitmapMesh}, {"nativeDrawBitmapMesh", "(JLandroid/graphics/Bitmap;II[FI[IIJ)V", (void*)CanvasJNI::drawBitmapMesh},
{"native_drawText","(J[CIIFFIJJ)V", (void*) CanvasJNI::drawTextChars}, {"native_drawText","(J[CIIFFIJJ)V", (void*) CanvasJNI::drawTextChars},
{"native_drawText","(JLjava/lang/String;IIFFIJJ)V", (void*) CanvasJNI::drawTextString}, {"native_drawText","(JLjava/lang/String;IIFFIJJ)V", (void*) CanvasJNI::drawTextString},
{"native_drawTextRun","(J[CIIIIFFZJJ)V", (void*) CanvasJNI::drawTextRunChars}, {"native_drawTextRun","(J[CIIIIFFZJJ)V", (void*) CanvasJNI::drawTextRunChars},

View File

@@ -132,10 +132,10 @@ static jint android_view_DisplayListCanvas_getMaxTextureHeight(JNIEnv* env, jobj
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static void android_view_DisplayListCanvas_drawPatch(JNIEnv* env, jobject clazz, static void android_view_DisplayListCanvas_drawPatch(JNIEnv* env, jobject clazz,
jlong rendererPtr, jlong bitmapPtr, jlong patchPtr, jlong rendererPtr, jobject jbitmap, jlong patchPtr,
float left, float top, float right, float bottom, jlong paintPtr) { float left, float top, float right, float bottom, jlong paintPtr) {
SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapPtr); SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(patchPtr); Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(patchPtr);
Paint* paint = reinterpret_cast<Paint*>(paintPtr); Paint* paint = reinterpret_cast<Paint*>(paintPtr);
@@ -273,7 +273,7 @@ static JNINativeMethod gMethods[] = {
{ "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction }, { "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction },
{ "nDrawPatch", "(JJJFFFFJ)V", (void*) android_view_DisplayListCanvas_drawPatch }, { "nDrawPatch", "(JLandroid/graphics/Bitmap;JFFFFJ)V", (void*) android_view_DisplayListCanvas_drawPatch },
{ "nDrawRects", "(JJJ)V", (void*) android_view_DisplayListCanvas_drawRegionAsRects }, { "nDrawRects", "(JJJ)V", (void*) android_view_DisplayListCanvas_drawRegionAsRects },
{ "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_DisplayListCanvas_drawRoundRectProps }, { "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_DisplayListCanvas_drawRoundRectProps },

View File

@@ -1568,11 +1568,6 @@ public final class Bitmap implements Parcelable {
nativePrepareToDraw(mSkBitmapPtr); nativePrepareToDraw(mSkBitmapPtr);
} }
/** @hide */
public final long getSkBitmap() {
return mSkBitmapPtr;
}
/** /**
* Refs the underlying SkPixelRef and returns a pointer to it. * Refs the underlying SkPixelRef and returns a pointer to it.
* *

View File

@@ -1323,7 +1323,7 @@ public class Canvas {
*/ */
public void drawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint) { public void drawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint) {
throwIfCannotDraw(bitmap); throwIfCannotDraw(bitmap);
native_drawBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), left, top, native_drawBitmap(mNativeCanvasWrapper, bitmap, left, top,
paint != null ? paint.getNativeInstance() : 0, mDensity, mScreenDensity, bitmap.mDensity); paint != null ? paint.getNativeInstance() : 0, mDensity, mScreenDensity, bitmap.mDensity);
} }
@@ -1369,7 +1369,7 @@ public class Canvas {
bottom = src.bottom; bottom = src.bottom;
} }
native_drawBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), left, top, right, bottom, native_drawBitmap(mNativeCanvasWrapper, bitmap, left, top, right, bottom,
dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity, dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,
bitmap.mDensity); bitmap.mDensity);
} }
@@ -1416,7 +1416,7 @@ public class Canvas {
bottom = src.bottom; bottom = src.bottom;
} }
native_drawBitmap(mNativeCanvasWrapper, bitmap.getSkBitmap(), left, top, right, bottom, native_drawBitmap(mNativeCanvasWrapper, bitmap, left, top, right, bottom,
dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity, dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,
bitmap.mDensity); bitmap.mDensity);
} }
@@ -1497,7 +1497,7 @@ public class Canvas {
* @param paint May be null. The paint used to draw the bitmap * @param paint May be null. The paint used to draw the bitmap
*/ */
public void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint) { public void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint) {
nativeDrawBitmapMatrix(mNativeCanvasWrapper, bitmap.getSkBitmap(), matrix.ni(), nativeDrawBitmapMatrix(mNativeCanvasWrapper, bitmap, matrix.ni(),
paint != null ? paint.getNativeInstance() : 0); paint != null ? paint.getNativeInstance() : 0);
} }
@@ -1552,7 +1552,7 @@ public class Canvas {
// no mul by 2, since we need only 1 color per vertex // no mul by 2, since we need only 1 color per vertex
checkRange(colors.length, colorOffset, count); checkRange(colors.length, colorOffset, count);
} }
nativeDrawBitmapMesh(mNativeCanvasWrapper, bitmap.getSkBitmap(), meshWidth, meshHeight, nativeDrawBitmapMesh(mNativeCanvasWrapper, bitmap, meshWidth, meshHeight,
verts, vertOffset, colors, colorOffset, verts, vertOffset, colors, colorOffset,
paint != null ? paint.getNativeInstance() : 0); paint != null ? paint.getNativeInstance() : 0);
} }
@@ -2062,13 +2062,13 @@ public class Canvas {
private static native void native_drawPath(long nativeCanvas, private static native void native_drawPath(long nativeCanvas,
long nativePath, long nativePath,
long nativePaint); long nativePaint);
private native void native_drawBitmap(long nativeCanvas, long nativeBitmap, private native void native_drawBitmap(long nativeCanvas, Bitmap bitmap,
float left, float top, float left, float top,
long nativePaintOrZero, long nativePaintOrZero,
int canvasDensity, int canvasDensity,
int screenDensity, int screenDensity,
int bitmapDensity); int bitmapDensity);
private native void native_drawBitmap(long nativeCanvas, long nativeBitmap, private native void native_drawBitmap(long nativeCanvas, Bitmap bitmap,
float srcLeft, float srcTop, float srcRight, float srcBottom, float srcLeft, float srcTop, float srcRight, float srcBottom,
float dstLeft, float dstTop, float dstRight, float dstBottom, float dstLeft, float dstTop, float dstRight, float dstBottom,
long nativePaintOrZero, int screenDensity, int bitmapDensity); long nativePaintOrZero, int screenDensity, int bitmapDensity);
@@ -2078,11 +2078,11 @@ public class Canvas {
boolean hasAlpha, boolean hasAlpha,
long nativePaintOrZero); long nativePaintOrZero);
private static native void nativeDrawBitmapMatrix(long nativeCanvas, private static native void nativeDrawBitmapMatrix(long nativeCanvas,
long nativeBitmap, Bitmap bitmap,
long nativeMatrix, long nativeMatrix,
long nativePaint); long nativePaint);
private static native void nativeDrawBitmapMesh(long nativeCanvas, private static native void nativeDrawBitmapMesh(long nativeCanvas,
long nativeBitmap, Bitmap bitmap,
int meshWidth, int meshHeight, int meshWidth, int meshHeight,
float[] verts, int vertOffset, float[] verts, int vertOffset,
int[] colors, int colorOffset, int[] colors, int colorOffset,

View File

@@ -98,7 +98,7 @@ public class NinePatch {
public NinePatch(Bitmap bitmap, byte[] chunk, String srcName) { public NinePatch(Bitmap bitmap, byte[] chunk, String srcName) {
mBitmap = bitmap; mBitmap = bitmap;
mSrcName = srcName; mSrcName = srcName;
mNativeChunk = validateNinePatchChunk(mBitmap.getSkBitmap(), chunk); mNativeChunk = validateNinePatchChunk(chunk);
} }
/** /**
@@ -199,12 +199,12 @@ public class NinePatch {
} }
void drawSoftware(Canvas canvas, RectF location, Paint paint) { void drawSoftware(Canvas canvas, RectF location, Paint paint) {
nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap.getSkBitmap(), mNativeChunk, nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap, mNativeChunk,
paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity); paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity);
} }
void drawSoftware(Canvas canvas, Rect location, Paint paint) { void drawSoftware(Canvas canvas, Rect location, Paint paint) {
nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap.getSkBitmap(), mNativeChunk, nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap, mNativeChunk,
paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity); paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity);
} }
@@ -252,7 +252,7 @@ public class NinePatch {
* that are transparent. * that are transparent.
*/ */
public final Region getTransparentRegion(Rect bounds) { public final Region getTransparentRegion(Rect bounds) {
long r = nativeGetTransparentRegion(mBitmap.getSkBitmap(), mNativeChunk, bounds); long r = nativeGetTransparentRegion(mBitmap, mNativeChunk, bounds);
return r != 0 ? new Region(r) : null; return r != 0 ? new Region(r) : null;
} }
@@ -271,11 +271,11 @@ public class NinePatch {
* If validation is successful, this method returns a native Res_png_9patch* * If validation is successful, this method returns a native Res_png_9patch*
* object used by the renderers. * object used by the renderers.
*/ */
private static native long validateNinePatchChunk(long bitmap, byte[] chunk); private static native long validateNinePatchChunk(byte[] chunk);
private static native void nativeFinalize(long chunk); private static native void nativeFinalize(long chunk);
private static native void nativeDraw(long canvas_instance, RectF loc, long bitmap_instance, private static native void nativeDraw(long canvas_instance, RectF loc, Bitmap bitmap_instance,
long c, long paint_instance_or_null, int destDensity, int srcDensity); long c, long paint_instance_or_null, int destDensity, int srcDensity);
private static native void nativeDraw(long canvas_instance, Rect loc, long bitmap_instance, private static native void nativeDraw(long canvas_instance, Rect loc, Bitmap bitmap_instance,
long c, long paint_instance_or_null, int destDensity, int srcDensity); long c, long paint_instance_or_null, int destDensity, int srcDensity);
private static native long nativeGetTransparentRegion(long bitmap, long chunk, Rect location); private static native long nativeGetTransparentRegion(Bitmap bitmap, long chunk, Rect location);
} }

View File

@@ -218,7 +218,7 @@ void DisplayListCanvas::drawLayer(DeferredLayerUpdater* layerHandle, float x, fl
} }
void DisplayListCanvas::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { void DisplayListCanvas::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) {
bitmap = refBitmap(bitmap); bitmap = refBitmap(*bitmap);
paint = refPaint(paint); paint = refPaint(paint);
addDrawOp(new (alloc()) DrawBitmapOp(bitmap, paint)); addDrawOp(new (alloc()) DrawBitmapOp(bitmap, paint));
@@ -284,7 +284,7 @@ void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, float srcLeft, float
dstRight = srcRight - srcLeft; dstRight = srcRight - srcLeft;
dstBottom = srcBottom - srcTop; dstBottom = srcBottom - srcTop;
addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(&bitmap), addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(bitmap),
srcLeft, srcTop, srcRight, srcBottom, srcLeft, srcTop, srcRight, srcBottom,
dstLeft, dstTop, dstRight, dstBottom, paint)); dstLeft, dstTop, dstRight, dstBottom, paint));
restore(); restore();
@@ -292,7 +292,7 @@ void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, float srcLeft, float
} }
} }
addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(&bitmap), addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(bitmap),
srcLeft, srcTop, srcRight, srcBottom, srcLeft, srcTop, srcRight, srcBottom,
dstLeft, dstTop, dstRight, dstBottom, paint)); dstLeft, dstTop, dstRight, dstBottom, paint));
} }
@@ -305,17 +305,17 @@ void DisplayListCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, in
paint = refPaint(paint); paint = refPaint(paint);
colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex
addDrawOp(new (alloc()) DrawBitmapMeshOp(refBitmap(&bitmap), meshWidth, meshHeight, addDrawOp(new (alloc()) DrawBitmapMeshOp(refBitmap(bitmap), meshWidth, meshHeight,
vertices, colors, paint)); vertices, colors, paint));
} }
void DisplayListCanvas::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch, void DisplayListCanvas::drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch,
float left, float top, float right, float bottom, const SkPaint* paint) { float left, float top, float right, float bottom, const SkPaint* paint) {
bitmap = refBitmap(bitmap); const SkBitmap* bitmapPtr = refBitmap(bitmap);
patch = refPatch(patch); patch = refPatch(patch);
paint = refPaint(paint); paint = refPaint(paint);
addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint)); addDrawOp(new (alloc()) DrawPatchOp(bitmapPtr, patch, left, top, right, bottom, paint));
} }
void DisplayListCanvas::drawColor(int color, SkXfermode::Mode mode) { void DisplayListCanvas::drawColor(int color, SkXfermode::Mode mode) {

View File

@@ -98,7 +98,7 @@ public:
// Bitmap-based // Bitmap-based
void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint); void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
// TODO: move drawPatch() to Canvas.h // TODO: move drawPatch() to Canvas.h
void drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch, void drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch,
float left, float top, float right, float bottom, const SkPaint* paint); float left, float top, float right, float bottom, const SkPaint* paint);
// Shapes // Shapes
@@ -345,7 +345,7 @@ private:
return cachedRegion; return cachedRegion;
} }
inline const SkBitmap* refBitmap(const SkBitmap* bitmap) { inline const SkBitmap* refBitmap(const SkBitmap& bitmap) {
// Note that this assumes the bitmap is immutable. There are cases this won't handle // Note that this assumes the bitmap is immutable. There are cases this won't handle
// correctly, such as creating the bitmap from scratch, drawing with it, changing its // correctly, such as creating the bitmap from scratch, drawing with it, changing its
// contents, and drawing again. The only fix would be to always copy it the first time, // contents, and drawing again. The only fix would be to always copy it the first time,

View File

@@ -59,13 +59,13 @@ void ResourceCache::unlock() {
mLock.unlock(); mLock.unlock();
} }
const SkBitmap* ResourceCache::insert(const SkBitmap* bitmapResource) { const SkBitmap* ResourceCache::insert(const SkBitmap& bitmapResource) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
BitmapKey bitmapKey(bitmapResource); BitmapKey bitmapKey(bitmapResource);
ssize_t index = mBitmapCache.indexOfKey(bitmapKey); ssize_t index = mBitmapCache.indexOfKey(bitmapKey);
if (index == NAME_NOT_FOUND) { if (index == NAME_NOT_FOUND) {
SkBitmap* cachedBitmap = new SkBitmap(*bitmapResource); SkBitmap* cachedBitmap = new SkBitmap(bitmapResource);
index = mBitmapCache.add(bitmapKey, cachedBitmap); index = mBitmapCache.add(bitmapKey, cachedBitmap);
return cachedBitmap; return cachedBitmap;
} }
@@ -121,7 +121,7 @@ void ResourceCache::decrementRefcountLocked(void* resource) {
} }
void ResourceCache::decrementRefcountLocked(const SkBitmap* bitmapResource) { void ResourceCache::decrementRefcountLocked(const SkBitmap* bitmapResource) {
BitmapKey bitmapKey(bitmapResource); BitmapKey bitmapKey(*bitmapResource);
ssize_t index = mBitmapCache.indexOfKey(bitmapKey); ssize_t index = mBitmapCache.indexOfKey(bitmapKey);
LOG_ALWAYS_FATAL_IF(index == NAME_NOT_FOUND, LOG_ALWAYS_FATAL_IF(index == NAME_NOT_FOUND,

View File

@@ -53,11 +53,11 @@ public:
class BitmapKey { class BitmapKey {
public: public:
BitmapKey(const SkBitmap* bitmap) BitmapKey(const SkBitmap& bitmap)
: mRefCount(1) : mRefCount(1)
, mBitmapDimensions(bitmap->dimensions()) , mBitmapDimensions(bitmap.dimensions())
, mPixelRefOrigin(bitmap->pixelRefOrigin()) , mPixelRefOrigin(bitmap.pixelRefOrigin())
, mPixelRefStableID(bitmap->pixelRef()->getStableID()) { } , mPixelRefStableID(bitmap.pixelRef()->getStableID()) { }
void operator=(const BitmapKey& other); void operator=(const BitmapKey& other);
bool operator==(const BitmapKey& other) const; bool operator==(const BitmapKey& other) const;
@@ -101,7 +101,7 @@ public:
* The cache stores a copy of the provided resource or refs an existing resource * The cache stores a copy of the provided resource or refs an existing resource
* if the bitmap has previously been inserted and returns the cached copy. * if the bitmap has previously been inserted and returns the cached copy.
*/ */
const SkBitmap* insert(const SkBitmap* resource); const SkBitmap* insert(const SkBitmap& resource);
void incrementRefcount(const Res_png_9patch* resource); void incrementRefcount(const Res_png_9patch* resource);