Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
GrQuad Class Reference

#include <GrQuad.h>

Public Types

enum class  Type {
  kAxisAligned , kRectilinear , kGeneral , kPerspective ,
  kLast = kPerspective
}
 

Public Member Functions

 GrQuad ()=default
 
 GrQuad (const GrQuad &)=default
 
 GrQuad (const SkRect &rect)
 
GrQuadoperator= (const GrQuad &)=default
 
SkPoint3 point3 (int i) const
 
SkPoint point (int i) const
 
void writeVertex (int cornerIdx, skgpu::VertexWriter &w) const
 
SkRect bounds () const
 
bool isFinite () const
 
float x (int i) const
 
float y (int i) const
 
float w (int i) const
 
float iw (int i) const
 
skvx::Vec< 4, float > x4f () const
 
skvx::Vec< 4, float > y4f () const
 
skvx::Vec< 4, float > w4f () const
 
skvx::Vec< 4, float > iw4f () const
 
Type quadType () const
 
bool hasPerspective () const
 
bool aaHasEffectOnRect (GrQuadAAFlags edgeFlags) const
 
bool asRect (SkRect *rect) const
 
const float * xs () const
 
float * xs ()
 
const float * ys () const
 
float * ys ()
 
const float * ws () const
 
float * ws ()
 
void setQuadType (Type newType)
 

Static Public Member Functions

static GrQuad MakeFromRect (const SkRect &, const SkMatrix &)
 
static GrQuad MakeFromSkQuad (const SkPoint pts[4], const SkMatrix &)
 

Static Public Attributes

static const int kTypeCount = static_cast<int>(Type::kLast) + 1
 

Friends

template<typename T >
class GrQuadListBase
 

Detailed Description

GrQuad is a collection of 4 points which can be used to represent an arbitrary quadrilateral. The points make a triangle strip with CCW triangles (top-left, bottom-left, top-right, bottom-right).

Definition at line 30 of file GrQuad.h.

Member Enumeration Documentation

◆ Type

enum class GrQuad::Type
strong
Enumerator
kAxisAligned 
kRectilinear 
kGeneral 
kPerspective 
kLast 

Definition at line 35 of file GrQuad.h.

35 {
36 // The 4 points remain an axis-aligned rectangle; their logical indices may not respect
37 // TL, BL, TR, BR ordering if the transform was a 90 degree rotation or mirror.
39 // The 4 points represent a rectangle subjected to a rotation, its corners are right angles.
41 // Arbitrary 2D quadrilateral; may have been a rectangle transformed with skew or some
42 // clipped polygon. Its w coordinates will all be 1.
44 // Even more general-purpose than kGeneral, this allows the w coordinates to be non-unity.
47 };

Constructor & Destructor Documentation

◆ GrQuad() [1/3]

GrQuad::GrQuad ( )
default

◆ GrQuad() [2/3]

GrQuad::GrQuad ( const GrQuad )
default

◆ GrQuad() [3/3]

GrQuad::GrQuad ( const SkRect rect)
inlineexplicit

Definition at line 54 of file GrQuad.h.

55 : fX{rect.fLeft, rect.fLeft, rect.fRight, rect.fRight}
56 , fY{rect.fTop, rect.fBottom, rect.fTop, rect.fBottom} {}
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350

Member Function Documentation

◆ aaHasEffectOnRect()

bool GrQuad::aaHasEffectOnRect ( GrQuadAAFlags  edgeFlags) const

Definition at line 135 of file GrQuad.cpp.

135 {
137 // If rect, ws must all be 1s so no need to divide
138 return aa_affects_rect(edgeFlags, fX[0], fY[0], fX[3], fY[3]);
139}
static bool aa_affects_rect(GrQuadAAFlags edgeFlags, float ql, float qt, float qr, float qb)
Definition GrQuad.cpp:15
#define SkASSERT(cond)
Definition SkAssert.h:116
Type quadType() const
Definition GrQuad.h:118

◆ asRect()

bool GrQuad::asRect ( SkRect rect) const

Definition at line 141 of file GrQuad.cpp.

141 {
142 if (this->quadType() != Type::kAxisAligned) {
143 return false;
144 }
145
146 *rect = this->bounds();
147 // v0 at the geometric top-left is unique amongst axis-aligned vertex orders
148 // (90, 180, 270 rotations or axis flips all move v0).
149 return fX[0] == rect->fLeft && fY[0] == rect->fTop;
150}
SkRect bounds() const
Definition GrQuad.h:81

◆ bounds()

SkRect GrQuad::bounds ( ) const
inline

Definition at line 81 of file GrQuad.h.

81 {
82 if (fType == GrQuad::Type::kPerspective) {
83 return this->projectedBounds();
84 }
85 // Calculate min/max directly on the 4 floats, instead of loading/unloading into SIMD. Since
86 // there's no horizontal min/max, it's not worth it. Defining non-perspective case in header
87 // also leads to substantial performance boost due to inlining.
88 auto min = [](const float c[4]) { return std::min(std::min(c[0], c[1]),
89 std::min(c[2], c[3]));};
90 auto max = [](const float c[4]) { return std::max(std::max(c[0], c[1]),
91 std::max(c[2], c[3]));};
92 return { min(fX), min(fY), max(fX), max(fY) };
93 }
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48

◆ hasPerspective()

bool GrQuad::hasPerspective ( ) const
inline

Definition at line 120 of file GrQuad.h.

120{ return fType == Type::kPerspective; }

◆ isFinite()

bool GrQuad::isFinite ( ) const
inline

Definition at line 95 of file GrQuad.h.

95 {
96 // If any coordinate is infinity or NaN, then multiplying it with 0 will make accum NaN
97 float accum = 0;
98 for (int i = 0; i < 4; ++i) {
99 accum *= fX[i];
100 accum *= fY[i];
101 accum *= fW[i];
102 }
103 SkASSERT(0 == accum || SkIsNaN(accum));
104
105 return accum == 0.0f;
106 }
static bool SkIsNaN(T x)

◆ iw()

float GrQuad::iw ( int  i) const
inline

Definition at line 111 of file GrQuad.h.

111{ return sk_ieee_float_divide(1.f, fW[i]); }
static constexpr float sk_ieee_float_divide(float numer, float denom)

◆ iw4f()

skvx::Vec< 4, float > GrQuad::iw4f ( ) const
inline

Definition at line 116 of file GrQuad.h.

116{ return 1.f / this->w4f(); }
skvx::Vec< 4, float > w4f() const
Definition GrQuad.h:115

◆ MakeFromRect()

GrQuad GrQuad::MakeFromRect ( const SkRect rect,
const SkMatrix m 
)
static

Definition at line 107 of file GrQuad.cpp.

107 {
108 V4f x, y, w;
109 SkMatrix::TypeMask tm = m.getType();
110 Type type;
112 map_rect_translate_scale(rect, m, &x, &y);
113 w = 1.f;
115 } else {
116 map_rect_general(rect, m, &x, &y, &w);
118 }
119 return GrQuad(x, y, w, type);
120}
static void map_rect_general(const SkRect &rect, const SkMatrix &matrix, V4f *xs, V4f *ys, V4f *ws)
Definition GrQuad.cpp:63
static GrQuad::Type quad_type_for_transformed_rect(const SkMatrix &matrix)
Definition GrQuad.cpp:78
static void map_rect_translate_scale(const SkRect &rect, const SkMatrix &m, V4f *xs, V4f *ys)
Definition GrQuad.cpp:24
GrQuad()=default
@ kTranslate_Mask
translation SkMatrix
Definition SkMatrix.h:193
@ kScale_Mask
scale SkMatrix
Definition SkMatrix.h:194
double y
double x
SkScalar w

◆ MakeFromSkQuad()

GrQuad GrQuad::MakeFromSkQuad ( const SkPoint  pts[4],
const SkMatrix matrix 
)
static

Definition at line 122 of file GrQuad.cpp.

122 {
123 V4f xs, ys;
125 Type type = quad_type_for_points(pts, matrix);
126 if (matrix.isIdentity()) {
127 return GrQuad(xs, ys, 1.f, type);
128 } else {
129 V4f mx, my, mw;
130 map_quad_general(xs, ys, matrix, &mx, &my, &mw);
131 return GrQuad(mx, my, mw, type);
132 }
133}
static void map_quad_general(const V4f &qx, const V4f &qy, const SkMatrix &m, V4f *xs, V4f *ys, V4f *ws)
Definition GrQuad.cpp:43
static void rearrange_sk_to_gr_points(const SkPoint skQuadPts[4], V4f *xs, V4f *ys)
Definition GrQuad.cpp:72
static GrQuad::Type quad_type_for_points(const SkPoint pts[4], const SkMatrix &matrix)
Definition GrQuad.cpp:92
const float * xs() const
Definition GrQuad.h:132
const float * ys() const
Definition GrQuad.h:134
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258

◆ operator=()

GrQuad & GrQuad::operator= ( const GrQuad )
default

◆ point()

SkPoint GrQuad::point ( int  i) const
inline

Definition at line 69 of file GrQuad.h.

69 {
70 if (fType == Type::kPerspective) {
71 return {fX[i] / fW[i], fY[i] / fW[i]};
72 } else {
73 return {fX[i], fY[i]};
74 }
75 }

◆ point3()

SkPoint3 GrQuad::point3 ( int  i) const
inline

Definition at line 67 of file GrQuad.h.

67{ return {fX[i], fY[i], fW[i]}; }

◆ quadType()

Type GrQuad::quadType ( ) const
inline

Definition at line 118 of file GrQuad.h.

118{ return fType; }

◆ setQuadType()

void GrQuad::setQuadType ( Type  newType)
inline

Definition at line 140 of file GrQuad.h.

140 {
141 if (newType != Type::kPerspective && fType == Type::kPerspective) {
142 fW[0] = fW[1] = fW[2] = fW[3] = 1.f;
143 }
144 SkASSERT(newType == Type::kPerspective ||
145 (SkScalarNearlyEqual(fW[0], 1.f) && SkScalarNearlyEqual(fW[1], 1.f) &&
146 SkScalarNearlyEqual(fW[2], 1.f) && SkScalarNearlyEqual(fW[3], 1.f)));
147
148 fType = newType;
149 }
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107

◆ w()

float GrQuad::w ( int  i) const
inline

Definition at line 110 of file GrQuad.h.

110{ return fW[i]; }

◆ w4f()

skvx::Vec< 4, float > GrQuad::w4f ( ) const
inline

Definition at line 115 of file GrQuad.h.

115{ return skvx::Vec<4, float>::Load(fW); }
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition SkVx.h:109

◆ writeVertex()

void GrQuad::writeVertex ( int  cornerIdx,
skgpu::VertexWriter w 
) const
inline

Definition at line 77 of file GrQuad.h.

77 {
78 w << this->point(cornerIdx);
79 }
SkPoint point(int i) const
Definition GrQuad.h:69

◆ ws() [1/2]

float * GrQuad::ws ( )
inline

Definition at line 137 of file GrQuad.h.

137{ return fW; }

◆ ws() [2/2]

const float * GrQuad::ws ( ) const
inline

Definition at line 136 of file GrQuad.h.

136{ return fW; }

◆ x()

float GrQuad::x ( int  i) const
inline

Definition at line 108 of file GrQuad.h.

108{ return fX[i]; }

◆ x4f()

skvx::Vec< 4, float > GrQuad::x4f ( ) const
inline

Definition at line 113 of file GrQuad.h.

113{ return skvx::Vec<4, float>::Load(fX); }

◆ xs() [1/2]

float * GrQuad::xs ( )
inline

Definition at line 133 of file GrQuad.h.

133{ return fX; }

◆ xs() [2/2]

const float * GrQuad::xs ( ) const
inline

Definition at line 132 of file GrQuad.h.

132{ return fX; }

◆ y()

float GrQuad::y ( int  i) const
inline

Definition at line 109 of file GrQuad.h.

109{ return fY[i]; }

◆ y4f()

skvx::Vec< 4, float > GrQuad::y4f ( ) const
inline

Definition at line 114 of file GrQuad.h.

114{ return skvx::Vec<4, float>::Load(fY); }

◆ ys() [1/2]

float * GrQuad::ys ( )
inline

Definition at line 135 of file GrQuad.h.

135{ return fY; }

◆ ys() [2/2]

const float * GrQuad::ys ( ) const
inline

Definition at line 134 of file GrQuad.h.

134{ return fY; }

Friends And Related Symbol Documentation

◆ GrQuadListBase

template<typename T >
friend class GrQuadListBase
friend

Definition at line 152 of file GrQuad.h.

Member Data Documentation

◆ kTypeCount

const int GrQuad::kTypeCount = static_cast<int>(Type::kLast) + 1
static

Definition at line 48 of file GrQuad.h.


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