OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkColorMatrixFilter.h" | 9 #include "SkColorMatrixFilter.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
11 | 11 |
12 #define WIDTH 500 | 12 #define WIDTH 500 |
13 #define HEIGHT 500 | 13 #define HEIGHT 500 |
14 | 14 |
15 class SkOnce { | 15 class SkDoOnce { |
16 public: | 16 public: |
17 SkOnce() : fOnce(false) {}; | 17 SkDoOnce() : fOnce(false) {}; |
18 | 18 |
19 bool once() const { | 19 bool once() const { |
20 if (fOnce) { | 20 if (fOnce) { |
21 return false; | 21 return false; |
22 } | 22 } |
23 fOnce = true; | 23 fOnce = true; |
24 return true; | 24 return true; |
25 } | 25 } |
26 | 26 |
27 private: | 27 private: |
28 mutable bool fOnce; | 28 mutable bool fOnce; |
29 }; | 29 }; |
30 | 30 |
31 static void setColorMatrix(SkPaint* paint, const SkColorMatrix& matrix) { | 31 static void setColorMatrix(SkPaint* paint, const SkColorMatrix& matrix) { |
32 paint->setColorFilter(SkNEW_ARGS(SkColorMatrixFilter, (matrix)))->unref(); | 32 paint->setColorFilter(SkNEW_ARGS(SkColorMatrixFilter, (matrix)))->unref(); |
33 } | 33 } |
34 | 34 |
35 static void setArray(SkPaint* paint, const SkScalar array[]) { | 35 static void setArray(SkPaint* paint, const SkScalar array[]) { |
36 paint->setColorFilter(SkNEW_ARGS(SkColorMatrixFilter, (array)))->unref(); | 36 paint->setColorFilter(SkNEW_ARGS(SkColorMatrixFilter, (array)))->unref(); |
37 } | 37 } |
38 | 38 |
39 namespace skiagm { | 39 namespace skiagm { |
40 | 40 |
41 class ColorMatrixGM : public GM { | 41 class ColorMatrixGM : public GM { |
42 SkOnce fOnce; | 42 SkDoOnce fOnce; |
43 void init() { | 43 void init() { |
44 if (fOnce.once()) { | 44 if (fOnce.once()) { |
45 fSolidBitmap = this->createSolidBitmap(64, 64); | 45 fSolidBitmap = this->createSolidBitmap(64, 64); |
46 fTransparentBitmap = this->createTransparentBitmap(64, 64); | 46 fTransparentBitmap = this->createTransparentBitmap(64, 64); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 public: | 50 public: |
51 ColorMatrixGM() { | 51 ColorMatrixGM() { |
52 this->setBGColor(0xFF808080); | 52 this->setBGColor(0xFF808080); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 SkBitmap fTransparentBitmap; | 168 SkBitmap fTransparentBitmap; |
169 typedef GM INHERITED; | 169 typedef GM INHERITED; |
170 }; | 170 }; |
171 | 171 |
172 ////////////////////////////////////////////////////////////////////////////// | 172 ////////////////////////////////////////////////////////////////////////////// |
173 | 173 |
174 static GM* MyFactory(void*) { return new ColorMatrixGM; } | 174 static GM* MyFactory(void*) { return new ColorMatrixGM; } |
175 static GMRegistry reg(MyFactory); | 175 static GMRegistry reg(MyFactory); |
176 | 176 |
177 } | 177 } |
OLD | NEW |