Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
skgpu::tess::CullTest Class Reference

#include <CullTest.h>

Public Member Functions

 CullTest ()=default
 
 CullTest (const SkRect &devCullBounds, const SkMatrix &m)
 
void set (const SkRect &devCullBounds, const SkMatrix &m)
 
bool isVisible (SkPoint p) const
 
bool areVisible3 (const SkPoint p[3]) const
 
bool areVisible4 (const SkPoint p[4]) const
 

Detailed Description

Definition at line 26 of file CullTest.h.

Constructor & Destructor Documentation

◆ CullTest() [1/2]

skgpu::tess::CullTest::CullTest ( )
default

◆ CullTest() [2/2]

skgpu::tess::CullTest::CullTest ( const SkRect devCullBounds,
const SkMatrix m 
)
inline

Definition at line 30 of file CullTest.h.

30 {
31 this->set(devCullBounds, m);
32 }
void set(const SkRect &devCullBounds, const SkMatrix &m)
Definition: CullTest.h:34

Member Function Documentation

◆ areVisible3()

bool skgpu::tess::CullTest::areVisible3 ( const SkPoint  p[3]) const
inline

Definition at line 57 of file CullTest.h.

57 {
58 // Transform p0..2 to device space.
59 auto val0 = fMatY * p[0].fY;
60 auto val1 = fMatY * p[1].fY;
61 auto val2 = fMatY * p[2].fY;
62 val0 = fMatX*p[0].fX + val0;
63 val1 = fMatX*p[1].fX + val1;
64 val2 = fMatX*p[2].fX + val2;
65 // At this point: valN = {xN, yN, -xN, -yN} in device space.
66
67 // Find the device-space bounding box of p0..2.
68 val0 = max(val0, val1);
69 val0 = max(val0, val2);
70 // At this point: val0 = [r, b, -l, -t] of the device-space bounding box of p0..2.
71
72 // Does fCullBounds intersect the device-space bounding box of p0..2?
73 // i.e., l0 < r1 && t0 < b1 && r0 > l1 && b0 > t1.
74 return all(fCullBounds < val0);
75 }
static float max(float r, float g, float b)
Definition: hsl.cpp:49
SIT bool all(const Vec< 1, T > &x)
Definition: SkVx.h:582

◆ areVisible4()

bool skgpu::tess::CullTest::areVisible4 ( const SkPoint  p[4]) const
inline

Definition at line 78 of file CullTest.h.

78 {
79 // Transform p0..3 to device space.
80 auto val0 = fMatY * p[0].fY;
81 auto val1 = fMatY * p[1].fY;
82 auto val2 = fMatY * p[2].fY;
83 auto val3 = fMatY * p[3].fY;
84 val0 = fMatX*p[0].fX + val0;
85 val1 = fMatX*p[1].fX + val1;
86 val2 = fMatX*p[2].fX + val2;
87 val3 = fMatX*p[3].fX + val3;
88 // At this point: valN = {xN, yN, -xN, -yN} in device space.
89
90 // Find the device-space bounding box of p0..3.
91 val0 = max(val0, val1);
92 val2 = max(val2, val3);
93 val0 = max(val0, val2);
94 // At this point: val0 = [r, b, -l, -t] of the device-space bounding box of p0..3.
95
96 // Does fCullBounds intersect the device-space bounding box of p0..3?
97 // i.e., l0 < r1 && t0 < b1 && r0 > l1 && b0 > t1.
98 return all(fCullBounds < val0);
99 }

◆ isVisible()

bool skgpu::tess::CullTest::isVisible ( SkPoint  p) const
inline

Definition at line 49 of file CullTest.h.

49 {
50 // devPt = [x, y, -x, -y] in device space.
51 auto devPt = fMatX*p.fX + fMatY*p.fY;
52 // i.e., l < x && t < y && r > x && b > y.
53 return all(fCullBounds < devPt);
54 }

◆ set()

void skgpu::tess::CullTest::set ( const SkRect devCullBounds,
const SkMatrix m 
)
inline

Definition at line 34 of file CullTest.h.

34 {
35 SkASSERT(!m.hasPerspective());
36 // [fMatX, fMatY] maps path coordinates to the float4 [x, y, -x, -y] in device space.
37 fMatX = {m.getScaleX(), m.getSkewY(), -m.getScaleX(), -m.getSkewY()};
38 fMatY = {m.getSkewX(), m.getScaleY(), -m.getSkewX(), -m.getScaleY()};
39 // Store the cull bounds as [l, t, -r, -b] for faster math.
40 // Also subtract the matrix translate from the cull bounds ahead of time, rather than adding
41 // it to every point every time we test.
42 fCullBounds = {devCullBounds.fLeft - m.getTranslateX(),
43 devCullBounds.fTop - m.getTranslateY(),
44 m.getTranslateX() - devCullBounds.fRight,
45 m.getTranslateY() - devCullBounds.fBottom};
46 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

The documentation for this class was generated from the following file: