OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkLocalMatrixShader.h" | 8 #include "SkLocalMatrixShader.h" |
9 | 9 |
10 SkFlattenable* SkLocalMatrixShader::CreateProc(SkReadBuffer& buffer) { | 10 SkFlattenable* SkLocalMatrixShader::CreateProc(SkReadBuffer& buffer) { |
11 SkMatrix lm; | 11 SkMatrix lm; |
12 buffer.readMatrix(&lm); | 12 buffer.readMatrix(&lm); |
13 SkAutoTUnref<SkShader> shader(buffer.readShader()); | 13 SkAutoTUnref<SkShader> baseShader(buffer.readShader()); |
14 if (!shader.get()) { | 14 if (!baseShader) { |
15 return nullptr; | 15 return nullptr; |
16 } | 16 } |
17 return SkShader::CreateLocalMatrixShader(shader, lm); | 17 return baseShader->newWithLocalMatrix(lm); |
18 } | 18 } |
19 | 19 |
20 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const { | 20 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const { |
21 buffer.writeMatrix(this->getLocalMatrix()); | 21 buffer.writeMatrix(this->getLocalMatrix()); |
22 buffer.writeFlattenable(fProxyShader.get()); | 22 buffer.writeFlattenable(fProxyShader.get()); |
23 } | 23 } |
24 | 24 |
25 SkShader::Context* SkLocalMatrixShader::onCreateContext(const ContextRec& rec, | 25 SkShader::Context* SkLocalMatrixShader::onCreateContext(const ContextRec& rec, |
26 void* storage) const { | 26 void* storage) const { |
27 ContextRec newRec(rec); | 27 ContextRec newRec(rec); |
(...skipping 12 matching lines...) Expand all Loading... |
40 str->append("SkLocalMatrixShader: ("); | 40 str->append("SkLocalMatrixShader: ("); |
41 | 41 |
42 fProxyShader->toString(str); | 42 fProxyShader->toString(str); |
43 | 43 |
44 this->INHERITED::toString(str); | 44 this->INHERITED::toString(str); |
45 | 45 |
46 str->append(")"); | 46 str->append(")"); |
47 } | 47 } |
48 #endif | 48 #endif |
49 | 49 |
50 SkShader* SkShader::CreateLocalMatrixShader(SkShader* proxy, const SkMatrix& loc
alMatrix) { | 50 SkShader* SkShader::newWithLocalMatrix(const SkMatrix& localMatrix) const { |
51 if (nullptr == proxy) { | |
52 return nullptr; | |
53 } | |
54 | |
55 if (localMatrix.isIdentity()) { | 51 if (localMatrix.isIdentity()) { |
56 return SkRef(proxy); | 52 return SkRef(const_cast<SkShader*>(this)); |
57 } | 53 } |
58 | 54 |
59 const SkMatrix* lm = &localMatrix; | 55 const SkMatrix* lm = &localMatrix; |
60 | 56 |
| 57 SkShader* baseShader = const_cast<SkShader*>(this); |
61 SkMatrix otherLocalMatrix; | 58 SkMatrix otherLocalMatrix; |
62 SkAutoTUnref<SkShader> otherProxy(proxy->refAsALocalMatrixShader(&otherLocal
Matrix)); | 59 SkAutoTUnref<SkShader> proxy(this->refAsALocalMatrixShader(&otherLocalMatrix
)); |
63 if (otherProxy.get()) { | 60 if (proxy) { |
64 otherLocalMatrix.preConcat(localMatrix); | 61 otherLocalMatrix.preConcat(localMatrix); |
65 lm = &otherLocalMatrix; | 62 lm = &otherLocalMatrix; |
66 proxy = otherProxy.get(); | 63 baseShader = proxy.get(); |
67 } | 64 } |
68 | 65 |
69 return new SkLocalMatrixShader(proxy, *lm); | 66 return new SkLocalMatrixShader(baseShader, *lm); |
70 } | 67 } |
OLD | NEW |