Don't increment the paint's generation ID when drawing bitmaps
When the renderer draws a bitmap as part of a display list with an
alpha < 1.0f, the paint is temporarily modified to alter the opacity
of the bitmap. This has the side effect of increasing the paint's
generation ID counter which can break paint caching.
Change-Id: I5055d059ad1639829fa50af3d946e296c4dab877
diff --git a/libs/hwui/DisplayListOp.h b/libs/hwui/DisplayListOp.h
index 97812d4..9db8fe8 100644
--- a/libs/hwui/DisplayListOp.h
+++ b/libs/hwui/DisplayListOp.h
@@ -176,8 +176,8 @@
*/
DeferredDisplayState state;
protected:
- SkPaint* getPaint(OpenGLRenderer& renderer) {
- return renderer.filterPaint(mPaint);
+ SkPaint* getPaint(OpenGLRenderer& renderer, bool alwaysCopy = false) {
+ return renderer.filterPaint(mPaint, alwaysCopy);
}
SkPaint* mPaint; // should be accessed via getPaint() when applying
@@ -643,16 +643,13 @@
virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty, uint32_t level,
bool caching, int multipliedAlpha) {
- SkPaint* paint = getPaint(renderer);
- int oldAlpha = -1;
- if (caching && multipliedAlpha < 255) {
- oldAlpha = paint->getAlpha();
+ bool makeCopy = caching && multipliedAlpha < 255;
+ SkPaint* paint = getPaint(renderer, makeCopy);
+ if (makeCopy) {
+ // The paint is safe to modify since we're working on a copy
paint->setAlpha(multipliedAlpha);
}
status_t ret = renderer.drawBitmap(mBitmap, mLocalBounds.left, mLocalBounds.top, paint);
- if (oldAlpha >= 0) {
- paint->setAlpha(oldAlpha);
- }
return ret;
}
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 34d1c98..9df0c58 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -2942,8 +2942,14 @@
mDrawModifiers.mPaintFilterSetBits = setBits & SkPaint::kAllFlags;
}
-SkPaint* OpenGLRenderer::filterPaint(SkPaint* paint) {
- if (CC_LIKELY(!mDrawModifiers.mHasDrawFilter || !paint)) return paint;
+SkPaint* OpenGLRenderer::filterPaint(SkPaint* paint, bool alwaysCopy) {
+ if (CC_LIKELY(!mDrawModifiers.mHasDrawFilter || !paint)) {
+ if (CC_UNLIKELY(alwaysCopy)) {
+ mFilteredPaint = *paint;
+ return &mFilteredPaint;
+ }
+ return paint;
+ }
uint32_t flags = paint->getFlags();
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 80f2081..9144a33 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -259,7 +259,7 @@
virtual void resetPaintFilter();
virtual void setupPaintFilter(int clearBits, int setBits);
- SkPaint* filterPaint(SkPaint* paint);
+ SkPaint* filterPaint(SkPaint* paint, bool alwaysCopy = false);
bool disallowDeferral() {
// returns true if the OpenGLRenderer's state can be completely represented by