diff --git a/libs/hwui/BakedOpRenderer.cpp b/libs/hwui/BakedOpRenderer.cpp index 09312825234ea..e65746eea98a7 100644 --- a/libs/hwui/BakedOpRenderer.cpp +++ b/libs/hwui/BakedOpRenderer.cpp @@ -139,9 +139,7 @@ void BakedOpRenderer::endFrame(const Rect& repaintRect) { mCaches.pathCache.trim(); mCaches.tessellationCache.trim(); -#if DEBUG_OPENGL - GLUtils::dumpGLErrors(); -#endif + GL_CHECKPOINT(); #if DEBUG_MEMORY_USAGE mCaches.dumpMemoryUsage(); diff --git a/libs/hwui/Dither.cpp b/libs/hwui/Dither.cpp index 1ba651174c8ae..ec2013e27401c 100644 --- a/libs/hwui/Dither.cpp +++ b/libs/hwui/Dither.cpp @@ -54,7 +54,6 @@ void Dither::bindDitherTexture() { 15 * dither, 7 * dither, 13 * dither, 5 * dither }; - glPixelStorei(GL_UNPACK_ALIGNMENT, sizeof(GLfloat)); glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, DITHER_KERNEL_SIZE, DITHER_KERNEL_SIZE, 0, GL_RED, GL_FLOAT, &pattern); } else { @@ -65,7 +64,6 @@ void Dither::bindDitherTexture() { 15, 7, 13, 5 }; - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, DITHER_KERNEL_SIZE, DITHER_KERNEL_SIZE, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &pattern); } diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index ed31a2c271212..68bae6dc47f6b 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -458,7 +458,6 @@ void FontRenderer::checkTextureUpdate() { GLuint lastTextureId = 0; bool resetPixelStore = false; - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Iterate over all the cache textures and see which ones need to be updated checkTextureUpdateForCache(caches, mACacheTextures, resetPixelStore, lastTextureId); diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp index 1473bc88c0607..e899ac71ff366 100644 --- a/libs/hwui/GradientCache.cpp +++ b/libs/hwui/GradientCache.cpp @@ -273,8 +273,6 @@ void GradientCache::generateTexture(uint32_t* colors, float* positions, memcpy(pixels + rowBytes, pixels, rowBytes); - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - if (mUseFloatTexture) { // We have to use GL_RGBA16F because GL_RGBA32F does not support filtering texture->upload(GL_RGBA16F, width, height, GL_RGBA, GL_FLOAT, pixels); diff --git a/libs/hwui/Layer.cpp b/libs/hwui/Layer.cpp index 83692664d76f3..114347d94357a 100644 --- a/libs/hwui/Layer.cpp +++ b/libs/hwui/Layer.cpp @@ -207,7 +207,6 @@ void Layer::allocateTexture() { #endif if (texture.mId) { texture.updateSize(getWidth(), getHeight(), GL_RGBA); - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glTexImage2D(renderTarget, 0, GL_RGBA, getWidth(), getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); } diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp index 0cf643fb686ed..0f219e4792f65 100644 --- a/libs/hwui/LayerRenderer.cpp +++ b/libs/hwui/LayerRenderer.cpp @@ -373,7 +373,6 @@ bool LayerRenderer::copyLayer(RenderState& renderState, Layer* layer, SkBitmap* GLenum format; GLenum type; - GLenum error = GL_NO_ERROR; bool status = false; switch (bitmap->colorType()) { @@ -408,7 +407,7 @@ bool LayerRenderer::copyLayer(RenderState& renderState, Layer* layer, SkBitmap* renderState.bindFramebuffer(fbo); glGenTextures(1, &texture); - if ((error = glGetError()) != GL_NO_ERROR) goto error; + GL_CHECKPOINT(); caches.textureState().activateTexture(0); caches.textureState().bindTexture(texture); @@ -423,11 +422,11 @@ bool LayerRenderer::copyLayer(RenderState& renderState, Layer* layer, SkBitmap* glTexImage2D(GL_TEXTURE_2D, 0, format, bitmap->width(), bitmap->height(), 0, format, type, nullptr); - if ((error = glGetError()) != GL_NO_ERROR) goto error; + GL_CHECKPOINT(); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); - if ((error = glGetError()) != GL_NO_ERROR) goto error; + GL_CHECKPOINT(); { LayerRenderer renderer(renderState, layer); @@ -438,7 +437,7 @@ bool LayerRenderer::copyLayer(RenderState& renderState, Layer* layer, SkBitmap* renderer.translate(0.0f, bitmap->height()); renderer.scale(1.0f, -1.0f); - if ((error = glGetError()) != GL_NO_ERROR) goto error; + GL_CHECKPOINT(); { Rect bounds; @@ -448,19 +447,12 @@ bool LayerRenderer::copyLayer(RenderState& renderState, Layer* layer, SkBitmap* glReadPixels(0, 0, bitmap->width(), bitmap->height(), format, type, bitmap->getPixels()); - if ((error = glGetError()) != GL_NO_ERROR) goto error; + GL_CHECKPOINT(); } status = true; } -error: -#if DEBUG_OPENGL - if (error != GL_NO_ERROR) { - ALOGD("GL error while copying layer into bitmap = 0x%x", error); - } -#endif - renderState.bindFramebuffer(previousFbo); layer->setAlpha(alpha, mode); layer->setFbo(previousLayerFbo); diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 0cd763df78d1f..1bfa3084d2667 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -195,9 +195,7 @@ bool OpenGLRenderer::finish() { } if (!suppressErrorChecks()) { -#if DEBUG_OPENGL - GLUtils::dumpGLErrors(); -#endif + GL_CHECKPOINT(); #if DEBUG_MEMORY_USAGE mCaches.dumpMemoryUsage(); diff --git a/libs/hwui/PixelBuffer.cpp b/libs/hwui/PixelBuffer.cpp index 96247260f0f42..6df994c623f23 100644 --- a/libs/hwui/PixelBuffer.cpp +++ b/libs/hwui/PixelBuffer.cpp @@ -20,6 +20,7 @@ #include "Extensions.h" #include "Properties.h" #include "renderstate/RenderState.h" +#include "utils/GLUtils.h" #include @@ -112,14 +113,10 @@ uint8_t* GpuPixelBuffer::map(AccessMode mode) { if (mAccessMode == kAccessMode_None) { mCaches.pixelBufferState().bind(mBuffer); mMappedPointer = (uint8_t*) glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, getSize(), mode); -#if DEBUG_OPENGL - if (!mMappedPointer) { - GLenum status = GL_NO_ERROR; - while ((status = glGetError()) != GL_NO_ERROR) { - ALOGE("Could not map GPU pixel buffer: 0x%x", status); - } + if (CC_UNLIKELY(!mMappedPointer)) { + GLUtils::dumpGLErrors(); + LOG_ALWAYS_FATAL("Failed to map PBO"); } -#endif mAccessMode = mode; } diff --git a/libs/hwui/TextDropShadowCache.cpp b/libs/hwui/TextDropShadowCache.cpp index f1e28b7dfa40f..62a20fcfa699e 100644 --- a/libs/hwui/TextDropShadowCache.cpp +++ b/libs/hwui/TextDropShadowCache.cpp @@ -200,8 +200,6 @@ ShadowTexture* TextDropShadowCache::get(const SkPaint* paint, const char* glyphs } // Textures are Alpha8 - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - texture->upload(GL_ALPHA, shadow.width, shadow.height, GL_ALPHA, GL_UNSIGNED_BYTE, shadow.image); texture->setFilter(GL_LINEAR); diff --git a/libs/hwui/Texture.cpp b/libs/hwui/Texture.cpp index 771d004cb91d2..9fc0c199815db 100644 --- a/libs/hwui/Texture.cpp +++ b/libs/hwui/Texture.cpp @@ -122,7 +122,6 @@ void Texture::upload(GLint internalformat, uint32_t width, uint32_t height, static void uploadToTexture(bool resize, GLenum format, GLenum type, GLsizei stride, GLsizei bpp, GLsizei width, GLsizei height, const GLvoid * data) { - glPixelStorei(GL_UNPACK_ALIGNMENT, bpp); const bool useStride = stride != width && Caches::getInstance().extensions().hasUnpackRowLength(); if ((stride == width) || useStride) { diff --git a/libs/hwui/renderstate/TextureState.cpp b/libs/hwui/renderstate/TextureState.cpp index 26ebdee06c083..78b8edae2eed1 100644 --- a/libs/hwui/renderstate/TextureState.cpp +++ b/libs/hwui/renderstate/TextureState.cpp @@ -43,6 +43,7 @@ TextureState::TextureState() glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); LOG_ALWAYS_FATAL_IF(maxTextureUnits < kTextureUnitsCount, "At least %d texture units are required!", kTextureUnitsCount); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } void TextureState::activateTexture(GLuint textureUnit) { diff --git a/libs/hwui/utils/GLUtils.h b/libs/hwui/utils/GLUtils.h index 6c521e4955a02..85a10f94dc4c1 100644 --- a/libs/hwui/utils/GLUtils.h +++ b/libs/hwui/utils/GLUtils.h @@ -16,12 +16,14 @@ #ifndef GLUTILS_H #define GLUTILS_H +#include "Debug.h" + #include namespace android { namespace uirenderer { -#if 0 +#if DEBUG_OPENGL #define GL_CHECKPOINT() LOG_ALWAYS_FATAL_IF(GLUtils::dumpGLErrors(),\ "GL errors! %s:%d", __FILE__, __LINE__) #else