Skip to content

Commit 2aac1a0

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Improve the power off fade animation." into jb-mr1-dev
2 parents e70bf65 + 252c206 commit 2aac1a0

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

services/java/com/android/server/power/DisplayPowerController.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,9 @@ final class DisplayPowerController {
206206
// May be 0 if no warm-up is required.
207207
private int mLightSensorWarmUpTimeConfig;
208208

209-
// True if we should animate the backlight when turning the screen on or off, which
210-
// tends to be efficient for LCD displays but not for OLED displays.
211-
// False if we should play the electron beam animation instead, which is better for
212-
// OLED displays.
213-
private boolean mElectronBeamAnimatesBacklightConfig;
209+
// True if we should fade the screen while turning it off, false if we should play
210+
// a stylish electron beam animation instead.
211+
private boolean mElectronBeamFadesConfig;
214212

215213
// The pending power request.
216214
// Initially null until the first call to requestPowerState.
@@ -396,7 +394,7 @@ public DisplayPowerController(Looper looper, Context context, Notifier notifier,
396394
mScreenBrightnessRangeMinimum = clampAbsoluteBrightness(screenBrightnessMinimum);
397395
mScreenBrightnessRangeMaximum = PowerManager.BRIGHTNESS_ON;
398396

399-
mElectronBeamAnimatesBacklightConfig = resources.getBoolean(
397+
mElectronBeamFadesConfig = resources.getBoolean(
400398
com.android.internal.R.bool.config_animateScreenLights);
401399

402400
if (!DEBUG_PRETEND_PROXIMITY_SENSOR_ABSENT) {
@@ -682,8 +680,8 @@ private void updatePowerState() {
682680
if (mPowerState.getElectronBeamLevel() == 1.0f) {
683681
mPowerState.dismissElectronBeam();
684682
} else if (mPowerState.prepareElectronBeam(
685-
mElectronBeamAnimatesBacklightConfig ?
686-
ElectronBeam.MODE_BLANK :
683+
mElectronBeamFadesConfig ?
684+
ElectronBeam.MODE_FADE :
687685
ElectronBeam.MODE_WARM_UP)) {
688686
mElectronBeamOnAnimator.start();
689687
} else {
@@ -704,8 +702,8 @@ private void updatePowerState() {
704702
if (mPowerState.getElectronBeamLevel() == 0.0f) {
705703
setScreenOn(false);
706704
} else if (mPowerState.prepareElectronBeam(
707-
mElectronBeamAnimatesBacklightConfig ?
708-
ElectronBeam.MODE_BLANK :
705+
mElectronBeamFadesConfig ?
706+
ElectronBeam.MODE_FADE :
709707
ElectronBeam.MODE_COOL_DOWN)
710708
&& mPowerState.isScreenOn()) {
711709
mElectronBeamOffAnimator.start();

services/java/com/android/server/power/ElectronBeam.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ final class ElectronBeam {
8080
private EGLContext mEglContext;
8181
private EGLSurface mEglSurface;
8282
private boolean mSurfaceVisible;
83+
private float mSurfaceAlpha;
8384

8485
// Texture names. We only use one texture, which contains the screenshot.
8586
private final int[] mTexNames = new int[1];
@@ -90,9 +91,20 @@ final class ElectronBeam {
9091
private final FloatBuffer mVertexBuffer = createNativeFloatBuffer(8);
9192
private final FloatBuffer mTexCoordBuffer = createNativeFloatBuffer(8);
9293

94+
/**
95+
* Animates an electron beam warming up.
96+
*/
9397
public static final int MODE_WARM_UP = 0;
98+
99+
/**
100+
* Animates an electron beam shutting off.
101+
*/
94102
public static final int MODE_COOL_DOWN = 1;
95-
public static final int MODE_BLANK = 2;
103+
104+
/**
105+
* Animates a simple dim layer to fade the contents of the screen in or out progressively.
106+
*/
107+
public static final int MODE_FADE = 2;
96108

97109
public ElectronBeam(Display display) {
98110
mDisplay = display;
@@ -138,7 +150,7 @@ public boolean prepare(int mode) {
138150

139151
private boolean tryPrepare() {
140152
if (createSurface()) {
141-
if (mMode == MODE_BLANK) {
153+
if (mMode == MODE_FADE) {
142154
return true;
143155
}
144156
return createEglContext()
@@ -182,7 +194,7 @@ public boolean draw(float level) {
182194
return false;
183195
}
184196

185-
if (mMode == MODE_BLANK) {
197+
if (mMode == MODE_FADE) {
186198
return showSurface(1.0f - level);
187199
}
188200

@@ -504,7 +516,7 @@ private boolean createSurface() {
504516
if (mSurface == null) {
505517
try {
506518
int flags;
507-
if (mMode == MODE_BLANK) {
519+
if (mMode == MODE_FADE) {
508520
flags = Surface.FX_SURFACE_DIM | Surface.HIDDEN;
509521
} else {
510522
flags = Surface.OPAQUE | Surface.HIDDEN;
@@ -579,11 +591,12 @@ private void destroySurface() {
579591
}
580592
mSurface = null;
581593
mSurfaceVisible = false;
594+
mSurfaceAlpha = 0f;
582595
}
583596
}
584597

585598
private boolean showSurface(float alpha) {
586-
if (!mSurfaceVisible) {
599+
if (!mSurfaceVisible || mSurfaceAlpha != alpha) {
587600
Surface.openTransaction();
588601
try {
589602
mSurface.setLayer(ELECTRON_BEAM_LAYER);
@@ -593,6 +606,7 @@ private boolean showSurface(float alpha) {
593606
Surface.closeTransaction();
594607
}
595608
mSurfaceVisible = true;
609+
mSurfaceAlpha = alpha;
596610
}
597611
return true;
598612
}
@@ -683,5 +697,6 @@ public void dump(PrintWriter pw) {
683697
pw.println(" mDisplayWidth=" + mDisplayWidth);
684698
pw.println(" mDisplayHeight=" + mDisplayHeight);
685699
pw.println(" mSurfaceVisible=" + mSurfaceVisible);
700+
pw.println(" mSurfaceAlpha=" + mSurfaceAlpha);
686701
}
687702
}

0 commit comments

Comments
 (0)