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

Unified 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: cleanup 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/core/SkPaint.h » ('j') | include/core/SkPaint.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/stroke_rect_shader.cpp
diff --git a/gm/stroke_rect_shader.cpp b/gm/stroke_rect_shader.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..99cf38766369642b1a1a68773b97878bed08a5e4
--- /dev/null
+++ b/gm/stroke_rect_shader.cpp
@@ -0,0 +1,60 @@
+/*
robertphillips 2016/07/06 15:01:47 What's up with the naming of this file?
bsalomon 2016/07/06 15:57:53 I don't understand. What is up with it? The unders
+ * 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"
+
robertphillips 2016/07/06 15:01:47 Are we testing the degenerate rect cases somewhere
bsalomon 2016/07/06 15:57:53 The strokedrect GM tests more varieties of rects +
+namespace skiagm {
+
robertphillips 2016/07/06 15:01:47 // Draw stroked rects (both AA and nonAA) with all
bsalomon 2016/07/06 15:57:53 Done.
+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;
robertphillips 2016/07/06 15:01:47 What are your thoughts on the style proposal that
bsalomon 2016/07/06 15:57:53 I don't agree with it, but I'm fine abiding by it.
+ auto 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.
robertphillips 2016/07/06 15:01:47 kRect.centerX(), kRect.centerY() ?
bsalomon 2016/07/06 15:57:53 Done.
+ canvas->translate(kRect.width() / 2, kRect.height() / 2);
+ 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.01);
+ canvas->drawRect(kRect, paint);
+ canvas->translate(kRect.width() + kPad, 0);
+
robertphillips 2016/07/06 15:01:47 Wrong comment ?
bsalomon 2016/07/06 15:57:53 Done.
+ // This miter limit should effectively produce a bevel join.
+ paint.setStrokeJoin(SkPaint::kRound_Join);
+ canvas->drawRect(kRect, paint);
+ canvas->translate(kRect.width() + kPad, 0);
+
robertphillips 2016/07/06 15:01:47 // Hairlines, make bevel and round joins appear th
bsalomon 2016/07/06 15:57:53 If we are going to test that I think it'd be bette
+ paint.setStrokeWidth(0);
+ canvas->drawRect(kRect, paint);
robertphillips 2016/07/06 15:01:47 Rm this translate ?
bsalomon 2016/07/06 15:57:53 Done.
+ canvas->translate(kRect.width() + kPad, 0);
+
+ canvas->restore();
+ canvas->translate(0, kRect.height() + kPad);
+ }
+}
+
+}
« no previous file with comments | « no previous file | include/core/SkPaint.h » ('j') | include/core/SkPaint.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698