blob: 09f30fb7c9f28e33ab39d66039008588cb1362d2 [file] [log] [blame]
halcanary1b5c6042015-02-18 11:29:56 -08001/*
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
halcanary7a14b312015-10-01 07:28:13 -07008#include "Resources.h"
9#include "SkImage.h"
halcanary1b5c6042015-02-18 11:29:56 -080010#include "gm.h"
11#include "sk_tool_utils.h"
halcanary1b5c6042015-02-18 11:29:56 -080012
halcanary7a14b312015-10-01 07:28:13 -070013static void draw_rotated_image(SkCanvas* canvas, const SkImage* image) {
14 sk_tool_utils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156),
robertphillips943a4622015-09-03 13:32:33 -070015 SK_ColorWHITE, 12);
halcanary7a14b312015-10-01 07:28:13 -070016 if (!image) {
17 return;
18 }
19 SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
halcanary1b5c6042015-02-18 11:29:56 -080020 SkPaint paint;
halcanary7a14b312015-10-01 07:28:13 -070021 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]);
halcanary1b5c6042015-02-18 11:29:56 -080033 }
34 }
35}
halcanarya8448bc2015-04-17 13:27:24 -070036
halcanary7a14b312015-10-01 07:28:13 -070037DEF_SIMPLE_GM(repeated_bitmap, canvas, 576, 576) {
Hal Canaryc465d132017-12-08 10:21:31 -050038 draw_rotated_image(canvas, GetResourceAsImage("images/randPixels.png").get());
halcanary7a14b312015-10-01 07:28:13 -070039}
40
halcanarya8448bc2015-04-17 13:27:24 -070041DEF_SIMPLE_GM(repeated_bitmap_jpg, canvas, 576, 576) {
Hal Canaryc465d132017-12-08 10:21:31 -050042 draw_rotated_image(canvas, GetResourceAsImage("images/color_wheel.jpg").get());
halcanarya8448bc2015-04-17 13:27:24 -070043}