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 "sk_tool_utils.h" | 10 #include "sk_tool_utils.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 void onDrawContent(SkCanvas* canvas) override { | 82 void onDrawContent(SkCanvas* canvas) override { |
83 SkPaint paint; | 83 SkPaint paint; |
84 paint.setAntiAlias(true); | 84 paint.setAntiAlias(true); |
85 paint.setTextSize(SkIntToScalar(24)); | 85 paint.setTextSize(SkIntToScalar(24)); |
86 SkAutoTUnref<SkBlurDrawLooper> looper( | 86 SkAutoTUnref<SkBlurDrawLooper> looper( |
87 SkBlurDrawLooper::Create(SK_ColorBLUE, | 87 SkBlurDrawLooper::Create(SK_ColorBLUE, |
88 SkBlurMask::ConvertRadiusToSigma(SkIntToSca
lar(2)), | 88 SkBlurMask::ConvertRadiusToSigma(SkIntToSca
lar(2)), |
89 0, 0)); | 89 0, 0)); |
90 paint.setLooper(looper); | 90 paint.setLooper(looper); |
91 SkScalar height = paint.getFontMetrics(NULL); | 91 SkScalar height = paint.getFontMetrics(nullptr); |
92 if (!fDecodeSucceeded) { | 92 if (!fDecodeSucceeded) { |
93 SkString failure; | 93 SkString failure; |
94 if (fResPath.size() == 0) { | 94 if (fResPath.size() == 0) { |
95 failure.printf("resource path is required!"); | 95 failure.printf("resource path is required!"); |
96 } else { | 96 } else { |
97 failure.printf("Failed to decode %s", fCurrFile.c_str()); | 97 failure.printf("Failed to decode %s", fCurrFile.c_str()); |
98 } | 98 } |
99 canvas->drawText(failure.c_str(), failure.size(), 0, height, paint); | 99 canvas->drawText(failure.c_str(), failure.size(), 0, height, paint); |
100 return; | 100 return; |
101 } | 101 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 this->decodeCurrFile(); | 162 this->decodeCurrFile(); |
163 } | 163 } |
164 | 164 |
165 void decodeCurrFile() { | 165 void decodeCurrFile() { |
166 if (fCurrFile.size() == 0) { | 166 if (fCurrFile.size() == 0) { |
167 fDecodeSucceeded = false; | 167 fDecodeSucceeded = false; |
168 return; | 168 return; |
169 } | 169 } |
170 SkFILEStream stream(fCurrFile.c_str()); | 170 SkFILEStream stream(fCurrFile.c_str()); |
171 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream)); | 171 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream)); |
172 if (NULL == decoder.get()) { | 172 if (nullptr == decoder.get()) { |
173 fDecodeSucceeded = false; | 173 fDecodeSucceeded = false; |
174 return; | 174 return; |
175 } | 175 } |
176 if (!fPremul) { | 176 if (!fPremul) { |
177 decoder->setRequireUnpremultipliedColors(true); | 177 decoder->setRequireUnpremultipliedColors(true); |
178 } | 178 } |
179 fDecodeSucceeded = decoder->decode(&stream, &fBitmap, kN32_SkColorType, | 179 fDecodeSucceeded = decoder->decode(&stream, &fBitmap, kN32_SkColorType, |
180 SkImageDecoder::kDecodePixels_Mode) != SkImageDecoder::kFailure; | 180 SkImageDecoder::kDecodePixels_Mode) != SkImageDecoder::kFailure; |
181 this->inval(NULL); | 181 this->inval(nullptr); |
182 } | 182 } |
183 | 183 |
184 void togglePremul() { | 184 void togglePremul() { |
185 fPremul = !fPremul; | 185 fPremul = !fPremul; |
186 this->decodeCurrFile(); | 186 this->decodeCurrFile(); |
187 } | 187 } |
188 | 188 |
189 typedef SampleView INHERITED; | 189 typedef SampleView INHERITED; |
190 }; | 190 }; |
191 | 191 |
192 ////////////////////////////////////////////////////////////////////////////// | 192 ////////////////////////////////////////////////////////////////////////////// |
193 | 193 |
194 static SkView* MyFactory() { | 194 static SkView* MyFactory() { |
195 return new UnpremulView(GetResourcePath()); | 195 return new UnpremulView(GetResourcePath()); |
196 } | 196 } |
197 static SkViewRegister reg(MyFactory); | 197 static SkViewRegister reg(MyFactory); |
OLD | NEW |