From: scroggo Date: Fri, 11 Jul 2014 17:42:12 +0000 (-0700) Subject: Use SkShader's localMat for SkLocalMatrixShader. X-Git-Tag: submit/tizen/20180928.044319~6795 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c870d494dd0dc88f3f4155a0d6257a1be8280880;p=platform%2Fupstream%2FlibSkiaSharp.git Use SkShader's localMat for SkLocalMatrixShader. Instead of setting SkShader::fLocalMatrix to Identity and storing a separate SkMatrix inside SkLocalMatrixShader, reuse SkShader::fLocalMatrix. R=reed@google.com Author: scroggo@google.com Review URL: https://codereview.chromium.org/386693003 --- diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index ca26eb4496..03d983fe58 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -231,13 +231,14 @@ private: // V27: Remove SkUnitMapper from gradients (and skia). // V28: No longer call bitmap::flatten inside SkWriteBuffer::writeBitmap. // V29: Removed SaveFlags parameter from save(). + // V30: Remove redundant SkMatrix from SkLocalMatrixShader. // Note: If the picture version needs to be increased then please follow the // steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw // Only SKPs within the min/current picture version range (inclusive) can be read. static const uint32_t MIN_PICTURE_VERSION = 19; - static const uint32_t CURRENT_PICTURE_VERSION = 29; + static const uint32_t CURRENT_PICTURE_VERSION = 30; mutable uint32_t fUniqueID; diff --git a/include/core/SkReadBuffer.h b/include/core/SkReadBuffer.h index 5db86345ad..faf7eb81a5 100644 --- a/include/core/SkReadBuffer.h +++ b/include/core/SkReadBuffer.h @@ -45,6 +45,7 @@ public: kColorShaderNoBool_Version = 26, kNoUnitMappers_Version = 27, kNoMoreBitmapFlatten_Version = 28, + kSimplifyLocalMatrix_Version = 30, }; /** diff --git a/include/core/SkShader.h b/include/core/SkShader.h index 8871f1b021..33a7a15b0f 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -41,11 +41,17 @@ public: /** * Returns the local matrix. + * + * FIXME: This can be incorrect for a Shader with its own local matrix + * that is also wrapped via CreateLocalMatrixShader. */ const SkMatrix& getLocalMatrix() const { return fLocalMatrix; } /** * Returns true if the local matrix is not an identity matrix. + * + * FIXME: This can be incorrect for a Shader with its own local matrix + * that is also wrapped via CreateLocalMatrixShader. */ bool hasLocalMatrix() const { return !fLocalMatrix.isIdentity(); } @@ -474,7 +480,10 @@ protected: private: SkMatrix fLocalMatrix; - + + // So the SkLocalMatrixShader can whack fLocalMatrix in its SkReadBuffer constructor. + friend class SkLocalMatrixShader; + typedef SkFlattenable INHERITED; }; diff --git a/src/core/SkLocalMatrixShader.cpp b/src/core/SkLocalMatrixShader.cpp index 53580e6ac9..c77f38d6d6 100644 --- a/src/core/SkLocalMatrixShader.cpp +++ b/src/core/SkLocalMatrixShader.cpp @@ -8,7 +8,9 @@ #include "SkLocalMatrixShader.h" SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffer) { - buffer.readMatrix(&fProxyLocalMatrix); + if (buffer.isVersionLT(SkReadBuffer::kSimplifyLocalMatrix_Version)) { + buffer.readMatrix(&(INHERITED::fLocalMatrix)); + } fProxyShader.reset(buffer.readShader()); if (NULL == fProxyShader.get()) { sk_throw(); @@ -17,7 +19,6 @@ SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffe void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const { this->INHERITED::flatten(buffer); - buffer.writeMatrix(fProxyLocalMatrix); buffer.writeFlattenable(fProxyShader.get()); } @@ -26,10 +27,10 @@ SkShader::Context* SkLocalMatrixShader::onCreateContext(const ContextRec& rec, ContextRec newRec(rec); SkMatrix tmp; if (rec.fLocalMatrix) { - tmp.setConcat(fProxyLocalMatrix, *rec.fLocalMatrix); + tmp.setConcat(this->getLocalMatrix(), *rec.fLocalMatrix); newRec.fLocalMatrix = &tmp; } else { - newRec.fLocalMatrix = &fProxyLocalMatrix; + newRec.fLocalMatrix = &this->getLocalMatrix(); } return fProxyShader->createContext(newRec, storage); } diff --git a/src/core/SkLocalMatrixShader.h b/src/core/SkLocalMatrixShader.h index b56cd4726f..7eb7c1337a 100644 --- a/src/core/SkLocalMatrixShader.h +++ b/src/core/SkLocalMatrixShader.h @@ -15,8 +15,8 @@ class SkLocalMatrixShader : public SkShader { public: SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) - : fProxyShader(SkRef(proxy)) - , fProxyLocalMatrix(localMatrix) + : INHERITED(&localMatrix) + , fProxyShader(SkRef(proxy)) {} virtual size_t contextSize() const SK_OVERRIDE { @@ -36,7 +36,7 @@ public: virtual bool asNewEffect(GrContext* context, const SkPaint& paint, const SkMatrix* localMatrix, GrColor* grColor, GrEffect** grEffect) const SK_OVERRIDE { - SkMatrix tmp = fProxyLocalMatrix; + SkMatrix tmp = this->getLocalMatrix(); if (localMatrix) { tmp.preConcat(*localMatrix); } @@ -55,7 +55,7 @@ public: virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OVERRIDE { if (localMatrix) { - *localMatrix = fProxyLocalMatrix; + *localMatrix = this->getLocalMatrix(); } return SkRef(fProxyShader.get()); } @@ -70,7 +70,6 @@ protected: private: SkAutoTUnref fProxyShader; - SkMatrix fProxyLocalMatrix; typedef SkShader INHERITED; };