Pass Bitmap instead of SkBitmap in drawNinePatch & drawBitmapMesh
Test: refactoring cl. bug:32216791 Change-Id: I5adcd59daf752d36012456b0a9960c59d07e2e3d
This commit is contained in:
@@ -212,6 +212,12 @@ Bitmap& toBitmap(JNIEnv* env, jobject bitmap) {
|
||||
return localBitmap->bitmap();
|
||||
}
|
||||
|
||||
Bitmap& toBitmap(JNIEnv* env, jlong bitmapHandle) {
|
||||
SkASSERT(env);
|
||||
LocalScopedBitmap localBitmap(bitmapHandle);
|
||||
return localBitmap->bitmap();
|
||||
}
|
||||
|
||||
} // namespace bitmap
|
||||
|
||||
} // namespace android
|
||||
|
||||
@@ -42,6 +42,7 @@ jobject createBitmap(JNIEnv* env, Bitmap* bitmap,
|
||||
void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap);
|
||||
|
||||
Bitmap& toBitmap(JNIEnv* env, jobject bitmap);
|
||||
Bitmap& toBitmap(JNIEnv* env, jlong bitmapHandle);
|
||||
|
||||
/** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in
|
||||
sync with isPremultiplied
|
||||
|
||||
@@ -341,13 +341,12 @@ static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmap
|
||||
jlong paintHandle, jint dstDensity, jint srcDensity) {
|
||||
|
||||
Canvas* canvas = get_canvas(canvasHandle);
|
||||
SkBitmap skiaBitmap;
|
||||
bitmap::toSkBitmap(bitmapHandle, &skiaBitmap);
|
||||
Bitmap& bitmap = android::bitmap::toBitmap(env, bitmapHandle);
|
||||
const android::Res_png_9patch* chunk = reinterpret_cast<android::Res_png_9patch*>(chunkHandle);
|
||||
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
|
||||
|
||||
if (CC_LIKELY(dstDensity == srcDensity || dstDensity == 0 || srcDensity == 0)) {
|
||||
canvas->drawNinePatch(skiaBitmap, *chunk, left, top, right, bottom, paint);
|
||||
canvas->drawNinePatch(bitmap, *chunk, left, top, right, bottom, paint);
|
||||
} else {
|
||||
canvas->save(SaveFlags::MatrixClip);
|
||||
|
||||
@@ -361,7 +360,7 @@ static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmap
|
||||
}
|
||||
filteredPaint.setFilterQuality(kLow_SkFilterQuality);
|
||||
|
||||
canvas->drawNinePatch(skiaBitmap, *chunk, 0, 0, (right-left)/scale, (bottom-top)/scale,
|
||||
canvas->drawNinePatch(bitmap, *chunk, 0, 0, (right-left)/scale, (bottom-top)/scale,
|
||||
&filteredPaint);
|
||||
|
||||
canvas->restore();
|
||||
@@ -464,8 +463,7 @@ static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jobject jbi
|
||||
AutoJavaIntArray colorA(env, jcolors, colorIndex + ptCount);
|
||||
|
||||
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
|
||||
SkBitmap bitmap;
|
||||
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
|
||||
Bitmap& bitmap = android::bitmap::toBitmap(env, jbitmap);
|
||||
get_canvas(canvasHandle)->drawBitmapMesh(bitmap, meshWidth, meshHeight,
|
||||
vertA.ptr(), colorA.ptr(), paint);
|
||||
}
|
||||
|
||||
@@ -527,8 +527,10 @@ void RecordingCanvas::drawBitmap(Bitmap& hwuiBitmap, float srcLeft, float srcTop
|
||||
}
|
||||
}
|
||||
|
||||
void RecordingCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
|
||||
void RecordingCanvas::drawBitmapMesh(Bitmap& hwuiBitmap, int meshWidth, int meshHeight,
|
||||
const float* vertices, const int* colors, const SkPaint* paint) {
|
||||
SkBitmap bitmap;
|
||||
hwuiBitmap.getSkBitmap(&bitmap);
|
||||
int vertexCount = (meshWidth + 1) * (meshHeight + 1);
|
||||
addOp(alloc().create_trivial<BitmapMeshOp>(
|
||||
calcBoundsOfPoints(vertices, vertexCount * 2),
|
||||
@@ -539,9 +541,11 @@ void RecordingCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int
|
||||
refBuffer<int>(colors, vertexCount))); // 1 color per vertex
|
||||
}
|
||||
|
||||
void RecordingCanvas::drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& patch,
|
||||
void RecordingCanvas::drawNinePatch(Bitmap& hwuiBitmap, const android::Res_png_9patch& patch,
|
||||
float dstLeft, float dstTop, float dstRight, float dstBottom,
|
||||
const SkPaint* paint) {
|
||||
SkBitmap bitmap;
|
||||
hwuiBitmap.getSkBitmap(&bitmap);
|
||||
addOp(alloc().create_trivial<PatchOp>(
|
||||
Rect(dstLeft, dstTop, dstRight, dstBottom),
|
||||
*(mState.currentSnapshot()->transform),
|
||||
|
||||
@@ -181,9 +181,9 @@ public:
|
||||
virtual void drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop,
|
||||
float srcRight, float srcBottom, float dstLeft, float dstTop,
|
||||
float dstRight, float dstBottom, const SkPaint* paint) override;
|
||||
virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
|
||||
virtual void drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight,
|
||||
const float* vertices, const int* colors, const SkPaint* paint) override;
|
||||
virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
|
||||
virtual void drawNinePatch(Bitmap& bitmap, const android::Res_png_9patch& chunk,
|
||||
float dstLeft, float dstTop, float dstRight, float dstBottom,
|
||||
const SkPaint* paint) override;
|
||||
|
||||
|
||||
@@ -515,9 +515,10 @@ void SkiaCanvas::drawBitmap(Bitmap& hwuiBitmap, float srcLeft, float srcTop,
|
||||
mCanvas->drawBitmapRect(bitmap, srcRect, dstRect, paint);
|
||||
}
|
||||
|
||||
void SkiaCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
|
||||
void SkiaCanvas::drawBitmapMesh(Bitmap& hwuiBitmap, int meshWidth, int meshHeight,
|
||||
const float* vertices, const int* colors, const SkPaint* paint) {
|
||||
|
||||
SkBitmap bitmap;
|
||||
hwuiBitmap.getSkBitmap(&bitmap);
|
||||
const int ptCount = (meshWidth + 1) * (meshHeight + 1);
|
||||
const int indexCount = meshWidth * meshHeight * 6;
|
||||
|
||||
@@ -615,8 +616,10 @@ void SkiaCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshH
|
||||
indexCount, tmpPaint);
|
||||
}
|
||||
|
||||
void SkiaCanvas::drawNinePatch(const SkBitmap& bitmap, const Res_png_9patch& chunk,
|
||||
void SkiaCanvas::drawNinePatch(Bitmap& hwuiBitmap, const Res_png_9patch& chunk,
|
||||
float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) {
|
||||
SkBitmap bitmap;
|
||||
hwuiBitmap.getSkBitmap(&bitmap);
|
||||
SkRect bounds = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
|
||||
NinePatch::Draw(mCanvas.get(), bounds, bitmap, chunk, paint, nullptr);
|
||||
}
|
||||
|
||||
@@ -129,9 +129,9 @@ public:
|
||||
virtual void drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop,
|
||||
float srcRight, float srcBottom, float dstLeft, float dstTop,
|
||||
float dstRight, float dstBottom, const SkPaint* paint) override;
|
||||
virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
|
||||
virtual void drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight,
|
||||
const float* vertices, const int* colors, const SkPaint* paint) override;
|
||||
virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
|
||||
virtual void drawNinePatch(Bitmap& bitmap, const android::Res_png_9patch& chunk,
|
||||
float dstLeft, float dstTop, float dstRight, float dstBottom,
|
||||
const SkPaint* paint) override;
|
||||
|
||||
|
||||
@@ -225,9 +225,9 @@ public:
|
||||
virtual void drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop,
|
||||
float srcRight, float srcBottom, float dstLeft, float dstTop,
|
||||
float dstRight, float dstBottom, const SkPaint* paint) = 0;
|
||||
virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
|
||||
virtual void drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight,
|
||||
const float* vertices, const int* colors, const SkPaint* paint) = 0;
|
||||
virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
|
||||
virtual void drawNinePatch(Bitmap& bitmap, const android::Res_png_9patch& chunk,
|
||||
float dstLeft, float dstTop, float dstRight, float dstBottom,
|
||||
const SkPaint* paint) = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user