OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 namespace skiagm { | 10 namespace skiagm { |
11 | 11 |
12 static const char* gConfigNames[] = { | 12 static const char* gColorTypeNames[] = { |
13 "unknown config", | 13 "unknown", |
14 "A8", | 14 "A8", |
15 "Index8", | |
16 "565", | 15 "565", |
17 "4444", | 16 "4444", |
18 "8888" | 17 "8888", |
| 18 "8888", |
| 19 "Index8", |
19 }; | 20 }; |
20 | 21 |
21 SkBitmap::Config gConfigs[] = { | 22 static const SkColorType gColorTypes[] = { |
22 SkBitmap::kRGB_565_Config, | 23 kRGB_565_SkColorType, |
23 SkBitmap::kARGB_4444_Config, // TODO(edisonn): Should we remove it from GM? | 24 kARGB_4444_SkColorType, |
24 // it fails to copy in bitmap with this config. | 25 kPMColor_SkColorType, |
25 SkBitmap::kARGB_8888_Config, | |
26 }; | 26 }; |
27 | 27 |
28 #define NUM_CONFIGS (sizeof(gConfigs) / sizeof(SkBitmap::Config)) | 28 #define NUM_CONFIGS SK_ARRAY_COUNT(gColorTypes) |
29 | 29 |
30 static void draw_checks(SkCanvas* canvas, int width, int height) { | 30 static void draw_checks(SkCanvas* canvas, int width, int height) { |
31 SkPaint paint; | 31 SkPaint paint; |
32 paint.setColor(SK_ColorRED); | 32 paint.setColor(SK_ColorRED); |
33 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), | 33 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), |
34 SkIntToScalar(width / 2), SkIntToScalar(height / 2), paint); | 34 SkIntToScalar(width / 2), SkIntToScalar(height / 2), paint); |
35 paint.setColor(SK_ColorGREEN); | 35 paint.setColor(SK_ColorGREEN); |
36 canvas->drawRectCoords(SkIntToScalar(width / 2), SkIntToScalar(0), | 36 canvas->drawRectCoords(SkIntToScalar(width / 2), SkIntToScalar(0), |
37 SkIntToScalar(width), SkIntToScalar(height / 2), paint); | 37 SkIntToScalar(width), SkIntToScalar(height / 2), paint); |
38 paint.setColor(SK_ColorBLUE); | 38 paint.setColor(SK_ColorBLUE); |
(...skipping 26 matching lines...) Expand all Loading... |
65 SkScalar horizMargin = 10; | 65 SkScalar horizMargin = 10; |
66 SkScalar vertMargin = 10; | 66 SkScalar vertMargin = 10; |
67 | 67 |
68 SkBitmap src; | 68 SkBitmap src; |
69 src.allocN32Pixels(40, 40); | 69 src.allocN32Pixels(40, 40); |
70 SkCanvas canvasTmp(src); | 70 SkCanvas canvasTmp(src); |
71 | 71 |
72 draw_checks(&canvasTmp, 40, 40); | 72 draw_checks(&canvasTmp, 40, 40); |
73 | 73 |
74 for (unsigned i = 0; i < NUM_CONFIGS; ++i) { | 74 for (unsigned i = 0; i < NUM_CONFIGS; ++i) { |
75 src.copyTo(&fDst[i], gConfigs[i]); | 75 src.copyTo(&fDst[i], gColorTypes[i]); |
76 } | 76 } |
77 | 77 |
78 canvas->clear(0xFFDDDDDD); | 78 canvas->clear(0xFFDDDDDD); |
79 paint.setAntiAlias(true); | 79 paint.setAntiAlias(true); |
80 SkScalar width = SkIntToScalar(40); | 80 SkScalar width = SkIntToScalar(40); |
81 SkScalar height = SkIntToScalar(40); | 81 SkScalar height = SkIntToScalar(40); |
82 if (paint.getFontSpacing() > height) { | 82 if (paint.getFontSpacing() > height) { |
83 height = paint.getFontSpacing(); | 83 height = paint.getFontSpacing(); |
84 } | 84 } |
85 for (unsigned i = 0; i < NUM_CONFIGS; i++) { | 85 for (unsigned i = 0; i < NUM_CONFIGS; i++) { |
86 const char* name = gConfigNames[src.config()]; | 86 const char* name = gColorTypeNames[src.colorType()]; |
87 SkScalar textWidth = paint.measureText(name, strlen(name)); | 87 SkScalar textWidth = paint.measureText(name, strlen(name)); |
88 if (textWidth > width) { | 88 if (textWidth > width) { |
89 width = textWidth; | 89 width = textWidth; |
90 } | 90 } |
91 } | 91 } |
92 SkScalar horizOffset = width + horizMargin; | 92 SkScalar horizOffset = width + horizMargin; |
93 SkScalar vertOffset = height + vertMargin; | 93 SkScalar vertOffset = height + vertMargin; |
94 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); | 94 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
95 | 95 |
96 for (unsigned i = 0; i < NUM_CONFIGS; i++) { | 96 for (unsigned i = 0; i < NUM_CONFIGS; i++) { |
97 canvas->save(); | 97 canvas->save(); |
98 // Draw destination config name | 98 // Draw destination config name |
99 const char* name = gConfigNames[fDst[i].config()]; | 99 const char* name = gColorTypeNames[fDst[i].colorType()]; |
100 SkScalar textWidth = paint.measureText(name, strlen(name)); | 100 SkScalar textWidth = paint.measureText(name, strlen(name)); |
101 SkScalar x = (width - textWidth) / SkScalar(2); | 101 SkScalar x = (width - textWidth) / SkScalar(2); |
102 SkScalar y = paint.getFontSpacing() / SkScalar(2); | 102 SkScalar y = paint.getFontSpacing() / SkScalar(2); |
103 canvas->drawText(name, strlen(name), x, y, paint); | 103 canvas->drawText(name, strlen(name), x, y, paint); |
104 | 104 |
105 // Draw destination bitmap | 105 // Draw destination bitmap |
106 canvas->translate(0, vertOffset); | 106 canvas->translate(0, vertOffset); |
107 x = (width - 40) / SkScalar(2); | 107 x = (width - 40) / SkScalar(2); |
108 canvas->drawBitmap(fDst[i], x, 0, &paint); | 108 canvas->drawBitmap(fDst[i], x, 0, &paint); |
109 canvas->restore(); | 109 canvas->restore(); |
110 | 110 |
111 canvas->translate(horizOffset, 0); | 111 canvas->translate(horizOffset, 0); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 virtual uint32_t onGetFlags() const { return kSkipPicture_Flag | 115 virtual uint32_t onGetFlags() const { return kSkipPicture_Flag |
116 | kSkipPipe_Flag; } | 116 | kSkipPipe_Flag; } |
117 | 117 |
118 private: | 118 private: |
119 typedef GM INHERITED; | 119 typedef GM INHERITED; |
120 }; | 120 }; |
121 | 121 |
122 ////////////////////////////////////////////////////////////////////////////// | 122 ////////////////////////////////////////////////////////////////////////////// |
123 | 123 |
124 #ifndef SK_BUILD_FOR_ANDROID | 124 #ifndef SK_BUILD_FOR_ANDROID |
125 static GM* MyFactory(void*) { return new BitmapCopyGM; } | 125 static GM* MyFactory(void*) { return new BitmapCopyGM; } |
126 static GMRegistry reg(MyFactory); | 126 static GMRegistry reg(MyFactory); |
127 #endif | 127 #endif |
128 } | 128 } |
OLD | NEW |