diff options
author | Romain Guy <romainguy@google.com> | 2010-09-20 19:04:33 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2010-09-21 16:48:50 -0700 |
commit | ddb80bebb0776e6d852aab6e8bba5d5591847a55 (patch) | |
tree | 460e39e115bf75648a3b4dbc9788c911751bd848 /libs/hwui/SkiaShader.cpp | |
parent | ee916f14cbd1fe1422c063ce2ef7b185e2bc5c6f (diff) | |
download | frameworks_base-ddb80bebb0776e6d852aab6e8bba5d5591847a55.zip frameworks_base-ddb80bebb0776e6d852aab6e8bba5d5591847a55.tar.gz frameworks_base-ddb80bebb0776e6d852aab6e8bba5d5591847a55.tar.bz2 |
Add support for circular gradients to the GL renderer.
This change also adds full support for local transformation matrices on
sweep and radial gradients.
Change-Id: Id8773bc0766575190e3f3d51984fc5e57b266c3f
Diffstat (limited to 'libs/hwui/SkiaShader.cpp')
-rw-r--r-- | libs/hwui/SkiaShader.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/libs/hwui/SkiaShader.cpp b/libs/hwui/SkiaShader.cpp index c5d9767..9e1f6c2 100644 --- a/libs/hwui/SkiaShader.cpp +++ b/libs/hwui/SkiaShader.cpp @@ -209,6 +209,30 @@ void SkiaLinearGradientShader::updateTransforms(Program* program, const mat4& mo } /////////////////////////////////////////////////////////////////////////////// +// Circular gradient shader +/////////////////////////////////////////////////////////////////////////////// + +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, + tileMode, matrix, blend), + mRadius(radius) { +} + +void SkiaCircularGradientShader::describe(ProgramDescription& description, + const Extensions& extensions) { + description.hasGradient = true; + description.gradientType = ProgramDescription::kGradientCircular; +} + +void SkiaCircularGradientShader::setupProgram(Program* program, const mat4& modelView, + const Snapshot& snapshot, GLuint* textureUnit) { + SkiaSweepGradientShader::setupProgram(program, modelView, snapshot, textureUnit); + glUniform1f(program->getUniform("gradientRadius"), 1.0f / mRadius); +} + +/////////////////////////////////////////////////////////////////////////////// // Sweep gradient shader /////////////////////////////////////////////////////////////////////////////// @@ -219,6 +243,13 @@ SkiaSweepGradientShader::SkiaSweepGradientShader(float x, float y, uint32_t* col mX(x), mY(y), mColors(colors), mPositions(positions), mCount(count) { } +SkiaSweepGradientShader::SkiaSweepGradientShader(Type type, float x, float y, uint32_t* colors, + float* positions, int count, SkShader* key, SkShader::TileMode tileMode, + SkMatrix* matrix, bool blend): + SkiaShader(type, key, tileMode, tileMode, matrix, blend), + mX(x), mY(y), mColors(colors), mPositions(positions), mCount(count) { +} + SkiaSweepGradientShader::~SkiaSweepGradientShader() { delete[] mColors; delete[] mPositions; @@ -243,10 +274,15 @@ void SkiaSweepGradientShader::setupProgram(Program* program, const mat4& modelVi float left = mX; float top = mY; + mat4 shaderMatrix; if (mMatrix) { - mat4 shaderMatrix(*mMatrix); + shaderMatrix.load(*mMatrix); shaderMatrix.mapPoint(left, top); } + + mat4 copy(shaderMatrix); + shaderMatrix.loadInverse(copy); + snapshot.transform->mapPoint(left, top); mat4 screenSpace(*snapshot.transform); @@ -255,6 +291,7 @@ void SkiaSweepGradientShader::setupProgram(Program* program, const mat4& modelVi // Uniforms bindTexture(texture->id, gTileModes[mTileX], gTileModes[mTileY], textureSlot); glUniform1i(program->getUniform("gradientSampler"), textureSlot); + glUniformMatrix4fv(program->getUniform("gradientMatrix"), 1, GL_FALSE, &shaderMatrix.data[0]); glUniform2f(program->getUniform("gradientStart"), left, top); glUniformMatrix4fv(program->getUniform("screenSpace"), 1, GL_FALSE, &screenSpace.data[0]); } |