Flutter Engine
The Flutter Engine
CullTestTest.cpp
Go to the documentation of this file.
1/*
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
10#include "include/core/SkRect.h"
12#include "src/base/SkRandom.h"
14#include "tests/Test.h"
15
16#include <initializer_list>
17
18namespace skgpu::tess {
19
22 SkMatrix::Translate(25, -1000),
23 SkMatrix::Scale(.5f, 1000.1f),
24 SkMatrix::MakeAll(1000.1f, .0f, -100,
25 0.0f, .5f, -3000,
26 0.0f, .0f, 1),
27 SkMatrix::MakeAll(0, 1, 0,
28 1, 0, 0,
29 0, 0, 1),
30 SkMatrix::MakeAll( 2, 7.0f, -100,
31 -8000, .5f, 2000,
32 0, .0f, 1),
33};
34
35DEF_TEST(CullTestTest, reporter) {
36 SkRandom rand;
37 float l=10, t=2000, r=100, b=2064;
38 SkRect viewportRect{l, t, r, b};
39 float valuesL[4] = {l-20, l-10, l+10, l+20};
40 float valuesT[4] = {t-20, t-10, t+10, t+20};
41 float valuesR[4] = {r+20, r+10, r-10, r-20};
42 float valuesB[4] = {b+20, b+10, b-10, b-20};
43 for (SkMatrix m : gMatrices) {
44 CullTest cullTest(viewportRect, m);
45 SkMatrix inverse;
46 SkAssertResult(m.invert(&inverse));
47 for (const float* y : {valuesT, valuesB}) {
48 for (const float* x : {valuesL, valuesR}) {
49 for (int i = 0; i < 500; ++i) {
50 int mask = rand.nextU();
51 const SkPoint devPts[4] = {{x[(mask >> 0) & 3], y[(mask >> 2) & 3]},
52 {x[(mask >> 4) & 3], y[(mask >> 6) & 3]},
53 {x[(mask >> 8) & 3], y[(mask >> 10) & 3]},
54 {x[(mask >> 12) & 3], y[(mask >> 14) & 3]}};
55
56 SkPoint localPts[4];
57 inverse.mapPoints(localPts, devPts, 4);
58
60 cullTest.isVisible(localPts[0]) ==
61 viewportRect.contains(devPts[0].fX, devPts[0].fY));
62
63 {
64 SkRect devBounds3;
65 devBounds3.setBounds(devPts, 3);
66 // Outset devBounds because SkRect::intersects returns false on empty, which is NOT
67 // the behavior we want.
68 devBounds3.outset(1e-3f, 1e-3f);
70 cullTest.areVisible3(localPts) == viewportRect.intersects(devBounds3));
71 }
72
73 {
74 SkRect devBounds4;
75 devBounds4.setBounds(devPts, 4);
76 // Outset devBounds because SkRect::intersects returns false on empty, which is NOT
77 // the behavior we want.
78 devBounds4.outset(1e-3f, 1e-3f);
80 cullTest.areVisible4(localPts) == viewportRect.intersects(devBounds4));
81 }
82 }}}
83 }
84}
85
86} // namespace skgpu::tess
reporter
Definition: FontMgrTest.cpp:39
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
Definition: SkMatrix.cpp:770
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition: SkMatrix.h:179
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
uint32_t nextU()
Definition: SkRandom.h:42
bool isVisible(SkPoint p) const
Definition: CullTest.h:49
bool areVisible3(const SkPoint p[3]) const
Definition: CullTest.h:57
bool areVisible4(const SkPoint p[4]) const
Definition: CullTest.h:78
static bool b
double y
double x
const SkMatrix gMatrices[]
DEF_TEST(CullTestTest, reporter)
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
void outset(float dx, float dy)
Definition: SkRect.h:1077
void setBounds(const SkPoint pts[], int count)
Definition: SkRect.h:881