Flutter Engine
The Flutter Engine
stroke_rect_shader.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"
13#include "include/core/SkRect.h"
19
20#include <initializer_list>
21#include <utility>
22
23namespace skiagm {
24
25// Draw stroked rects (both AA and nonAA) with all the types of joins:
26// bevel, miter, miter-limited-to-bevel, round
27// and as a hairline.
28DEF_SIMPLE_GM(stroke_rect_shader, canvas, 690, 300) {
29 constexpr SkRect kRect {0, 0, 100, 100};
30 constexpr SkPoint kPts[] {{kRect.fLeft, kRect.fTop}, {kRect.fRight, kRect.fBottom}};
34
35 // Do a large initial translate so that local coords disagree with device coords significantly
36 // for the first rect drawn.
37 canvas->translate(kRect.centerX(), kRect.centerY());
38 constexpr SkScalar kPad = 20;
39 for (auto aa : {false, true}) {
41 paint.setShader(shader);
43 paint.setAntiAlias(aa);
44
45 canvas->save();
46
47 constexpr SkScalar kStrokeWidth = 10;
48 paint.setStrokeWidth(kStrokeWidth);
49
50 paint.setStrokeJoin(SkPaint::kBevel_Join);
51 canvas->drawRect(kRect, paint);
52 canvas->translate(kRect.width() + kPad, 0);
53
54 paint.setStrokeJoin(SkPaint::kMiter_Join);
55 canvas->drawRect(kRect, paint);
56 canvas->translate(kRect.width() + kPad, 0);
57
58 // This miter limit should effectively produce a bevel join.
59 paint.setStrokeMiter(0.01f);
60 canvas->drawRect(kRect, paint);
61 canvas->translate(kRect.width() + kPad, 0);
62
63 paint.setStrokeJoin(SkPaint::kRound_Join);
64 canvas->drawRect(kRect, paint);
65 canvas->translate(kRect.width() + kPad, 0);
66
67 paint.setStrokeWidth(0);
68 canvas->drawRect(kRect, paint);
69
70 canvas->restore();
71 canvas->translate(0, kRect.height() + kPad);
72 }
73}
74
75} // namespace skiagm
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr int kPad
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kRound_Join
adds circle
Definition: SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
const DlColor kColors[]
static constexpr SkPoint kPts[kPtsCount]
Definition: emptypath.cpp:123
DEF_SIMPLE_GM(hugebitmapshader, canvas, 100, 100)
static constexpr float kStrokeWidth