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

Unverified Commit bb29ca95 authored by Likai Ding's avatar Likai Ding Committed by Michael Bestas
Browse files

Gallery: faster texture upload

TileTexture.Uploader uses a fixed time slot (4ms) to upload tiles.
However, typical GL idle time is much longer than that. To better
utilize it, a third parameter is added to onGLIdle method to indicate
the due time. This can cut ~170ms on certain devices.

CRs-Fixed: 1024519
Change-Id: I8347b87f85815a4deaf10eb10f234a56b047681e
parent 04cdc161
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ public class TextureUploader implements OnGLIdleListener {
    }

    @Override
    public boolean onGLIdle(GLCanvas canvas, boolean renderRequested) {
    public boolean onGLIdle(GLCanvas canvas, boolean renderRequested, long dueTime) {
        int uploadQuota = QUOTA_PER_FRAME;
        uploadQuota = upload(canvas, mFgTextures, uploadQuota, false);
        if (uploadQuota < QUOTA_PER_FRAME) mGLRoot.requestRender();
+7 −10
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.os.SystemClock;

import com.android.gallery3d.ui.GLRoot;
import com.android.gallery3d.ui.GLRoot.OnGLIdleListener;
@@ -42,10 +41,6 @@ public class TiledTexture implements Texture {
    private static final int TILE_SIZE = CONTENT_SIZE + 2 * BORDER_SIZE;
    private static final int INIT_CAPACITY = 8;

    // We are targeting at 60fps, so we have 16ms for each frame.
    // In this 16ms, we use about 4~8 ms to upload tiles.
    private static final long UPLOAD_TILE_LIMIT = 4; // ms

    private static Tile sFreeTileHead = null;
    private static final Object sFreeTileLock = new Object();

@@ -88,18 +83,20 @@ public class TiledTexture implements Texture {
        }

        @Override
        public boolean onGLIdle(GLCanvas canvas, boolean renderRequested) {
        public boolean onGLIdle(GLCanvas canvas, boolean renderRequested, long dueTime) {
            ArrayDeque<TiledTexture> deque = mTextures;
            synchronized (this) {
                long now = SystemClock.uptimeMillis();
                long dueTime = now + UPLOAD_TILE_LIMIT;
                while (now < dueTime && !deque.isEmpty()) {
                long now = System.nanoTime();
                long uploadTime = 0;
                while (now + uploadTime < dueTime && !deque.isEmpty()) {
                    TiledTexture t = deque.peekFirst();
                    if (t.uploadNextTile(canvas)) {
                        deque.removeFirst();
                        mGlRoot.requestRender();
                    }
                    now = SystemClock.uptimeMillis();
                    long t1 = System.nanoTime();
                    uploadTime = t1 - now;
                    now = t1;
                }
                mIsQueued = !mTextures.isEmpty();

+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ public interface GLRoot {
    // Mainly used for uploading textures.
    public static interface OnGLIdleListener {
        public boolean onGLIdle(
                GLCanvas canvas, boolean renderRequested);
                GLCanvas canvas, boolean renderRequested, long dueTime);
    }

    public void addOnGLIdleListener(OnGLIdleListener listener);
+13 −2
Original line number Diff line number Diff line
@@ -78,6 +78,8 @@ public class GLRootView extends GLSurfaceView
    private static final int FLAG_INITIALIZED = 1;
    private static final int FLAG_NEED_LAYOUT = 2;

    private static final long FRAME_INTERVAL = 16000000;

    private GL11 mGL;
    private GLCanvas mCanvas;
    private GLView mContentView;
@@ -111,6 +113,8 @@ public class GLRootView extends GLSurfaceView
    private boolean mInDownState = false;
    private boolean mFirstDraw = true;

    private long mDueTime;

    public GLRootView(Context context) {
        this(context, null);
    }
@@ -339,6 +343,7 @@ public class GLRootView extends GLSurfaceView

    @Override
    public void onDrawFrame(GL10 gl) {
        mDueTime = System.nanoTime() + FRAME_INTERVAL;
        AnimationTime.update();
        long t0;
        if (DEBUG_PROFILE_SLOW_ONLY) {
@@ -499,9 +504,15 @@ public class GLRootView extends GLSurfaceView
                listener = mIdleListeners.removeFirst();
            }
            mRenderLock.lock();
            boolean keepInQueue;
            boolean keepInQueue = false;
            try {
                keepInQueue = listener.onGLIdle(mCanvas, mRenderRequested);
                if (mCanvas != null) {
                    long t = System.nanoTime();
                    if (mDueTime < t) {
                        mDueTime = t + FRAME_INTERVAL / 2;
                    }
                    keepInQueue = listener.onGLIdle(mCanvas, mRenderRequested, mDueTime);
                }
            } finally {
                mRenderLock.unlock();
            }
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public class PreparePageFadeoutTexture implements OnGLIdleListener {
    }

    @Override
    public boolean onGLIdle(GLCanvas canvas, boolean renderRequested) {
    public boolean onGLIdle(GLCanvas canvas, boolean renderRequested, long dueTime) {
        if (!mCancelled) {
            try {
                canvas.beginRenderTarget(mTexture);
Loading