aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/stroke_rect_shader.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-07-06 11:54:59 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-06 11:54:59 -0700
commita7d85ba138ee09739defbd277b04c479fdef82a6 (patch)
treeae5af2c5d489a22c9bb4331238cdd9fa6164ccd0 /gm/stroke_rect_shader.cpp
parent52fa668dc589501f5e48a7c5b1958882b86ff496 (diff)
Add gm that tests shaded stroked rectangles.
Fix GPU handling of previously untested cases. Move rect->path fallback from SkGpuDevice to GrDrawContext. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2125663003 Review-Url: https://codereview.chromium.org/2125663003
Diffstat (limited to 'gm/stroke_rect_shader.cpp')
-rw-r--r--gm/stroke_rect_shader.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/gm/stroke_rect_shader.cpp b/gm/stroke_rect_shader.cpp
new file mode 100644
index 0000000000..0eb09e9a6f
--- /dev/null
+++ b/gm/stroke_rect_shader.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkGradientShader.h"
+
+namespace skiagm {
+
+// Draw stroked rects (both AA and nonAA) with all the types of joins:
+// bevel, miter, miter-limited-to-bevel, round
+// and as a hairline.
+DEF_SIMPLE_GM(stroke_rect_shader, canvas, 690, 300) {
+ static constexpr SkRect kRect {0, 0, 100, 100};
+ static constexpr SkPoint kPts[] {{kRect.fLeft, kRect.fTop}, {kRect.fRight, kRect.fBottom}};
+ static constexpr SkColor kColors[] {SK_ColorRED, SK_ColorBLUE};
+ SkPaint paint;
+ sk_sp<SkShader> shader = SkGradientShader::MakeLinear(kPts, kColors, nullptr, 2,
+ SkShader::kClamp_TileMode);
+ paint.setShader(std::move(shader));
+ paint.setStyle(SkPaint::kStroke_Style);
+ // Do a large initial translate so that local coords disagree with device coords significantly
+ // for the first rect drawn.
+ canvas->translate(kRect.centerX(), kRect.centerY());
+ static constexpr SkScalar kPad = 20;
+ for (auto aa : {false, true}) {
+ paint.setAntiAlias(aa);
+ canvas->save();
+
+ static constexpr SkScalar kStrokeWidth = 10;
+ paint.setStrokeWidth(kStrokeWidth);
+
+ paint.setStrokeJoin(SkPaint::kBevel_Join);
+ canvas->drawRect(kRect, paint);
+ canvas->translate(kRect.width() + kPad, 0);
+
+ paint.setStrokeJoin(SkPaint::kMiter_Join);
+ canvas->drawRect(kRect, paint);
+ canvas->translate(kRect.width() + kPad, 0);
+
+ // This miter limit should effectively produce a bevel join.
+ paint.setStrokeMiter(0.01f);
+ canvas->drawRect(kRect, paint);
+ canvas->translate(kRect.width() + kPad, 0);
+
+ paint.setStrokeJoin(SkPaint::kRound_Join);
+ canvas->drawRect(kRect, paint);
+ canvas->translate(kRect.width() + kPad, 0);
+
+ paint.setStrokeWidth(0);
+ canvas->drawRect(kRect, paint);
+
+ canvas->restore();
+ canvas->translate(0, kRect.height() + kPad);
+ }
+}
+
+}