2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkLocalMatrixShader.h"
10 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
11 SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffer) {
12 if (buffer.isVersionLT(SkReadBuffer::kSimplifyLocalMatrix_Version)) {
13 buffer.readMatrix(&(INHERITED::fLocalMatrix));
15 fProxyShader.reset(buffer.readShader());
16 if (NULL == fProxyShader.get()) {
22 SkFlattenable* SkLocalMatrixShader::CreateProc(SkReadBuffer& buffer) {
24 buffer.readMatrix(&lm);
25 SkAutoTUnref<SkShader> shader(buffer.readShader());
29 return SkShader::CreateLocalMatrixShader(shader, lm);
32 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const {
33 buffer.writeMatrix(this->getLocalMatrix());
34 buffer.writeFlattenable(fProxyShader.get());
37 SkShader::Context* SkLocalMatrixShader::onCreateContext(const ContextRec& rec,
38 void* storage) const {
39 ContextRec newRec(rec);
41 if (rec.fLocalMatrix) {
42 tmp.setConcat(*rec.fLocalMatrix, this->getLocalMatrix());
43 newRec.fLocalMatrix = &tmp;
45 newRec.fLocalMatrix = &this->getLocalMatrix();
47 return fProxyShader->createContext(newRec, storage);
50 #ifndef SK_IGNORE_TO_STRING
51 void SkLocalMatrixShader::toString(SkString* str) const {
52 str->append("SkLocalMatrixShader: (");
54 fProxyShader->toString(str);
56 this->INHERITED::toString(str);
62 SkShader* SkShader::CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) {
67 if (localMatrix.isIdentity()) {
71 const SkMatrix* lm = &localMatrix;
73 SkMatrix otherLocalMatrix;
74 SkAutoTUnref<SkShader> otherProxy(proxy->refAsALocalMatrixShader(&otherLocalMatrix));
75 if (otherProxy.get()) {
76 otherLocalMatrix.preConcat(localMatrix);
77 lm = &otherLocalMatrix;
78 proxy = otherProxy.get();
81 return SkNEW_ARGS(SkLocalMatrixShader, (proxy, *lm));