From 52c0fcde2829d71acc4fea41fe1852df81ecc30f Mon Sep 17 00:00:00 2001 From: Josh Tsuji Date: Tue, 20 Apr 2021 18:29:59 -0400 Subject: [PATCH] Revert "Added exposure effect on ImageWallpaper" This reverts commit 068978ca8585dfb366f4795419e5a28285118caa. Reason for revert: breaks wakeup Bug: 185681677 Change-Id: I100846a4698f89ee9bd65492986643c11dc21a8b --- .../raw/image_wallpaper_fragment_shader.glsl | 47 +------------------ .../com/android/systemui/ImageWallpaper.java | 43 ++--------------- .../glwallpaper/ImageGLWallpaper.java | 8 ---- .../glwallpaper/ImageWallpaperRenderer.java | 9 ---- .../android/systemui/ImageWallpaperTest.java | 3 +- 5 files changed, 8 insertions(+), 102 deletions(-) diff --git a/packages/SystemUI/res/raw/image_wallpaper_fragment_shader.glsl b/packages/SystemUI/res/raw/image_wallpaper_fragment_shader.glsl index 7aca9f8440fc5..e4b6e07786649 100644 --- a/packages/SystemUI/res/raw/image_wallpaper_fragment_shader.glsl +++ b/packages/SystemUI/res/raw/image_wallpaper_fragment_shader.glsl @@ -1,54 +1,11 @@ precision mediump float; -#define GAMMA 2.2 -#define INV_GAMMA 1.0 / GAMMA // The actual wallpaper texture. uniform sampler2D uTexture; -uniform float uExposure; varying vec2 vTextureCoordinates; -// Following the Rec. ITU-R BT.709. -float relativeLuminance(vec3 color) { - return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b; -} - -// Adjusts the exposure of some luminance value. -float relativeExposureCompensation(in float lum, in float ev) { - return lum * pow(2.0, ev); -} - -vec4 srgbToLinear(in vec4 color) { - vec4 linearColor = vec4(color); - linearColor.rgb = pow(linearColor.rgb, vec3(GAMMA)); - return linearColor; -} - -vec4 linearToSrgb(in vec4 color) { - vec4 srgbColor = vec4(color); - srgbColor.rgb = pow(srgbColor.rgb, vec3(INV_GAMMA)); - return srgbColor; -} - -/* - * Normalizes a value inside a range to a normalized range [0,1]. - */ -float normalizedRange(in float value, in float inMin, in float inMax) { - float valueClamped = clamp(value, inMin, inMax); - return (value - inMin) / (inMax - inMin); -} - void main() { - // Gets the pixel value of the wallpaper for this uv coordinates on screen. - vec4 color = srgbToLinear(texture2D(uTexture, vTextureCoordinates)); - float lum = relativeLuminance(color.rgb); - - // Transform it using the S curve created by the smoothstep. This will increase the contrast. - lum = smoothstep(0., 1., lum) + 0.001; - - lum = relativeExposureCompensation(lum, mix(-5., 10., uExposure)); - lum = mix(clamp(lum, 0.0, 1.0), 1.0, normalizedRange(uExposure, 0.55, 1.0)); - color.rgb *= lum; - - gl_FragColor = linearToSrgb(color); + // gets the pixel value of the wallpaper for this uv coordinates on screen. + gl_FragColor = texture2D(uTexture, vTextureCoordinates); } \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java index a6cf9e9958f4f..76cec0b334778 100644 --- a/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java +++ b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java @@ -29,7 +29,6 @@ import android.util.ArraySet; import android.util.Log; import android.util.MathUtils; import android.util.Size; -import android.view.Choreographer; import android.view.DisplayInfo; import android.view.SurfaceHolder; import android.view.WindowManager; @@ -39,7 +38,6 @@ import androidx.annotation.NonNull; import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.glwallpaper.EglHelper; import com.android.systemui.glwallpaper.ImageWallpaperRenderer; -import com.android.systemui.plugins.statusbar.StatusBarStateController; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -56,11 +54,10 @@ public class ImageWallpaper extends WallpaperService { private static final String TAG = ImageWallpaper.class.getSimpleName(); // We delayed destroy render context that subsequent render requests have chance to cancel it. // This is to avoid destroying then recreating render context in a very short time. - private static final int DELAY_FINISH_RENDERING = 3000; + private static final int DELAY_FINISH_RENDERING = 1000; private static final @android.annotation.NonNull RectF LOCAL_COLOR_BOUNDS = new RectF(0, 0, 1, 1); private static final boolean DEBUG = false; - private final StatusBarStateController mStatusBarStateController; private final ArrayList mLocalColorsToAdd = new ArrayList<>(); private final ArraySet mColorAreas = new ArraySet<>(); private volatile int mPages = 1; @@ -69,9 +66,8 @@ public class ImageWallpaper extends WallpaperService { private Bitmap mMiniBitmap; @Inject - public ImageWallpaper(StatusBarStateController statusBarStateController) { + public ImageWallpaper() { super(); - mStatusBarStateController = statusBarStateController; } @Override @@ -94,9 +90,7 @@ public class ImageWallpaper extends WallpaperService { mMiniBitmap = null; } - - class GLEngine extends Engine implements StatusBarStateController.StateListener, - Choreographer.FrameCallback { + class GLEngine extends Engine { // Surface is rejected if size below a threshold on some devices (ie. 8px on elfin) // set min to 64 px (CTS covers this), please refer to ag/4867989 for detail. @VisibleForTesting @@ -107,14 +101,13 @@ public class ImageWallpaper extends WallpaperService { private ImageWallpaperRenderer mRenderer; private EglHelper mEglHelper; private final Runnable mFinishRenderingTask = this::finishRendering; + private boolean mNeedRedraw; private int mWidth = 1; private int mHeight = 1; private int mImgWidth = 1; private int mImgHeight = 1; private float mPageWidth = 1.f; private float mPageOffset = 1.f; - private volatile float mDozeAmount; - private volatile boolean mNewDozeValue = false; GLEngine() { } @@ -139,14 +132,8 @@ public class ImageWallpaper extends WallpaperService { mWidth = window.width(); mMiniBitmap = null; if (mWorker != null && mWorker.getThreadHandler() != null) { - mWorker.getThreadHandler().post(() -> { - updateMiniBitmap(); - Choreographer.getInstance().postFrameCallback(GLEngine.this); - }); + mWorker.getThreadHandler().post(this::updateMiniBitmap); } - - mDozeAmount = mStatusBarStateController.getDozeAmount(); - mStatusBarStateController.addCallback(this); } EglHelper getEglHelperInstance() { @@ -223,14 +210,11 @@ public class ImageWallpaper extends WallpaperService { public void onDestroy() { mMiniBitmap = null; mWorker.getThreadHandler().post(() -> { - Choreographer.getInstance().removeFrameCallback(this); mRenderer.finish(); mRenderer = null; mEglHelper.finish(); mEglHelper = null; }); - - mStatusBarStateController.removeCallback(this); } @Override @@ -351,16 +335,9 @@ public class ImageWallpaper extends WallpaperService { @Override public void onSurfaceRedrawNeeded(SurfaceHolder holder) { if (mWorker == null) return; - mDozeAmount = mStatusBarStateController.getDozeAmount(); mWorker.getThreadHandler().post(this::drawFrame); } - @Override - public void onDozeAmountChanged(float linear, float eased) { - mDozeAmount = linear; - mNewDozeValue = true; - } - private void drawFrame() { preRender(); requestRender(); @@ -416,7 +393,6 @@ public class ImageWallpaper extends WallpaperService { && frame.width() > 0 && frame.height() > 0; if (readyToRender) { - mRenderer.setExposureValue(1 - mDozeAmount); mRenderer.onDrawFrame(); if (!mEglHelper.swapBuffer()) { Log.e(TAG, "drawFrame failed!"); @@ -474,14 +450,5 @@ public class ImageWallpaper extends WallpaperService { mEglHelper.dump(prefix, fd, out, args); mRenderer.dump(prefix, fd, out, args); } - - @Override - public void doFrame(long frameTimeNanos) { - if (mNewDozeValue) { - drawFrame(); - mNewDozeValue = false; - } - Choreographer.getInstance().postFrameCallback(this); - } } } diff --git a/packages/SystemUI/src/com/android/systemui/glwallpaper/ImageGLWallpaper.java b/packages/SystemUI/src/com/android/systemui/glwallpaper/ImageGLWallpaper.java index 58c41d582413e..1a53c28c0fc56 100644 --- a/packages/SystemUI/src/com/android/systemui/glwallpaper/ImageGLWallpaper.java +++ b/packages/SystemUI/src/com/android/systemui/glwallpaper/ImageGLWallpaper.java @@ -29,7 +29,6 @@ import static android.opengl.GLES20.glDrawArrays; import static android.opengl.GLES20.glEnableVertexAttribArray; import static android.opengl.GLES20.glGenTextures; import static android.opengl.GLES20.glTexParameteri; -import static android.opengl.GLES20.glUniform1f; import static android.opengl.GLES20.glUniform1i; import static android.opengl.GLES20.glVertexAttribPointer; @@ -53,7 +52,6 @@ class ImageGLWallpaper { private static final String A_POSITION = "aPosition"; private static final String A_TEXTURE_COORDINATES = "aTextureCoordinates"; private static final String U_TEXTURE = "uTexture"; - private static final String U_EXPOSURE = "uExposure"; private static final int POSITION_COMPONENT_COUNT = 2; private static final int TEXTURE_COMPONENT_COUNT = 2; private static final int BYTES_PER_FLOAT = 4; @@ -85,7 +83,6 @@ class ImageGLWallpaper { private int mAttrPosition; private int mAttrTextureCoordinates; private int mUniTexture; - private int mUniExposure; private int mTextureId; ImageGLWallpaper(ImageGLProgram program) { @@ -128,7 +125,6 @@ class ImageGLWallpaper { private void setupUniforms() { mUniTexture = mProgram.getUniformHandle(U_TEXTURE); - mUniExposure = mProgram.getUniformHandle(U_EXPOSURE); } void draw() { @@ -175,10 +171,6 @@ class ImageGLWallpaper { glUniform1i(mUniTexture, 0); } - void setExposureValue(float exposureValue) { - glUniform1f(mUniExposure, exposureValue); - } - /** * Called to dump current state. * @param prefix prefix. diff --git a/packages/SystemUI/src/com/android/systemui/glwallpaper/ImageWallpaperRenderer.java b/packages/SystemUI/src/com/android/systemui/glwallpaper/ImageWallpaperRenderer.java index cdf88f3898bb7..01a353ce8f1f7 100644 --- a/packages/SystemUI/src/com/android/systemui/glwallpaper/ImageWallpaperRenderer.java +++ b/packages/SystemUI/src/com/android/systemui/glwallpaper/ImageWallpaperRenderer.java @@ -46,7 +46,6 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer { private final ImageGLWallpaper mWallpaper; private final Rect mSurfaceSize = new Rect(); private final WallpaperTexture mTexture; - private float mExposureValue; public ImageWallpaperRenderer(Context context) { final WallpaperManager wpm = context.getSystemService(WallpaperManager.class); @@ -67,13 +66,6 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer { mTexture.use(c); } - /** - * @hide - */ - public void setExposureValue(float exposureValue) { - mExposureValue = exposureValue; - } - @Override public boolean isWcgContent() { return mTexture.isWcgContent(); @@ -102,7 +94,6 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer { public void onDrawFrame() { glClear(GL_COLOR_BUFFER_BIT); glViewport(0, 0, mSurfaceSize.width(), mSurfaceSize.height()); - mWallpaper.setExposureValue(mExposureValue); mWallpaper.useTexture(); mWallpaper.draw(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java b/packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java index daa896cc6a8b9..e1ddaada44cf8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ImageWallpaperTest.java @@ -41,7 +41,6 @@ import android.view.DisplayInfo; import android.view.SurfaceHolder; import com.android.systemui.glwallpaper.ImageWallpaperRenderer; -import com.android.systemui.plugins.statusbar.StatusBarStateController; import org.junit.Before; import org.junit.Ignore; @@ -100,7 +99,7 @@ public class ImageWallpaperTest extends SysuiTestCase { } private ImageWallpaper createImageWallpaper() { - return new ImageWallpaper(mock(StatusBarStateController.class)) { + return new ImageWallpaper() { @Override public Engine onCreateEngine() { return new GLEngine(mHandler) {