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