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

Side by Side Diff: gm/stroke_rect_shader.cpp

Issue 2125663003: Add gm that tests shaded stroked rectangles. (Closed) Base URL: https://skia.googlesource.com/skia.git@fixgmwidth
Patch Set: fix windows double->scalar warning Created 4 years, 5 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/SkPaint.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 #include "SkGradientShader.h"
10
11 namespace skiagm {
12
13 // Draw stroked rects (both AA and nonAA) with all the types of joins:
14 // bevel, miter, miter-limited-to-bevel, round
15 // and as a hairline.
16 DEF_SIMPLE_GM(stroke_rect_shader, canvas, 690, 300) {
17 static constexpr SkRect kRect {0, 0, 100, 100};
18 static constexpr SkPoint kPts[] {{kRect.fLeft, kRect.fTop}, {kRect.fRight, k Rect.fBottom}};
19 static constexpr SkColor kColors[] {SK_ColorRED, SK_ColorBLUE};
20 SkPaint paint;
21 sk_sp<SkShader> shader = SkGradientShader::MakeLinear(kPts, kColors, nullptr , 2,
22 SkShader::kClamp_TileM ode);
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 co ords significantly
26 // for the first rect drawn.
27 canvas->translate(kRect.centerX(), kRect.centerY());
28 static constexpr SkScalar kPad = 20;
29 for (auto aa : {false, true}) {
30 paint.setAntiAlias(aa);
31 canvas->save();
32
33 static constexpr SkScalar kStrokeWidth = 10;
34 paint.setStrokeWidth(kStrokeWidth);
35
36 paint.setStrokeJoin(SkPaint::kBevel_Join);
37 canvas->drawRect(kRect, paint);
38 canvas->translate(kRect.width() + kPad, 0);
39
40 paint.setStrokeJoin(SkPaint::kMiter_Join);
41 canvas->drawRect(kRect, paint);
42 canvas->translate(kRect.width() + kPad, 0);
43
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);
48
49 paint.setStrokeJoin(SkPaint::kRound_Join);
50 canvas->drawRect(kRect, paint);
51 canvas->translate(kRect.width() + kPad, 0);
52
53 paint.setStrokeWidth(0);
54 canvas->drawRect(kRect, paint);
55
56 canvas->restore();
57 canvas->translate(0, kRect.height() + kPad);
58 }
59 }
60
61 }
OLDNEW
« no previous file with comments | « no previous file | include/core/SkPaint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698