blob: 2123130c7f5df7396d63781b671facb6afecfdc8 [file] [log] [blame]
Robert Phillipsd5caeb82020-01-08 16:27:59 -05001/*
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
12static 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 */
33class StrokeRectAnisotropicGM : public skiagm::GM {
34public:
35 StrokeRectAnisotropicGM() {}
36
37protected:
38
39 SkString onShortName() override {
40 return SkString("strokerect_anisotropic");
41 }
42
43 SkISize onISize() override {
44 return SkISize::Make(160, 160);
45 }
46
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
78private:
John Stiles7571f9e2020-09-02 22:42:33 -040079 using INHERITED = GM;
Robert Phillipsd5caeb82020-01-08 16:27:59 -050080};
81DEF_GM(return new StrokeRectAnisotropicGM;)
82