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 SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffer) {
11 if (buffer.isVersionLT(SkReadBuffer::kSimplifyLocalMatrix_Version)) {
12 buffer.readMatrix(&(INHERITED::fLocalMatrix));
14 fProxyShader.reset(buffer.readShader());
15 if (NULL == fProxyShader.get()) {
20 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const {
21 this->INHERITED::flatten(buffer);
22 buffer.writeFlattenable(fProxyShader.get());
25 SkShader::Context* SkLocalMatrixShader::onCreateContext(const ContextRec& rec,
26 void* storage) const {
27 ContextRec newRec(rec);
29 if (rec.fLocalMatrix) {
30 tmp.setConcat(*rec.fLocalMatrix, this->getLocalMatrix());
31 newRec.fLocalMatrix = &tmp;
33 newRec.fLocalMatrix = &this->getLocalMatrix();
35 return fProxyShader->createContext(newRec, storage);
38 #ifndef SK_IGNORE_TO_STRING
39 void SkLocalMatrixShader::toString(SkString* str) const {
40 str->append("SkLocalMatrixShader: (");
42 fProxyShader->toString(str);
44 this->INHERITED::toString(str);
50 SkShader* SkShader::CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) {
51 if (localMatrix.isIdentity()) {
55 const SkMatrix* lm = &localMatrix;
57 SkMatrix otherLocalMatrix;
58 SkAutoTUnref<SkShader> otherProxy(proxy->refAsALocalMatrixShader(&otherLocalMatrix));
59 if (otherProxy.get()) {
60 otherLocalMatrix.preConcat(localMatrix);
61 lm = &otherLocalMatrix;
62 proxy = otherProxy.get();
65 return SkNEW_ARGS(SkLocalMatrixShader, (proxy, *lm));