Skip to content

Commit 4865909

Browse files
committed
Skip eglSwapBuffers() call when we do not draw to GL
The fix is to track when we issue GL drawing commands, and to skip the call to eglSwapBuffers() when a DisplayList does not result in any actual rendering calls to GL. Issue #6364143 QuickMuni list items and buttons flicker instead of fade Change-Id: I60a02c61a58c32d92481a1e814b4c8a49c6a37a3
1 parent 20c15a4 commit 4865909

File tree

7 files changed

+235
-162
lines changed

7 files changed

+235
-162
lines changed

core/java/android/view/DisplayList.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ public abstract class DisplayList {
6161
*/
6262
public static final int STATUS_INVOKE = 0x2;
6363

64+
/**
65+
* Indicates that the display list performed GL drawing operations.
66+
*
67+
* @see HardwareCanvas#drawDisplayList(DisplayList, android.graphics.Rect, int)
68+
*/
69+
public static final int STATUS_DREW = 0x4;
70+
6471
/**
6572
* Starts recording the display list. All operations performed on the
6673
* returned canvas are recorded and stored in this display list.

core/java/android/view/HardwareRenderer.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11021102

11031103
onPreDraw(dirty);
11041104

1105+
int status = DisplayList.STATUS_DONE;
11051106
int saveCount = canvas.save();
11061107
callbacks.onHardwarePreDraw(canvas);
11071108

@@ -1135,7 +1136,7 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11351136
drawDisplayListStartTime = System.nanoTime();
11361137
}
11371138

1138-
int status = canvas.drawDisplayList(displayList, mRedrawClip,
1139+
status = canvas.drawDisplayList(displayList, mRedrawClip,
11391140
DisplayList.FLAG_CLIP_CHILDREN);
11401141

11411142
if (mProfileEnabled) {
@@ -1171,22 +1172,25 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11711172
onPostDraw();
11721173

11731174
attachInfo.mIgnoreDirtyState = false;
1175+
1176+
if ((status & DisplayList.STATUS_DREW) == DisplayList.STATUS_DREW) {
11741177

1175-
long eglSwapBuffersStartTime = 0;
1176-
if (mProfileEnabled) {
1177-
eglSwapBuffersStartTime = System.nanoTime();
1178-
}
1179-
1180-
sEgl.eglSwapBuffers(sEglDisplay, mEglSurface);
1181-
1182-
if (mProfileEnabled) {
1183-
long now = System.nanoTime();
1184-
float total = (now - eglSwapBuffersStartTime) * 0.000001f;
1185-
mProfileData[mProfileCurrentFrame + 2] = total;
1178+
long eglSwapBuffersStartTime = 0;
1179+
if (mProfileEnabled) {
1180+
eglSwapBuffersStartTime = System.nanoTime();
1181+
}
1182+
1183+
sEgl.eglSwapBuffers(sEglDisplay, mEglSurface);
1184+
1185+
if (mProfileEnabled) {
1186+
long now = System.nanoTime();
1187+
float total = (now - eglSwapBuffersStartTime) * 0.000001f;
1188+
mProfileData[mProfileCurrentFrame + 2] = total;
1189+
}
1190+
1191+
checkEglErrors();
11861192
}
11871193

1188-
checkEglErrors();
1189-
11901194
return dirty == null;
11911195
}
11921196
}

include/private/hwui/DrawGlInfo.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ struct DrawGlInfo {
7272
// The functor needs to be invoked again but will
7373
// not redraw. Only the functor is invoked again
7474
// (unless another functor requests a redraw.)
75-
kStatusInvoke = 0x2
75+
kStatusInvoke = 0x2,
76+
// DisplayList actually issued GL drawing commands.
77+
// This is used to signal the HardwareRenderer that the
78+
// buffers should be flipped - otherwise, there were no
79+
// changes to the buffer, so no need to flip. Some hardware
80+
// has issues with stale buffer contents when no GL
81+
// commands are issued.
82+
kStatusDrew = 0x4
7683
};
7784
}; // struct DrawGlInfo
7885

0 commit comments

Comments
 (0)