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 "SkShader.h" | 8 #include "SkLocalMatrixShader.h" |
9 #include "SkReadBuffer.h" | |
10 #include "SkWriteBuffer.h" | |
11 | |
12 class SkLocalMatrixShader : public SkShader { | |
13 public: | |
14 SkLocalMatrixShader(SkShader* proxy, const SkMatrix& localMatrix) | |
15 : fProxyShader(SkRef(proxy)) | |
16 , fProxyLocalMatrix(localMatrix) | |
17 {} | |
18 | |
19 virtual size_t contextSize() const SK_OVERRIDE { | |
20 return fProxyShader->contextSize(); | |
21 } | |
22 | |
23 virtual BitmapType asABitmap(SkBitmap* bitmap, SkMatrix* matrix, | |
24 TileMode* mode) const SK_OVERRIDE { | |
25 return fProxyShader->asABitmap(bitmap, matrix, mode); | |
26 } | |
27 | |
28 virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE { | |
29 return fProxyShader->asAGradient(info); | |
30 } | |
31 | |
32 // TODO: need to augment this API to pass in a localmatrix (which we can aug
ment) | |
33 virtual GrEffectRef* asNewEffect(GrContext* ctx, const SkPaint& paint, | |
34 const SkMatrix* localMatrix) const SK_OVERR
IDE { | |
35 SkMatrix tmp = fProxyLocalMatrix; | |
36 if (localMatrix) { | |
37 tmp.preConcat(*localMatrix); | |
38 } | |
39 return fProxyShader->asNewEffect(ctx, paint, &tmp); | |
40 } | |
41 | |
42 virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OV
ERRIDE { | |
43 if (localMatrix) { | |
44 *localMatrix = fProxyLocalMatrix; | |
45 } | |
46 return SkRef(fProxyShader.get()); | |
47 } | |
48 | |
49 SK_TO_STRING_OVERRIDE() | |
50 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixShader) | |
51 | |
52 protected: | |
53 SkLocalMatrixShader(SkReadBuffer&); | |
54 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | |
55 virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE
; | |
56 | |
57 private: | |
58 SkAutoTUnref<SkShader> fProxyShader; | |
59 SkMatrix fProxyLocalMatrix; | |
60 | |
61 typedef SkShader INHERITED; | |
62 }; | |
63 | 9 |
64 SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffe
r) { | 10 SkLocalMatrixShader::SkLocalMatrixShader(SkReadBuffer& buffer) : INHERITED(buffe
r) { |
65 buffer.readMatrix(&fProxyLocalMatrix); | 11 buffer.readMatrix(&fProxyLocalMatrix); |
66 fProxyShader.reset(buffer.readFlattenable<SkShader>()); | 12 fProxyShader.reset(buffer.readShader()); |
67 if (NULL == fProxyShader.get()) { | 13 if (NULL == fProxyShader.get()) { |
68 sk_throw(); | 14 sk_throw(); |
69 } | 15 } |
70 } | 16 } |
71 | 17 |
72 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const { | 18 void SkLocalMatrixShader::flatten(SkWriteBuffer& buffer) const { |
73 this->INHERITED::flatten(buffer); | 19 this->INHERITED::flatten(buffer); |
74 buffer.writeMatrix(fProxyLocalMatrix); | 20 buffer.writeMatrix(fProxyLocalMatrix); |
75 buffer.writeFlattenable(fProxyShader.get()); | 21 buffer.writeFlattenable(fProxyShader.get()); |
76 } | 22 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 SkMatrix otherLocalMatrix; | 56 SkMatrix otherLocalMatrix; |
111 SkAutoTUnref<SkShader> otherProxy(proxy->refAsALocalMatrixShader(&otherLocal
Matrix)); | 57 SkAutoTUnref<SkShader> otherProxy(proxy->refAsALocalMatrixShader(&otherLocal
Matrix)); |
112 if (otherProxy.get()) { | 58 if (otherProxy.get()) { |
113 otherLocalMatrix.preConcat(localMatrix); | 59 otherLocalMatrix.preConcat(localMatrix); |
114 lm = &otherLocalMatrix; | 60 lm = &otherLocalMatrix; |
115 proxy = otherProxy.get(); | 61 proxy = otherProxy.get(); |
116 } | 62 } |
117 | 63 |
118 return SkNEW_ARGS(SkLocalMatrixShader, (proxy, *lm)); | 64 return SkNEW_ARGS(SkLocalMatrixShader, (proxy, *lm)); |
119 } | 65 } |
OLD | NEW |