Merge changes I100846a4,I61b12a00 into sc-dev

* changes:
  Revert "Added exposure effect on ImageWallpaper"
  Revert "Stops ImageWallpaper Thread when phone is idle"
This commit is contained in:
TreeHugger Robot
2021-04-21 00:57:50 +00:00
committed by Android (Google) Code Review
5 changed files with 9 additions and 144 deletions

View File

@@ -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);
}

View File

@@ -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;
@@ -60,7 +58,6 @@ public class ImageWallpaper extends WallpaperService {
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<RectF> mLocalColorsToAdd = new ArrayList<>();
private final ArraySet<RectF> 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,16 +101,13 @@ public class ImageWallpaper extends WallpaperService {
private ImageWallpaperRenderer mRenderer;
private EglHelper mEglHelper;
private final Runnable mFinishRenderingTask = this::finishRendering;
private final Runnable mInitChoreographerTask = this::initChoreographerInternal;
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;
private volatile boolean mShouldScheduleFrame = false;
GLEngine() {
}
@@ -143,9 +134,6 @@ public class ImageWallpaper extends WallpaperService {
if (mWorker != null && mWorker.getThreadHandler() != null) {
mWorker.getThreadHandler().post(this::updateMiniBitmap);
}
mDozeAmount = mStatusBarStateController.getDozeAmount();
mStatusBarStateController.addCallback(this);
}
EglHelper getEglHelperInstance() {
@@ -221,11 +209,7 @@ public class ImageWallpaper extends WallpaperService {
@Override
public void onDestroy() {
mMiniBitmap = null;
mStatusBarStateController.removeCallback(this);
mWorker.getThreadHandler().post(() -> {
finishChoreographerInternal();
mRenderer.finish();
mRenderer = null;
mEglHelper.finish();
@@ -351,28 +335,17 @@ 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) {
initChoreographer();
mDozeAmount = linear;
mNewDozeValue = true;
}
private void drawFrame() {
preRender();
requestRender();
postRender();
}
/**
* Important: this method should only be invoked from the ImageWallpaper (worker) Thread.
*/
public void preRender() {
// This method should only be invoked from worker thread.
Trace.beginSection("ImageWallpaper#preRender");
preRenderInternal();
Trace.endSection();
@@ -407,10 +380,8 @@ public class ImageWallpaper extends WallpaperService {
}
}
/**
* Important: this method should only be invoked from the ImageWallpaper (worker) Thread.
*/
public void requestRender() {
// This method should only be invoked from worker thread.
Trace.beginSection("ImageWallpaper#requestRender");
requestRenderInternal();
Trace.endSection();
@@ -422,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!");
@@ -434,10 +404,8 @@ public class ImageWallpaper extends WallpaperService {
}
}
/**
* Important: this method should only be invoked from the ImageWallpaper (worker) Thread.
*/
public void postRender() {
// This method should only be invoked from worker thread.
Trace.beginSection("ImageWallpaper#postRender");
scheduleFinishRendering();
Trace.endSection();
@@ -456,7 +424,6 @@ public class ImageWallpaper extends WallpaperService {
private void finishRendering() {
Trace.beginSection("ImageWallpaper#finishRendering");
finishChoreographerInternal();
if (mEglHelper != null) {
mEglHelper.destroyEglSurface();
mEglHelper.destroyEglContext();
@@ -464,35 +431,6 @@ public class ImageWallpaper extends WallpaperService {
Trace.endSection();
}
private void initChoreographer() {
if (!mWorker.getThreadHandler().hasCallbacks(mInitChoreographerTask)
&& !mShouldScheduleFrame) {
mWorker.getThreadHandler().post(mInitChoreographerTask);
}
}
/**
* Subscribes the engine to listen to Choreographer frame events.
* Important: this method should only be invoked from the ImageWallpaper (worker) Thread.
*/
private void initChoreographerInternal() {
if (!mShouldScheduleFrame) {
// Prepare EGL Context and Surface
preRender();
mShouldScheduleFrame = true;
Choreographer.getInstance().postFrameCallback(GLEngine.this);
}
}
/**
* Unsubscribe the engine from listening to Choreographer frame events.
* Important: this method should only be invoked from the ImageWallpaper (worker) Thread.
*/
private void finishChoreographerInternal() {
mShouldScheduleFrame = false;
Choreographer.getInstance().removeFrameCallback(GLEngine.this);
}
private boolean needSupportWideColorGamut() {
return mRenderer.isWcgContent();
}
@@ -512,17 +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;
}
if (mShouldScheduleFrame) {
Choreographer.getInstance().postFrameCallback(this);
}
}
}
}

View File

@@ -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.

View File

@@ -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();
}

View File

@@ -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) {