1 /*
2 * Copyright 2020 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"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPath.h"
11
draw_sqooshed_rect(SkCanvas * canvas,SkVector xlate,const SkPaint & p)12 static void draw_sqooshed_rect(SkCanvas* canvas, SkVector xlate, const SkPaint& p) {
13 canvas->save();
14 canvas->translate(xlate.fX, xlate.fY);
15 canvas->scale(0.03f, 2.0f);
16 canvas->drawRect(SkRect::MakeLTRB(-500, -10, 500, 10), p);
17 canvas->restore();
18 }
19
20 /*
21 * This GM is intended to wring out any lingering anisotropic
22 * stroke rect bugs. It contains a repro case for crbug.com/935303
23 * The pattern is:
24 *
25 * miter @ miter @ bevel @ bevel @
26 * whole pixels half pixels whole pixels half pixels
27 *
28 * AA
29 *
30 * non-AA
31 *
32 */
33 class StrokeRectAnisotropicGM : public skiagm::GM {
34 public:
StrokeRectAnisotropicGM()35 StrokeRectAnisotropicGM() {}
36
37 protected:
38
onShortName()39 SkString onShortName() override {
40 return SkString("strokerect_anisotropic");
41 }
42
onISize()43 SkISize onISize() override {
44 return SkISize::Make(160, 160);
45 }
46
onDraw(SkCanvas * canvas)47 void onDraw(SkCanvas* canvas) override {
48
49 SkPaint aaPaint;
50 aaPaint.setColor(SkColorSetARGB(255, 0, 0, 0));
51 aaPaint.setAntiAlias(true);
52 aaPaint.setStrokeWidth(10);
53 aaPaint.setStyle(SkPaint::kStroke_Style);
54
55 SkPaint bwPaint;
56 bwPaint.setColor(SkColorSetARGB(255, 0, 0, 0));
57 bwPaint.setStrokeWidth(10);
58 bwPaint.setStyle(SkPaint::kStroke_Style);
59
60 // The two miter columns
61 draw_sqooshed_rect(canvas, { 20.0f, 40.5f }, aaPaint); // whole pixels
62 draw_sqooshed_rect(canvas, { 20.0f, 110.5f }, bwPaint); // whole pixels
63
64 draw_sqooshed_rect(canvas, { 60.5f, 40.0f }, aaPaint); // half pixels
65 draw_sqooshed_rect(canvas, { 60.5f, 110.0f }, bwPaint); // half pixels
66
67 aaPaint.setStrokeJoin(SkPaint::kBevel_Join);
68 bwPaint.setStrokeJoin(SkPaint::kBevel_Join);
69
70 // The two bevel columns
71 draw_sqooshed_rect(canvas, { 100.0f, 40.5f }, aaPaint); // whole pixels
72 draw_sqooshed_rect(canvas, { 100.0f, 110.5f }, bwPaint); // whole pixels
73
74 draw_sqooshed_rect(canvas, { 140.5f, 40.0f }, aaPaint); // half pixels
75 draw_sqooshed_rect(canvas, { 140.5f, 110.0f }, bwPaint); // half pixels
76 }
77
78 private:
79 using INHERITED = GM;
80 };
81 DEF_GM(return new StrokeRectAnisotropicGM;)
82
83