Flutter Engine
The Flutter Engine
repeated_bitmap.cpp
Go to the documentation of this file.
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"
13#include "include/core/SkRect.h"
18#include "tools/DecodeUtils.h"
19#include "tools/Resources.h"
20#include "tools/ToolUtils.h"
21
23 SkString* errorMsg) {
24 ToolUtils::draw_checkerboard(canvas, SkColorSetRGB(156, 154, 156), SK_ColorWHITE, 12);
25 if (!image) {
26 *errorMsg = "No image. Did you forget to set the resourcePath?";
28 }
29 SkRect rect = SkRect::MakeLTRB(-68.0f, -68.0f, 68.0f, 68.0f);
31 paint.setColor(SkColorSetRGB(49, 48, 49));
32 SkScalar scale = std::min(128.0f / image->width(),
33 128.0f / image->height());
34 SkScalar point[2] = {-0.5f * image->width(), -0.5f * image->height()};
35 for (int j = 0; j < 4; ++j) {
36 for (int i = 0; i < 4; ++i) {
37 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
38 canvas->translate(96.0f + 192.0f * i, 96.0f + 192.0f * j);
39 canvas->rotate(18.0f * (i + 4 * j));
40 canvas->drawRect(rect, paint);
41 canvas->scale(scale, scale);
42 canvas->drawImage(image, point[0], point[1]);
43 }
44 }
46}
47
48DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap, canvas, errorMsg, 576, 576) {
49 return draw_rotated_image(
50 canvas, ToolUtils::GetResourceAsImage("images/randPixels.png").get(), errorMsg);
51}
52
53DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap_jpg, canvas, errorMsg, 576, 576) {
54 return draw_rotated_image(
55 canvas, ToolUtils::GetResourceAsImage("images/color_wheel.jpg").get(), errorMsg);
56}
#define SkColorSetRGB(r, g, b)
Definition: SkColor.h:57
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
static float min(float r, float g, float b)
Definition: hsl.cpp:48
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
void draw_checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: ToolUtils.cpp:174
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
const myers::Point & get(const myers::Segment &)
DrawResult
Definition: gm.h:104
DEF_SIMPLE_GM_CAN_FAIL(repeated_bitmap, canvas, errorMsg, 576, 576)
static skiagm::DrawResult draw_rotated_image(SkCanvas *canvas, const SkImage *image, SkString *errorMsg)
const Scalar scale
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646