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

Commit 9e90a995 authored by Chet Haase's avatar Chet Haase
Browse files

Reuse display lists at the java level.

Objects are invalidated and reset instead of being nulled out
and recreated. This avoids creating small amounts of garbage for
the display list and canvas objects.

Change-Id: I464fac7ea8944c19ad6d03f13a95d9017e3f4262
parent a74c22b7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -257911,7 +257911,7 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="arg0" type="T">
<parameter name="t" type="T">
</parameter>
</method>
</interface>
+5 −5
Original line number Diff line number Diff line
@@ -73,19 +73,19 @@ public class LayoutTransition {

    /**
     * A flag indicating the animation that runs on those items that are changing
     * due to a new item disappearing from the container.
     * due to an item disappearing from the container.
     */
    public static final int CHANGE_DISAPPEARING = 1;

    /**
     * A flag indicating the animation that runs on those items that are changing
     * due to a new item appearing in the container.
     * A flag indicating the animation that runs on those items that are appearing
     * in the container.
     */
    public static final int APPEARING = 2;

    /**
     * A flag indicating the animation that runs on those items that are changing
     * due to a new item appearing in the container.
     * A flag indicating the animation that runs on those items that are disappearing
     * from the container.
     */
    public static final int DISAPPEARING = 3;

+15 −0
Original line number Diff line number Diff line
@@ -46,4 +46,19 @@ abstract class DisplayList {
     * @see android.view.HardwareCanvas#drawDisplayList(DisplayList) 
     */
    abstract boolean isReady();

    /**
     * Invalidates the display list, indicating that it should be repopulated
     * with new drawing commands prior to being used again. Calling this method
     * causes calls to {@link #isValid()} to return <code>false</code>.
     */
    abstract void invalidate();

    /**
     * Returns whether the display list is currently usable. If this returns false,
     * the display list should be re-recorded prior to replaying it.
     *
     * @return boolean true if the display list is able to be replayed, false otherwise.
     */
    abstract boolean isValid();
}
+18 −3
Original line number Diff line number Diff line
@@ -80,6 +80,10 @@ class GLES20Canvas extends HardwareCanvas {
    protected GLES20Canvas(boolean record, boolean translucent) {
        mOpaque = !translucent;

        setupRenderer(record);
    }

    protected void setupRenderer(boolean record) {
        if (record) {
            mRenderer = nCreateDisplayListRenderer();
        } else {
@@ -89,7 +93,11 @@ class GLES20Canvas extends HardwareCanvas {
        if (mRenderer == 0) {
            throw new IllegalStateException("Could not create GLES20Canvas renderer");
        } else {
            if (mFinalizer == null) {
                mFinalizer = new CanvasFinalizer(mRenderer);
            } else {
                mFinalizer.replaceNativeObject(mRenderer);
            }
        }
    }

@@ -99,15 +107,22 @@ class GLES20Canvas extends HardwareCanvas {
    private static native void nDestroyRenderer(int renderer);

    private static class CanvasFinalizer {
        final int mRenderer;
        int mRenderer;

        CanvasFinalizer(int renderer) {
            mRenderer = renderer;
        }

        void replaceNativeObject(int newRenderer) {
            if (mRenderer != 0) {
                nDestroyRenderer(mRenderer);
            }
            mRenderer = newRenderer;
        }

        @Override
        protected void finalize() throws Throwable {
            nDestroyRenderer(mRenderer);
            replaceNativeObject(0);
        }
    }

+32 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ class GLES20DisplayList extends DisplayList {

    private boolean mStarted = false;
    private boolean mRecorded = false;
    private boolean mValid = false;

    int mNativeDisplayList;

@@ -38,13 +39,30 @@ class GLES20DisplayList extends DisplayList {
            throw new IllegalStateException("Recording has already started");
        }

        if (mCanvas != null) {
            ((GLES20RecordingCanvas) mCanvas).reset();
        } else {
            mCanvas = new GLES20RecordingCanvas(true);
        }
        mStarted = true;
        mRecorded = false;
        mValid = true;

        return mCanvas;
    }

    @Override
    void invalidate() {
        mStarted = false;
        mRecorded = false;
        mValid = false;
    }

    @Override
    boolean isValid() {
        return mValid;
    }

    @Override
    void end() {
        if (mCanvas != null) {
@@ -52,7 +70,11 @@ class GLES20DisplayList extends DisplayList {
            mRecorded = true;

            mNativeDisplayList = mCanvas.getDisplayList();
            if (mFinalizer == null) {
                mFinalizer = new DisplayListFinalizer(mNativeDisplayList);
            } else {
                mFinalizer.replaceNativeObject(mNativeDisplayList);
            }
        }
    }

@@ -68,9 +90,16 @@ class GLES20DisplayList extends DisplayList {
            mNativeDisplayList = nativeDisplayList;
        }

        void replaceNativeObject(int newNativeDisplayList) {
            if (mNativeDisplayList != 0) {
                GLES20Canvas.destroyDisplayList(mNativeDisplayList);
            }
            mNativeDisplayList = newNativeDisplayList;
        }

        @Override
        protected void finalize() throws Throwable {
            GLES20Canvas.destroyDisplayList(mNativeDisplayList);
            replaceNativeObject(0);
        }
    }
}
Loading