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

Commit 8fb95426 authored by Romain Guy's avatar Romain Guy
Browse files

Fix save()/restore() issues in the OpenGL renderer.

The save stack now behaves exactly like in Skia.

Change-Id: If7e642f41f2c8f693f6e8c26cba81507d466562e
parent 31d5becb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -385,7 +385,7 @@ public abstract class HardwareRenderer {
                onPreDraw();

                Canvas canvas = mCanvas;
                int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
                int saveCount = canvas.save();
                canvas.translate(0, -yOffset);

                try {
+6 −8
Original line number Diff line number Diff line
@@ -6630,8 +6630,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
     * @see android.widget.ScrollBarDrawable
     * @hide
     */
    protected void onDrawHorizontalScrollBar(Canvas canvas,
                                             Drawable scrollBar,
    protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar,
            int l, int t, int r, int b) {
        scrollBar.setBounds(l, t, r, b);
        scrollBar.draw(canvas);
@@ -6651,8 +6650,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
     * @see android.widget.ScrollBarDrawable
     * @hide
     */
    protected void onDrawVerticalScrollBar(Canvas canvas,
                                           Drawable scrollBar,
    protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar,
            int l, int t, int r, int b) {
        scrollBar.setBounds(l, t, r, b);
        scrollBar.draw(canvas);
+0 −2
Original line number Diff line number Diff line
@@ -1363,7 +1363,6 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
                                ", metrics=" + cxt.getResources().getDisplayMetrics() +
                                ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo());
                    }
                    int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
                    try {
                        canvas.translate(0, -yoff);
                        if (mTranslator != null) {
@@ -1374,7 +1373,6 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
                        mView.draw(canvas);
                    } finally {
                        mAttachInfo.mIgnoreDirtyState = false;
                        canvas.restoreToCount(saveCount);
                    }

                    if (Config.DEBUG && ViewDebug.consistencyCheckEnabled) {
+1 −2
Original line number Diff line number Diff line
@@ -111,8 +111,7 @@ public class ScrollBarDrawable extends Drawable {
        }

        Rect r = getBounds();
        if (canvas.quickReject(r.left, r.top, r.right, r.bottom, 
                Canvas.EdgeType.AA)) {
        if (canvas.quickReject(r.left, r.top, r.right, r.bottom, Canvas.EdgeType.AA)) {
            return;
        }
        if (drawTrack) {
+19 −12
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ void OpenGLRenderer::setViewport(int width, int height) {

void OpenGLRenderer::prepare() {
    mSnapshot = new Snapshot(mFirstSnapshot);
    mSaveCount = 0;
    mSaveCount = 1;

    glDisable(GL_SCISSOR_TEST);

@@ -219,19 +219,17 @@ int OpenGLRenderer::save(int flags) {
}

void OpenGLRenderer::restore() {
    if (mSaveCount == 0) return;

    if (restoreSnapshot()) {
    if (mSaveCount > 1 && restoreSnapshot()) {
        setScissorFromClip();
    }
}

void OpenGLRenderer::restoreToCount(int saveCount) {
    if (saveCount <= 0 || saveCount > mSaveCount) return;
    if (saveCount < 1) saveCount = 1;

    bool restoreClip = false;

    while (mSaveCount != saveCount - 1) {
    while (mSaveCount > saveCount) {
        restoreClip |= restoreSnapshot();
    }

@@ -242,7 +240,7 @@ void OpenGLRenderer::restoreToCount(int saveCount) {

int OpenGLRenderer::saveSnapshot() {
    mSnapshot = new Snapshot(mSnapshot);
    return ++mSaveCount;
    return mSaveCount++;
}

bool OpenGLRenderer::restoreSnapshot() {
@@ -263,10 +261,18 @@ bool OpenGLRenderer::restoreSnapshot() {
        composeLayer(current, previous);
    }

    mSnapshot = previous;
    bool skip = mSnapshot->skip;
    if (!skip) {
        mSaveCount--;
    }
    mSnapshot = previous;

    if (!skip) {
        return restoreClip;
    } else {
        bool restorePreviousClip = restoreSnapshot();
        return restoreClip || restorePreviousClip;
    }
}

///////////////////////////////////////////////////////////////////////////////
@@ -324,18 +330,20 @@ bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top,
    glClear(GL_COLOR_BUFFER_BIT);
    glEnable(GL_SCISSOR_TEST);

    // Save the layer in the snapshot
    snapshot->flags |= Snapshot::kFlagIsLayer;
    layer->mode = mode;
    layer->alpha = alpha / 255.0f;
    layer->layer.set(left, top, right, bottom);

    // Save the layer in the snapshot
    snapshot->flags |= Snapshot::kFlagIsLayer;
    snapshot->layer = layer;
    snapshot->fbo = layer->fbo;

    // Creates a new snapshot to draw into the FBO
    saveSnapshot();
    mSaveCount--;

    mSnapshot->skip = true;
    mSnapshot->transform.loadTranslate(-left, -top, 0.0f);
    mSnapshot->setClip(0.0f, 0.0f, right - left, bottom - top);
    mSnapshot->viewport.set(0.0f, 0.0f, right - left, bottom - top);
@@ -432,7 +440,6 @@ const Rect& OpenGLRenderer::getClipBounds() {
bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
    Rect r(left, top, right, bottom);
    mSnapshot->transform.mapRect(r);

    return !mSnapshot->clipRect.intersects(r);
}

Loading