OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 20 matching lines...) Expand all Loading... |
31 "mandrill_132x130_12x10.astc", // kASTC_12x10_Format | 31 "mandrill_132x130_12x10.astc", // kASTC_12x10_Format |
32 "mandrill_132x132_12x12.astc", // kASTC_12x12_Format | 32 "mandrill_132x132_12x12.astc", // kASTC_12x12_Format |
33 }; | 33 }; |
34 | 34 |
35 static const int kNumASTCFilenames = SK_ARRAY_COUNT(kASTCFilenames); | 35 static const int kNumASTCFilenames = SK_ARRAY_COUNT(kASTCFilenames); |
36 | 36 |
37 static inline const char *get_astc_filename(int idx) { | 37 static inline const char *get_astc_filename(int idx) { |
38 if (idx < 0 || kNumASTCFilenames <= idx) { | 38 if (idx < 0 || kNumASTCFilenames <= idx) { |
39 return ""; | 39 return ""; |
40 } | 40 } |
41 | |
42 return kASTCFilenames[idx]; | 41 return kASTCFilenames[idx]; |
43 } | 42 } |
44 | 43 |
45 namespace { | 44 namespace { |
46 const int kGMDimension = 600; | 45 const int kGMDimension = 600; |
47 const int kBitmapDimension = kGMDimension / 4; | 46 const int kBitmapDimension = kGMDimension / 4; |
48 } // namespace | 47 } // namespace |
49 | 48 |
50 DEF_SIMPLE_GM(astcbitmap, canvas, kGMDimension, kGMDimension) { | 49 DEF_SIMPLE_GM(astcbitmap, canvas, kGMDimension, kGMDimension) { |
51 for (int j = 0; j < 4; ++j) { | 50 for (int j = 0; j < 4; ++j) { |
52 for (int i = 0; i < 4; ++i) { | 51 for (int i = 0; i < 4; ++i) { |
53 SkString filename = GetResourcePath(get_astc_filename(j*4+i)); | 52 SkBitmap bm; |
54 if (filename == GetResourcePath("")) { | 53 if (GetResourceAsBitmap(get_astc_filename(j*4+i), &bm)) { |
55 continue; | |
56 } | |
57 | |
58 SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c
_str())); | |
59 if (nullptr == fileData) { | |
60 SkDebugf("Could not open the file. Did you forget to set the
resourcePath?\n"); | |
61 return; | |
62 } | |
63 | |
64 SkBitmap bm; | |
65 if (!SkInstallDiscardablePixelRef(fileData, &bm)) { | |
66 SkDebugf("Could not install discardable pixel ref.\n"); | |
67 return; | |
68 } | |
69 | |
70 const SkScalar bmX = static_cast<SkScalar>(i*kBitmapDimension); | 54 const SkScalar bmX = static_cast<SkScalar>(i*kBitmapDimension); |
71 const SkScalar bmY = static_cast<SkScalar>(j*kBitmapDimension); | 55 const SkScalar bmY = static_cast<SkScalar>(j*kBitmapDimension); |
72 canvas->drawBitmap(bm, bmX, bmY); | 56 canvas->drawBitmap(bm, bmX, bmY); |
73 } | 57 } |
74 } | 58 } |
| 59 } |
75 } | 60 } |
| 61 |
| 62 DEF_SIMPLE_GM(astc_image, canvas, kGMDimension, kGMDimension) { |
| 63 for (int j = 0; j < 4; ++j) { |
| 64 for (int i = 0; i < 4; ++i) { |
| 65 SkAutoTUnref<SkImage> image(GetResourceAsImage(get_astc_filename(j*4
+i))); |
| 66 if (image) { |
| 67 const SkScalar bmX = static_cast<SkScalar>(i*kBitmapDimension); |
| 68 const SkScalar bmY = static_cast<SkScalar>(j*kBitmapDimension); |
| 69 canvas->drawImage(image, bmX, bmY); |
| 70 } |
| 71 } |
| 72 } |
| 73 } |
OLD | NEW |