blob: 5657e3ae1b5d9596cb98545bda9856a4f76de1b8 [file] [log] [blame]
Chris Dalton0cfe5e12021-05-13 10:42:30 -06001/*
2 * Copyright 2021 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 "tests/Test.h"
9
10#include "include/utils/SkRandom.h"
11#include "src/gpu/tessellate/GrCullTest.h"
12
13const SkMatrix gMatrices[] = {
14 SkMatrix::I(),
15 SkMatrix::Translate(25, -1000),
16 SkMatrix::Scale(.5f, 1000.1f),
17 SkMatrix::MakeAll(1000.1f, .0f, -100,
18 0.0f, .5f, -3000,
19 0.0f, .0f, 1),
20 SkMatrix::MakeAll(0, 1, 0,
21 1, 0, 0,
22 0, 0, 1),
23 SkMatrix::MakeAll( 2, 7.0f, -100,
24 -8000, .5f, 2000,
25 0, .0f, 1),
26};
27
28DEF_TEST(CullTestTest, reporter) {
29 SkRandom rand;
30 float l=10, t=2000, r=100, b=2064;
31 SkRect viewportRect{l, t, r, b};
32 float valuesL[4] = {l-20, l-10, l+10, l+20};
33 float valuesT[4] = {t-20, t-10, t+10, t+20};
34 float valuesR[4] = {r+20, r+10, r-10, r-20};
35 float valuesB[4] = {b+20, b+10, b-10, b-20};
36 for (SkMatrix m : gMatrices) {
37 GrCullTest cullTest(viewportRect, m);
38 SkMatrix inverse;
39 SkAssertResult(m.invert(&inverse));
40 for (const float* y : {valuesT, valuesB}) {
41 for (const float* x : {valuesL, valuesR}) {
42 for (int i = 0; i < 500; ++i) {
43 int mask = rand.nextU();
44 const SkPoint devPts[4] = {{x[(mask >> 0) & 3], y[(mask >> 2) & 3]},
45 {x[(mask >> 4) & 3], y[(mask >> 6) & 3]},
46 {x[(mask >> 8) & 3], y[(mask >> 10) & 3]},
47 {x[(mask >> 12) & 3], y[(mask >> 14) & 3]}};
48
49 SkPoint localPts[4];
50 inverse.mapPoints(localPts, devPts, 4);
51
52 REPORTER_ASSERT(reporter,
53 cullTest.isVisible(localPts[0]) ==
54 viewportRect.contains(devPts[0].fX, devPts[0].fY));
55
56 {
57 SkRect devBounds3;
58 devBounds3.setBounds(devPts, 3);
59 // Outset devBounds because SkRect::intersects returns false on empty, which is NOT
60 // the behavior we want.
61 devBounds3.outset(1e-3f, 1e-3f);
62 REPORTER_ASSERT(reporter,
63 cullTest.areVisible3(localPts) == viewportRect.intersects(devBounds3));
64 }
65
66 {
67 SkRect devBounds4;
68 devBounds4.setBounds(devPts, 4);
69 // Outset devBounds because SkRect::intersects returns false on empty, which is NOT
70 // the behavior we want.
71 devBounds4.outset(1e-3f, 1e-3f);
72 REPORTER_ASSERT(reporter,
73 cullTest.areVisible4(localPts) == viewportRect.intersects(devBounds4));
74 }
75 }}}
76 }
77}