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

Commit d44fbe55 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Keep the SkPaint used when creating a layer.

This will allow us to inspect the paint for thing other than
color and xfermode, such as SkColorFilters and SkShaders.

bug: 10650594
Change-Id: I2c3ddd07a3966e1e77af34136307e2b59b2898c1
parent 8eea3ea5
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -451,8 +451,7 @@ void DisplayList::setViewProperties(OpenGLRenderer& renderer, T& handler,
            }

            SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
                    0, 0, mRight - mLeft, mBottom - mTop,
                    mAlpha * 255, SkXfermode::kSrcOver_Mode, saveFlags);
                    0, 0, mRight - mLeft, mBottom - mTop, mAlpha * 255, saveFlags);
            handler(op, PROPERTY_SAVECOUNT, mClipToBounds);
        }
    }
+15 −17
Original line number Diff line number Diff line
@@ -327,9 +327,13 @@ private:

class SaveLayerOp : public StateOp {
public:
    SaveLayerOp(float left, float top, float right, float bottom,
            int alpha, SkXfermode::Mode mode, int flags)
            : mArea(left, top, right, bottom), mAlpha(alpha), mMode(mode), mFlags(flags) {}
    SaveLayerOp(float left, float top, float right, float bottom, int alpha, int flags)
            : mArea(left, top, right, bottom), mPaint(&mCachedPaint), mFlags(flags) {
        mCachedPaint.setAlpha(alpha);
    }

    SaveLayerOp(float left, float top, float right, float bottom, const SkPaint* paint, int flags)
            : mArea(left, top, right, bottom), mPaint(paint), mFlags(flags) {}

    virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level,
            bool useQuickReject) {
@@ -340,11 +344,11 @@ public:
        // NOTE: don't issue full saveLayer, since that has side effects/is costly. instead just
        // setup the snapshot for deferral, and re-issue the op at flush time
        deferStruct.mRenderer.saveLayerDeferred(mArea.left, mArea.top, mArea.right, mArea.bottom,
                mAlpha, mMode, mFlags);
                mPaint, mFlags);
    }

    virtual void applyState(OpenGLRenderer& renderer, int saveCount) const {
        renderer.saveLayer(mArea.left, mArea.top, mArea.right, mArea.bottom, mAlpha, mMode, mFlags);
        renderer.saveLayer(mArea.left, mArea.top, mArea.right, mArea.bottom, mPaint, mFlags);
    }

    virtual void output(int level, uint32_t logFlags) const {
@@ -357,21 +361,15 @@ public:
    int getFlags() { return mFlags; }

private:
    // Special case, reserved for direct DisplayList usage
    SaveLayerOp() {}
    DisplayListOp* reinit(float left, float top, float right, float bottom,
            int alpha, SkXfermode::Mode mode, int flags) {
        mArea.set(left, top, right, bottom);
        mAlpha = alpha;
        mMode = mode;
        mFlags = flags;
        return this;
    bool isSaveLayerAlpha() const {
        SkXfermode::Mode mode = OpenGLRenderer::getXfermodeDirect(mPaint);
        int alpha = OpenGLRenderer::getAlphaDirect(mPaint);
        return alpha < 255 && mode == SkXfermode::kSrcOver_Mode;
    }

    bool isSaveLayerAlpha() const { return mAlpha < 255 && mMode == SkXfermode::kSrcOver_Mode; }
    Rect mArea;
    int mAlpha;
    SkXfermode::Mode mMode;
    const SkPaint* mPaint;
    SkPaint mCachedPaint;
    int mFlags;
};

+3 −2
Original line number Diff line number Diff line
@@ -182,8 +182,9 @@ void DisplayListRenderer::onSnapshotRestored(const Snapshot& removed, const Snap
}

int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
        int alpha, SkXfermode::Mode mode, int flags) {
    addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, alpha, mode, flags));
        const SkPaint* paint, int flags) {
    paint = refPaint(paint);
    addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, paint, flags));
    return StatefulBaseRenderer::save(flags);
}

+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ public:
    virtual void restore();
    virtual void restoreToCount(int saveCount);
    virtual int saveLayer(float left, float top, float right, float bottom,
            int alpha, SkXfermode::Mode mode, int flags);
            const SkPaint* paint, int flags);

    // Matrix
    virtual void translate(float dx, float dy, float dz);
+9 −5
Original line number Diff line number Diff line
@@ -731,11 +731,11 @@ void OpenGLRenderer::onSnapshotRestored(const Snapshot& removed, const Snapshot&
///////////////////////////////////////////////////////////////////////////////

int OpenGLRenderer::saveLayer(float left, float top, float right, float bottom,
        int alpha, SkXfermode::Mode mode, int flags) {
        const SkPaint* paint, int flags) {
    const int count = saveSnapshot(flags);

    if (!currentSnapshot()->isIgnored()) {
        createLayer(left, top, right, bottom, alpha, mode, flags);
        createLayer(left, top, right, bottom, paint, flags);
    }

    return count;
@@ -786,7 +786,7 @@ void OpenGLRenderer::updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect
}

int OpenGLRenderer::saveLayerDeferred(float left, float top, float right, float bottom,
        int alpha, SkXfermode::Mode mode, int flags) {
        const SkPaint* paint, int flags) {
    const int count = saveSnapshot(flags);

    if (!currentSnapshot()->isIgnored() && (flags & SkCanvas::kClipToLayer_SaveFlag)) {
@@ -797,7 +797,7 @@ int OpenGLRenderer::saveLayerDeferred(float left, float top, float right, float
        Rect bounds(left, top, right, bottom);
        Rect clip;
        calculateLayerBoundsAndClip(bounds, clip, true);
        updateSnapshotIgnoreForLayer(bounds, clip, true, alpha);
        updateSnapshotIgnoreForLayer(bounds, clip, true, getAlphaDirect(paint));

        if (!currentSnapshot()->isIgnored()) {
            mSnapshot->resetTransform(-bounds.left, -bounds.top, 0.0f);
@@ -862,12 +862,15 @@ int OpenGLRenderer::saveLayerDeferred(float left, float top, float right, float
 *     something actually gets drawn are the layers regions cleared.
 */
bool OpenGLRenderer::createLayer(float left, float top, float right, float bottom,
        int alpha, SkXfermode::Mode mode, int flags) {
        const SkPaint* paint, int flags) {
    LAYER_LOGD("Requesting layer %.2fx%.2f", right - left, bottom - top);
    LAYER_LOGD("Layer cache size = %d", mCaches.layerCache.getSize());

    const bool fboLayer = flags & SkCanvas::kClipToLayer_SaveFlag;

    SkXfermode::Mode mode = getXfermodeDirect(paint);
    int alpha = getAlphaDirect(paint);

    // Window coordinates of the layer
    Rect clip;
    Rect bounds(left, top, right, bottom);
@@ -889,6 +892,7 @@ bool OpenGLRenderer::createLayer(float left, float top, float right, float botto
    layer->layer.set(bounds);
    layer->texCoords.set(0.0f, bounds.getHeight() / float(layer->getHeight()),
            bounds.getWidth() / float(layer->getWidth()), 0.0f);

    layer->setColorFilter(mDrawModifiers.mColorFilter);
    layer->setBlend(true);
    layer->setDirty(false);
Loading