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:
committed by
Android (Google) Code Review
commit
3723a67112
@@ -1,54 +1,11 @@
|
|||||||
precision mediump float;
|
precision mediump float;
|
||||||
#define GAMMA 2.2
|
|
||||||
#define INV_GAMMA 1.0 / GAMMA
|
|
||||||
|
|
||||||
// The actual wallpaper texture.
|
// The actual wallpaper texture.
|
||||||
uniform sampler2D uTexture;
|
uniform sampler2D uTexture;
|
||||||
uniform float uExposure;
|
|
||||||
|
|
||||||
varying vec2 vTextureCoordinates;
|
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() {
|
void main() {
|
||||||
// Gets the pixel value of the wallpaper for this uv coordinates on screen.
|
// gets the pixel value of the wallpaper for this uv coordinates on screen.
|
||||||
vec4 color = srgbToLinear(texture2D(uTexture, vTextureCoordinates));
|
gl_FragColor = 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);
|
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,6 @@ import android.util.ArraySet;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.MathUtils;
|
import android.util.MathUtils;
|
||||||
import android.util.Size;
|
import android.util.Size;
|
||||||
import android.view.Choreographer;
|
|
||||||
import android.view.DisplayInfo;
|
import android.view.DisplayInfo;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@@ -39,7 +38,6 @@ import androidx.annotation.NonNull;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.systemui.glwallpaper.EglHelper;
|
import com.android.systemui.glwallpaper.EglHelper;
|
||||||
import com.android.systemui.glwallpaper.ImageWallpaperRenderer;
|
import com.android.systemui.glwallpaper.ImageWallpaperRenderer;
|
||||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -60,7 +58,6 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
private static final @android.annotation.NonNull RectF LOCAL_COLOR_BOUNDS =
|
private static final @android.annotation.NonNull RectF LOCAL_COLOR_BOUNDS =
|
||||||
new RectF(0, 0, 1, 1);
|
new RectF(0, 0, 1, 1);
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
private final StatusBarStateController mStatusBarStateController;
|
|
||||||
private final ArrayList<RectF> mLocalColorsToAdd = new ArrayList<>();
|
private final ArrayList<RectF> mLocalColorsToAdd = new ArrayList<>();
|
||||||
private final ArraySet<RectF> mColorAreas = new ArraySet<>();
|
private final ArraySet<RectF> mColorAreas = new ArraySet<>();
|
||||||
private volatile int mPages = 1;
|
private volatile int mPages = 1;
|
||||||
@@ -69,9 +66,8 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
private Bitmap mMiniBitmap;
|
private Bitmap mMiniBitmap;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ImageWallpaper(StatusBarStateController statusBarStateController) {
|
public ImageWallpaper() {
|
||||||
super();
|
super();
|
||||||
mStatusBarStateController = statusBarStateController;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -94,9 +90,7 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
mMiniBitmap = null;
|
mMiniBitmap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GLEngine extends Engine {
|
||||||
class GLEngine extends Engine implements StatusBarStateController.StateListener,
|
|
||||||
Choreographer.FrameCallback {
|
|
||||||
// Surface is rejected if size below a threshold on some devices (ie. 8px on elfin)
|
// 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.
|
// set min to 64 px (CTS covers this), please refer to ag/4867989 for detail.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -107,16 +101,13 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
private ImageWallpaperRenderer mRenderer;
|
private ImageWallpaperRenderer mRenderer;
|
||||||
private EglHelper mEglHelper;
|
private EglHelper mEglHelper;
|
||||||
private final Runnable mFinishRenderingTask = this::finishRendering;
|
private final Runnable mFinishRenderingTask = this::finishRendering;
|
||||||
private final Runnable mInitChoreographerTask = this::initChoreographerInternal;
|
private boolean mNeedRedraw;
|
||||||
private int mWidth = 1;
|
private int mWidth = 1;
|
||||||
private int mHeight = 1;
|
private int mHeight = 1;
|
||||||
private int mImgWidth = 1;
|
private int mImgWidth = 1;
|
||||||
private int mImgHeight = 1;
|
private int mImgHeight = 1;
|
||||||
private float mPageWidth = 1.f;
|
private float mPageWidth = 1.f;
|
||||||
private float mPageOffset = 1.f;
|
private float mPageOffset = 1.f;
|
||||||
private volatile float mDozeAmount;
|
|
||||||
private volatile boolean mNewDozeValue = false;
|
|
||||||
private volatile boolean mShouldScheduleFrame = false;
|
|
||||||
|
|
||||||
GLEngine() {
|
GLEngine() {
|
||||||
}
|
}
|
||||||
@@ -143,9 +134,6 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
if (mWorker != null && mWorker.getThreadHandler() != null) {
|
if (mWorker != null && mWorker.getThreadHandler() != null) {
|
||||||
mWorker.getThreadHandler().post(this::updateMiniBitmap);
|
mWorker.getThreadHandler().post(this::updateMiniBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
mDozeAmount = mStatusBarStateController.getDozeAmount();
|
|
||||||
mStatusBarStateController.addCallback(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EglHelper getEglHelperInstance() {
|
EglHelper getEglHelperInstance() {
|
||||||
@@ -221,11 +209,7 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
mMiniBitmap = null;
|
mMiniBitmap = null;
|
||||||
|
|
||||||
mStatusBarStateController.removeCallback(this);
|
|
||||||
|
|
||||||
mWorker.getThreadHandler().post(() -> {
|
mWorker.getThreadHandler().post(() -> {
|
||||||
finishChoreographerInternal();
|
|
||||||
mRenderer.finish();
|
mRenderer.finish();
|
||||||
mRenderer = null;
|
mRenderer = null;
|
||||||
mEglHelper.finish();
|
mEglHelper.finish();
|
||||||
@@ -351,28 +335,17 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
@Override
|
@Override
|
||||||
public void onSurfaceRedrawNeeded(SurfaceHolder holder) {
|
public void onSurfaceRedrawNeeded(SurfaceHolder holder) {
|
||||||
if (mWorker == null) return;
|
if (mWorker == null) return;
|
||||||
mDozeAmount = mStatusBarStateController.getDozeAmount();
|
|
||||||
mWorker.getThreadHandler().post(this::drawFrame);
|
mWorker.getThreadHandler().post(this::drawFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDozeAmountChanged(float linear, float eased) {
|
|
||||||
initChoreographer();
|
|
||||||
|
|
||||||
mDozeAmount = linear;
|
|
||||||
mNewDozeValue = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawFrame() {
|
private void drawFrame() {
|
||||||
preRender();
|
preRender();
|
||||||
requestRender();
|
requestRender();
|
||||||
postRender();
|
postRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Important: this method should only be invoked from the ImageWallpaper (worker) Thread.
|
|
||||||
*/
|
|
||||||
public void preRender() {
|
public void preRender() {
|
||||||
|
// This method should only be invoked from worker thread.
|
||||||
Trace.beginSection("ImageWallpaper#preRender");
|
Trace.beginSection("ImageWallpaper#preRender");
|
||||||
preRenderInternal();
|
preRenderInternal();
|
||||||
Trace.endSection();
|
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() {
|
public void requestRender() {
|
||||||
|
// This method should only be invoked from worker thread.
|
||||||
Trace.beginSection("ImageWallpaper#requestRender");
|
Trace.beginSection("ImageWallpaper#requestRender");
|
||||||
requestRenderInternal();
|
requestRenderInternal();
|
||||||
Trace.endSection();
|
Trace.endSection();
|
||||||
@@ -422,7 +393,6 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
&& frame.width() > 0 && frame.height() > 0;
|
&& frame.width() > 0 && frame.height() > 0;
|
||||||
|
|
||||||
if (readyToRender) {
|
if (readyToRender) {
|
||||||
mRenderer.setExposureValue(1 - mDozeAmount);
|
|
||||||
mRenderer.onDrawFrame();
|
mRenderer.onDrawFrame();
|
||||||
if (!mEglHelper.swapBuffer()) {
|
if (!mEglHelper.swapBuffer()) {
|
||||||
Log.e(TAG, "drawFrame failed!");
|
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() {
|
public void postRender() {
|
||||||
|
// This method should only be invoked from worker thread.
|
||||||
Trace.beginSection("ImageWallpaper#postRender");
|
Trace.beginSection("ImageWallpaper#postRender");
|
||||||
scheduleFinishRendering();
|
scheduleFinishRendering();
|
||||||
Trace.endSection();
|
Trace.endSection();
|
||||||
@@ -456,7 +424,6 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
|
|
||||||
private void finishRendering() {
|
private void finishRendering() {
|
||||||
Trace.beginSection("ImageWallpaper#finishRendering");
|
Trace.beginSection("ImageWallpaper#finishRendering");
|
||||||
finishChoreographerInternal();
|
|
||||||
if (mEglHelper != null) {
|
if (mEglHelper != null) {
|
||||||
mEglHelper.destroyEglSurface();
|
mEglHelper.destroyEglSurface();
|
||||||
mEglHelper.destroyEglContext();
|
mEglHelper.destroyEglContext();
|
||||||
@@ -464,35 +431,6 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
Trace.endSection();
|
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() {
|
private boolean needSupportWideColorGamut() {
|
||||||
return mRenderer.isWcgContent();
|
return mRenderer.isWcgContent();
|
||||||
}
|
}
|
||||||
@@ -512,17 +450,5 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
mEglHelper.dump(prefix, fd, out, args);
|
mEglHelper.dump(prefix, fd, out, args);
|
||||||
mRenderer.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import static android.opengl.GLES20.glDrawArrays;
|
|||||||
import static android.opengl.GLES20.glEnableVertexAttribArray;
|
import static android.opengl.GLES20.glEnableVertexAttribArray;
|
||||||
import static android.opengl.GLES20.glGenTextures;
|
import static android.opengl.GLES20.glGenTextures;
|
||||||
import static android.opengl.GLES20.glTexParameteri;
|
import static android.opengl.GLES20.glTexParameteri;
|
||||||
import static android.opengl.GLES20.glUniform1f;
|
|
||||||
import static android.opengl.GLES20.glUniform1i;
|
import static android.opengl.GLES20.glUniform1i;
|
||||||
import static android.opengl.GLES20.glVertexAttribPointer;
|
import static android.opengl.GLES20.glVertexAttribPointer;
|
||||||
|
|
||||||
@@ -53,7 +52,6 @@ class ImageGLWallpaper {
|
|||||||
private static final String A_POSITION = "aPosition";
|
private static final String A_POSITION = "aPosition";
|
||||||
private static final String A_TEXTURE_COORDINATES = "aTextureCoordinates";
|
private static final String A_TEXTURE_COORDINATES = "aTextureCoordinates";
|
||||||
private static final String U_TEXTURE = "uTexture";
|
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 POSITION_COMPONENT_COUNT = 2;
|
||||||
private static final int TEXTURE_COMPONENT_COUNT = 2;
|
private static final int TEXTURE_COMPONENT_COUNT = 2;
|
||||||
private static final int BYTES_PER_FLOAT = 4;
|
private static final int BYTES_PER_FLOAT = 4;
|
||||||
@@ -85,7 +83,6 @@ class ImageGLWallpaper {
|
|||||||
private int mAttrPosition;
|
private int mAttrPosition;
|
||||||
private int mAttrTextureCoordinates;
|
private int mAttrTextureCoordinates;
|
||||||
private int mUniTexture;
|
private int mUniTexture;
|
||||||
private int mUniExposure;
|
|
||||||
private int mTextureId;
|
private int mTextureId;
|
||||||
|
|
||||||
ImageGLWallpaper(ImageGLProgram program) {
|
ImageGLWallpaper(ImageGLProgram program) {
|
||||||
@@ -128,7 +125,6 @@ class ImageGLWallpaper {
|
|||||||
|
|
||||||
private void setupUniforms() {
|
private void setupUniforms() {
|
||||||
mUniTexture = mProgram.getUniformHandle(U_TEXTURE);
|
mUniTexture = mProgram.getUniformHandle(U_TEXTURE);
|
||||||
mUniExposure = mProgram.getUniformHandle(U_EXPOSURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
@@ -175,10 +171,6 @@ class ImageGLWallpaper {
|
|||||||
glUniform1i(mUniTexture, 0);
|
glUniform1i(mUniTexture, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setExposureValue(float exposureValue) {
|
|
||||||
glUniform1f(mUniExposure, exposureValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to dump current state.
|
* Called to dump current state.
|
||||||
* @param prefix prefix.
|
* @param prefix prefix.
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
|
|||||||
private final ImageGLWallpaper mWallpaper;
|
private final ImageGLWallpaper mWallpaper;
|
||||||
private final Rect mSurfaceSize = new Rect();
|
private final Rect mSurfaceSize = new Rect();
|
||||||
private final WallpaperTexture mTexture;
|
private final WallpaperTexture mTexture;
|
||||||
private float mExposureValue;
|
|
||||||
|
|
||||||
public ImageWallpaperRenderer(Context context) {
|
public ImageWallpaperRenderer(Context context) {
|
||||||
final WallpaperManager wpm = context.getSystemService(WallpaperManager.class);
|
final WallpaperManager wpm = context.getSystemService(WallpaperManager.class);
|
||||||
@@ -67,13 +66,6 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
|
|||||||
mTexture.use(c);
|
mTexture.use(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void setExposureValue(float exposureValue) {
|
|
||||||
mExposureValue = exposureValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWcgContent() {
|
public boolean isWcgContent() {
|
||||||
return mTexture.isWcgContent();
|
return mTexture.isWcgContent();
|
||||||
@@ -102,7 +94,6 @@ public class ImageWallpaperRenderer implements GLWallpaperRenderer {
|
|||||||
public void onDrawFrame() {
|
public void onDrawFrame() {
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glViewport(0, 0, mSurfaceSize.width(), mSurfaceSize.height());
|
glViewport(0, 0, mSurfaceSize.width(), mSurfaceSize.height());
|
||||||
mWallpaper.setExposureValue(mExposureValue);
|
|
||||||
mWallpaper.useTexture();
|
mWallpaper.useTexture();
|
||||||
mWallpaper.draw();
|
mWallpaper.draw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import android.view.DisplayInfo;
|
|||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
|
|
||||||
import com.android.systemui.glwallpaper.ImageWallpaperRenderer;
|
import com.android.systemui.glwallpaper.ImageWallpaperRenderer;
|
||||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
@@ -100,7 +99,7 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ImageWallpaper createImageWallpaper() {
|
private ImageWallpaper createImageWallpaper() {
|
||||||
return new ImageWallpaper(mock(StatusBarStateController.class)) {
|
return new ImageWallpaper() {
|
||||||
@Override
|
@Override
|
||||||
public Engine onCreateEngine() {
|
public Engine onCreateEngine() {
|
||||||
return new GLEngine(mHandler) {
|
return new GLEngine(mHandler) {
|
||||||
|
|||||||
Reference in New Issue
Block a user