xref: /aosp_15_r20/external/skia/gm/crbug_1162942.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2020 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 #include "src/base/SkFloatBits.h"
13 
14 // This tests a scenario where when the 2D projection of a perspective quad is inset we degenerate
15 // the inset 2d geometry to a triangle because an inset vertex crosses the opposite edge. When we
16 // project back to 3D and try to move the original verts along the original edges so that they
17 // project to the 2D points. Whether an edge can be moved along depends on whether the adjacent edge
18 // at the vertex is AA. However, in the degenerate triangle case the 2D point may not fall along
19 // either of the edges. Thus, if we're constrained to moving along one edge and solve for X or Y the
20 // other value may go wildly away from projecting to the 2D value. The current approach is to force
21 // AA on at both edges that meet at a vertex whose inset point has been replaced by an off-edge
22 // point if either is AA originally. This gives us an additional vector to move along so that we can
23 // find a 3D point that projects to the 2D point in both X and Y.
24 DEF_SIMPLE_GM(crbug_1162942, canvas, 620, 200) {
25     // Matrix and quad values taken from Chrome repro scenario.
26     SkMatrix ctm = SkMatrix::MakeAll(
27             SkBits2Float(0x3FCC7F75), SkBits2Float(0x3D5784FC), SkBits2Float(0x44C48C99),
28             SkBits2Float(0x3F699F7F), SkBits2Float(0x3E0A0D37), SkBits2Float(0x43908518),
29             SkBits2Float(0x3AA17423), SkBits2Float(0x3A6CCDC3), SkBits2Float(0x3F2EFEEC));
30     ctm.postTranslate(-1500.f, -325.f);
31 
32     SkPoint pts[4] = {{SkBits2Float(0x3F39778B), SkBits2Float(0x43FF7FFC)},
33                       {SkBits2Float(0x0), SkBits2Float(0x43FF7FFA)},
34                       {SkBits2Float(0xB83B055E), SkBits2Float(0x42500003)},
35                       {SkBits2Float(0x3F39776F), SkBits2Float(0x4250000D)}};
36     SkRect bounds;
37     bounds.setBounds(pts, 4);
38 
39     canvas->clear(SK_ColorWHITE);
40 
41     SkCanvas::QuadAAFlags flags[] = {
42             (SkCanvas::QuadAAFlags) (SkCanvas::kTop_QuadAAFlag    | SkCanvas::kLeft_QuadAAFlag ),
43             (SkCanvas::QuadAAFlags) (SkCanvas::kBottom_QuadAAFlag | SkCanvas::kRight_QuadAAFlag),
44             (SkCanvas::QuadAAFlags) (SkCanvas::kBottom_QuadAAFlag),
45             (SkCanvas::QuadAAFlags) (SkCanvas::kRight_QuadAAFlag),
46             (SkCanvas::QuadAAFlags) (SkCanvas::kRight_QuadAAFlag  | SkCanvas::kLeft_QuadAAFlag),
47             (SkCanvas::QuadAAFlags) (SkCanvas::kTop_QuadAAFlag    | SkCanvas::kBottom_QuadAAFlag),
48     };
49 
50     SkColor color = SK_ColorGREEN;
51     for (auto aaFlags : flags) {
52         canvas->save();
53         canvas->concat(ctm);
54         canvas->experimental_DrawEdgeAAQuad(bounds, pts, aaFlags, color, SkBlendMode::kSrcOver);
55         SkColor rgb = color & 0x00FFFFFF;
56         color = 0xFF000000 | (rgb << 4) | (rgb >> 20);
57         canvas->restore();
58         canvas->translate(0, 25);
59     }
60 }
61 
62