Normalize GL_UNPACK_ALIGNMENT
Several places were setting GL_UNPACK_ALIGNMENT
unneccessarily, whereas other places were assuming an
unpack alignment of 1. Since we never actually
do explicit row-alignment, set GL_UNPACK_ALIGNMENT
to 1 at context creation time and never change it
Bug: 26584230
Also turns on aggressive glGetError checking to
better catch potential problem zones
Change-Id: I190c8f0f0494a7f046d5ed769405c75d363be59a
diff --git a/libs/hwui/BakedOpRenderer.cpp b/libs/hwui/BakedOpRenderer.cpp
index 0931282..e65746e 100644
--- a/libs/hwui/BakedOpRenderer.cpp
+++ b/libs/hwui/BakedOpRenderer.cpp
@@ -139,9 +139,7 @@
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 1ba6511..ec2013e 100644
--- a/libs/hwui/Dither.cpp
+++ b/libs/hwui/Dither.cpp
@@ -54,7 +54,6 @@
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 @@
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 ed31a2c..68bae6d 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -458,7 +458,6 @@
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 1473bc8..e899ac7 100644
--- a/libs/hwui/GradientCache.cpp
+++ b/libs/hwui/GradientCache.cpp
@@ -273,8 +273,6 @@
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 8369266..114347d 100644
--- a/libs/hwui/Layer.cpp
+++ b/libs/hwui/Layer.cpp
@@ -207,7 +207,6 @@
#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 0cf643f..0f219e4 100644
--- a/libs/hwui/LayerRenderer.cpp
+++ b/libs/hwui/LayerRenderer.cpp
@@ -373,7 +373,6 @@
GLenum format;
GLenum type;
- GLenum error = GL_NO_ERROR;
bool status = false;
switch (bitmap->colorType()) {
@@ -408,7 +407,7 @@
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 @@
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 @@
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 @@
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 0cd763d..1bfa308 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -195,9 +195,7 @@
}
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 9624726..6df994c 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 <utils/Log.h>
@@ -112,14 +113,10 @@
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 f1e28b7..62a20fc 100644
--- a/libs/hwui/TextDropShadowCache.cpp
+++ b/libs/hwui/TextDropShadowCache.cpp
@@ -200,8 +200,6 @@
}
// 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 771d004..9fc0c19 100644
--- a/libs/hwui/Texture.cpp
+++ b/libs/hwui/Texture.cpp
@@ -122,7 +122,6 @@
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 26ebdee..78b8eda 100644
--- a/libs/hwui/renderstate/TextureState.cpp
+++ b/libs/hwui/renderstate/TextureState.cpp
@@ -43,6 +43,7 @@
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 6c521e4..85a10f9 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 <cutils/log.h>
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