diff options
author | Romain Guy <romainguy@google.com> | 2013-02-27 11:53:12 -0800 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2013-02-27 11:53:12 -0800 |
commit | 758724fd09a1599f2c55130f81953cfa6c17c300 (patch) | |
tree | ca84f352115851317bf012534a69d748def6092e | |
parent | c0e55bd3cfe1d7be2276e4f528fee2231763a5c1 (diff) | |
download | frameworks_base-758724fd09a1599f2c55130f81953cfa6c17c300.zip frameworks_base-758724fd09a1599f2c55130f81953cfa6c17c300.tar.gz frameworks_base-758724fd09a1599f2c55130f81953cfa6c17c300.tar.bz2 |
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
-rw-r--r-- | libs/hwui/DisplayListOp.h | 15 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 10 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.h | 2 |
3 files changed, 15 insertions, 12 deletions
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 @@ public: */ 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 @@ public: 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 @@ void OpenGLRenderer::setupPaintFilter(int clearBits, int setBits) { 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 @@ public: 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 |