summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2014-08-06 13:42:24 -0700
committerChris Craik <ccraik@google.com>2014-08-06 21:11:31 +0000
commit796475006f5d670e8383a2050f11719522437a43 (patch)
treeb7c017f959a270bf1e106b9e65f1b037fa54f584 /libs
parentd1a7fca1451bf4ab7f9b704c0bace180095c2237 (diff)
downloadframeworks_base-796475006f5d670e8383a2050f11719522437a43.zip
frameworks_base-796475006f5d670e8383a2050f11719522437a43.tar.gz
frameworks_base-796475006f5d670e8383a2050f11719522437a43.tar.bz2
Move bitmap transforms out of bitmap ops
bug:11359533 This allows us to deduplicate a lot between the two ops, and fixes the shader coordinate space for the left,top argument drawBitmap to match software. Change-Id: I53da05af9ee74c74e9e70b4ab8053190ca220b16
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/DisplayListOp.h46
-rw-r--r--libs/hwui/DisplayListRenderer.cpp47
-rw-r--r--libs/hwui/DisplayListRenderer.h8
-rwxr-xr-xlibs/hwui/OpenGLRenderer.cpp53
-rwxr-xr-xlibs/hwui/OpenGLRenderer.h8
-rw-r--r--libs/hwui/Renderer.h8
6 files changed, 41 insertions, 129 deletions
diff --git a/libs/hwui/DisplayListOp.h b/libs/hwui/DisplayListOp.h
index 777a35a..6883cc5 100644
--- a/libs/hwui/DisplayListOp.h
+++ b/libs/hwui/DisplayListOp.h
@@ -639,9 +639,10 @@ private:
class DrawBitmapOp : public DrawBoundedOp {
public:
- DrawBitmapOp(const SkBitmap* bitmap, float left, float top, const SkPaint* paint)
- : DrawBoundedOp(left, top, left + bitmap->width(), top + bitmap->height(), paint),
- mBitmap(bitmap), mAtlas(Caches::getInstance().assetAtlas) {
+ DrawBitmapOp(const SkBitmap* bitmap, const SkPaint* paint)
+ : DrawBoundedOp(0, 0, bitmap->width(), bitmap->height(), paint)
+ , mBitmap(bitmap)
+ , mAtlas(Caches::getInstance().assetAtlas) {
mEntry = mAtlas.getEntry(bitmap);
if (mEntry) {
mEntryGenerationId = mAtlas.getGenerationId();
@@ -650,8 +651,7 @@ public:
}
virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) {
- return renderer.drawBitmap(mBitmap, mLocalBounds.left, mLocalBounds.top,
- getPaint(renderer));
+ return renderer.drawBitmap(mBitmap, getPaint(renderer));
}
AssetAtlas::Entry* getAtlasEntry() {
@@ -745,35 +745,6 @@ protected:
UvMapper mUvMapper;
};
-class DrawBitmapMatrixOp : public DrawBoundedOp {
-public:
- DrawBitmapMatrixOp(const SkBitmap* bitmap, const SkMatrix& matrix, const SkPaint* paint)
- : DrawBoundedOp(paint), mBitmap(bitmap), mMatrix(matrix) {
- mLocalBounds.set(0, 0, bitmap->width(), bitmap->height());
- const mat4 transform(matrix);
- transform.mapRect(mLocalBounds);
- }
-
- virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) {
- return renderer.drawBitmap(mBitmap, mMatrix, getPaint(renderer));
- }
-
- virtual void output(int level, uint32_t logFlags) const {
- OP_LOG("Draw bitmap %p matrix " SK_MATRIX_STRING, mBitmap, SK_MATRIX_ARGS(&mMatrix));
- }
-
- virtual const char* name() { return "DrawBitmapMatrix"; }
-
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
- const DeferredDisplayState& state) {
- deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
- }
-
-private:
- const SkBitmap* mBitmap;
- const SkMatrix mMatrix;
-};
-
class DrawBitmapRectOp : public DrawBoundedOp {
public:
DrawBitmapRectOp(const SkBitmap* bitmap,
@@ -807,12 +778,11 @@ private:
class DrawBitmapDataOp : public DrawBitmapOp {
public:
- DrawBitmapDataOp(const SkBitmap* bitmap, float left, float top, const SkPaint* paint)
- : DrawBitmapOp(bitmap, left, top, paint) {}
+ DrawBitmapDataOp(const SkBitmap* bitmap, const SkPaint* paint)
+ : DrawBitmapOp(bitmap, paint) {}
virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) {
- return renderer.drawBitmapData(mBitmap, mLocalBounds.left,
- mLocalBounds.top, getPaint(renderer));
+ return renderer.drawBitmapData(mBitmap, getPaint(renderer));
}
virtual void output(int level, uint32_t logFlags) const {
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 5286ef8..b210e64 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -194,51 +194,42 @@ status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
return DrawGlInfo::kStatusDone;
}
-status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint) {
- bitmap = refBitmap(bitmap);
- paint = refPaint(paint);
-
- addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint));
- return DrawGlInfo::kStatusDone;
-}
-
-status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkMatrix& matrix,
- const SkPaint* paint) {
+status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) {
bitmap = refBitmap(bitmap);
paint = refPaint(paint);
- addDrawOp(new (alloc()) DrawBitmapMatrixOp(bitmap, matrix, paint));
+ addDrawOp(new (alloc()) DrawBitmapOp(bitmap, paint));
return DrawGlInfo::kStatusDone;
}
status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop,
float dstRight, float dstBottom, const SkPaint* paint) {
- bitmap = refBitmap(bitmap);
- paint = refPaint(paint);
-
- if (srcLeft == 0 && srcTop == 0 &&
- srcRight == bitmap->width() && srcBottom == bitmap->height() &&
- (srcBottom - srcTop == dstBottom - dstTop) &&
- (srcRight - srcLeft == dstRight - dstLeft)) {
+ if (srcLeft == 0 && srcTop == 0
+ && srcRight == bitmap->width() && srcBottom == bitmap->height()
+ && (srcBottom - srcTop == dstBottom - dstTop)
+ && (srcRight - srcLeft == dstRight - dstLeft)) {
// transform simple rect to rect drawing case into position bitmap ops, since they merge
- addDrawOp(new (alloc()) DrawBitmapOp(bitmap, dstLeft, dstTop, paint));
- return DrawGlInfo::kStatusDone;
- }
+ save(SkCanvas::kMatrix_SaveFlag);
+ translate(dstLeft, dstTop);
+ drawBitmap(bitmap, paint);
+ restore();
+ } else {
+ bitmap = refBitmap(bitmap);
+ paint = refPaint(paint);
- addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
- srcLeft, srcTop, srcRight, srcBottom,
- dstLeft, dstTop, dstRight, dstBottom, paint));
+ addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
+ srcLeft, srcTop, srcRight, srcBottom,
+ dstLeft, dstTop, dstRight, dstBottom, paint));
+ }
return DrawGlInfo::kStatusDone;
}
-status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint) {
+status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint) {
bitmap = refBitmapData(bitmap);
paint = refPaint(paint);
- addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, left, top, paint));
+ addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, paint));
return DrawGlInfo::kStatusDone;
}
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index d1d8572..1b3a48a 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -105,15 +105,11 @@ public:
virtual status_t drawColor(int color, SkXfermode::Mode mode);
// Bitmap-based
- virtual status_t drawBitmap(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint);
- virtual status_t drawBitmap(const SkBitmap* bitmap, const SkMatrix& matrix,
- const SkPaint* paint);
+ virtual status_t drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
virtual status_t drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop,
float dstRight, float dstBottom, const SkPaint* paint);
- virtual status_t drawBitmapData(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint);
+ virtual status_t drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint);
virtual status_t drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
const float* vertices, const int* colors, const SkPaint* paint);
virtual status_t drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 5fbef2e..e00d2e3 100755
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -2034,12 +2034,8 @@ status_t OpenGLRenderer::drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry*
return DrawGlInfo::kStatusDrew;
}
-status_t OpenGLRenderer::drawBitmap(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint) {
- const float right = left + bitmap->width();
- const float bottom = top + bitmap->height();
-
- if (quickRejectSetupScissor(left, top, right, bottom)) {
+status_t OpenGLRenderer::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) {
+ if (quickRejectSetupScissor(0, 0, bitmap->width(), bitmap->height())) {
return DrawGlInfo::kStatusDone;
}
@@ -2049,49 +2045,16 @@ status_t OpenGLRenderer::drawBitmap(const SkBitmap* bitmap, float left, float to
const AutoTexture autoCleanup(texture);
if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) {
- drawAlphaBitmap(texture, left, top, paint);
+ drawAlphaBitmap(texture, 0, 0, paint);
} else {
- drawTextureRect(left, top, right, bottom, texture, paint);
+ drawTextureRect(0, 0, bitmap->width(), bitmap->height(), texture, paint);
}
return DrawGlInfo::kStatusDrew;
}
-status_t OpenGLRenderer::drawBitmap(const SkBitmap* bitmap, const SkMatrix& matrix,
- const SkPaint* paint) {
- Rect r(0.0f, 0.0f, bitmap->width(), bitmap->height());
- const mat4 transform(matrix);
- transform.mapRect(r);
-
- if (quickRejectSetupScissor(r.left, r.top, r.right, r.bottom)) {
- return DrawGlInfo::kStatusDone;
- }
-
- mCaches.activeTexture(0);
- Texture* texture = getTexture(bitmap);
- if (!texture) return DrawGlInfo::kStatusDone;
- const AutoTexture autoCleanup(texture);
-
- // This could be done in a cheaper way, all we need is pass the matrix
- // to the vertex shader. The save/restore is a bit overkill.
- save(SkCanvas::kMatrix_SaveFlag);
- concatMatrix(matrix);
- if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) {
- drawAlphaBitmap(texture, 0.0f, 0.0f, paint);
- } else {
- drawTextureRect(0.0f, 0.0f, bitmap->width(), bitmap->height(), texture, paint);
- }
- restore();
-
- return DrawGlInfo::kStatusDrew;
-}
-
-status_t OpenGLRenderer::drawBitmapData(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint) {
- const float right = left + bitmap->width();
- const float bottom = top + bitmap->height();
-
- if (quickRejectSetupScissor(left, top, right, bottom)) {
+status_t OpenGLRenderer::drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint) {
+ if (quickRejectSetupScissor(0, 0, bitmap->width(), bitmap->height())) {
return DrawGlInfo::kStatusDone;
}
@@ -2100,9 +2063,9 @@ status_t OpenGLRenderer::drawBitmapData(const SkBitmap* bitmap, float left, floa
const AutoTexture autoCleanup(texture);
if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) {
- drawAlphaBitmap(texture, left, top, paint);
+ drawAlphaBitmap(texture, 0, 0, paint);
} else {
- drawTextureRect(left, top, right, bottom, texture, paint);
+ drawTextureRect(0, 0, bitmap->width(), bitmap->height(), texture, paint);
}
return DrawGlInfo::kStatusDrew;
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 3bc591f..fd228db 100755
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -161,17 +161,13 @@ public:
virtual status_t drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1);
virtual status_t drawLayer(Layer* layer, float x, float y);
- virtual status_t drawBitmap(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint);
+ virtual status_t drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
status_t drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount,
TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint);
- virtual status_t drawBitmap(const SkBitmap* bitmap, const SkMatrix& matrix,
- const SkPaint* paint);
virtual status_t drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop,
float dstRight, float dstBottom, const SkPaint* paint);
- virtual status_t drawBitmapData(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint);
+ virtual status_t drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint);
virtual status_t drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
const float* vertices, const int* colors, const SkPaint* paint);
status_t drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
diff --git a/libs/hwui/Renderer.h b/libs/hwui/Renderer.h
index 40a21e4..f5cd266 100644
--- a/libs/hwui/Renderer.h
+++ b/libs/hwui/Renderer.h
@@ -160,15 +160,11 @@ public:
virtual status_t drawColor(int color, SkXfermode::Mode mode) = 0;
// Bitmap-based
- virtual status_t drawBitmap(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint) = 0;
- virtual status_t drawBitmap(const SkBitmap* bitmap, const SkMatrix& matrix,
- const SkPaint* paint) = 0;
+ virtual status_t drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) = 0;
virtual status_t drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop,
float dstRight, float dstBottom, const SkPaint* paint) = 0;
- virtual status_t drawBitmapData(const SkBitmap* bitmap, float left, float top,
- const SkPaint* paint) = 0;
+ virtual status_t drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint) = 0;
virtual status_t drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
const float* vertices, const int* colors, const SkPaint* paint) = 0;
virtual status_t drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,