Skip to content

Commit 78eb122

Browse files
author
Jeff Brown
committed
Dejank electron beam.
On some devices it can take hundreds of milliseconds to get a brand new EGL surface performing in tip-top shape. To get it ready make it do a few pushups before the show begins. Bug: 7318962 Change-Id: I7ae92ce100c368327042a29ffa65faee9b567c8d
1 parent 9cf36b7 commit 78eb122

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ final class ElectronBeam {
6363
private static final float HSTRETCH_DURATION = 0.5f;
6464
private static final float VSTRETCH_DURATION = 1.0f - HSTRETCH_DURATION;
6565

66+
// The number of frames to draw when preparing the animation so that it will
67+
// be ready to run smoothly. We use 3 frames because we are triple-buffered.
68+
// See code for details.
69+
private static final int DEJANK_FRAMES = 3;
70+
6671
// Set to true when the animation context has been fully prepared.
6772
private boolean mPrepared;
6873
private int mMode;
@@ -145,6 +150,19 @@ public boolean prepare(int mode) {
145150

146151
// Done.
147152
mPrepared = true;
153+
154+
// Dejanking optimization.
155+
// Some GL drivers can introduce a lot of lag in the first few frames as they
156+
// initialize their state and allocate graphics buffers for rendering.
157+
// Work around this problem by rendering the first frame of the animation a few
158+
// times. The rest of the animation should run smoothly thereafter.
159+
// The frames we draw here aren't visible because we are essentially just
160+
// painting the screenshot as-is.
161+
if (mode == MODE_COOL_DOWN) {
162+
for (int i = 0; i < DEJANK_FRAMES; i++) {
163+
draw(1.0f);
164+
}
165+
}
148166
return true;
149167
}
150168

0 commit comments

Comments
 (0)