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

Commit 4e13461e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add debug log to trace wallpaper rendering"

parents 196200de e88b165e
Loading
Loading
Loading
Loading
+32 −3
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.ActivityManager;
import android.content.Context;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.HandlerThread;
import android.os.HandlerThread;
import android.os.Trace;
import android.service.wallpaper.WallpaperService;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.util.Log;
import android.util.Size;
import android.util.Size;
@@ -48,6 +49,7 @@ public class ImageWallpaper extends WallpaperService {
    private static final int DELAY_FINISH_RENDERING = 1000;
    private static final int DELAY_FINISH_RENDERING = 1000;
    private static final int INTERVAL_WAIT_FOR_RENDERING = 100;
    private static final int INTERVAL_WAIT_FOR_RENDERING = 100;
    private static final int PATIENCE_WAIT_FOR_RENDERING = 10;
    private static final int PATIENCE_WAIT_FOR_RENDERING = 10;
    private static final boolean DEBUG = true;
    private HandlerThread mWorker;
    private HandlerThread mWorker;


    @Override
    @Override
@@ -125,6 +127,10 @@ public class ImageWallpaper extends WallpaperService {
        @Override
        @Override
        public void onAmbientModeChanged(boolean inAmbientMode, long animationDuration) {
        public void onAmbientModeChanged(boolean inAmbientMode, long animationDuration) {
            if (!mNeedTransition) return;
            if (!mNeedTransition) return;
            if (DEBUG) {
                Log.d(TAG, "onAmbientModeChanged: inAmbient=" + inAmbientMode
                        + ", duration=" + animationDuration);
            }
            mWorker.getThreadHandler().post(
            mWorker.getThreadHandler().post(
                    () -> mRenderer.updateAmbientMode(inAmbientMode, animationDuration));
                    () -> mRenderer.updateAmbientMode(inAmbientMode, animationDuration));
            if (inAmbientMode && animationDuration == 0) {
            if (inAmbientMode && animationDuration == 0) {
@@ -184,16 +190,31 @@ public class ImageWallpaper extends WallpaperService {


        @Override
        @Override
        public void onSurfaceRedrawNeeded(SurfaceHolder holder) {
        public void onSurfaceRedrawNeeded(SurfaceHolder holder) {
            if (DEBUG) {
                Log.d(TAG, "onSurfaceRedrawNeeded: mNeedRedraw=" + mNeedRedraw);
            }

            mWorker.getThreadHandler().post(() -> {
            mWorker.getThreadHandler().post(() -> {
                if (mNeedRedraw) {
                if (mNeedRedraw) {
                    preRender();
                    drawFrame();
                    requestRender();
                    postRender();
                    mNeedRedraw = false;
                    mNeedRedraw = false;
                }
                }
            });
            });
        }
        }


        @Override
        public void onVisibilityChanged(boolean visible) {
            if (DEBUG) {
                Log.d(TAG, "wallpaper visibility changes: " + visible);
            }
        }

        private void drawFrame() {
            preRender();
            requestRender();
            postRender();
        }

        @Override
        @Override
        public void onStatePostChange() {
        public void onStatePostChange() {
            // When back to home, we try to release EGL, which is preserved in lock screen or aod.
            // When back to home, we try to release EGL, which is preserved in lock screen or aod.
@@ -205,7 +226,9 @@ public class ImageWallpaper extends WallpaperService {
        @Override
        @Override
        public void preRender() {
        public void preRender() {
            // This method should only be invoked from worker thread.
            // This method should only be invoked from worker thread.
            Trace.beginSection("ImageWallpaper#preRender");
            preRenderInternal();
            preRenderInternal();
            Trace.endSection();
        }
        }


        private void preRenderInternal() {
        private void preRenderInternal() {
@@ -240,7 +263,9 @@ public class ImageWallpaper extends WallpaperService {
        @Override
        @Override
        public void requestRender() {
        public void requestRender() {
            // This method should only be invoked from worker thread.
            // This method should only be invoked from worker thread.
            Trace.beginSection("ImageWallpaper#requestRender");
            requestRenderInternal();
            requestRenderInternal();
            Trace.endSection();
        }
        }


        private void requestRenderInternal() {
        private void requestRenderInternal() {
@@ -263,8 +288,10 @@ public class ImageWallpaper extends WallpaperService {
        @Override
        @Override
        public void postRender() {
        public void postRender() {
            // This method should only be invoked from worker thread.
            // This method should only be invoked from worker thread.
            Trace.beginSection("ImageWallpaper#postRender");
            notifyWaitingThread();
            notifyWaitingThread();
            scheduleFinishRendering();
            scheduleFinishRendering();
            Trace.endSection();
        }
        }


        private void notifyWaitingThread() {
        private void notifyWaitingThread() {
@@ -289,12 +316,14 @@ public class ImageWallpaper extends WallpaperService {
        }
        }


        private void finishRendering() {
        private void finishRendering() {
            Trace.beginSection("ImageWallpaper#finishRendering");
            if (mEglHelper != null) {
            if (mEglHelper != null) {
                mEglHelper.destroyEglSurface();
                mEglHelper.destroyEglSurface();
                if (!needPreserveEglContext()) {
                if (!needPreserveEglContext()) {
                    mEglHelper.destroyEglContext();
                    mEglHelper.destroyEglContext();
                }
                }
            }
            }
            Trace.endSection();
        }
        }


        private boolean needPreserveEglContext() {
        private boolean needPreserveEglContext() {
+16 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ public class EglHelper {
    // Below two constants make drawing at low priority, so other things can preempt our drawing.
    // Below two constants make drawing at low priority, so other things can preempt our drawing.
    private static final int EGL_CONTEXT_PRIORITY_LEVEL_IMG = 0x3100;
    private static final int EGL_CONTEXT_PRIORITY_LEVEL_IMG = 0x3100;
    private static final int EGL_CONTEXT_PRIORITY_LOW_IMG = 0x3103;
    private static final int EGL_CONTEXT_PRIORITY_LOW_IMG = 0x3103;
    private static final boolean DEBUG = true;


    private EGLDisplay mEglDisplay;
    private EGLDisplay mEglDisplay;
    private EGLConfig mEglConfig;
    private EGLConfig mEglConfig;
@@ -146,6 +147,10 @@ public class EglHelper {
     * @return true if EglSurface is ready.
     * @return true if EglSurface is ready.
     */
     */
    public boolean createEglSurface(SurfaceHolder surfaceHolder) {
    public boolean createEglSurface(SurfaceHolder surfaceHolder) {
        if (DEBUG) {
            Log.d(TAG, "createEglSurface start");
        }

        if (hasEglDisplay()) {
        if (hasEglDisplay()) {
            mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig, surfaceHolder, null, 0);
            mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig, surfaceHolder, null, 0);
        } else {
        } else {
@@ -163,6 +168,9 @@ public class EglHelper {
            return false;
            return false;
        }
        }


        if (DEBUG) {
            Log.d(TAG, "createEglSurface done");
        }
        return true;
        return true;
    }
    }


@@ -190,6 +198,10 @@ public class EglHelper {
     * @return true if EglContext is ready.
     * @return true if EglContext is ready.
     */
     */
    public boolean createEglContext() {
    public boolean createEglContext() {
        if (DEBUG) {
            Log.d(TAG, "createEglContext start");
        }

        int[] attrib_list = new int[] {EGL_CONTEXT_CLIENT_VERSION, 2,
        int[] attrib_list = new int[] {EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_LOW_IMG, EGL_NONE};
                EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_LOW_IMG, EGL_NONE};
        if (hasEglDisplay()) {
        if (hasEglDisplay()) {
@@ -203,6 +215,10 @@ public class EglHelper {
            Log.w(TAG, "eglCreateContext failed: " + GLUtils.getEGLErrorString(eglGetError()));
            Log.w(TAG, "eglCreateContext failed: " + GLUtils.getEGLErrorString(eglGetError()));
            return false;
            return false;
        }
        }

        if (DEBUG) {
            Log.d(TAG, "createEglContext done");
        }
        return true;
        return true;
    }
    }


+11 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.glwallpaper;
import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator;
import android.util.Log;


import com.android.systemui.Interpolators;
import com.android.systemui.Interpolators;


@@ -30,6 +31,7 @@ class ImageRevealHelper {
    private static final String TAG = ImageRevealHelper.class.getSimpleName();
    private static final String TAG = ImageRevealHelper.class.getSimpleName();
    private static final float MAX_REVEAL = 0f;
    private static final float MAX_REVEAL = 0f;
    private static final float MIN_REVEAL = 1f;
    private static final float MIN_REVEAL = 1f;
    private static final boolean DEBUG = true;


    private final ValueAnimator mAnimator;
    private final ValueAnimator mAnimator;
    private final RevealStateListener mRevealListener;
    private final RevealStateListener mRevealListener;
@@ -57,6 +59,9 @@ class ImageRevealHelper {
            @Override
            @Override
            public void onAnimationEnd(Animator animation) {
            public void onAnimationEnd(Animator animation) {
                if (!mIsCanceled && mRevealListener != null) {
                if (!mIsCanceled && mRevealListener != null) {
                    if (DEBUG) {
                        Log.d(TAG, "transition end");
                    }
                    mRevealListener.onRevealEnd();
                    mRevealListener.onRevealEnd();
                }
                }
                mIsCanceled = false;
                mIsCanceled = false;
@@ -65,6 +70,9 @@ class ImageRevealHelper {
            @Override
            @Override
            public void onAnimationStart(Animator animation) {
            public void onAnimationStart(Animator animation) {
                if (mRevealListener != null) {
                if (mRevealListener != null) {
                    if (DEBUG) {
                        Log.d(TAG, "transition start");
                    }
                    mRevealListener.onRevealStart(true /* animate */);
                    mRevealListener.onRevealStart(true /* animate */);
                }
                }
            }
            }
@@ -82,6 +90,9 @@ class ImageRevealHelper {
    }
    }


    void updateAwake(boolean awake, long duration) {
    void updateAwake(boolean awake, long duration) {
        if (DEBUG) {
            Log.d(TAG, "updateAwake: awake=" + awake + ", duration=" + duration);
        }
        mAwake = awake;
        mAwake = awake;
        mAnimator.setDuration(duration);
        mAnimator.setDuration(duration);
        if (duration == 0) {
        if (duration == 0) {
+8 −0
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer,
    private static final String TAG = ImageWallpaperRenderer.class.getSimpleName();
    private static final String TAG = ImageWallpaperRenderer.class.getSimpleName();
    private static final float SCALE_VIEWPORT_MIN = 1f;
    private static final float SCALE_VIEWPORT_MIN = 1f;
    private static final float SCALE_VIEWPORT_MAX = 1.1f;
    private static final float SCALE_VIEWPORT_MAX = 1.1f;
    private static final boolean DEBUG = true;


    private final WallpaperManager mWallpaperManager;
    private final WallpaperManager mWallpaperManager;
    private final ImageGLProgram mProgram;
    private final ImageGLProgram mProgram;
@@ -107,6 +108,9 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer,
    }
    }


    private boolean loadBitmap() {
    private boolean loadBitmap() {
        if (DEBUG) {
            Log.d(TAG, "loadBitmap: mBitmap=" + mBitmap);
        }
        if (mWallpaperManager != null && mBitmap == null) {
        if (mWallpaperManager != null && mBitmap == null) {
            mBitmap = mWallpaperManager.getBitmap();
            mBitmap = mWallpaperManager.getBitmap();
            mWallpaperManager.forgetLoadedWallpaper();
            mWallpaperManager.forgetLoadedWallpaper();
@@ -119,6 +123,9 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer,
                mSurfaceSize.set(0, 0, surfaceWidth, surfaceHeight);
                mSurfaceSize.set(0, 0, surfaceWidth, surfaceHeight);
            }
            }
        }
        }
        if (DEBUG) {
            Log.d(TAG, "loadBitmap done");
        }
        return mBitmap != null;
        return mBitmap != null;
    }
    }


@@ -223,6 +230,7 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer,
        out.print(prefix); out.print("mXOffset="); out.print(mXOffset);
        out.print(prefix); out.print("mXOffset="); out.print(mXOffset);
        out.print(prefix); out.print("mYOffset="); out.print(mYOffset);
        out.print(prefix); out.print("mYOffset="); out.print(mYOffset);
        out.print(prefix); out.print("threshold="); out.print(mImageProcessHelper.getThreshold());
        out.print(prefix); out.print("threshold="); out.print(mImageProcessHelper.getThreshold());
        out.print(prefix); out.print("mReveal="); out.print(mImageRevealHelper.getReveal());
        mWallpaper.dump(prefix, fd, out, args);
        mWallpaper.dump(prefix, fd, out, args);
    }
    }
}
}