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