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 |
| 10 #include "Resources.h" |
9 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
10 | |
11 #include "SkTypeface.h" | |
12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
13 #include "SkStream.h" | 13 #include "SkStream.h" |
| 14 #include "SkTypeface.h" |
14 | 15 |
15 static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty
le) { | 16 static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty
le) { |
16 SkSafeUnref(paint->setTypeface(SkTypeface::CreateFromName(name, style))); | 17 SkSafeUnref(paint->setTypeface(SkTypeface::CreateFromName(name, style))); |
17 } | 18 } |
18 | 19 |
19 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { | 20 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { |
20 SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()), | 21 SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()), |
21 SkIntToScalar(bm.height())); | 22 SkIntToScalar(bm.height())); |
22 mat.mapRect(&bounds); | 23 mat.mapRect(&bounds); |
23 return SkSize::Make(bounds.width(), bounds.height()); | 24 return SkSize::Make(bounds.width(), bounds.height()); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 187 |
187 protected: | 188 protected: |
188 SkString fFilename; | 189 SkString fFilename; |
189 int fSize; | 190 int fSize; |
190 | 191 |
191 SkScalar getScale() SK_OVERRIDE { | 192 SkScalar getScale() SK_OVERRIDE { |
192 return 192.f/fSize; | 193 return 192.f/fSize; |
193 } | 194 } |
194 | 195 |
195 void makeBitmap() SK_OVERRIDE { | 196 void makeBitmap() SK_OVERRIDE { |
196 SkString path(skiagm::GM::gResourcePath); | 197 SkString resourcePath = GetResourcePath(); |
197 path.append("/"); | 198 resourcePath.append("/"); |
198 path.append(fFilename); | 199 resourcePath.append(fFilename); |
199 | 200 |
200 SkImageDecoder *codec = NULL; | 201 SkImageDecoder* codec = NULL; |
201 SkFILEStream stream(path.c_str()); | 202 SkFILEStream stream(resourcePath.c_str()); |
202 if (stream.isValid()) { | 203 if (stream.isValid()) { |
203 codec = SkImageDecoder::Factory(&stream); | 204 codec = SkImageDecoder::Factory(&stream); |
204 } | 205 } |
205 if (codec) { | 206 if (codec) { |
206 stream.rewind(); | 207 stream.rewind(); |
207 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); | 208 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); |
208 SkDELETE(codec); | 209 SkDELETE(codec); |
209 } else { | 210 } else { |
210 fBM.allocN32Pixels(1, 1); | 211 fBM.allocN32Pixels(1, 1); |
211 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | 212 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
(...skipping 13 matching lines...) Expand all Loading... |
225 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) | 226 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) |
226 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) | 227 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) |
227 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) | 228 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) |
228 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) | 229 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) |
229 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) | 230 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) |
230 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) | 231 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) |
231 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) | 232 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) |
232 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) | 233 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) |
233 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) | 234 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) |
234 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) | 235 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) |
OLD | NEW |