OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkBitmapProcShader.h" | 8 #include "SkBitmapProcShader.h" |
| 9 #include "SkEmptyShader.h" |
9 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
10 #include "SkMallocPixelRef.h" | 11 #include "SkMallocPixelRef.h" |
11 #include "SkPaint.h" | 12 #include "SkPaint.h" |
12 #include "SkPicture.h" | 13 #include "SkPicture.h" |
13 #include "SkPictureShader.h" | 14 #include "SkPictureShader.h" |
14 #include "SkScalar.h" | 15 #include "SkScalar.h" |
15 #include "SkShader.h" | 16 #include "SkShader.h" |
16 #include "SkWriteBuffer.h" | 17 #include "SkWriteBuffer.h" |
17 | 18 |
18 SkShader::SkShader(const SkMatrix* localMatrix) { | 19 SkShader::SkShader(const SkMatrix* localMatrix) { |
(...skipping 18 matching lines...) Expand all Loading... |
37 | 38 |
38 void SkShader::flatten(SkWriteBuffer& buffer) const { | 39 void SkShader::flatten(SkWriteBuffer& buffer) const { |
39 this->INHERITED::flatten(buffer); | 40 this->INHERITED::flatten(buffer); |
40 bool hasLocalM = this->hasLocalMatrix(); | 41 bool hasLocalM = this->hasLocalMatrix(); |
41 buffer.writeBool(hasLocalM); | 42 buffer.writeBool(hasLocalM); |
42 if (hasLocalM) { | 43 if (hasLocalM) { |
43 buffer.writeMatrix(fLocalMatrix); | 44 buffer.writeMatrix(fLocalMatrix); |
44 } | 45 } |
45 } | 46 } |
46 | 47 |
47 bool SkShader::computeTotalInverse(const SkMatrix& matrix, SkMatrix* totalInvers
e) const { | 48 bool SkShader::computeTotalInverse(const ContextRec& rec, SkMatrix* totalInverse
) const { |
48 const SkMatrix* m = &matrix; | 49 const SkMatrix* m = rec.fMatrix; |
49 SkMatrix total; | 50 SkMatrix total; |
50 | 51 |
51 if (this->hasLocalMatrix()) { | 52 if (this->hasLocalMatrix()) { |
52 total.setConcat(matrix, this->getLocalMatrix()); | 53 total.setConcat(*m, this->getLocalMatrix()); |
53 m = &total; | 54 m = &total; |
54 } | 55 } |
55 | |
56 return m->invert(totalInverse); | 56 return m->invert(totalInverse); |
57 } | 57 } |
58 | 58 |
59 bool SkShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const
{ | 59 SkShader::Context* SkShader::createContext(const ContextRec& rec, void* storage)
const { |
60 return this->computeTotalInverse(*rec.fMatrix, totalInverse); | 60 if (!this->computeTotalInverse(rec, NULL)) { |
| 61 return NULL; |
| 62 } |
| 63 return this->onCreateContext(rec, storage); |
61 } | 64 } |
62 | 65 |
63 SkShader::Context* SkShader::createContext(const ContextRec&, void* storage) con
st { | 66 SkShader::Context* SkShader::onCreateContext(const ContextRec&, void*) const { |
64 return NULL; | 67 return NULL; |
65 } | 68 } |
66 | 69 |
67 size_t SkShader::contextSize() const { | 70 size_t SkShader::contextSize() const { |
68 return 0; | 71 return 0; |
69 } | 72 } |
70 | 73 |
71 SkShader::Context::Context(const SkShader& shader, const ContextRec& rec) | 74 SkShader::Context::Context(const SkShader& shader, const ContextRec& rec) |
72 : fShader(shader) | 75 : fShader(shader) |
73 { | 76 { |
74 SkASSERT(fShader.validContext(rec)); | |
75 | |
76 // Because the context parameters must be valid at this point, we know that
the matrix is | 77 // Because the context parameters must be valid at this point, we know that
the matrix is |
77 // invertible. | 78 // invertible. |
78 SkAssertResult(fShader.computeTotalInverse(*rec.fMatrix, &fTotalInverse)); | 79 SkAssertResult(fShader.computeTotalInverse(rec, &fTotalInverse)); |
79 fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse); | 80 fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse); |
80 | 81 |
81 fPaintAlpha = rec.fPaint->getAlpha(); | 82 fPaintAlpha = rec.fPaint->getAlpha(); |
82 } | 83 } |
83 | 84 |
84 SkShader::Context::~Context() {} | 85 SkShader::Context::~Context() {} |
85 | 86 |
86 SkShader::Context::ShadeProc SkShader::Context::asAShadeProc(void** ctx) { | 87 SkShader::Context::ShadeProc SkShader::Context::asAShadeProc(void** ctx) { |
87 return NULL; | 88 return NULL; |
88 } | 89 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 182 } |
182 | 183 |
183 SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const { | 184 SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const { |
184 return kNone_GradientType; | 185 return kNone_GradientType; |
185 } | 186 } |
186 | 187 |
187 GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const { | 188 GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const { |
188 return NULL; | 189 return NULL; |
189 } | 190 } |
190 | 191 |
| 192 SkShader* SkShader::CreateEmptyShader() { |
| 193 return SkNEW(SkEmptyShader); |
| 194 } |
| 195 |
191 SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, | 196 SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, |
192 const SkMatrix* localMatrix) { | 197 const SkMatrix* localMatrix) { |
193 return ::CreateBitmapShader(src, tmx, tmy, localMatrix, NULL); | 198 return ::CreateBitmapShader(src, tmx, tmy, localMatrix, NULL); |
194 } | 199 } |
195 | 200 |
196 SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t
my, | 201 SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t
my, |
197 const SkMatrix* localMatrix) { | 202 const SkMatrix* localMatrix) { |
198 return SkPictureShader::Create(src, tmx, tmy, localMatrix); | 203 return SkPictureShader::Create(src, tmx, tmy, localMatrix); |
199 } | 204 } |
200 | 205 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 } | 244 } |
240 | 245 |
241 uint32_t SkColorShader::ColorShaderContext::getFlags() const { | 246 uint32_t SkColorShader::ColorShaderContext::getFlags() const { |
242 return fFlags; | 247 return fFlags; |
243 } | 248 } |
244 | 249 |
245 uint8_t SkColorShader::ColorShaderContext::getSpan16Alpha() const { | 250 uint8_t SkColorShader::ColorShaderContext::getSpan16Alpha() const { |
246 return SkGetPackedA32(fPMColor); | 251 return SkGetPackedA32(fPMColor); |
247 } | 252 } |
248 | 253 |
249 SkShader::Context* SkColorShader::createContext(const ContextRec& rec, void* sto
rage) const { | 254 SkShader::Context* SkColorShader::onCreateContext(const ContextRec& rec, void* s
torage) const { |
250 if (!this->validContext(rec)) { | |
251 return NULL; | |
252 } | |
253 | |
254 return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, rec)); | 255 return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, rec)); |
255 } | 256 } |
256 | 257 |
257 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade
r, | 258 SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shade
r, |
258 const ContextRec& rec) | 259 const ContextRec& rec) |
259 : INHERITED(shader, rec) | 260 : INHERITED(shader, rec) |
260 { | 261 { |
261 SkColor color = shader.fColor; | 262 SkColor color = shader.fColor; |
262 unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(rec.fPaint->getA
lpha())); | 263 unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(rec.fPaint->getA
lpha())); |
263 | 264 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 #include "SkEmptyShader.h" | 333 #include "SkEmptyShader.h" |
333 | 334 |
334 void SkEmptyShader::toString(SkString* str) const { | 335 void SkEmptyShader::toString(SkString* str) const { |
335 str->append("SkEmptyShader: ("); | 336 str->append("SkEmptyShader: ("); |
336 | 337 |
337 this->INHERITED::toString(str); | 338 this->INHERITED::toString(str); |
338 | 339 |
339 str->append(")"); | 340 str->append(")"); |
340 } | 341 } |
341 #endif | 342 #endif |
OLD | NEW |