Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1723)

Unified Diff: src/core/SkShader.cpp

Issue 272593002: add localmatrix-shader (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/core/SkShader.h ('K') | « samplecode/SamplePatch.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkShader.cpp
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 0c954f869b359522263c77804b9fe25e74159da9..2af10a08d7d3b885fed70a966b1d667d06c65b98 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -75,6 +75,10 @@ size_t SkShader::contextSize() const {
return 0;
}
+SkShader* SkShader::refLocalMatrixShader(SkMatrix*) const {
+ return false;
+}
+
SkShader::Context::Context(const SkShader& shader, const ContextRec& rec)
: fShader(shader), fCTM(*rec.fMatrix)
{
@@ -344,3 +348,96 @@ void SkEmptyShader::toString(SkString* str) const {
str->append(")");
}
#endif
+
+//////////////////////////////////////////////////////////////////////////////////
+
+class SkLocalMatrixShader : public SkShader {
scroggo 2014/05/07 14:15:41 Would it make sense to put this in its own file?
reed1 2014/05/07 20:37:31 If it get big enough, yes. When I begin, it was pr
+public:
+ SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix)
+ : fProxyShader(SkRef(proxy))
+ , fProxyLocalMatrix(localMatrix)
+ {}
+
+ virtual size_t contextSize() const SK_OVERRIDE {
+ return fProxyShader->contextSize();
+ }
+
+ virtual SkShader* refLocalMatrixShader(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;
+};
+
+SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffer) {
+ buffer.readMatrix(&fProxyLocalMatrix);
+ fProxyShader.reset(buffer.readFlattenable<SkShader>());
+ if (NULL == fProxyShader.get()) {
+ sk_throw();
+ }
+}
+
+void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const {
+ this->INHERITED::flatten(buffer);
+ buffer.writeMatrix(fProxyLocalMatrix);
+ buffer.writeFlattenable(fProxyShader.get());
+}
+
+SkShader::Context* SkLocalMatrixShader::onCreateContext(const ContextRec& rec,
scroggo 2014/05/07 14:15:41 Doesn't this class need to also override asNewEffe
reed1 2014/05/07 20:37:31 Indeed, I need to forward all of those guys. Maybe
+ void* storage) const {
+ ContextRec newRec(rec);
+ SkMatrix tmp;
+ if (rec.fLocalMatrix) {
+ tmp.setConcat(*rec.fLocalMatrix, fProxyLocalMatrix);
scroggo 2014/05/07 14:15:41 This ordering seems backwards to me. It appears to
reed1 2014/05/07 20:37:31 Good catch. Done.
+ newRec.fLocalMatrix = &tmp;
+ } else {
+ newRec.fLocalMatrix = &fProxyLocalMatrix;
+ }
+ return fProxyShader->createContext(newRec, storage);
+}
+
+#ifndef SK_IGNORE_TO_STRING
+void SkLocalMatrixShader::toString(SkString* str) const {
+ str->append("SkLocalMatrixShader: (");
+
+ fProxyShader->toString(str);
+
+ this->INHERITED::toString(str);
+
+ str->append(")");
+}
+#endif
+
+SkShader* SkShader::CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) {
+ if (localMatrix.isIdentity()) {
+ return SkRef(proxy);
+ }
+
+ const SkMatrix* lm = &localMatrix;
+
+ SkMatrix otherLocalMatrix;
+ SkAutoTUnref<SkShader> otherProxy(proxy->refLocalMatrixShader(&otherLocalMatrix));
+ if (otherProxy.get()) {
+ otherLocalMatrix.postConcat(localMatrix);
+ lm = &otherLocalMatrix;
+ proxy = otherProxy.get();
+ }
+
+ return SkNEW_ARGS(SkLocalMatrixShader, (proxy, *lm));
+}
+
« include/core/SkShader.h ('K') | « samplecode/SamplePatch.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698