Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / gm / repeated_bitmap.cpp
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 "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkImage.h"
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"
18 #include "tools/Resources.h"
19 #include "tools/ToolUtils.h"
20
21 static skiagm::DrawResult draw_rotated_image(SkCanvas* canvas, const SkImage* image,
22                                              SkString* errorMsg) {
23     ToolUtils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156), SK_ColorWHITE, 12);
24     if (!image) {
25         *errorMsg = "No image. Did you forget to set the resourcePath?";
26         return skiagm::DrawResult::kFail;
27     }
28     SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
29     SkPaint paint;
30     paint.setColor(SkColorSetRGB(49, 48, 49));
31     SkScalar scale = std::min(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]);
42         }
43     }
44     return skiagm::DrawResult::kOk;
45 }
46
47 DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap, canvas, errorMsg, 576, 576) {
48     return draw_rotated_image(canvas, GetResourceAsImage("images/randPixels.png").get(), errorMsg);
49 }
50
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);
53 }