Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 758724fd authored by Romain Guy's avatar Romain Guy
Browse files

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
parent c0e55bd3
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -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;
    }

+8 −2
Original line number Diff line number Diff line
@@ -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();

+1 −1
Original line number Diff line number Diff line
@@ -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