• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkLocalMatrixShader.h"
9 
10 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
SkLocalMatrixShader(SkReadBuffer & buffer)11 SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffer) {
12     if (buffer.isVersionLT(SkReadBuffer::kSimplifyLocalMatrix_Version)) {
13         buffer.readMatrix(&(INHERITED::fLocalMatrix));
14     }
15     fProxyShader.reset(buffer.readShader());
16     if (NULL == fProxyShader.get()) {
17         sk_throw();
18     }
19 }
20 #endif
21 
CreateProc(SkReadBuffer & buffer)22 SkFlattenable* SkLocalMatrixShader::CreateProc(SkReadBuffer& buffer) {
23     SkMatrix lm;
24     buffer.readMatrix(&lm);
25     SkAutoTUnref<SkShader> shader(buffer.readShader());
26     if (!shader.get()) {
27         return NULL;
28     }
29     return SkShader::CreateLocalMatrixShader(shader, lm);
30 }
31 
flatten(SkWriteBuffer & buffer) const32 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const {
33     buffer.writeMatrix(this->getLocalMatrix());
34     buffer.writeFlattenable(fProxyShader.get());
35 }
36 
onCreateContext(const ContextRec & rec,void * storage) const37 SkShader::Context* SkLocalMatrixShader::onCreateContext(const ContextRec& rec,
38                                                         void* storage) const {
39     ContextRec newRec(rec);
40     SkMatrix tmp;
41     if (rec.fLocalMatrix) {
42         tmp.setConcat(*rec.fLocalMatrix, this->getLocalMatrix());
43         newRec.fLocalMatrix = &tmp;
44     } else {
45         newRec.fLocalMatrix = &this->getLocalMatrix();
46     }
47     return fProxyShader->createContext(newRec, storage);
48 }
49 
50 #ifndef SK_IGNORE_TO_STRING
toString(SkString * str) const51 void SkLocalMatrixShader::toString(SkString* str) const {
52     str->append("SkLocalMatrixShader: (");
53 
54     fProxyShader->toString(str);
55 
56     this->INHERITED::toString(str);
57 
58     str->append(")");
59 }
60 #endif
61 
CreateLocalMatrixShader(SkShader * proxy,const SkMatrix & localMatrix)62 SkShader* SkShader::CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) {
63     if (localMatrix.isIdentity()) {
64         return SkRef(proxy);
65     }
66 
67     const SkMatrix* lm = &localMatrix;
68 
69     SkMatrix otherLocalMatrix;
70     SkAutoTUnref<SkShader> otherProxy(proxy->refAsALocalMatrixShader(&otherLocalMatrix));
71     if (otherProxy.get()) {
72         otherLocalMatrix.preConcat(localMatrix);
73         lm = &otherLocalMatrix;
74         proxy = otherProxy.get();
75     }
76 
77     return SkNEW_ARGS(SkLocalMatrixShader, (proxy, *lm));
78 }
79