Skip to content

Commit 9044ef0

Browse files
committed
Make sure set GL state properly
when taking a screenshot, in particular, we could end up with stale GL state when drawing LayerDim which resulted in incortect rendering. Bug: 5467587 Change-Id: Id9fbed2843481d31063620f3662b364c7e3ac781
1 parent f522e09 commit 9044ef0

File tree

4 files changed

+30
-40
lines changed

4 files changed

+30
-40
lines changed

services/surfaceflinger/Layer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,33 +280,33 @@ void Layer::onDraw(const Region& clip) const
280280
return;
281281
}
282282

283-
GLenum target = GL_TEXTURE_EXTERNAL_OES;
284283
if (!isProtected()) {
285-
glBindTexture(target, mTextureName);
284+
glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName);
285+
GLenum filter = GL_NEAREST;
286286
if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) {
287287
// TODO: we could be more subtle with isFixedSize()
288-
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
289-
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
290-
} else {
291-
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
292-
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
288+
filter = GL_LINEAR;
293289
}
294-
glEnable(target);
290+
glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter);
291+
glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter);
295292
glMatrixMode(GL_TEXTURE);
296293
glLoadMatrixf(mTextureMatrix);
297294
glMatrixMode(GL_MODELVIEW);
295+
glEnable(GL_TEXTURE_EXTERNAL_OES);
296+
glDisable(GL_TEXTURE_2D);
298297
} else {
299-
target = GL_TEXTURE_2D;
300-
glBindTexture(target, mFlinger->getProtectedTexName());
301-
glEnable(target);
298+
glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName());
302299
glMatrixMode(GL_TEXTURE);
303300
glLoadIdentity();
304301
glMatrixMode(GL_MODELVIEW);
302+
glDisable(GL_TEXTURE_EXTERNAL_OES);
303+
glEnable(GL_TEXTURE_2D);
305304
}
306305

307306
drawWithOpenGL(clip);
308307

309-
glDisable(target);
308+
glDisable(GL_TEXTURE_EXTERNAL_OES);
309+
glDisable(GL_TEXTURE_2D);
310310
}
311311

312312
// As documented in libhardware header, formats in the range

services/surfaceflinger/LayerBase.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,9 @@ void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
388388
const uint32_t fbHeight = hw.getHeight();
389389
glColor4f(red,green,blue,alpha);
390390

391-
#if defined(GL_OES_EGL_image_external)
392-
if (GLExtensions::getInstance().haveTextureExternal()) {
393-
glDisable(GL_TEXTURE_EXTERNAL_OES);
394-
}
395-
#endif
391+
glDisable(GL_TEXTURE_EXTERNAL_OES);
396392
glDisable(GL_TEXTURE_2D);
397393
glDisable(GL_BLEND);
398-
glDisable(GL_DITHER);
399394

400395
Region::const_iterator it = clip.begin();
401396
Region::const_iterator const end = clip.end();
@@ -457,12 +452,6 @@ void LayerBase::drawWithOpenGL(const Region& clip) const
457452
texCoords[3].u = 1;
458453
texCoords[3].v = 1;
459454

460-
if (needsDithering()) {
461-
glEnable(GL_DITHER);
462-
} else {
463-
glDisable(GL_DITHER);
464-
}
465-
466455
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
467456
glVertexPointer(2, GL_FLOAT, 0, mVertices);
468457
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
@@ -476,6 +465,7 @@ void LayerBase::drawWithOpenGL(const Region& clip) const
476465
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
477466
}
478467
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
468+
glDisable(GL_BLEND);
479469
}
480470

481471
void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const

services/surfaceflinger/LayerDim.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ void LayerDim::onDraw(const Region& clip) const
4949
const DisplayHardware& hw(graphicPlane(0).displayHardware());
5050
const GLfloat alpha = s.alpha/255.0f;
5151
const uint32_t fbHeight = hw.getHeight();
52-
glDisable(GL_DITHER);
52+
glDisable(GL_TEXTURE_EXTERNAL_OES);
53+
glDisable(GL_TEXTURE_2D);
5354

5455
if (s.alpha == 0xFF) {
5556
glDisable(GL_BLEND);
@@ -60,11 +61,6 @@ void LayerDim::onDraw(const Region& clip) const
6061

6162
glColor4f(0, 0, 0, alpha);
6263

63-
#if defined(GL_OES_EGL_image_external)
64-
if (GLExtensions::getInstance().haveTextureExternal()) {
65-
glDisable(GL_TEXTURE_EXTERNAL_OES);
66-
}
67-
#endif
6864
glVertexPointer(2, GL_FLOAT, 0, mVertices);
6965

7066
while (it != end) {
@@ -73,8 +69,9 @@ void LayerDim::onDraw(const Region& clip) const
7369
glScissor(r.left, sy, r.width(), r.height());
7470
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
7571
}
72+
glDisable(GL_BLEND);
73+
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
7674
}
77-
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
7875
}
7976

8077
// ---------------------------------------------------------------------------

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,9 @@ void SurfaceFlinger::debugFlashRegions()
10291029
composeSurfaces(repaint);
10301030
}
10311031

1032+
glDisable(GL_TEXTURE_EXTERNAL_OES);
1033+
glDisable(GL_TEXTURE_2D);
10321034
glDisable(GL_BLEND);
1033-
glDisable(GL_DITHER);
10341035
glDisable(GL_SCISSOR_TEST);
10351036

10361037
static int toggle = 0;
@@ -1073,9 +1074,6 @@ void SurfaceFlinger::drawWormhole() const
10731074
const int32_t width = hw.getWidth();
10741075
const int32_t height = hw.getHeight();
10751076

1076-
glDisable(GL_BLEND);
1077-
glDisable(GL_DITHER);
1078-
10791077
if (LIKELY(!mDebugBackground)) {
10801078
glClearColor(0,0,0,0);
10811079
Region::const_iterator it = region.begin();
@@ -1090,19 +1088,20 @@ void SurfaceFlinger::drawWormhole() const
10901088
const GLshort vertices[][2] = { { 0, 0 }, { width, 0 },
10911089
{ width, height }, { 0, height } };
10921090
const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
1091+
10931092
glVertexPointer(2, GL_SHORT, 0, vertices);
10941093
glTexCoordPointer(2, GL_SHORT, 0, tcoords);
10951094
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1096-
#if defined(GL_OES_EGL_image_external)
1097-
if (GLExtensions::getInstance().haveTextureExternal()) {
1098-
glDisable(GL_TEXTURE_EXTERNAL_OES);
1099-
}
1100-
#endif
1095+
1096+
glDisable(GL_TEXTURE_EXTERNAL_OES);
11011097
glEnable(GL_TEXTURE_2D);
11021098
glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
11031099
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
11041100
glMatrixMode(GL_TEXTURE);
11051101
glLoadIdentity();
1102+
1103+
glDisable(GL_BLEND);
1104+
11061105
glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1);
11071106
Region::const_iterator it = region.begin();
11081107
Region::const_iterator const end = region.end();
@@ -1813,6 +1812,8 @@ status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy,
18131812
GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
18141813

18151814
// redraw the screen entirely...
1815+
glDisable(GL_TEXTURE_EXTERNAL_OES);
1816+
glDisable(GL_TEXTURE_2D);
18161817
glClearColor(0,0,0,1);
18171818
glClear(GL_COLOR_BUFFER_BIT);
18181819
glMatrixMode(GL_MODELVIEW);
@@ -2004,6 +2005,7 @@ status_t SurfaceFlinger::electronBeamOffAnimationImplLocked()
20042005
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
20052006
glDeleteTextures(1, &tname);
20062007
glDisable(GL_TEXTURE_2D);
2008+
glDisable(GL_BLEND);
20072009
return NO_ERROR;
20082010
}
20092011

@@ -2148,6 +2150,7 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
21482150
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
21492151
glDeleteTextures(1, &tname);
21502152
glDisable(GL_TEXTURE_2D);
2153+
glDisable(GL_BLEND);
21512154

21522155
return NO_ERROR;
21532156
}

0 commit comments

Comments
 (0)