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 "Checkerboard.h" |
8 #include "Resources.h" | 9 #include "Resources.h" |
9 #include "SkData.h" | 10 #include "SkData.h" |
10 #include "gm.h" | 11 #include "gm.h" |
11 #include "sk_tool_utils.h" | 12 #include "sk_tool_utils.h" |
12 | 13 |
13 static void checkerboard( | |
14 SkCanvas* canvas, int w, int h, int size, SkColor c1, SkColor c2) { | |
15 SkAutoCanvasRestore autoCanvasRestore(canvas, true); | |
16 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h))); | |
17 canvas->drawColor(c1); | |
18 SkPaint paint; | |
19 paint.setColor(c2); | |
20 SkScalar s = SkIntToScalar(size); | |
21 for (int y = 0; y < h; y += size) { | |
22 SkScalar ty = SkIntToScalar(y); | |
23 bool oddRow = (y % (2 * size)) != 0; | |
24 for (int x = oddRow ? size : 0; x < w; x += (2 * size)) { | |
25 SkScalar tx = SkIntToScalar(x); | |
26 canvas->drawRect(SkRect::MakeXYWH(tx, ty, s, s), paint); | |
27 } | |
28 } | |
29 } | |
30 | |
31 static void draw_bitmap(SkCanvas* canvas, const char* resource, int x, int y) { | 14 static void draw_bitmap(SkCanvas* canvas, const char* resource, int x, int y) { |
32 SkBitmap bitmap; | 15 SkBitmap bitmap; |
33 if (GetResourceAsBitmap(resource, &bitmap)) { | 16 if (GetResourceAsBitmap(resource, &bitmap)) { |
34 canvas->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); | 17 canvas->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); |
35 } else { | 18 } else { |
36 SkDebugf("\nCould not decode file '%s'. Did you forget" | 19 SkDebugf("\nCould not decode file '%s'. Did you forget" |
37 " to set the resourcePath?\n", resource); | 20 " to set the resourcePath?\n", resource); |
38 } | 21 } |
39 } | 22 } |
40 | 23 |
41 /* | 24 /* |
42 This GM tests whether the image decoders properly decode each color | 25 This GM tests whether the image decoders properly decode each color |
43 channel. Four copies of the same image should appear in the GM, and | 26 channel. Four copies of the same image should appear in the GM, and |
44 the letter R should be red, B should be blue, G green, C cyan, M | 27 the letter R should be red, B should be blue, G green, C cyan, M |
45 magenta, Y yellow, and K black. In all but the JPEG version of the | 28 magenta, Y yellow, and K black. In all but the JPEG version of the |
46 image, the letters should be on a white disc on a transparent | 29 image, the letters should be on a white disc on a transparent |
47 background (rendered as a checkerboard). The JPEG image has a grey | 30 background (rendered as a checkerboard). The JPEG image has a grey |
48 background and compression artifacts. | 31 background and compression artifacts. |
49 */ | 32 */ |
50 DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) { | 33 DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) { |
51 canvas->clear(SK_ColorWHITE); | 34 sk_tools::DrawCheckerboard(canvas); |
52 checkerboard(canvas, 256, 556, 8, 0xFF999999, 0xFF666666); | |
53 draw_bitmap(canvas, "color_wheel.png", 0, 0); // top left | 35 draw_bitmap(canvas, "color_wheel.png", 0, 0); // top left |
54 draw_bitmap(canvas, "color_wheel.gif", 128, 0); // top right | 36 draw_bitmap(canvas, "color_wheel.gif", 128, 0); // top right |
55 draw_bitmap(canvas, "color_wheel.webp", 0, 128); // bottom left | 37 draw_bitmap(canvas, "color_wheel.webp", 0, 128); // bottom left |
56 draw_bitmap(canvas, "color_wheel.jpg", 128, 128); // bottom right | 38 draw_bitmap(canvas, "color_wheel.jpg", 128, 128); // bottom right |
57 } | 39 } |
58 | 40 |
59 DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) { | 41 DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) { |
60 SkPaint paint; | 42 SkPaint paint; |
61 sk_tool_utils::set_portable_typeface(&paint, NULL, SkTypeface::kBold); | 43 sk_tool_utils::set_portable_typeface(&paint, NULL, SkTypeface::kBold); |
62 paint.setTextSize(18.0f); | 44 paint.setTextSize(18.0f); |
63 | 45 |
64 canvas->clear(SK_ColorLTGRAY); | 46 canvas->clear(SK_ColorLTGRAY); |
65 paint.setColor(SK_ColorRED); | 47 paint.setColor(SK_ColorRED); |
66 canvas->drawText("R", 1, 8.0f, 20.0f, paint); | 48 canvas->drawText("R", 1, 8.0f, 20.0f, paint); |
67 paint.setColor(SK_ColorGREEN); | 49 paint.setColor(SK_ColorGREEN); |
68 canvas->drawText("G", 1, 24.0f, 20.0f, paint); | 50 canvas->drawText("G", 1, 24.0f, 20.0f, paint); |
69 paint.setColor(SK_ColorBLUE); | 51 paint.setColor(SK_ColorBLUE); |
70 canvas->drawText("B", 1, 40.0f, 20.0f, paint); | 52 canvas->drawText("B", 1, 40.0f, 20.0f, paint); |
71 paint.setColor(SK_ColorCYAN); | 53 paint.setColor(SK_ColorCYAN); |
72 canvas->drawText("C", 1, 56.0f, 20.0f, paint); | 54 canvas->drawText("C", 1, 56.0f, 20.0f, paint); |
73 paint.setColor(SK_ColorMAGENTA); | 55 paint.setColor(SK_ColorMAGENTA); |
74 canvas->drawText("M", 1, 72.0f, 20.0f, paint); | 56 canvas->drawText("M", 1, 72.0f, 20.0f, paint); |
75 paint.setColor(SK_ColorYELLOW); | 57 paint.setColor(SK_ColorYELLOW); |
76 canvas->drawText("Y", 1, 88.0f, 20.0f, paint); | 58 canvas->drawText("Y", 1, 88.0f, 20.0f, paint); |
77 paint.setColor(SK_ColorBLACK); | 59 paint.setColor(SK_ColorBLACK); |
78 canvas->drawText("K", 1, 104.0f, 20.0f, paint); | 60 canvas->drawText("K", 1, 104.0f, 20.0f, paint); |
79 } | 61 } |
OLD | NEW |