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

Commit be34f2f3 authored by John Reck's avatar John Reck
Browse files

DisplayList lifecycle changes

 Bug: 13360343
 Change DisplayList to be more forgiving with weaker lifecycle
 requirements. Is more self-managed with a strong reference
 to the renderer it needs

 Also fix naming mismatch

Change-Id: I5c89453a72a52954f6f959f0846199705dbb6476
parent 863d691e
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -122,9 +122,6 @@ import android.graphics.Path;
 * @hide
 */
public class DisplayList {
    private boolean mValid;
    private final long mNativeDisplayList;

    /**
     * Flag used when calling
     * {@link HardwareCanvas#drawDisplayList(DisplayList, android.graphics.Rect, int)}
@@ -175,6 +172,10 @@ public class DisplayList {
     */
    public static final int STATUS_DREW = 0x4;

    private boolean mValid;
    private final long mNativeDisplayList;
    private HardwareRenderer mRenderer;

    private DisplayList(String name) {
        mNativeDisplayList = nCreate();
        nSetDisplayListName(mNativeDisplayList, name);
@@ -233,7 +234,13 @@ public class DisplayList {
        GLES20RecordingCanvas canvas = (GLES20RecordingCanvas) endCanvas;
        canvas.onPostDraw();
        long displayListData = canvas.finishRecording();
        renderer.swapDisplayListData(mNativeDisplayList, displayListData);
        if (renderer != mRenderer) {
            // If we are changing renderers first destroy with the old
            // renderer, then set with the new one
            destroyDisplayListData();
        }
        mRenderer = renderer;
        setDisplayListData(displayListData);
        canvas.recycle();
        mValid = true;
    }
@@ -245,14 +252,22 @@ public class DisplayList {
     *
     * @hide
     */
    public void destroyDisplayListData(HardwareRenderer renderer) {
        if (renderer == null) {
            throw new IllegalArgumentException("Cannot destroyDisplayListData with a null renderer");
        }
        renderer.swapDisplayListData(mNativeDisplayList, 0);
    public void destroyDisplayListData() {
        if (!mValid) return;

        setDisplayListData(0);
        mRenderer = null;
        mValid = false;
    }

    private void setDisplayListData(long newData) {
        if (mRenderer != null) {
            mRenderer.setDisplayListData(mNativeDisplayList, newData);
        } else {
            throw new IllegalStateException("Trying to set data without a renderer! data=" + newData);
        }
    }

    /**
     * Returns whether the display list is currently usable. If this returns false,
     * the display list should be re-recorded prior to replaying it.
@@ -907,6 +922,7 @@ public class DisplayList {
    @Override
    protected void finalize() throws Throwable {
        try {
            destroyDisplayListData();
            nDestroyDisplayList(mNativeDisplayList);
        } finally {
            super.finalize();
+3 −3
Original line number Diff line number Diff line
@@ -1196,10 +1196,10 @@ public class GLRenderer extends HardwareRenderer {
        }
    }

    void swapDisplayListData(long displayList, long newData) {
        nSwapDisplayListData(displayList, newData);
    void setDisplayListData(long displayList, long newData) {
        nSetDisplayListData(displayList, newData);
    }
    private static native void nSwapDisplayListData(long displayList, long newData);
    private static native void nSetDisplayListData(long displayList, long newData);

    private DisplayList buildDisplayList(View view, HardwareCanvas canvas) {
        if (mDrawDelta <= 0) {
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ final class HardwareLayer {
        }

        if (mDisplayList != null) {
            mDisplayList.destroyDisplayListData(mRenderer);
            mDisplayList.destroyDisplayListData();
            mDisplayList = null;
        }
        if (mRenderer != null) {
+1 −1
Original line number Diff line number Diff line
@@ -562,7 +562,7 @@ public abstract class HardwareRenderer {
        mRequested = requested;
    }

    abstract void swapDisplayListData(long displayList, long newData);
    abstract void setDisplayListData(long displayList, long newData);

    /**
     * Describes a series of frames that should be drawn on screen as a graph.
+3 −3
Original line number Diff line number Diff line
@@ -148,8 +148,8 @@ public class ThreadedRenderer extends HardwareRenderer {
    }

    @Override
    void swapDisplayListData(long displayList, long newData) {
        nSwapDisplayListData(mNativeProxy, displayList, newData);
    void setDisplayListData(long displayList, long newData) {
        nSetDisplayListData(mNativeProxy, displayList, newData);
    }

    @Override
@@ -257,7 +257,7 @@ public class ThreadedRenderer extends HardwareRenderer {
    private static native boolean nInitialize(long nativeProxy, Surface window);
    private static native void nUpdateSurface(long nativeProxy, Surface window);
    private static native void nSetup(long nativeProxy, int width, int height);
    private static native void nSwapDisplayListData(long nativeProxy, long displayList,
    private static native void nSetDisplayListData(long nativeProxy, long displayList,
            long newData);
    private static native void nDrawDisplayList(long nativeProxy, long displayList,
            int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom);
Loading