Flutter Engine
The Flutter Engine
bigrect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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"
12#include "include/core/SkRect.h"
14
15// Draws big rects with clip (0, 0, 35, 35). The size of the rects is given by big.
16static void draw_big_rect(SkCanvas* canvas, SkScalar big, const SkPaint& rectPaint) {
17 // Looks like this:
18 // +--+-+----+-+----+
19 // | | | | | |
20 // |--+-+----+-+----+
21 // |--+-+----+-+----+
22 // | | | | | |
23 // | | | +-+ |
24 // +--+-+--+ +--+
25 // +--+-+--+ +--+
26 // | | | +-+ |
27 // | | | | | |
28 // +--+-+----+-+----+
29
30 canvas->clipRect({0, 0, 35, 35});
31
32 // Align to pixel boundaries.
33 canvas->translate(0.5, 0.5);
34
35 SkRect horiz = SkRect::MakeLTRB(-big, 5, big, 10);
36 canvas->drawRect(horiz, rectPaint);
37
38 SkRect vert = SkRect::MakeLTRB(5, -big, 10, big);
39 canvas->drawRect(vert, rectPaint);
40
41 SkRect fromLeft = SkRect::MakeLTRB(-big, 20, 17, 25);
42 canvas->drawRect(fromLeft, rectPaint);
43
44 SkRect fromTop = SkRect::MakeLTRB(20, -big, 25, 17);
45 canvas->drawRect(fromTop, rectPaint);
46
47 SkRect fromRight = SkRect::MakeLTRB(28, 20, big, 25);
48 canvas->drawRect(fromRight, rectPaint);
49
50 SkRect fromBottom = SkRect::MakeLTRB(20, 28, 25, big);
51 canvas->drawRect(fromBottom, rectPaint);
52
53 SkRect leftBorder = SkRect::MakeLTRB(-2, -1, 0, 35);
54 canvas->drawRect(leftBorder, rectPaint);
55
56 SkRect topBorder = SkRect::MakeLTRB(-1, -2, 35, 0);
57 canvas->drawRect(topBorder, rectPaint);
58
59 SkRect rightBorder = SkRect::MakeLTRB(34, -1, 36, 35);
60 canvas->drawRect(rightBorder, rectPaint);
61
62 SkRect bottomBorder = SkRect::MakeLTRB(-1, 34, 35, 36);
63 canvas->drawRect(bottomBorder, rectPaint);
64
65 SkPaint outOfBoundsPaint;
66 outOfBoundsPaint.setColor(SK_ColorRED);
67 outOfBoundsPaint.setStyle(SkPaint::kStroke_Style);
68 outOfBoundsPaint.setStrokeWidth(0);
69
70 SkRect outOfBounds = SkRect::MakeLTRB(-1, -1, 35, 35);
71 canvas->drawRect(outOfBounds, outOfBoundsPaint);
72}
73
74DEF_SIMPLE_GM(bigrect, canvas, 325, 125) {
75 // Test with sizes:
76 // - reasonable size (for comparison),
77 // - outside the range of int32, and
78 // - outside the range of SkFixed.
79 static const SkScalar sizes[] = {SkIntToScalar(100), 5e10f, 1e6f};
80
81 for (int i = 0; i < 8; i++) {
82 for (int j = 0; j < 3; j++) {
83 canvas->save();
84 canvas->translate(SkIntToScalar(i*40+5), SkIntToScalar(j*40+5));
85
87 paint.setColor(SK_ColorBLUE);
88 // These are the three parameters that affect the behavior of SkDraw::drawRect.
89 if (i & 1) {
91 } else {
93 }
94 if (i & 2) {
95 paint.setStrokeWidth(1);
96 } else {
97 paint.setStrokeWidth(0);
98 }
99 if (i & 4) {
100 paint.setAntiAlias(true);
101 } else {
102 paint.setAntiAlias(false);
103 }
104
105 draw_big_rect(canvas, sizes[j], paint);
106 canvas->restore();
107 }
108 }
109}
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static void draw_big_rect(SkCanvas *canvas, SkScalar big, const SkPaint &rectPaint)
Definition: bigrect.cpp:16
DEF_SIMPLE_GM(bigrect, canvas, 325, 125)
Definition: bigrect.cpp:74
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 setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646