diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/Matrix.cpp | 21 | ||||
-rw-r--r-- | libs/hwui/Matrix.h | 4 | ||||
-rw-r--r-- | libs/hwui/SkiaShader.cpp | 3 |
3 files changed, 22 insertions, 6 deletions
diff --git a/libs/hwui/Matrix.cpp b/libs/hwui/Matrix.cpp index c64b483..74d50e4 100644 --- a/libs/hwui/Matrix.cpp +++ b/libs/hwui/Matrix.cpp @@ -80,7 +80,7 @@ void Matrix4::load(const SkMatrix& v) { data[kScaleZ] = 1.0f; - mSimpleMatrix = (!v[SkMatrix::kMPersp0] && !v[SkMatrix::kMPersp1] && !v[SkMatrix::kMPersp2]); + mSimpleMatrix = (v.getType() <= SkMatrix::kScale_Mask); } void Matrix4::copyTo(SkMatrix& v) const { @@ -232,9 +232,26 @@ void Matrix4::loadOrtho(float left, float right, float bottom, float top, float data[kTranslateZ] = -(far + near) / (far - near); } +#define MUL_ADD_STORE(a, b, c) a = (a) * (b) + (c) + +void Matrix4::mapPoint(float& x, float& y) const { + if (mSimpleMatrix) { + MUL_ADD_STORE(x, data[kScaleX], data[kTranslateX]); + MUL_ADD_STORE(y, data[kScaleY], data[kTranslateY]); + return; + } + + float dx = x * data[kScaleX] + y * data[kSkewX] + data[kTranslateX]; + float dy = x * data[kSkewY] + y * data[kScaleY] + data[kTranslateY]; + float dz = x * data[kPerspective0] + y * data[kPerspective1] + data[kPerspective2]; + if (dz) dz = 1.0f / dz; + + x = dx * dz; + y = dy * dz; +} + void Matrix4::mapRect(Rect& r) const { if (mSimpleMatrix) { - #define MUL_ADD_STORE(a, b, c) a = (a) * (b) + (c) MUL_ADD_STORE(r.left, data[kScaleX], data[kTranslateX]); MUL_ADD_STORE(r.right, data[kScaleX], data[kTranslateX]); MUL_ADD_STORE(r.top, data[kScaleY], data[kTranslateY]); diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h index ebc8b29..c247a67 100644 --- a/libs/hwui/Matrix.h +++ b/libs/hwui/Matrix.h @@ -104,10 +104,8 @@ public: void copyTo(float* v) const; void copyTo(SkMatrix& v) const; - /** - * Does not apply rotations! - */ void mapRect(Rect& r) const; + void mapPoint(float& x, float& y) const; float getTranslateX(); float getTranslateY(); diff --git a/libs/hwui/SkiaShader.cpp b/libs/hwui/SkiaShader.cpp index 3569d6a..c7a01b1 100644 --- a/libs/hwui/SkiaShader.cpp +++ b/libs/hwui/SkiaShader.cpp @@ -164,7 +164,8 @@ void SkiaLinearGradientShader::setupProgram(Program* program, const mat4& modelV Rect start(mBounds[0], mBounds[1], mBounds[2], mBounds[3]); if (mMatrix) { mat4 shaderMatrix(*mMatrix); - shaderMatrix.mapRect(start); + shaderMatrix.mapPoint(start.left, start.top); + shaderMatrix.mapPoint(start.right, start.bottom); } snapshot.transform.mapRect(start); |