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
This commit is contained in:
parent
5884e9eb26
commit
c492e67810
@ -280,33 +280,33 @@ void Layer::onDraw(const Region& clip) const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum target = GL_TEXTURE_EXTERNAL_OES;
|
|
||||||
if (!isProtected()) {
|
if (!isProtected()) {
|
||||||
glBindTexture(target, mTextureName);
|
glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName);
|
||||||
|
GLenum filter = GL_NEAREST;
|
||||||
if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) {
|
if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) {
|
||||||
// TODO: we could be more subtle with isFixedSize()
|
// TODO: we could be more subtle with isFixedSize()
|
||||||
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
filter = GL_LINEAR;
|
||||||
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
} else {
|
|
||||||
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
}
|
}
|
||||||
glEnable(target);
|
glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter);
|
||||||
|
glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter);
|
||||||
glMatrixMode(GL_TEXTURE);
|
glMatrixMode(GL_TEXTURE);
|
||||||
glLoadMatrixf(mTextureMatrix);
|
glLoadMatrixf(mTextureMatrix);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glEnable(GL_TEXTURE_EXTERNAL_OES);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
} else {
|
} else {
|
||||||
target = GL_TEXTURE_2D;
|
glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName());
|
||||||
glBindTexture(target, mFlinger->getProtectedTexName());
|
|
||||||
glEnable(target);
|
|
||||||
glMatrixMode(GL_TEXTURE);
|
glMatrixMode(GL_TEXTURE);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawWithOpenGL(clip);
|
drawWithOpenGL(clip);
|
||||||
|
|
||||||
glDisable(target);
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
// As documented in libhardware header, formats in the range
|
// As documented in libhardware header, formats in the range
|
||||||
|
@ -388,14 +388,9 @@ void LayerBase::clearWithOpenGL(const Region& clip, GLclampf red,
|
|||||||
const uint32_t fbHeight = hw.getHeight();
|
const uint32_t fbHeight = hw.getHeight();
|
||||||
glColor4f(red,green,blue,alpha);
|
glColor4f(red,green,blue,alpha);
|
||||||
|
|
||||||
#if defined(GL_OES_EGL_image_external)
|
|
||||||
if (GLExtensions::getInstance().haveTextureExternal()) {
|
|
||||||
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
||||||
}
|
|
||||||
#endif
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_DITHER);
|
|
||||||
|
|
||||||
Region::const_iterator it = clip.begin();
|
Region::const_iterator it = clip.begin();
|
||||||
Region::const_iterator const end = clip.end();
|
Region::const_iterator const end = clip.end();
|
||||||
@ -457,12 +452,6 @@ void LayerBase::drawWithOpenGL(const Region& clip) const
|
|||||||
texCoords[3].u = 1;
|
texCoords[3].u = 1;
|
||||||
texCoords[3].v = 1;
|
texCoords[3].v = 1;
|
||||||
|
|
||||||
if (needsDithering()) {
|
|
||||||
glEnable(GL_DITHER);
|
|
||||||
} else {
|
|
||||||
glDisable(GL_DITHER);
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glVertexPointer(2, GL_FLOAT, 0, mVertices);
|
glVertexPointer(2, GL_FLOAT, 0, mVertices);
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
|
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
|
||||||
@ -476,6 +465,7 @@ void LayerBase::drawWithOpenGL(const Region& clip) const
|
|||||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
}
|
}
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
|
void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
|
||||||
|
@ -49,7 +49,8 @@ void LayerDim::onDraw(const Region& clip) const
|
|||||||
const DisplayHardware& hw(graphicPlane(0).displayHardware());
|
const DisplayHardware& hw(graphicPlane(0).displayHardware());
|
||||||
const GLfloat alpha = s.alpha/255.0f;
|
const GLfloat alpha = s.alpha/255.0f;
|
||||||
const uint32_t fbHeight = hw.getHeight();
|
const uint32_t fbHeight = hw.getHeight();
|
||||||
glDisable(GL_DITHER);
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
if (s.alpha == 0xFF) {
|
if (s.alpha == 0xFF) {
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
@ -60,11 +61,6 @@ void LayerDim::onDraw(const Region& clip) const
|
|||||||
|
|
||||||
glColor4f(0, 0, 0, alpha);
|
glColor4f(0, 0, 0, alpha);
|
||||||
|
|
||||||
#if defined(GL_OES_EGL_image_external)
|
|
||||||
if (GLExtensions::getInstance().haveTextureExternal()) {
|
|
||||||
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
glVertexPointer(2, GL_FLOAT, 0, mVertices);
|
glVertexPointer(2, GL_FLOAT, 0, mVertices);
|
||||||
|
|
||||||
while (it != end) {
|
while (it != end) {
|
||||||
@ -73,8 +69,9 @@ void LayerDim::onDraw(const Region& clip) const
|
|||||||
glScissor(r.left, sy, r.width(), r.height());
|
glScissor(r.left, sy, r.width(), r.height());
|
||||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
}
|
}
|
||||||
}
|
glDisable(GL_BLEND);
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@ -1029,8 +1029,9 @@ void SurfaceFlinger::debugFlashRegions()
|
|||||||
composeSurfaces(repaint);
|
composeSurfaces(repaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDisable(GL_DITHER);
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
static int toggle = 0;
|
static int toggle = 0;
|
||||||
@ -1073,9 +1074,6 @@ void SurfaceFlinger::drawWormhole() const
|
|||||||
const int32_t width = hw.getWidth();
|
const int32_t width = hw.getWidth();
|
||||||
const int32_t height = hw.getHeight();
|
const int32_t height = hw.getHeight();
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
|
||||||
glDisable(GL_DITHER);
|
|
||||||
|
|
||||||
if (LIKELY(!mDebugBackground)) {
|
if (LIKELY(!mDebugBackground)) {
|
||||||
glClearColor(0,0,0,0);
|
glClearColor(0,0,0,0);
|
||||||
Region::const_iterator it = region.begin();
|
Region::const_iterator it = region.begin();
|
||||||
@ -1090,19 +1088,20 @@ void SurfaceFlinger::drawWormhole() const
|
|||||||
const GLshort vertices[][2] = { { 0, 0 }, { width, 0 },
|
const GLshort vertices[][2] = { { 0, 0 }, { width, 0 },
|
||||||
{ width, height }, { 0, height } };
|
{ width, height }, { 0, height } };
|
||||||
const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
|
const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
|
||||||
|
|
||||||
glVertexPointer(2, GL_SHORT, 0, vertices);
|
glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||||
glTexCoordPointer(2, GL_SHORT, 0, tcoords);
|
glTexCoordPointer(2, GL_SHORT, 0, tcoords);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
#if defined(GL_OES_EGL_image_external)
|
|
||||||
if (GLExtensions::getInstance().haveTextureExternal()) {
|
|
||||||
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
||||||
}
|
|
||||||
#endif
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
|
glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
|
||||||
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||||
glMatrixMode(GL_TEXTURE);
|
glMatrixMode(GL_TEXTURE);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1);
|
glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1);
|
||||||
Region::const_iterator it = region.begin();
|
Region::const_iterator it = region.begin();
|
||||||
Region::const_iterator const end = region.end();
|
Region::const_iterator const end = region.end();
|
||||||
@ -1813,6 +1812,8 @@ status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy,
|
|||||||
GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
|
GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
|
||||||
|
|
||||||
// redraw the screen entirely...
|
// redraw the screen entirely...
|
||||||
|
glDisable(GL_TEXTURE_EXTERNAL_OES);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
glClearColor(0,0,0,1);
|
glClearColor(0,0,0,1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@ -2004,6 +2005,7 @@ status_t SurfaceFlinger::electronBeamOffAnimationImplLocked()
|
|||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glDeleteTextures(1, &tname);
|
glDeleteTextures(1, &tname);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2148,6 +2150,7 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked()
|
|||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glDeleteTextures(1, &tname);
|
glDeleteTextures(1, &tname);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user