• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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/SkMatrix.h"
11 #include "include/core/SkRect.h"
12 
13 // Bad quads dumped from SkiaRenderer in crbug.com/1178833. These should all draw as really thin
14 // lines.
15 DEF_SIMPLE_GM(crbug_1177833, canvas, 400, 400) {
16     canvas->clear(SK_ColorBLACK);
17     canvas->translate(-700, -700);
18     // This quad had two issues. The inset collapsed the inner 2D projected quad to a point but
19     // didn't enable enough degrees of freedom to adjust the 4 3D points to project to that point.
20     // Also, the outset produced a 2D projected point far away from the original quad but the
21     // shader was not checking the geometric subset and so pixels far away from the projection of
22     // the quad would have positive coverage.
23     {
24         canvas->save();
25         canvas->concat(SkMatrix::MakeAll(SkBits2Float(0xbf79250e), SkBits2Float(0x3e9da860), SkBits2Float(0x44914c8a),
26                                          SkBits2Float(0xbf982962), SkBits2Float(0xbf280002), SkBits2Float(0x44c3116e),
27                                          SkBits2Float(0xba9bfe62), SkBits2Float(0x39d10455), SkBits2Float(0x3fc9b377)));
28         SkRect rect = {SkBits2Float(0x00000000),
29                        SkBits2Float(0x00000000),
30                        SkBits2Float(0x40a00000),
31                        SkBits2Float(0x43560000)};
32         SkPoint clip[4] = {{SkBits2Float(0x409fff57), SkBits2Float(0x40c86a18)},
33                            {SkBits2Float(0x409fff57), SkBits2Float(0x4314dc8c)},
34                            {SkBits2Float(0x407f6b0d), SkBits2Float(0x43157fff)},
35                            {SkBits2Float(0x4040859c), SkBits2Float(0x43140374)}};
36         SkCanvas::QuadAAFlags aaFlags = static_cast<SkCanvas::QuadAAFlags>(0x00000002);
37         SkColor4f color = {SkBits2Float(0x3f6eeef0),
38                            SkBits2Float(0x3f6eeef0),
39                            SkBits2Float(0x3f6eeef0),
40                            SkBits2Float(0x3f800000)};
41         SkBlendMode mode = static_cast<SkBlendMode>(0x00000003);
42         canvas->experimental_DrawEdgeAAQuad(rect, clip, aaFlags, color, mode);
43         canvas->restore();
44     }
45     // This quad also exposed the inset collapse to a point without enough degrees of freedom issue.
46     canvas->save();
47     canvas->translate(-300, 0);
48     {
49         canvas->save();
50         canvas->concat(SkMatrix::MakeAll(SkBits2Float(0x3f54dd8a), SkBits2Float(0xbf9096a4), SkBits2Float(0x447eae34),
51                                          SkBits2Float(0x3f3f6905), SkBits2Float(0xbe5208ba), SkBits2Float(0x4418118b),
52                                          SkBits2Float(0x3aa134a1), SkBits2Float(0xb93ef249), SkBits2Float(0x3f580bd4)));
53         SkRect rect = {SkBits2Float(0x00000000),
54                        SkBits2Float(0x00000000),
55                        SkBits2Float(0x40a00000),
56                        SkBits2Float(0x43560000)};
57         SkPoint clip[4] = {{SkBits2Float(0x40a0000e), SkBits2Float(0x40c86b5a)},
58                            {SkBits2Float(0x40a0001e), SkBits2Float(0x4314dd5f)},
59                            {SkBits2Float(0x407f76eb), SkBits2Float(0x431580c2)},
60                            {SkBits2Float(0x404092e7), SkBits2Float(0x43140445)}};
61         SkCanvas::QuadAAFlags aaFlags = static_cast<SkCanvas::QuadAAFlags>(0x00000002);
62         SkColor4f color = {SkBits2Float(0x3f6eeef0),
63                            SkBits2Float(0x3f6eeef0),
64                            SkBits2Float(0x3f6eeef0),
65                            SkBits2Float(0x3f800000)};
66         SkBlendMode mode = static_cast<SkBlendMode>(0x00000003);
67         canvas->experimental_DrawEdgeAAQuad(rect, clip, aaFlags, color, mode);
68         canvas->restore();
69     }
70     canvas->restore();
71     // This quad exposed a similar issue to the point issue above, but when collapsing to a
72     // triangle. When a 2D quad edge collapsed from insetting we'd replace it with a point off of
73     // its adjacent edges. We need to ensure the code that moves the 3D point that projects to
74     // the 2D point has 2 degrees of freedom so it can find the correct 3D point.
75     {
76         canvas->save();
77         canvas->concat(SkMatrix::MakeAll(SkBits2Float(0x3f54b255), SkBits2Float(0x3eb5a94d), SkBits2Float(0x443d7419),
78                                          SkBits2Float(0x3f885d66), SkBits2Float(0x3f5a6b9c), SkBits2Float(0x443c7334),
79                                          SkBits2Float(0x3aa95ea5), SkBits2Float(0xb8a1391e), SkBits2Float(0x3f84dde5)));
80         SkRect rect = {SkBits2Float(0x00000000),
81                        SkBits2Float(0x00000000),
82                        SkBits2Float(0x40a00000),
83                        SkBits2Float(0x43100000)};
84         SkPoint clip[4] = {{SkBits2Float(0x405a654c), SkBits2Float(0x42e8c790)},
85                            {SkBits2Float(0x3728c61b), SkBits2Float(0x42e7df31)},
86                            {SkBits2Float(0xb678ecc5), SkBits2Float(0x412db4e0)},
87                            {SkBits2Float(0x4024b2ad), SkBits2Float(0x413ab3ed)}};
88         SkCanvas::QuadAAFlags aaFlags = static_cast<SkCanvas::QuadAAFlags>(0x00000004);
89         SkColor4f color = {SkBits2Float(0x3f800000),
90                            SkBits2Float(0x3f800000),
91                            SkBits2Float(0x3f800000),
92                            SkBits2Float(0x3f800000)};
93         SkBlendMode mode = static_cast<SkBlendMode>(0x00000003);
94         canvas->experimental_DrawEdgeAAQuad(rect, clip, aaFlags, color, mode);
95         canvas->restore();
96     }
97 }
98 
99