Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
#define W
Definition aaa.cpp:17
#define N
Definition beziers.cpp:19
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void translate(SkScalar dx, SkScalar dy)
void rotate(SkScalar degrees)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
SkScalar nextUScalar1()
Definition SkRandom.h:101
SkScalar nextSScalar1()
Definition SkRandom.h:113
StrokeRectsGM(bool rotated)
SkString getName() const override
void onDraw(SkCanvas *canvas) override
static void rnd_rect(SkRect *r, SkRandom &rand)
SkISize getISize() override
const Paint & paint
#define H
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
double y
double x
constexpr SkScalar SH
constexpr SkScalar SW
SkScalar w
SkScalar h
Definition SkMD5.cpp:130
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