diff --git a/include/core/SkShader.h b/include/core/SkShader.h index 323d29df4b..4c264e4741 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -39,6 +39,7 @@ class GrFragmentProcessor; */ class SK_API SkShader : public SkFlattenable { public: + SkShader(const SkMatrix* localMatrix = NULL); virtual ~SkShader(); /** @@ -466,8 +467,6 @@ public: const SkMatrix& ctm, const SkPaint&) const; protected: - SkShader(const SkMatrix* localMatrix = nullptr); - void flatten(SkWriteBuffer&) const override; bool computeTotalInverse(const ContextRec&, SkMatrix* totalInverse) const; @@ -499,7 +498,9 @@ protected: const SkMatrix* /*local matrix*/) const; private: - const SkMatrix fLocalMatrix; + // This is essentially const, but not officially so it can be modified in + // constructors. + SkMatrix fLocalMatrix; // So the SkLocalMatrixShader can whack fLocalMatrix in its SkReadBuffer constructor. friend class SkLocalMatrixShader; diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp index 6aa5c45245..71026824cd 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -106,10 +106,7 @@ SkPictureShader::SkPictureShader(sk_sp picture, TileMode tmx, TileMod sk_sp SkPictureShader::Make(sk_sp picture, TileMode tmx, TileMode tmy, const SkMatrix* localMatrix, const SkRect* tile) { - if (!picture || - picture->cullRect().isEmpty() || - (tile && tile->isEmpty()) || - (localMatrix && !localMatrix->invert(nullptr))) { + if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) { return SkShader::MakeEmptyShader(); } return sk_sp(new SkPictureShader(std::move(picture), tmx, tmy, localMatrix, tile)); diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 1b12f01969..81aae116d5 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -45,11 +45,13 @@ static inline void dec_shader_counter() { #endif } -SkShader::SkShader(const SkMatrix* localMatrix) - : fLocalMatrix(localMatrix ? *localMatrix : SkMatrix::I()) { - SkASSERT(!localMatrix || localMatrix->invert(nullptr)); - +SkShader::SkShader(const SkMatrix* localMatrix) { inc_shader_counter(); + if (localMatrix) { + fLocalMatrix = *localMatrix; + } else { + fLocalMatrix.reset(); + } // Pre-cache so future calls to fLocalMatrix.getType() are threadsafe. (void)fLocalMatrix.getType(); } diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp index 733889df0b..64a09dd2dc 100644 --- a/src/image/SkImageShader.cpp +++ b/src/image/SkImageShader.cpp @@ -100,9 +100,7 @@ sk_sp SkImageShader::Make(sk_sp image, TileMode tx, TileMode const SkMatrix* localMatrix, SkTBlitterAllocator* allocator) { SkShader* shader; - if (!image || - bitmap_is_too_big(image->width(), image->height()) || - (localMatrix && !localMatrix->invert(nullptr))) { + if (!image || bitmap_is_too_big(image->width(), image->height())) { if (nullptr == allocator) { shader = new SkEmptyShader; } else {