Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: gm/bigrect.cpp

Issue 1893433002: In SkDraw::drawRect, use SkPath for huge rects. Base URL: https://skia.googlesource.com/skia@fixed-assert
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/core/SkRect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.h"
9
10 // Draws big rects with clip (0, 0, 35, 35). The size of the rects is given by b ig.
11 void DrawBigRect(SkCanvas* canvas, SkScalar big, const SkPaint& rectPaint) {
12 // Looks like this:
13 // +-+-+--+-+------+
14 // | | | | | +---+
15 // | +-+ | | +---+
16 // | | | |
17 // +------+-+------+
18 // +------+-+------+
19 // | | | |
20 // +---+ | | +-+ |
21 // +---+ | | | | |
22 // +------+-+--+-+-+
23
24 canvas->clipRect({0, 0, 35, 35});
25
26 // Align to pixel boundaries.
27 canvas->translate(0.5, 0.5);
28
29 SkRect tl = SkRect::MakeLTRB(5, -big, 10, 10);
30 canvas->drawRect(tl, rectPaint);
31
32 SkRect tr = SkRect::MakeLTRB(25, 5, big, 10);
33 canvas->drawRect(tr, rectPaint);
34
35 SkRect br = SkRect::MakeLTRB(25, 25, 30, big);
36 canvas->drawRect(br, rectPaint);
37
38 SkRect bl = SkRect::MakeLTRB(-big, 25, 10, 30);
39 canvas->drawRect(bl, rectPaint);
40
41 SkRect horiz = SkRect::MakeLTRB(-big, 15, big, 20);
42 canvas->drawRect(horiz, rectPaint);
43
44 SkRect vert = SkRect::MakeLTRB(15, -big, 20, big);
45 canvas->drawRect(vert, rectPaint);
46
47 SkRect leftBorder = SkRect::MakeLTRB(-2, -1, 0, 35);
48 canvas->drawRect(leftBorder, rectPaint);
49
50 SkRect topBorder = SkRect::MakeLTRB(-1, -2, 35, 0);
51 canvas->drawRect(topBorder, rectPaint);
52
53 SkRect rightBorder = SkRect::MakeLTRB(34, -1, 36, 35);
54 canvas->drawRect(rightBorder, rectPaint);
55
56 SkRect bottomBorder = SkRect::MakeLTRB(-1, 34, 35, 36);
57 canvas->drawRect(bottomBorder, rectPaint);
58
59 SkPaint outOfBoundsPaint;
60 outOfBoundsPaint.setColor(SK_ColorRED);
61 outOfBoundsPaint.setStyle(SkPaint::kStroke_Style);
62 outOfBoundsPaint.setStrokeWidth(0);
63
64 SkRect outOfBounds = SkRect::MakeLTRB(-1, -1, 35, 35);
65 canvas->drawRect(outOfBounds, outOfBoundsPaint);
66 }
67
68 DEF_SIMPLE_GM(bigrect, canvas, 325, 125) {
69 // Test with sizes:
70 // - reasonable size (for comparison),
71 // - outside the range of int32, and
72 // - outside the range of SkFixed.
73 static const SkScalar sizes[] = {SkIntToScalar(100), 5e10f, 1e6f};
74
75 for (int i = 0; i < 8; i++) {
76 for (int j = 0; j < 3; j++) {
77 canvas->save();
78 canvas->translate(SkIntToScalar(i*40+5), SkIntToScalar(j*40+5));
79
80 SkPaint paint;
81 paint.setColor(SK_ColorBLUE);
82 // These are the three parameters that affect the behavior of SkDraw ::drawRect.
83 if (i & 1) {
84 paint.setStyle(SkPaint::kFill_Style);
85 } else {
86 paint.setStyle(SkPaint::kStroke_Style);
87 }
88 if (i & 2) {
89 paint.setStrokeWidth(1);
90 } else {
91 paint.setStrokeWidth(0);
92 }
93 if (i & 4) {
94 paint.setAntiAlias(true);
95 } else {
96 paint.setAntiAlias(false);
97 }
98
99 const SkScalar big = SkFloatToScalar(sizes[j]);
100 DrawBigRect(canvas, big, paint);
101 canvas->restore();
102 }
103 }
104 }
OLDNEW
« no previous file with comments | « no previous file | include/core/SkRect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698