Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
GrStencilSettings Class Reference

#include <GrStencilSettings.h>

Classes

struct  Face
 

Public Member Functions

 GrStencilSettings ()
 
 GrStencilSettings (const GrUserStencilSettings &user, bool hasStencilClip, int numStencilBits)
 
 GrStencilSettings (const GrStencilSettings &that)
 
GrStencilSettingsoperator= (const GrStencilSettings &that)
 
void invalidate ()
 
void setDisabled ()
 
void reset (const GrUserStencilSettings &, bool hasStencilClip, int numStencilBits)
 
void reset (const GrStencilSettings &)
 
bool isValid () const
 
bool isDisabled () const
 
bool doesWrite () const
 
bool isTwoSided () const
 
bool usesWrapOp () const
 
void genKey (skgpu::KeyBuilder *b, bool includeRefsAndMasks) const
 
bool operator!= (const GrStencilSettings &that) const
 
bool operator== (const GrStencilSettings &) const
 
const FacesingleSidedFace () const
 
const FacepostOriginCWFace (GrSurfaceOrigin origin) const
 
const FacepostOriginCCWFace (GrSurfaceOrigin origin) const
 

Static Public Member Functions

static const GrUserStencilSettingsSetClipBitSettings (bool setToInside)
 

Detailed Description

This class defines concrete stencil settings that map directly to the underlying hardware. It is deduced from user stencil settings, stencil clip status, and the number of bits in the target stencil buffer.

Definition at line 51 of file GrStencilSettings.h.

Constructor & Destructor Documentation

◆ GrStencilSettings() [1/3]

GrStencilSettings::GrStencilSettings ( )
inline

Definition at line 53 of file GrStencilSettings.h.

53{ this->setDisabled(); }

◆ GrStencilSettings() [2/3]

GrStencilSettings::GrStencilSettings ( const GrUserStencilSettings user,
bool  hasStencilClip,
int  numStencilBits 
)
inline

Definition at line 54 of file GrStencilSettings.h.

54 {
55 this->reset(user, hasStencilClip, numStencilBits);
56 }
void reset(const GrUserStencilSettings &, bool hasStencilClip, int numStencilBits)

◆ GrStencilSettings() [3/3]

GrStencilSettings::GrStencilSettings ( const GrStencilSettings that)
inline

Definition at line 57 of file GrStencilSettings.h.

57{ this->reset(that); }

Member Function Documentation

◆ doesWrite()

bool GrStencilSettings::doesWrite ( ) const
inline

Definition at line 67 of file GrStencilSettings.h.

67 { SkASSERT(this->isValid());
68 return !(fFlags & kNoModifyStencil_StencilFlag); }
@ kNoModifyStencil_StencilFlag
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool isValid() const

◆ genKey()

void GrStencilSettings::genKey ( skgpu::KeyBuilder b,
bool  includeRefsAndMasks 
) const

Definition at line 249 of file GrStencilSettings.cpp.

249 {
250 b->addBits(6, fFlags, "stencilFlags");
251 if (this->isDisabled()) {
252 return;
253 }
254 if (!this->isTwoSided()) {
255 if (includeRefs) {
256 b->addBytes(sizeof(Face), &fCWFace, "stencilCWFace");
257 } else {
258 Face tempFace = fCWFace;
259 tempFace.fRef = 0;
260 b->addBytes(sizeof(Face), &tempFace, "stencilCWFace");
261 }
262 } else {
263 if (includeRefs) {
264 b->addBytes(sizeof(Face), &fCWFace, "stencilCWFace");
265 b->addBytes(sizeof(Face), &fCCWFace, "stencilCCWFace");
266 } else {
267 Face tempFaces[2];
268 tempFaces[0] = fCWFace;
269 tempFaces[0].fRef = 0;
270 tempFaces[1] = fCCWFace;
271 tempFaces[1].fRef = 0;
272 b->addBytes(sizeof(Face), &tempFaces[0], "stencilCWFace");
273 b->addBytes(sizeof(Face), &tempFaces[1], "stencilCCWFace");
274 }
275 }
276 // We rely on GrStencilSettings::Face being tightly packed for the key to be reliable.
277 static_assert(0 == offsetof(Face, fRef));
278 static_assert(2 == sizeof(Face::fRef));
279 static_assert(2 == offsetof(Face, fTest));
280 static_assert(2 == sizeof(Face::fTest));
281 static_assert(4 == offsetof(Face, fTestMask));
282 static_assert(2 == sizeof(Face::fTestMask));
283 static_assert(6 == offsetof(Face, fPassOp));
284 static_assert(1 == sizeof(Face::fPassOp));
285 static_assert(7 == offsetof(Face, fFailOp));
286 static_assert(1 == sizeof(Face::fFailOp));
287 static_assert(8 == offsetof(Face, fWriteMask));
288 static_assert(2 == sizeof(Face::fWriteMask));
289 static_assert(10 == sizeof(Face));
290}
bool isTwoSided() const
bool isDisabled() const
static bool b

◆ invalidate()

void GrStencilSettings::invalidate ( )
inline

Definition at line 60 of file GrStencilSettings.h.

60{ fFlags |= kInvalid_PrivateFlag; }

◆ isDisabled()

bool GrStencilSettings::isDisabled ( ) const
inline

Definition at line 66 of file GrStencilSettings.h.

66{ SkASSERT(this->isValid()); return fFlags & kDisabled_StencilFlag; }
@ kDisabled_StencilFlag

◆ isTwoSided()

bool GrStencilSettings::isTwoSided ( ) const
inline

Definition at line 69 of file GrStencilSettings.h.

69 { SkASSERT(this->isValid());
70 return !(fFlags & kSingleSided_StencilFlag); }
@ kSingleSided_StencilFlag

◆ isValid()

bool GrStencilSettings::isValid ( ) const
inline

Definition at line 65 of file GrStencilSettings.h.

65{ return !(fFlags & kInvalid_PrivateFlag); }

◆ operator!=()

bool GrStencilSettings::operator!= ( const GrStencilSettings that) const
inline

Definition at line 76 of file GrStencilSettings.h.

76{ return !(*this == that); }

◆ operator=()

GrStencilSettings & GrStencilSettings::operator= ( const GrStencilSettings that)
inline

Definition at line 58 of file GrStencilSettings.h.

58{ this->reset(that); return *this; }

◆ operator==()

bool GrStencilSettings::operator== ( const GrStencilSettings that) const

Definition at line 73 of file GrStencilSettings.cpp.

73 {
74 if ((kInvalid_PrivateFlag | kDisabled_StencilFlag) & (fFlags | that.fFlags)) {
75 // At least one is invalid and/or disabled.
76 if (kInvalid_PrivateFlag & (fFlags | that.fFlags)) {
77 return false; // We never allow invalid stencils to be equal.
78 }
79 // They're only equal if both are disabled.
80 return kDisabled_StencilFlag & (fFlags & that.fFlags);
81 }
82 if (kSingleSided_StencilFlag & (fFlags & that.fFlags)) {
83 return 0 == memcmp(&fCWFace, &that.fCWFace, sizeof(Face)); // Both are single sided.
84 } else if (kSingleSided_StencilFlag & (fFlags | that.fFlags)) {
85 return false;
86 } else {
87 return 0 == memcmp(&fCWFace, &that.fCWFace, 2 * sizeof(Face));
88 static_assert(sizeof(Face) ==
89 offsetof(GrStencilSettings, fCCWFace) - offsetof(GrStencilSettings, fCWFace));
90 }
91 // memcmp relies on GrStencilSettings::Face being tightly packed.
92 static_assert(0 == offsetof(Face, fRef));
93 static_assert(2 == sizeof(Face::fRef));
94 static_assert(2 == offsetof(Face, fTest));
95 static_assert(2 == sizeof(Face::fTest));
96 static_assert(4 == offsetof(Face, fTestMask));
97 static_assert(2 == sizeof(Face::fTestMask));
98 static_assert(6 == offsetof(Face, fPassOp));
99 static_assert(1 == sizeof(Face::fPassOp));
100 static_assert(7 == offsetof(Face, fFailOp));
101 static_assert(1 == sizeof(Face::fFailOp));
102 static_assert(8 == offsetof(Face, fWriteMask));
103 static_assert(2 == sizeof(Face::fWriteMask));
104 static_assert(10 == sizeof(Face));
105}

◆ postOriginCCWFace()

const Face & GrStencilSettings::postOriginCCWFace ( GrSurfaceOrigin  origin) const
inline

Definition at line 99 of file GrStencilSettings.h.

99 {
100 SkASSERT(this->isTwoSided());
101 return (kTopLeft_GrSurfaceOrigin == origin) ? fCCWFace : fCWFace;
102 }
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148

◆ postOriginCWFace()

const Face & GrStencilSettings::postOriginCWFace ( GrSurfaceOrigin  origin) const
inline

Definition at line 92 of file GrStencilSettings.h.

92 {
93 SkASSERT(this->isTwoSided());
94 return (kTopLeft_GrSurfaceOrigin == origin) ? fCWFace : fCCWFace;
95 }

◆ reset() [1/2]

void GrStencilSettings::reset ( const GrStencilSettings that)

Definition at line 59 of file GrStencilSettings.cpp.

59 {
60 fFlags = that.fFlags;
61 if ((kInvalid_PrivateFlag | kDisabled_StencilFlag) & fFlags) {
62 return;
63 }
64 if (!this->isTwoSided()) {
65 memcpy(&fCWFace, &that.fCWFace, sizeof(Face));
66 } else {
67 memcpy(&fCWFace, &that.fCWFace, 2 * sizeof(Face));
68 static_assert(sizeof(Face) ==
69 offsetof(GrStencilSettings, fCCWFace) - offsetof(GrStencilSettings, fCWFace));
70 }
71}

◆ reset() [2/2]

void GrStencilSettings::reset ( const GrUserStencilSettings user,
bool  hasStencilClip,
int  numStencilBits 
)

Definition at line 30 of file GrStencilSettings.cpp.

31 {
32 uint16_t cwFlags = user.fCWFlags[hasStencilClip];
33 if (cwFlags & kSingleSided_StencilFlag) {
34 SkASSERT(cwFlags == user.fCCWFlags[hasStencilClip]);
35 fFlags = cwFlags;
36 if (!this->isDisabled()) {
37 fCWFace.reset(user.fCWFace, hasStencilClip, numStencilBits);
38 }
39 return;
40 }
41
42 uint16_t ccwFlags = user.fCCWFlags[hasStencilClip];
43 fFlags = cwFlags & ccwFlags;
44 if (this->isDisabled()) {
45 return;
46 }
47 if (!(cwFlags & kDisabled_StencilFlag)) {
48 fCWFace.reset(user.fCWFace, hasStencilClip, numStencilBits);
49 } else {
50 fCWFace.setDisabled();
51 }
52 if (!(ccwFlags & kDisabled_StencilFlag)) {
53 fCCWFace.reset(user.fCCWFace, hasStencilClip, numStencilBits);
54 } else {
55 fCCWFace.setDisabled();
56 }
57}
void reset(const GrUserStencilSettings::Face &, bool useStencilClip, int numStencilBits)

◆ SetClipBitSettings()

const GrUserStencilSettings * GrStencilSettings::SetClipBitSettings ( bool  setToInside)
static

Gets the user stencil settings to directly set the clip bit.

Definition at line 245 of file GrStencilSettings.cpp.

245 {
246 return setToInside ? &gSetStencilClipBit : &gZeroStencilClipBit;
247}
static constexpr GrUserStencilSettings gSetStencilClipBit(GrUserStencilSettings::StaticInit< 0x0000, GrUserStencilTest::kAlways, 0xffff, GrUserStencilOp::kSetClipBit, GrUserStencilOp::kSetClipBit, 0x0000 >())
static constexpr GrUserStencilSettings gZeroStencilClipBit(GrUserStencilSettings::StaticInit< 0x0000, GrUserStencilTest::kAlways, 0xffff, GrUserStencilOp::kZeroClipBit, GrUserStencilOp::kZeroClipBit, 0x0000 >())

◆ setDisabled()

void GrStencilSettings::setDisabled ( )
inline

Definition at line 61 of file GrStencilSettings.h.

61{ fFlags = kAll_StencilFlags; }
@ kAll_StencilFlags

◆ singleSidedFace()

const Face & GrStencilSettings::singleSidedFace ( ) const
inline

Definition at line 84 of file GrStencilSettings.h.

84 {
85 SkASSERT(!this->isDisabled());
86 SkASSERT(!this->isTwoSided());
87 return fCWFace;
88 }

◆ usesWrapOp()

bool GrStencilSettings::usesWrapOp ( ) const
inline

Definition at line 71 of file GrStencilSettings.h.

71 { SkASSERT(this->isValid());
72 return !(fFlags & kNoWrapOps_StencilFlag); }
@ kNoWrapOps_StencilFlag

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