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
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -195,9 +195,7 @@ bool OpenGLRenderer::finish() {
|
||||
}
|
||||
|
||||
if (!suppressErrorChecks()) {
|
||||
#if DEBUG_OPENGL
|
||||
GLUtils::dumpGLErrors();
|
||||
#endif
|
||||
GL_CHECKPOINT();
|
||||
|
||||
#if DEBUG_MEMORY_USAGE
|
||||
mCaches.dumpMemoryUsage();
|
||||
|
||||
@@ -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 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user