blob: df6f4970d8bf9a90ff04c39fd203b74341504d1d [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:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000038 SkString getName() const override { return SkString("strokerect_anisotropic"); }
Robert Phillipsd5caeb82020-01-08 16:27:59 -050039
Leandro Lovisolo8f023882023-08-15 21:13:52 +000040 SkISize getISize() override { return SkISize::Make(160, 160); }
Robert Phillipsd5caeb82020-01-08 16:27:59 -050041
42 void onDraw(SkCanvas* canvas) override {
43
44 SkPaint aaPaint;
45 aaPaint.setColor(SkColorSetARGB(255, 0, 0, 0));
46 aaPaint.setAntiAlias(true);
47 aaPaint.setStrokeWidth(10);
48 aaPaint.setStyle(SkPaint::kStroke_Style);
49
50 SkPaint bwPaint;
51 bwPaint.setColor(SkColorSetARGB(255, 0, 0, 0));
52 bwPaint.setStrokeWidth(10);
53 bwPaint.setStyle(SkPaint::kStroke_Style);
54
55 // The two miter columns
56 draw_sqooshed_rect(canvas, { 20.0f, 40.5f }, aaPaint); // whole pixels
57 draw_sqooshed_rect(canvas, { 20.0f, 110.5f }, bwPaint); // whole pixels
58
59 draw_sqooshed_rect(canvas, { 60.5f, 40.0f }, aaPaint); // half pixels
60 draw_sqooshed_rect(canvas, { 60.5f, 110.0f }, bwPaint); // half pixels
61
62 aaPaint.setStrokeJoin(SkPaint::kBevel_Join);
63 bwPaint.setStrokeJoin(SkPaint::kBevel_Join);
64
65 // The two bevel columns
66 draw_sqooshed_rect(canvas, { 100.0f, 40.5f }, aaPaint); // whole pixels
67 draw_sqooshed_rect(canvas, { 100.0f, 110.5f }, bwPaint); // whole pixels
68
69 draw_sqooshed_rect(canvas, { 140.5f, 40.0f }, aaPaint); // half pixels
70 draw_sqooshed_rect(canvas, { 140.5f, 110.0f }, bwPaint); // half pixels
71 }
72
73private:
John Stiles7571f9e2020-09-02 22:42:33 -040074 using INHERITED = GM;
Robert Phillipsd5caeb82020-01-08 16:27:59 -050075};
76DEF_GM(return new StrokeRectAnisotropicGM;)
77