xref: /aosp_15_r20/external/skia/gm/strokerect_anisotropic.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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:
getName() const38     SkString getName() const override { return SkString("strokerect_anisotropic"); }
39 
getISize()40     SkISize getISize() override { return SkISize::Make(160, 160); }
41 
onDraw(SkCanvas * canvas)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 
73 private:
74     using INHERITED = GM;
75 };
76 DEF_GM(return new StrokeRectAnisotropicGM;)
77 
78