halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
halcanary | b0cce2c | 2015-01-26 12:49:00 -0800 | [diff] [blame] | 8 | #include "sk_tool_utils.h" |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 9 | #include "Resources.h" |
| 10 | #include "SkData.h" |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 11 | #include "gm.h" |
halcanary | 8b896e7 | 2014-12-02 11:00:40 -0800 | [diff] [blame] | 12 | #include "sk_tool_utils.h" |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 13 | |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 14 | static void draw_bitmap(SkCanvas* canvas, const char* resource, int x, int y) { |
| 15 | SkBitmap bitmap; |
| 16 | if (GetResourceAsBitmap(resource, &bitmap)) { |
| 17 | canvas->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); |
| 18 | } else { |
| 19 | SkDebugf("\nCould not decode file '%s'. Did you forget" |
| 20 | " to set the resourcePath?\n", resource); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | /* |
| 25 | This GM tests whether the image decoders properly decode each color |
| 26 | channel. Four copies of the same image should appear in the GM, and |
| 27 | the letter R should be red, B should be blue, G green, C cyan, M |
| 28 | magenta, Y yellow, and K black. In all but the JPEG version of the |
| 29 | image, the letters should be on a white disc on a transparent |
| 30 | background (rendered as a checkerboard). The JPEG image has a grey |
| 31 | background and compression artifacts. |
| 32 | */ |
| 33 | DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) { |
halcanary | b0cce2c | 2015-01-26 12:49:00 -0800 | [diff] [blame] | 34 | sk_tool_utils::draw_checkerboard(canvas); |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 35 | draw_bitmap(canvas, "color_wheel.png", 0, 0); // top left |
| 36 | draw_bitmap(canvas, "color_wheel.gif", 128, 0); // top right |
| 37 | draw_bitmap(canvas, "color_wheel.webp", 0, 128); // bottom left |
| 38 | draw_bitmap(canvas, "color_wheel.jpg", 128, 128); // bottom right |
| 39 | } |
halcanary | 5abbc42 | 2014-12-02 09:37:17 -0800 | [diff] [blame] | 40 | |
| 41 | DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) { |
| 42 | SkPaint paint; |
halcanary | 8b896e7 | 2014-12-02 11:00:40 -0800 | [diff] [blame] | 43 | sk_tool_utils::set_portable_typeface(&paint, NULL, SkTypeface::kBold); |
halcanary | 5abbc42 | 2014-12-02 09:37:17 -0800 | [diff] [blame] | 44 | paint.setTextSize(18.0f); |
| 45 | |
| 46 | canvas->clear(SK_ColorLTGRAY); |
| 47 | paint.setColor(SK_ColorRED); |
| 48 | canvas->drawText("R", 1, 8.0f, 20.0f, paint); |
| 49 | paint.setColor(SK_ColorGREEN); |
| 50 | canvas->drawText("G", 1, 24.0f, 20.0f, paint); |
| 51 | paint.setColor(SK_ColorBLUE); |
| 52 | canvas->drawText("B", 1, 40.0f, 20.0f, paint); |
| 53 | paint.setColor(SK_ColorCYAN); |
| 54 | canvas->drawText("C", 1, 56.0f, 20.0f, paint); |
| 55 | paint.setColor(SK_ColorMAGENTA); |
| 56 | canvas->drawText("M", 1, 72.0f, 20.0f, paint); |
| 57 | paint.setColor(SK_ColorYELLOW); |
| 58 | canvas->drawText("Y", 1, 88.0f, 20.0f, paint); |
| 59 | paint.setColor(SK_ColorBLACK); |
| 60 | canvas->drawText("K", 1, 104.0f, 20.0f, paint); |
| 61 | } |