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 "SkPictureShader.h" | 8 #include "SkPictureShader.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { | 47 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { |
48 this->INHERITED::flatten(buffer); | 48 this->INHERITED::flatten(buffer); |
49 | 49 |
50 buffer.write32(fTmx); | 50 buffer.write32(fTmx); |
51 buffer.write32(fTmy); | 51 buffer.write32(fTmy); |
52 fPicture->flatten(buffer); | 52 fPicture->flatten(buffer); |
53 } | 53 } |
54 | 54 |
55 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix) const { | 55 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
x* localM) const { |
56 SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); | 56 SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); |
57 | 57 |
58 SkMatrix m; | 58 SkMatrix m; |
59 if (this->hasLocalMatrix()) { | 59 if (this->hasLocalMatrix()) { |
60 m.setConcat(matrix, this->getLocalMatrix()); | 60 m.setConcat(matrix, this->getLocalMatrix()); |
61 } else { | 61 } else { |
62 m = matrix; | 62 m = matrix; |
63 } | 63 } |
| 64 if (localM) { |
| 65 m.preConcat(*localM); |
| 66 } |
64 | 67 |
65 // Use a rotation-invariant scale | 68 // Use a rotation-invariant scale |
66 SkPoint scale; | 69 SkPoint scale; |
67 if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) { | 70 if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) { |
68 // Decomposition failed, use an approximation. | 71 // Decomposition failed, use an approximation. |
69 scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m.
getSkewX()), | 72 scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m.
getSkewX()), |
70 SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m.
getSkewY())); | 73 SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m.
getSkewY())); |
71 } | 74 } |
72 SkSize scaledSize = SkSize::Make(scale.x() * fPicture->width(), scale.y() *
fPicture->height()); | 75 SkSize scaledSize = SkSize::Make(scale.x() * fPicture->width(), scale.y() *
fPicture->height()); |
73 | 76 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // ref count was incremented. | 111 // ref count was incremented. |
109 fCachedBitmapShader.get()->ref(); | 112 fCachedBitmapShader.get()->ref(); |
110 return fCachedBitmapShader; | 113 return fCachedBitmapShader; |
111 } | 114 } |
112 | 115 |
113 size_t SkPictureShader::contextSize() const { | 116 size_t SkPictureShader::contextSize() const { |
114 return sizeof(PictureShaderContext); | 117 return sizeof(PictureShaderContext); |
115 } | 118 } |
116 | 119 |
117 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void*
storage) const { | 120 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void*
storage) const { |
118 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix)); | 121 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix, rec.
fLocalMatrix)); |
119 if (NULL == bitmapShader.get()) { | 122 if (NULL == bitmapShader.get()) { |
120 return NULL; | 123 return NULL; |
121 } | 124 } |
122 return PictureShaderContext::Create(storage, *this, rec, bitmapShader); | 125 return PictureShaderContext::Create(storage, *this, rec, bitmapShader); |
123 } | 126 } |
124 | 127 |
125 ////////////////////////////////////////////////////////////////////////////////
///////// | 128 ////////////////////////////////////////////////////////////////////////////////
///////// |
126 | 129 |
127 SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage, | 130 SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage, |
128 const SkPictureShader& shader, const ContextRec& rec, SkShade
r* bitmapShader) { | 131 const SkPictureShader& shader, const ContextRec& rec, SkShade
r* bitmapShader) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 fPicture ? fPicture->height() : 0); | 186 fPicture ? fPicture->height() : 0); |
184 | 187 |
185 str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]); | 188 str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]); |
186 | 189 |
187 this->INHERITED::toString(str); | 190 this->INHERITED::toString(str); |
188 } | 191 } |
189 #endif | 192 #endif |
190 | 193 |
191 #if SK_SUPPORT_GPU | 194 #if SK_SUPPORT_GPU |
192 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { | 195 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { |
193 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
())); | 196 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
(), NULL)); |
194 if (!bitmapShader) { | 197 if (!bitmapShader) { |
195 return NULL; | 198 return NULL; |
196 } | 199 } |
197 return bitmapShader->asNewEffect(context, paint); | 200 return bitmapShader->asNewEffect(context, paint); |
198 } | 201 } |
199 #endif | 202 #endif |
OLD | NEW |