Skip to content

Commit 6a2defc

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Don't clear the dirty clip flag if it's not applied Bug #6833979"
2 parents db3c867 + 8a4ac61 commit 6a2defc

File tree

7 files changed

+59
-16
lines changed

7 files changed

+59
-16
lines changed

libs/hwui/Android.mk

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@ ifeq ($(USE_OPENGL_RENDERER),true)
4040
external/skia/include/utils
4141

4242
LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER -DGL_GLEXT_PROTOTYPES
43-
LOCAL_CFLAGS += -fvisibility=hidden
44-
# Uncomment the following line to use `perf`
45-
# LOCAL_CFLAGS += -fno-omit-frame-pointer -marm -mapcs
4643
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
4744
LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui
4845
LOCAL_MODULE := libhwui
4946
LOCAL_MODULE_TAGS := optional
50-
47+
48+
ifndef HWUI_COMPILE_SYMBOLS
49+
LOCAL_CFLAGS += -fvisibility=hidden
50+
endif
51+
52+
ifdef HWUI_COMPILE_FOR_PERF
53+
LOCAL_CFLAGS += -fno-omit-frame-pointer -marm -mapcs
54+
endif
55+
5156
include $(BUILD_SHARED_LIBRARY)
5257

5358
include $(call all-makefiles-under,$(LOCAL_PATH))

libs/hwui/Caches.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ void Caches::activeTexture(GLuint textureUnit) {
358358
}
359359
}
360360

361-
void Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
361+
bool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
362362
if (scissorEnabled && (x != mScissorX || y != mScissorY ||
363363
width != mScissorWidth || height != mScissorHeight)) {
364364

@@ -368,21 +368,28 @@ void Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
368368
mScissorY = y;
369369
mScissorWidth = width;
370370
mScissorHeight = height;
371+
372+
return true;
371373
}
374+
return false;
372375
}
373376

374-
void Caches::enableScissor() {
377+
bool Caches::enableScissor() {
375378
if (!scissorEnabled) {
376379
glEnable(GL_SCISSOR_TEST);
377380
scissorEnabled = true;
381+
return true;
378382
}
383+
return false;
379384
}
380385

381-
void Caches::disableScissor() {
386+
bool Caches::disableScissor() {
382387
if (scissorEnabled) {
383388
glDisable(GL_SCISSOR_TEST);
384389
scissorEnabled = false;
390+
return true;
385391
}
392+
return false;
386393
}
387394

388395
void Caches::setScissorEnabled(bool enabled) {

libs/hwui/Caches.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ class ANDROID_API Caches: public Singleton<Caches> {
197197
/**
198198
* Sets the scissor for the current surface.
199199
*/
200-
void setScissor(GLint x, GLint y, GLint width, GLint height);
200+
bool setScissor(GLint x, GLint y, GLint width, GLint height);
201201

202202
/**
203203
* Resets the scissor state.
204204
*/
205205
void resetScissor();
206206

207-
void enableScissor();
208-
void disableScissor();
207+
bool enableScissor();
208+
bool disableScissor();
209209
void setScissorEnabled(bool enabled);
210210

211211
/**

libs/hwui/Debug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
// Turn on to dump display list state
7272
#define DEBUG_DISPLAY_LIST 0
7373

74+
// Turn on to insert an event marker for each display list op
75+
#define DEBUG_DISPLAY_LIST_OPS_AS_EVENTS 0
76+
7477
#if DEBUG_INIT
7578
#define INIT_LOGD(...) ALOGD(__VA_ARGS__)
7679
#else

libs/hwui/DisplayListRenderer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,13 @@ status_t DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flag
852852
#endif
853853

854854
renderer.startMark(mName.string());
855+
855856
int restoreTo = renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
856857
DISPLAY_LIST_LOGD("%s%s %d %d", indent, "Save",
857858
SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag, restoreTo);
858859
setViewProperties(renderer, level);
859-
if (renderer.quickReject(0, 0, mWidth, mHeight)) {
860+
861+
if (renderer.quickRejectNoScissor(0, 0, mWidth, mHeight)) {
860862
DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, "RestoreToCount", restoreTo);
861863
renderer.restoreToCount(restoreTo);
862864
renderer.endMark();
@@ -865,6 +867,7 @@ status_t DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flag
865867

866868
DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
867869
int saveCount = renderer.getSaveCount() - 1;
870+
868871
while (!mReader.eof()) {
869872
int op = mReader.readInt();
870873
if (op & OP_MAY_BE_SKIPPED_MASK) {
@@ -880,6 +883,10 @@ status_t DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, int32_t flag
880883
}
881884
logBuffer.writeCommand(level, op);
882885

886+
#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
887+
Caches::getInstance().eventMark(strlen(OP_NAMES[op]), OP_NAMES[op]);
888+
#endif
889+
883890
switch (op) {
884891
case DrawGLFunction: {
885892
Functor *functor = (Functor *) getInt();

libs/hwui/OpenGLRenderer.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ status_t OpenGLRenderer::callDrawGLFunction(Functor* functor, Rect& dirty) {
313313
interrupt();
314314
detachFunctor(functor);
315315

316+
mCaches.enableScissor();
316317
if (mDirtyClip) {
317318
setScissorFromClip();
318319
}
@@ -982,7 +983,7 @@ void OpenGLRenderer::clearLayerRegions() {
982983
// The list contains bounds that have already been clipped
983984
// against their initial clip rect, and the current clip
984985
// is likely different so we need to disable clipping here
985-
mCaches.disableScissor();
986+
bool scissorChanged = mCaches.disableScissor();
986987

987988
Vertex mesh[count * 6];
988989
Vertex* vertex = mesh;
@@ -1009,6 +1010,8 @@ void OpenGLRenderer::clearLayerRegions() {
10091010
setupDrawVertices(&mesh[0].position[0]);
10101011

10111012
glDrawArrays(GL_TRIANGLES, 0, count * 6);
1013+
1014+
if (scissorChanged) mCaches.enableScissor();
10121015
} else {
10131016
for (uint32_t i = 0; i < count; i++) {
10141017
delete mLayers.itemAt(i);
@@ -1065,16 +1068,31 @@ void OpenGLRenderer::setScissorFromClip() {
10651068
Rect clip(*mSnapshot->clipRect);
10661069
clip.snapToPixelBoundaries();
10671070

1068-
mCaches.setScissor(clip.left, mSnapshot->height - clip.bottom,
1069-
clip.getWidth(), clip.getHeight());
1070-
1071-
mDirtyClip = false;
1071+
if (mCaches.setScissor(clip.left, mSnapshot->height - clip.bottom,
1072+
clip.getWidth(), clip.getHeight())) {
1073+
mDirtyClip = false;
1074+
}
10721075
}
10731076

10741077
const Rect& OpenGLRenderer::getClipBounds() {
10751078
return mSnapshot->getLocalClip();
10761079
}
10771080

1081+
bool OpenGLRenderer::quickRejectNoScissor(float left, float top, float right, float bottom) {
1082+
if (mSnapshot->isIgnored()) {
1083+
return true;
1084+
}
1085+
1086+
Rect r(left, top, right, bottom);
1087+
mSnapshot->transform->mapRect(r);
1088+
r.snapToPixelBoundaries();
1089+
1090+
Rect clipRect(*mSnapshot->clipRect);
1091+
clipRect.snapToPixelBoundaries();
1092+
1093+
return !clipRect.intersects(r);
1094+
}
1095+
10781096
bool OpenGLRenderer::quickReject(float left, float top, float right, float bottom) {
10791097
if (mSnapshot->isIgnored()) {
10801098
return true;
@@ -1112,6 +1130,8 @@ Rect* OpenGLRenderer::getClipRect() {
11121130
///////////////////////////////////////////////////////////////////////////////
11131131

11141132
void OpenGLRenderer::setupDraw(bool clear) {
1133+
// TODO: It would be best if we could do this before quickReject()
1134+
// changes the scissor test state
11151135
if (clear) clearLayerRegions();
11161136
if (mDirtyClip) {
11171137
setScissorFromClip();

libs/hwui/OpenGLRenderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class OpenGLRenderer {
105105

106106
ANDROID_API const Rect& getClipBounds();
107107
ANDROID_API bool quickReject(float left, float top, float right, float bottom);
108+
bool quickRejectNoScissor(float left, float top, float right, float bottom);
108109
virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
109110
virtual Rect* getClipRect();
110111

0 commit comments

Comments
 (0)