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 "SkEmptyShader.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
11 #include "SkMallocPixelRef.h" | 11 #include "SkMallocPixelRef.h" |
12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
13 #include "SkPicture.h" | 13 #include "SkPicture.h" |
14 #include "SkPictureShader.h" | 14 #include "SkPictureShader.h" |
15 #include "SkScalar.h" | 15 #include "SkScalar.h" |
16 #include "SkShader.h" | 16 #include "SkShader.h" |
| 17 #include "SkThread.h" |
17 #include "SkWriteBuffer.h" | 18 #include "SkWriteBuffer.h" |
18 | 19 |
| 20 //#define SK_TRACK_SHADER_LIFETIME |
| 21 |
| 22 #ifdef SK_TRACK_SHADER_LIFETIME |
| 23 static int32_t gShaderCounter; |
| 24 #endif |
| 25 |
| 26 static inline void inc_shader_counter() { |
| 27 #ifdef SK_TRACK_SHADER_LIFETIME |
| 28 int32_t prev = sk_atomic_inc(&gShaderCounter); |
| 29 SkDebugf("+++ shader counter %d\n", prev + 1); |
| 30 #endif |
| 31 } |
| 32 static inline void dec_shader_counter() { |
| 33 #ifdef SK_TRACK_SHADER_LIFETIME |
| 34 int32_t prev = sk_atomic_dec(&gShaderCounter); |
| 35 SkDebugf("--- shader counter %d\n", prev - 1); |
| 36 #endif |
| 37 } |
| 38 |
19 SkShader::SkShader(const SkMatrix* localMatrix) { | 39 SkShader::SkShader(const SkMatrix* localMatrix) { |
| 40 inc_shader_counter(); |
20 if (localMatrix) { | 41 if (localMatrix) { |
21 fLocalMatrix = *localMatrix; | 42 fLocalMatrix = *localMatrix; |
22 } else { | 43 } else { |
23 fLocalMatrix.reset(); | 44 fLocalMatrix.reset(); |
24 } | 45 } |
25 } | 46 } |
26 | 47 |
27 SkShader::SkShader(SkReadBuffer& buffer) | 48 SkShader::SkShader(SkReadBuffer& buffer) : INHERITED(buffer) { |
28 : INHERITED(buffer) { | 49 inc_shader_counter(); |
29 if (buffer.readBool()) { | 50 if (buffer.readBool()) { |
30 buffer.readMatrix(&fLocalMatrix); | 51 buffer.readMatrix(&fLocalMatrix); |
31 } else { | 52 } else { |
32 fLocalMatrix.reset(); | 53 fLocalMatrix.reset(); |
33 } | 54 } |
34 } | 55 } |
35 | 56 |
36 SkShader::~SkShader() { | 57 SkShader::~SkShader() { |
| 58 dec_shader_counter(); |
37 } | 59 } |
38 | 60 |
39 void SkShader::flatten(SkWriteBuffer& buffer) const { | 61 void SkShader::flatten(SkWriteBuffer& buffer) const { |
40 this->INHERITED::flatten(buffer); | 62 this->INHERITED::flatten(buffer); |
41 bool hasLocalM = this->hasLocalMatrix(); | 63 bool hasLocalM = this->hasLocalMatrix(); |
42 buffer.writeBool(hasLocalM); | 64 buffer.writeBool(hasLocalM); |
43 if (hasLocalM) { | 65 if (hasLocalM) { |
44 buffer.writeMatrix(fLocalMatrix); | 66 buffer.writeMatrix(fLocalMatrix); |
45 } | 67 } |
46 } | 68 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 208 } |
187 | 209 |
188 SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const { | 210 SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const { |
189 return kNone_GradientType; | 211 return kNone_GradientType; |
190 } | 212 } |
191 | 213 |
192 GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const { | 214 GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const { |
193 return NULL; | 215 return NULL; |
194 } | 216 } |
195 | 217 |
| 218 SkShader* SkShader::refAsALocalMatrixShader(SkMatrix*) const { |
| 219 return NULL; |
| 220 } |
| 221 |
196 SkShader* SkShader::CreateEmptyShader() { | 222 SkShader* SkShader::CreateEmptyShader() { |
197 return SkNEW(SkEmptyShader); | 223 return SkNEW(SkEmptyShader); |
198 } | 224 } |
199 | 225 |
200 SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, | 226 SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, |
201 const SkMatrix* localMatrix) { | 227 const SkMatrix* localMatrix) { |
202 return ::CreateBitmapShader(src, tmx, tmy, localMatrix, NULL); | 228 return ::CreateBitmapShader(src, tmx, tmy, localMatrix, NULL); |
203 } | 229 } |
204 | 230 |
205 SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t
my, | 231 SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t
my, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 #include "SkEmptyShader.h" | 363 #include "SkEmptyShader.h" |
338 | 364 |
339 void SkEmptyShader::toString(SkString* str) const { | 365 void SkEmptyShader::toString(SkString* str) const { |
340 str->append("SkEmptyShader: ("); | 366 str->append("SkEmptyShader: ("); |
341 | 367 |
342 this->INHERITED::toString(str); | 368 this->INHERITED::toString(str); |
343 | 369 |
344 str->append(")"); | 370 str->append(")"); |
345 } | 371 } |
346 #endif | 372 #endif |
OLD | NEW |