diff options
Diffstat (limited to 'libs/hwui/SkiaShader.cpp')
| -rw-r--r-- | libs/hwui/SkiaShader.cpp | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/libs/hwui/SkiaShader.cpp b/libs/hwui/SkiaShader.cpp index 797ed10..6a4a0c8 100644 --- a/libs/hwui/SkiaShader.cpp +++ b/libs/hwui/SkiaShader.cpp @@ -73,7 +73,7 @@ SkiaShader::SkiaShader(): mCaches(NULL) { } SkiaShader::SkiaShader(Type type, SkShader* key, SkShader::TileMode tileX, - SkShader::TileMode tileY, SkMatrix* matrix, bool blend): + SkShader::TileMode tileY, const SkMatrix* matrix, bool blend): mType(type), mKey(key), mTileX(tileX), mTileY(tileY), mBlend(blend), mCaches(NULL) { setMatrix(matrix); @@ -101,6 +101,49 @@ void SkiaShader::computeScreenSpaceMatrix(mat4& screenSpace, const mat4& modelVi } /////////////////////////////////////////////////////////////////////////////// +// Layer shader +/////////////////////////////////////////////////////////////////////////////// + +SkiaLayerShader::SkiaLayerShader(Layer* layer, const SkMatrix* matrix): + SkiaShader(kBitmap, NULL, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, + matrix, layer->isBlend()), mLayer(layer) { + updateLocalMatrix(matrix); +} + +SkiaShader* SkiaLayerShader::copy() { + SkiaLayerShader* copy = new SkiaLayerShader(); + copy->copyFrom(*this); + copy->mLayer = mLayer; + return copy; +} + +void SkiaLayerShader::describe(ProgramDescription& description, const Extensions& extensions) { + description.hasBitmap = true; +} + +void SkiaLayerShader::setupProgram(Program* program, const mat4& modelView, + const Snapshot& snapshot, GLuint* textureUnit) { + GLuint textureSlot = (*textureUnit)++; + Caches::getInstance().activeTexture(textureSlot); + + const float width = mLayer->getWidth(); + const float height = mLayer->getHeight(); + + mat4 textureTransform; + computeScreenSpaceMatrix(textureTransform, modelView); + + // Uniforms + mLayer->bindTexture(); + mLayer->setWrap(GL_CLAMP_TO_EDGE); + mLayer->setFilter(GL_LINEAR); + + glUniform1i(program->getUniform("bitmapSampler"), textureSlot); + glUniformMatrix4fv(program->getUniform("textureTransform"), 1, + GL_FALSE, &textureTransform.data[0]); + glUniform2f(program->getUniform("textureDimension"), 1.0f / width, 1.0f / height); +} + +/////////////////////////////////////////////////////////////////////////////// // Bitmap shader /////////////////////////////////////////////////////////////////////////////// @@ -142,7 +185,7 @@ void SkiaBitmapShader::describe(ProgramDescription& description, const Extension } void SkiaBitmapShader::setupProgram(Program* program, const mat4& modelView, - const Snapshot& snapshot, GLuint* textureUnit) { + const Snapshot&, GLuint* textureUnit) { GLuint textureSlot = (*textureUnit)++; Caches::getInstance().activeTexture(textureSlot); @@ -228,7 +271,7 @@ void SkiaLinearGradientShader::describe(ProgramDescription& description, } void SkiaLinearGradientShader::setupProgram(Program* program, const mat4& modelView, - const Snapshot& snapshot, GLuint* textureUnit) { + const Snapshot&, GLuint* textureUnit) { if (CC_UNLIKELY(!mIsSimple)) { GLuint textureSlot = (*textureUnit)++; Caches::getInstance().activeTexture(textureSlot); @@ -264,7 +307,7 @@ static void toCircularUnitMatrix(const float x, const float y, const float radiu SkiaCircularGradientShader::SkiaCircularGradientShader(float x, float y, float radius, uint32_t* colors, float* positions, int count, SkShader* key, SkShader::TileMode tileMode, SkMatrix* matrix, bool blend): - SkiaSweepGradientShader(kCircularGradient, x, y, colors, positions, count, key, + SkiaSweepGradientShader(kCircularGradient, colors, positions, count, key, tileMode, matrix, blend) { SkMatrix unitMatrix; toCircularUnitMatrix(x, y, radius, &unitMatrix); @@ -314,11 +357,12 @@ SkiaSweepGradientShader::SkiaSweepGradientShader(float x, float y, uint32_t* col mIsSimple = count == 2; } -SkiaSweepGradientShader::SkiaSweepGradientShader(Type type, float x, float y, uint32_t* colors, +SkiaSweepGradientShader::SkiaSweepGradientShader(Type type, uint32_t* colors, float* positions, int count, SkShader* key, SkShader::TileMode tileMode, SkMatrix* matrix, bool blend): SkiaShader(type, key, tileMode, tileMode, matrix, blend), mColors(colors), mPositions(positions), mCount(count) { + // protected method, that doesn't setup mUnitMatrix - should be handled by subclass mIsSimple = count == 2 && tileMode == SkShader::kClamp_TileMode; } |
