• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "Resources.h"
9 #include "SkImage.h"
10 #include "gm.h"
11 #include "sk_tool_utils.h"
12 
draw_rotated_image(SkCanvas * canvas,const SkImage * image,SkString * errorMsg)13 static skiagm::DrawResult draw_rotated_image(SkCanvas* canvas, const SkImage* image,
14                                              SkString* errorMsg) {
15     sk_tool_utils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156),
16                                      SK_ColorWHITE, 12);
17     if (!image) {
18         *errorMsg = "No image. Did you forget to set the resourcePath?";
19         return skiagm::DrawResult::kFail;
20     }
21     SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
22     SkPaint paint;
23     paint.setColor(SkColorSetRGB(49, 48, 49));
24     SkScalar scale = SkTMin(128.0f / image->width(),
25                             128.0f / image->height());
26     SkScalar point[2] = {-0.5f * image->width(), -0.5f * image->height()};
27     for (int j = 0; j < 4; ++j) {
28         for (int i = 0; i < 4; ++i) {
29             SkAutoCanvasRestore autoCanvasRestore(canvas, true);
30             canvas->translate(96.0f + 192.0f * i, 96.0f + 192.0f * j);
31             canvas->rotate(18.0f * (i + 4 * j));
32             canvas->drawRect(rect, paint);
33             canvas->scale(scale, scale);
34             canvas->drawImage(image, point[0], point[1]);
35         }
36     }
37     return skiagm::DrawResult::kOk;
38 }
39 
40 DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap, canvas, errorMsg, 576, 576) {
41     return draw_rotated_image(canvas, GetResourceAsImage("images/randPixels.png").get(), errorMsg);
42 }
43 
44 DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap_jpg, canvas, errorMsg, 576, 576) {
45     return draw_rotated_image(canvas, GetResourceAsImage("images/color_wheel.jpg").get(), errorMsg);
46 }
47