halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkImage.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkPaint.h" |
| 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkRefCnt.h" |
| 15 | #include "include/core/SkScalar.h" |
| 16 | #include "include/core/SkString.h" |
| 17 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "tools/Resources.h" |
| 19 | #include "tools/ToolUtils.h" |
halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 20 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 21 | static skiagm::DrawResult draw_rotated_image(SkCanvas* canvas, const SkImage* image, |
| 22 | SkString* errorMsg) { |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 23 | ToolUtils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156), SK_ColorWHITE, 12); |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 24 | if (!image) { |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 25 | *errorMsg = "No image. Did you forget to set the resourcePath?"; |
| 26 | return skiagm::DrawResult::kFail; |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 27 | } |
| 28 | SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f); |
halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 29 | SkPaint paint; |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 30 | paint.setColor(SkColorSetRGB(49, 48, 49)); |
| 31 | SkScalar scale = SkTMin(128.0f / image->width(), |
| 32 | 128.0f / image->height()); |
| 33 | SkScalar point[2] = {-0.5f * image->width(), -0.5f * image->height()}; |
| 34 | for (int j = 0; j < 4; ++j) { |
| 35 | for (int i = 0; i < 4; ++i) { |
| 36 | SkAutoCanvasRestore autoCanvasRestore(canvas, true); |
| 37 | canvas->translate(96.0f + 192.0f * i, 96.0f + 192.0f * j); |
| 38 | canvas->rotate(18.0f * (i + 4 * j)); |
| 39 | canvas->drawRect(rect, paint); |
| 40 | canvas->scale(scale, scale); |
| 41 | canvas->drawImage(image, point[0], point[1]); |
halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 42 | } |
| 43 | } |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 44 | return skiagm::DrawResult::kOk; |
halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 45 | } |
halcanary | a8448bc | 2015-04-17 13:27:24 -0700 | [diff] [blame] | 46 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 47 | DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap, canvas, errorMsg, 576, 576) { |
| 48 | return draw_rotated_image(canvas, GetResourceAsImage("images/randPixels.png").get(), errorMsg); |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 51 | DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap_jpg, canvas, errorMsg, 576, 576) { |
| 52 | return draw_rotated_image(canvas, GetResourceAsImage("images/color_wheel.jpg").get(), errorMsg); |
halcanary | a8448bc | 2015-04-17 13:27:24 -0700 | [diff] [blame] | 53 | } |