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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkFont.h" |
| 12 | #include "include/core/SkFontStyle.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/core/SkImage.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 14 | #include "include/core/SkPaint.h" |
| 15 | #include "include/core/SkRefCnt.h" |
| 16 | #include "include/core/SkScalar.h" |
| 17 | #include "include/core/SkTypeface.h" |
| 18 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "tools/Resources.h" |
| 20 | #include "tools/ToolUtils.h" |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 21 | |
halcanary | 2f0a728 | 2015-08-21 07:47:23 -0700 | [diff] [blame] | 22 | static void draw_image(SkCanvas* canvas, const char* resource, int x, int y) { |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 23 | sk_sp<SkImage> image(GetResourceAsImage(resource)); |
halcanary | 2f0a728 | 2015-08-21 07:47:23 -0700 | [diff] [blame] | 24 | if (image) { |
| 25 | canvas->drawImage(image, SkIntToScalar(x), SkIntToScalar(y)); |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 26 | } else { |
| 27 | SkDebugf("\nCould not decode file '%s'. Did you forget" |
| 28 | " to set the resourcePath?\n", resource); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | This GM tests whether the image decoders properly decode each color |
| 34 | channel. Four copies of the same image should appear in the GM, and |
| 35 | the letter R should be red, B should be blue, G green, C cyan, M |
| 36 | magenta, Y yellow, and K black. In all but the JPEG version of the |
| 37 | image, the letters should be on a white disc on a transparent |
| 38 | background (rendered as a checkerboard). The JPEG image has a grey |
| 39 | background and compression artifacts. |
| 40 | */ |
| 41 | DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) { |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 42 | ToolUtils::draw_checkerboard(canvas); |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 43 | draw_image(canvas, "images/color_wheel.png", 0, 0); // top left |
| 44 | draw_image(canvas, "images/color_wheel.gif", 128, 0); // top right |
| 45 | draw_image(canvas, "images/color_wheel.webp", 0, 128); // bottom left |
| 46 | draw_image(canvas, "images/color_wheel.jpg", 128, 128); // bottom right |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 47 | } |
halcanary | 5abbc42 | 2014-12-02 09:37:17 -0800 | [diff] [blame] | 48 | |
| 49 | DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) { |
Hal Canary | 0a7b393 | 2019-05-02 11:31:28 -0400 | [diff] [blame] | 50 | SkFont font(ToolUtils::create_portable_typeface("sans-serif", SkFontStyle::Bold()), 18); |
Mike Reed | 4de2f1f | 2019-01-05 16:35:13 -0500 | [diff] [blame] | 51 | font.setEdging(SkFont::Edging::kAlias); |
halcanary | 5abbc42 | 2014-12-02 09:37:17 -0800 | [diff] [blame] | 52 | |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 53 | canvas->clear(SK_ColorLTGRAY); |
Hal Canary | 0a7b393 | 2019-05-02 11:31:28 -0400 | [diff] [blame] | 54 | canvas->drawString("R", 8.0f, 20.0f, font, SkPaint(SkColors::kRed)); |
| 55 | canvas->drawString("G", 24.0f, 20.0f, font, SkPaint(SkColors::kGreen)); |
| 56 | canvas->drawString("B", 40.0f, 20.0f, font, SkPaint(SkColors::kBlue)); |
| 57 | canvas->drawString("C", 56.0f, 20.0f, font, SkPaint(SkColors::kCyan)); |
| 58 | canvas->drawString("M", 72.0f, 20.0f, font, SkPaint(SkColors::kMagenta)); |
| 59 | canvas->drawString("Y", 88.0f, 20.0f, font, SkPaint(SkColors::kYellow)); |
| 60 | canvas->drawString("K", 104.0f, 20.0f, font, SkPaint(SkColors::kBlack)); |
halcanary | 5abbc42 | 2014-12-02 09:37:17 -0800 | [diff] [blame] | 61 | } |