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 | |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 8 | #include "Resources.h" |
| 9 | #include "SkImage.h" |
halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 10 | #include "gm.h" |
| 11 | #include "sk_tool_utils.h" |
halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 12 | |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 13 | static void draw_rotated_image(SkCanvas* canvas, const SkImage* image) { |
| 14 | sk_tool_utils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156), |
robertphillips | 943a462 | 2015-09-03 13:32:33 -0700 | [diff] [blame] | 15 | SK_ColorWHITE, 12); |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 16 | if (!image) { |
| 17 | return; |
| 18 | } |
| 19 | SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f); |
halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 20 | SkPaint paint; |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 21 | paint.setColor(SkColorSetRGB(49, 48, 49)); |
| 22 | SkScalar scale = SkTMin(128.0f / image->width(), |
| 23 | 128.0f / image->height()); |
| 24 | SkScalar point[2] = {-0.5f * image->width(), -0.5f * image->height()}; |
| 25 | for (int j = 0; j < 4; ++j) { |
| 26 | for (int i = 0; i < 4; ++i) { |
| 27 | SkAutoCanvasRestore autoCanvasRestore(canvas, true); |
| 28 | canvas->translate(96.0f + 192.0f * i, 96.0f + 192.0f * j); |
| 29 | canvas->rotate(18.0f * (i + 4 * j)); |
| 30 | canvas->drawRect(rect, paint); |
| 31 | canvas->scale(scale, scale); |
| 32 | canvas->drawImage(image, point[0], point[1]); |
halcanary | 1b5c604 | 2015-02-18 11:29:56 -0800 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | } |
halcanary | a8448bc | 2015-04-17 13:27:24 -0700 | [diff] [blame] | 36 | |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 37 | DEF_SIMPLE_GM(repeated_bitmap, canvas, 576, 576) { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 38 | draw_rotated_image(canvas, GetResourceAsImage("images/randPixels.png").get()); |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 39 | } |
| 40 | |
halcanary | a8448bc | 2015-04-17 13:27:24 -0700 | [diff] [blame] | 41 | DEF_SIMPLE_GM(repeated_bitmap_jpg, canvas, 576, 576) { |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 42 | draw_rotated_image(canvas, GetResourceAsImage("images/color_wheel.jpg").get()); |
halcanary | a8448bc | 2015-04-17 13:27:24 -0700 | [diff] [blame] | 43 | } |