From e310f83d591dc3fb7bd5c684239481a586f00662 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Mon, 13 Jul 2015 13:34:07 -0700 Subject: [PATCH] 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 --- libs/hwui/SkiaShader.cpp | 4 ++++ libs/hwui/renderstate/TextureState.cpp | 8 ++++++-- libs/hwui/renderstate/TextureState.h | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/hwui/SkiaShader.cpp b/libs/hwui/SkiaShader.cpp index 2cfb9e1dc8c19..a2aa2d103048e 100644 --- a/libs/hwui/SkiaShader.cpp +++ b/libs/hwui/SkiaShader.cpp @@ -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) { diff --git a/libs/hwui/renderstate/TextureState.cpp b/libs/hwui/renderstate/TextureState.cpp index a211de7e5ff35..987d4cd55a5ec 100644 --- a/libs/hwui/renderstate/TextureState.cpp +++ b/libs/hwui/renderstate/TextureState.cpp @@ -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; diff --git a/libs/hwui/renderstate/TextureState.h b/libs/hwui/renderstate/TextureState.h index 5a57b9f6aaecb..d3c014c00bce4 100644 --- a/libs/hwui/renderstate/TextureState.h +++ b/libs/hwui/renderstate/TextureState.h @@ -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;