2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkGradientShader.h"
13 // Draw stroked rects (both AA and nonAA) with all the types of joins:
14 // bevel, miter, miter-limited-to-bevel, round
16 DEF_SIMPLE_GM(stroke_rect_shader, canvas, 690, 300) {
17 constexpr SkRect kRect {0, 0, 100, 100};
18 constexpr SkPoint kPts[] {{kRect.fLeft, kRect.fTop}, {kRect.fRight, kRect.fBottom}};
19 constexpr SkColor kColors[] {SK_ColorRED, SK_ColorBLUE};
21 sk_sp<SkShader> shader = SkGradientShader::MakeLinear(kPts, kColors, nullptr, 2,
22 SkShader::kClamp_TileMode);
23 paint.setShader(std::move(shader));
24 paint.setStyle(SkPaint::kStroke_Style);
25 // Do a large initial translate so that local coords disagree with device coords significantly
26 // for the first rect drawn.
27 canvas->translate(kRect.centerX(), kRect.centerY());
28 constexpr SkScalar kPad = 20;
29 for (auto aa : {false, true}) {
30 paint.setAntiAlias(aa);
33 constexpr SkScalar kStrokeWidth = 10;
34 paint.setStrokeWidth(kStrokeWidth);
36 paint.setStrokeJoin(SkPaint::kBevel_Join);
37 canvas->drawRect(kRect, paint);
38 canvas->translate(kRect.width() + kPad, 0);
40 paint.setStrokeJoin(SkPaint::kMiter_Join);
41 canvas->drawRect(kRect, paint);
42 canvas->translate(kRect.width() + kPad, 0);
44 // This miter limit should effectively produce a bevel join.
45 paint.setStrokeMiter(0.01f);
46 canvas->drawRect(kRect, paint);
47 canvas->translate(kRect.width() + kPad, 0);
49 paint.setStrokeJoin(SkPaint::kRound_Join);
50 canvas->drawRect(kRect, paint);
51 canvas->translate(kRect.width() + kPad, 0);
53 paint.setStrokeWidth(0);
54 canvas->drawRect(kRect, paint);
57 canvas->translate(0, kRect.height() + kPad);