blob: cc9c4dd9fc50860bb239bee72cb55de58a772551 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkImage.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040012#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 Kleinc0bd9f92019-04-23 12:05:21 -050018#include "tools/Resources.h"
19#include "tools/ToolUtils.h"
halcanary1b5c6042015-02-18 11:29:56 -080020
Chris Dalton50e24d72019-02-07 16:20:09 -070021static skiagm::DrawResult draw_rotated_image(SkCanvas* canvas, const SkImage* image,
22 SkString* errorMsg) {
Mike Kleinea3f0142019-03-20 11:12:10 -050023 ToolUtils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156), SK_ColorWHITE, 12);
halcanary7a14b312015-10-01 07:28:13 -070024 if (!image) {
Chris Dalton50e24d72019-02-07 16:20:09 -070025 *errorMsg = "No image. Did you forget to set the resourcePath?";
26 return skiagm::DrawResult::kFail;
halcanary7a14b312015-10-01 07:28:13 -070027 }
28 SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
halcanary1b5c6042015-02-18 11:29:56 -080029 SkPaint paint;
halcanary7a14b312015-10-01 07:28:13 -070030 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]);
halcanary1b5c6042015-02-18 11:29:56 -080042 }
43 }
Chris Dalton50e24d72019-02-07 16:20:09 -070044 return skiagm::DrawResult::kOk;
halcanary1b5c6042015-02-18 11:29:56 -080045}
halcanarya8448bc2015-04-17 13:27:24 -070046
Chris Dalton50e24d72019-02-07 16:20:09 -070047DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap, canvas, errorMsg, 576, 576) {
48 return draw_rotated_image(canvas, GetResourceAsImage("images/randPixels.png").get(), errorMsg);
halcanary7a14b312015-10-01 07:28:13 -070049}
50
Chris Dalton50e24d72019-02-07 16:20:09 -070051DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap_jpg, canvas, errorMsg, 576, 576) {
52 return draw_rotated_image(canvas, GetResourceAsImage("images/color_wheel.jpg").get(), errorMsg);
halcanarya8448bc2015-04-17 13:27:24 -070053}