Skip to content

Commit 561ff8a

Browse files
chethaaseAndroid (Google) Code Review
authored andcommitted
Merge "Skip eglSwapBuffers() call when we do not draw to GL" into jb-dev
2 parents d53710c + 4865909 commit 561ff8a

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
@@ -1104,6 +1104,7 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11041104

11051105
onPreDraw(dirty);
11061106

1107+
int status = DisplayList.STATUS_DONE;
11071108
int saveCount = canvas.save();
11081109
callbacks.onHardwarePreDraw(canvas);
11091110

@@ -1137,7 +1138,7 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11371138
drawDisplayListStartTime = System.nanoTime();
11381139
}
11391140

1140-
int status = canvas.drawDisplayList(displayList, mRedrawClip,
1141+
status = canvas.drawDisplayList(displayList, mRedrawClip,
11411142
DisplayList.FLAG_CLIP_CHILDREN);
11421143

11431144
if (mProfileEnabled) {
@@ -1173,22 +1174,25 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11731174
onPostDraw();
11741175

11751176
attachInfo.mIgnoreDirtyState = false;
1177+
1178+
if ((status & DisplayList.STATUS_DREW) == DisplayList.STATUS_DREW) {
11761179

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

1190-
checkEglErrors();
1191-
11921196
return dirty == null;
11931197
}
11941198
}

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)