Flutter Engine
The Flutter Engine
strokerects.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
11#include "include/core/SkRect.h"
13#include "include/core/SkSize.h"
15#include "src/base/SkRandom.h"
16
17namespace skiagm {
18
19#define W 400
20#define H 400
21#define N 100
22
25
26class StrokeRectsGM : public GM {
27public:
28 StrokeRectsGM(bool rotated) : fRotated(rotated) {}
29
30protected:
31 SkString getName() const override {
32 if (fRotated) {
33 return SkString("strokerects_rotated");
34 } else {
35 return SkString("strokerects");
36 }
37 }
38
39 SkISize getISize() override { return SkISize::Make(W * 2, H * 2); }
40
41 static void rnd_rect(SkRect* r, SkRandom& rand) {
42 SkScalar x = rand.nextUScalar1() * W;
43 SkScalar y = rand.nextUScalar1() * H;
44 SkScalar w = rand.nextUScalar1() * (W >> 2);
45 SkScalar h = rand.nextUScalar1() * (H >> 2);
46 SkScalar hoffset = rand.nextSScalar1();
47 SkScalar woffset = rand.nextSScalar1();
48
49 r->setXYWH(x, y, w, h);
50 r->offset(-w/2 + woffset, -h/2 + hoffset);
51 }
52
53 void onDraw(SkCanvas* canvas) override {
54 if (fRotated) {
55 canvas->rotate(45.f, SW, SH);
56 }
57
60
61 for (int y = 0; y < 2; y++) {
62 paint.setAntiAlias(!!y);
63 for (int x = 0; x < 2; x++) {
64 paint.setStrokeWidth(x * SkIntToScalar(3));
65
66 SkAutoCanvasRestore acr(canvas, true);
67 canvas->translate(SW * x, SH * y);
70 , SW - SkIntToScalar(2), SH - SkIntToScalar(2)
71 ));
72
73 SkRandom rand;
74 for (int i = 0; i < N; i++) {
75 SkRect r;
76 rnd_rect(&r, rand);
77 canvas->drawRect(r, paint);
78 }
79 }
80 }
81 }
82
83private:
84 bool fRotated;
85};
86
87//////////////////////////////////////////////////////////////////////////////
88
89DEF_GM( return new StrokeRectsGM(false); )
90DEF_GM( return new StrokeRectsGM(true); )
91
92} // namespace skiagm
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SkScalar nextUScalar1()
Definition: SkRandom.h:101
SkScalar nextSScalar1()
Definition: SkRandom.h:113
Definition: gm.h:110
StrokeRectsGM(bool rotated)
Definition: strokerects.cpp:28
SkString getName() const override
Definition: strokerects.cpp:31
void onDraw(SkCanvas *canvas) override
Definition: strokerects.cpp:53
static void rnd_rect(SkRect *r, SkRandom &rand)
Definition: strokerects.cpp:41
SkISize getISize() override
Definition: strokerects.cpp:39
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
constexpr SkScalar SH
Definition: strokerects.cpp:24
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
constexpr SkScalar SW
Definition: strokerects.cpp:23
SkScalar w
SkScalar h
#define N
Definition: strokerects.cpp:21
#define W
Definition: strokerects.cpp:19
#define H
Definition: strokerects.cpp:20
Definition: SkMD5.cpp:130
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
void setXYWH(float x, float y, float width, float height)
Definition: SkRect.h:931
void offset(float dx, float dy)
Definition: SkRect.h:1016
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646