Fix unsafety in SkiaShader storage, and texture unit accounting

bug:22390304

Fixes two issues:

1) The max texture unit wasn't large enough to handle the most complex
ComposeShader case (1 for draw primitive, 2 for gradient shader, 1 for
bitmap shader).

2) If a shader isn't supported by SkiaShader::store, the shader data
needs to be explicitly disabled, so we won't read uninitilized data
from it when trying to read shader information out.

Change-Id: I29ee7b7c1e07f67db88c1707bdc857daa305e713
This commit is contained in:
Chris Craik
2015-07-13 13:34:07 -07:00
parent 208934ff01
commit e310f83d59
3 changed files with 11 additions and 3 deletions

View File

@@ -370,7 +370,11 @@ void SkiaShader::store(Caches& caches, const SkShader& shader, const Matrix4& mo
if (tryStoreLayer(caches, shader, modelViewMatrix,
textureUnit, description, &outData->layerData)) {
outData->skiaShaderType = kLayer_SkiaShaderType;
return;
}
// Unknown/unsupported type, so explicitly ignore shader
outData->skiaShaderType = kNone_SkiaShaderType;
}
void SkiaShader::apply(Caches& caches, const SkiaShaderData& data) {

View File

@@ -22,7 +22,8 @@ namespace uirenderer {
const GLenum kTextureUnits[] = {
GL_TEXTURE0,
GL_TEXTURE1,
GL_TEXTURE2
GL_TEXTURE2,
GL_TEXTURE3
};
TextureState::TextureState()
@@ -33,10 +34,13 @@ TextureState::TextureState()
GLint maxTextureUnits;
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
LOG_ALWAYS_FATAL_IF(maxTextureUnits < kTextureUnitsCount,
"At least %d texture units are required!", kTextureUnitsCount);
"At least %d texture units are required!", kTextureUnitsCount);
}
void TextureState::activateTexture(GLuint textureUnit) {
LOG_ALWAYS_FATAL_IF(textureUnit >= kTextureUnitsCount,
"Tried to use texture unit index %d, only %d exist",
textureUnit, kTextureUnitsCount);
if (mTextureUnit != textureUnit) {
glActiveTexture(kTextureUnits[textureUnit]);
mTextureUnit = textureUnit;

View File

@@ -73,7 +73,7 @@ public:
void unbindTexture(GLuint texture);
private:
// total number of texture units available for use
static const int kTextureUnitsCount = 3;
static const int kTextureUnitsCount = 4;
TextureState();
GLuint mTextureUnit;