diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-12 20:42:21 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-12 20:42:21 +0000 |
commit | 5970f625e96cdc007c563ae72f343ae0d71719a1 (patch) | |
tree | d8768c59927628cabd07ab50f9a3b8e6e6779b84 /src/core | |
parent | 68a3815401f461976f76891d0477cb1440fa0aba (diff) |
re-land hide get/setLocalMatrix
This reverts commit b1d702a43b07934f5b001b1b09db2c57ede909a1.
TBR=scroggo@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/279903002
git-svn-id: http://skia.googlecode.com/svn/trunk@14702 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkLocalMatrixShader.cpp | 58 | ||||
-rw-r--r-- | src/core/SkLocalMatrixShader.h | 66 | ||||
-rw-r--r-- | src/core/SkPictureShader.cpp | 6 | ||||
-rw-r--r-- | src/core/SkShader.cpp | 15 |
4 files changed, 75 insertions, 70 deletions
diff --git a/src/core/SkLocalMatrixShader.cpp b/src/core/SkLocalMatrixShader.cpp index 7af025c442..53580e6ac9 100644 --- a/src/core/SkLocalMatrixShader.cpp +++ b/src/core/SkLocalMatrixShader.cpp @@ -5,65 +5,11 @@ * found in the LICENSE file. */ -#include "SkShader.h" -#include "SkReadBuffer.h" -#include "SkWriteBuffer.h" - -class SkLocalMatrixShader : public SkShader { -public: - SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) - : fProxyShader(SkRef(proxy)) - , fProxyLocalMatrix(localMatrix) - {} - - virtual size_t contextSize() const SK_OVERRIDE { - return fProxyShader->contextSize(); - } - - virtual BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, - TileMode* mode) const SK_OVERRIDE { - return fProxyShader->asABitmap(bitmap, matrix, mode); - } - - virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE { - return fProxyShader->asAGradient(info); - } - - // TODO: need to augment this API to pass in a localmatrix (which we can augment) - virtual GrEffectRef* asNewEffect(GrContext* ctx, const SkPaint& paint, - const SkMatrix* localMatrix) const SK_OVERRIDE { - SkMatrix tmp = fProxyLocalMatrix; - if (localMatrix) { - tmp.preConcat(*localMatrix); - } - return fProxyShader->asNewEffect(ctx, paint, &tmp); - } - - virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OVERRIDE { - if (localMatrix) { - *localMatrix = fProxyLocalMatrix; - } - return SkRef(fProxyShader.get()); - } - - SK_TO_STRING_OVERRIDE() - SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) - -protected: - SkLocalMatrixShader(SkReadBuffer&); - virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; - virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE; - -private: - SkAutoTUnref<SkShader> fProxyShader; - SkMatrix fProxyLocalMatrix; - - typedef SkShader INHERITED; -}; +#include "SkLocalMatrixShader.h" SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffer) { buffer.readMatrix(&fProxyLocalMatrix); - fProxyShader.reset(buffer.readFlattenable<SkShader>()); + fProxyShader.reset(buffer.readShader()); if (NULL == fProxyShader.get()) { sk_throw(); } diff --git a/src/core/SkLocalMatrixShader.h b/src/core/SkLocalMatrixShader.h new file mode 100644 index 0000000000..95e6237e59 --- /dev/null +++ b/src/core/SkLocalMatrixShader.h @@ -0,0 +1,66 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkLocalMatrixShader_DEFINED +#define SkLocalMatrixShader_DEFINED + +#include "SkShader.h" +#include "SkReadBuffer.h" +#include "SkWriteBuffer.h" + +class SkLocalMatrixShader : public SkShader { +public: + SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) + : fProxyShader(SkRef(proxy)) + , fProxyLocalMatrix(localMatrix) + {} + + virtual size_t contextSize() const SK_OVERRIDE { + return fProxyShader->contextSize(); + } + + virtual BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, + TileMode* mode) const SK_OVERRIDE { + return fProxyShader->asABitmap(bitmap, matrix, mode); + } + + virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE { + return fProxyShader->asAGradient(info); + } + + virtual GrEffectRef* asNewEffect(GrContext* ctx, const SkPaint& paint, + const SkMatrix* localMatrix) const SK_OVERRIDE { + SkMatrix tmp = fProxyLocalMatrix; + if (localMatrix) { + tmp.preConcat(*localMatrix); + } + return fProxyShader->asNewEffect(ctx, paint, &tmp); + } + + virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OVERRIDE { + if (localMatrix) { + *localMatrix = fProxyLocalMatrix; + } + return SkRef(fProxyShader.get()); + } + + SK_TO_STRING_OVERRIDE() + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) + +protected: + SkLocalMatrixShader(SkReadBuffer&); + virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; + virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE; + +private: + SkAutoTUnref<SkShader> fProxyShader; + SkMatrix fProxyLocalMatrix; + + typedef SkShader INHERITED; +}; + +#endif diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp index 300a65329b..ecb86e7e71 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -56,11 +56,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); SkMatrix m; - if (this->hasLocalMatrix()) { - m.setConcat(matrix, this->getLocalMatrix()); - } else { - m = matrix; - } + m.setConcat(matrix, this->getLocalMatrix()); if (localM) { m.preConcat(*localM); } diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 75a5fdbd36..6a418b6b45 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -60,7 +60,7 @@ SkShader::~SkShader() { void SkShader::flatten(SkWriteBuffer& buffer) const { this->INHERITED::flatten(buffer); - bool hasLocalM = this->hasLocalMatrix(); + bool hasLocalM = !fLocalMatrix.isIdentity(); buffer.writeBool(hasLocalM); if (hasLocalM) { buffer.writeMatrix(fLocalMatrix); @@ -68,13 +68,10 @@ void SkShader::flatten(SkWriteBuffer& buffer) const { } bool SkShader::computeTotalInverse(const ContextRec& rec, SkMatrix* totalInverse) const { - const SkMatrix* m = rec.fMatrix; - SkMatrix total; + SkMatrix total; + total.setConcat(*rec.fMatrix, fLocalMatrix); - if (this->hasLocalMatrix()) { - total.setConcat(*m, this->getLocalMatrix()); - m = &total; - } + const SkMatrix* m = &total; if (rec.fLocalMatrix) { total.setConcat(*m, *rec.fLocalMatrix); m = &total; @@ -235,9 +232,9 @@ SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t #ifndef SK_IGNORE_TO_STRING void SkShader::toString(SkString* str) const { - if (this->hasLocalMatrix()) { + if (!fLocalMatrix.isIdentity()) { str->append(" "); - this->getLocalMatrix().toString(str); + fLocalMatrix.toString(str); } } #endif |