OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 public: | 44 public: |
45 UnpremulView(SkString res) | 45 UnpremulView(SkString res) |
46 : fResPath(res) | 46 : fResPath(res) |
47 , fPremul(true) | 47 , fPremul(true) |
48 , fDecodeSucceeded(false) { | 48 , fDecodeSucceeded(false) { |
49 this->nextImage(); | 49 this->nextImage(); |
50 } | 50 } |
51 | 51 |
52 protected: | 52 protected: |
53 // overrides from SkEventSink | 53 // overrides from SkEventSink |
54 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { | 54 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
55 if (SampleCode::TitleQ(*evt)) { | 55 if (SampleCode::TitleQ(*evt)) { |
56 SampleCode::TitleR(evt, "unpremul"); | 56 SampleCode::TitleR(evt, "unpremul"); |
57 return true; | 57 return true; |
58 } | 58 } |
59 SkUnichar uni; | 59 SkUnichar uni; |
60 if (SampleCode::CharQ(*evt, &uni)) { | 60 if (SampleCode::CharQ(*evt, &uni)) { |
61 char utf8[kMaxBytesInUTF8Sequence]; | 61 char utf8[kMaxBytesInUTF8Sequence]; |
62 size_t size = SkUTF8_FromUnichar(uni, utf8); | 62 size_t size = SkUTF8_FromUnichar(uni, utf8); |
63 // Only consider events for single char keys | 63 // Only consider events for single char keys |
64 if (1 == size) { | 64 if (1 == size) { |
65 switch (utf8[0]) { | 65 switch (utf8[0]) { |
66 case fNextImageChar: | 66 case fNextImageChar: |
67 this->nextImage(); | 67 this->nextImage(); |
68 return true; | 68 return true; |
69 case fTogglePremulChar: | 69 case fTogglePremulChar: |
70 this->togglePremul(); | 70 this->togglePremul(); |
71 return true; | 71 return true; |
72 default: | 72 default: |
73 break; | 73 break; |
74 } | 74 } |
75 } | 75 } |
76 } | 76 } |
77 return this->INHERITED::onQuery(evt); | 77 return this->INHERITED::onQuery(evt); |
78 } | 78 } |
79 | 79 |
80 virtual void onDrawBackground(SkCanvas* canvas) SK_OVERRIDE { | 80 void onDrawBackground(SkCanvas* canvas) SK_OVERRIDE { |
81 SkPaint paint; | 81 SkPaint paint; |
82 SkAutoTUnref<SkShader> shader(createChecker()); | 82 SkAutoTUnref<SkShader> shader(createChecker()); |
83 paint.setShader(shader.get()); | 83 paint.setShader(shader.get()); |
84 canvas->drawPaint(paint); | 84 canvas->drawPaint(paint); |
85 } | 85 } |
86 | 86 |
87 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 87 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
88 SkPaint paint; | 88 SkPaint paint; |
89 paint.setAntiAlias(true); | 89 paint.setAntiAlias(true); |
90 paint.setTextSize(SkIntToScalar(24)); | 90 paint.setTextSize(SkIntToScalar(24)); |
91 SkAutoTUnref<SkBlurDrawLooper> looper( | 91 SkAutoTUnref<SkBlurDrawLooper> looper( |
92 SkBlurDrawLooper::Create(SK_ColorBLUE, | 92 SkBlurDrawLooper::Create(SK_ColorBLUE, |
93 SkBlurMask::ConvertRadiusToSigma(SkIntToSca
lar(2)), | 93 SkBlurMask::ConvertRadiusToSigma(SkIntToSca
lar(2)), |
94 0, 0)); | 94 0, 0)); |
95 paint.setLooper(looper); | 95 paint.setLooper(looper); |
96 SkScalar height = paint.getFontMetrics(NULL); | 96 SkScalar height = paint.getFontMetrics(NULL); |
97 if (!fDecodeSucceeded) { | 97 if (!fDecodeSucceeded) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 193 |
194 typedef SampleView INHERITED; | 194 typedef SampleView INHERITED; |
195 }; | 195 }; |
196 | 196 |
197 ////////////////////////////////////////////////////////////////////////////// | 197 ////////////////////////////////////////////////////////////////////////////// |
198 | 198 |
199 static SkView* MyFactory() { | 199 static SkView* MyFactory() { |
200 return new UnpremulView(GetResourcePath()); | 200 return new UnpremulView(GetResourcePath()); |
201 } | 201 } |
202 static SkViewRegister reg(MyFactory); | 202 static SkViewRegister reg(MyFactory); |
OLD | NEW |