Flutter Engine
The Flutter Engine
GrAppliedClip.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 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#ifndef GrAppliedClip_DEFINED
9#define GrAppliedClip_DEFINED
10
14
16
17
18/**
19 * Produced by GrHardClip. It provides a set of modifications to the hardware drawing state that
20 * implement the clip.
21 */
23public:
24 static const GrAppliedHardClip& Disabled() {
25 // The size doesn't really matter here since it's returned as const& so an actual scissor
26 // will never be set on it, and applied clips are not used to query or bounds test like
27 // the GrClip is.
28 static const GrAppliedHardClip kDisabled({1 << 29, 1 << 29});
29 return kDisabled;
30 }
31
32 GrAppliedHardClip(const SkISize& rtDims) : fScissorState(rtDims) {}
33 GrAppliedHardClip(const SkISize& logicalRTDims, const SkISize& backingStoreDims)
34 : fScissorState(backingStoreDims) {
35 fScissorState.set(SkIRect::MakeSize(logicalRTDims));
36 }
37
39 explicit GrAppliedHardClip(const GrAppliedHardClip&) = default;
40
41 const GrScissorState& scissorState() const { return fScissorState; }
42 const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
43 uint32_t stencilStackID() const { return fStencilStackID; }
44 bool hasStencilClip() const { return SkClipStack::kInvalidGenID != fStencilStackID; }
45
46 /**
47 * Intersects the applied clip with the provided rect. Returns false if the draw became empty.
48 * 'clippedDrawBounds' will be intersected with 'irect'. This returns false if the clip becomes
49 * empty or the draw no longer intersects the clip. In either case the draw can be skipped.
50 */
51 bool addScissor(const SkIRect& irect, SkRect* clippedDrawBounds) {
52 return fScissorState.intersect(irect) && clippedDrawBounds->intersect(SkRect::Make(irect));
53 }
54
55 void setScissor(const SkIRect& irect) {
56 fScissorState.set(irect);
57 }
58
59 void addWindowRectangles(const GrWindowRectsState& windowState) {
60 SkASSERT(!fWindowRectsState.enabled());
61 fWindowRectsState = windowState;
62 }
63
65 SkASSERT(!fWindowRectsState.enabled());
66 fWindowRectsState.set(windows, mode);
67 }
68
70 SkASSERT(SkClipStack::kInvalidGenID == fStencilStackID);
71 fStencilStackID = stencilStackID;
72 }
73
74 bool doesClip() const {
75 return fScissorState.enabled() || this->hasStencilClip() || fWindowRectsState.enabled();
76 }
77
78 bool operator==(const GrAppliedHardClip& that) const {
79 return fScissorState == that.fScissorState &&
80 fWindowRectsState == that.fWindowRectsState &&
81 fStencilStackID == that.fStencilStackID;
82 }
83 bool operator!=(const GrAppliedHardClip& that) const { return !(*this == that); }
84
85private:
86 GrScissorState fScissorState;
87 GrWindowRectsState fWindowRectsState;
88 uint32_t fStencilStackID = SkClipStack::kInvalidGenID;
89};
90
91/**
92 * Produced by GrClip. It provides a set of modifications to GrPipeline that implement the clip.
93 */
95public:
97 return GrAppliedClip({1 << 29, 1 << 29});
98 }
99
100 GrAppliedClip(const SkISize& rtDims) : fHardClip(rtDims) {}
101 GrAppliedClip(const SkISize& logicalRTDims, const SkISize& backingStoreDims)
102 : fHardClip(logicalRTDims, backingStoreDims) {}
103
104 GrAppliedClip(GrAppliedClip&& that) = default;
105 GrAppliedClip(const GrAppliedClip&) = delete;
106
107 const GrScissorState& scissorState() const { return fHardClip.scissorState(); }
108 const GrWindowRectsState& windowRectsState() const { return fHardClip.windowRectsState(); }
109 uint32_t stencilStackID() const { return fHardClip.stencilStackID(); }
110 bool hasStencilClip() const { return fHardClip.hasStencilClip(); }
111 int hasCoverageFragmentProcessor() const { return fCoverageFP != nullptr; }
113 SkASSERT(fCoverageFP != nullptr);
114 return fCoverageFP.get();
115 }
116 std::unique_ptr<GrFragmentProcessor> detachCoverageFragmentProcessor() {
117 SkASSERT(fCoverageFP != nullptr);
118 return std::move(fCoverageFP);
119 }
120
121 const GrAppliedHardClip& hardClip() const { return fHardClip; }
122 GrAppliedHardClip& hardClip() { return fHardClip; }
123
124 void addCoverageFP(std::unique_ptr<GrFragmentProcessor> fp) {
125 if (fCoverageFP == nullptr) {
126 fCoverageFP = std::move(fp);
127 } else {
128 // Compose this coverage FP with the previously-added coverage.
129 fCoverageFP = GrFragmentProcessor::Compose(std::move(fp), std::move(fCoverageFP));
130 }
131 }
132
133 bool doesClip() const {
134 return fHardClip.doesClip() || fCoverageFP != nullptr;
135 }
136
137 bool operator==(const GrAppliedClip& that) const {
138 if (fHardClip != that.fHardClip ||
139 this->hasCoverageFragmentProcessor() != that.hasCoverageFragmentProcessor()) {
140 return false;
141 }
142 if (fCoverageFP != nullptr && !fCoverageFP->isEqual(*that.fCoverageFP)) {
143 return false;
144 }
145 return true;
146 }
147 bool operator!=(const GrAppliedClip& that) const { return !(*this == that); }
148
149 void visitProxies(const GrVisitProxyFunc& func) const {
150 if (fCoverageFP != nullptr) {
151 fCoverageFP->visitProxies(func);
152 }
153 }
154
155private:
156 GrAppliedHardClip fHardClip;
157 std::unique_ptr<GrFragmentProcessor> fCoverageFP;
158};
159
160#endif
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
Definition: GrTypesPriv.h:943
#define SkASSERT(cond)
Definition: SkAssert.h:116
const GrAppliedHardClip & hardClip() const
std::unique_ptr< GrFragmentProcessor > detachCoverageFragmentProcessor()
static GrAppliedClip Disabled()
Definition: GrAppliedClip.h:96
const GrWindowRectsState & windowRectsState() const
uint32_t stencilStackID() const
void visitProxies(const GrVisitProxyFunc &func) const
GrAppliedClip(const GrAppliedClip &)=delete
GrAppliedClip(const SkISize &rtDims)
bool hasStencilClip() const
GrAppliedHardClip & hardClip()
bool operator==(const GrAppliedClip &that) const
const GrFragmentProcessor * coverageFragmentProcessor() const
bool operator!=(const GrAppliedClip &that) const
const GrScissorState & scissorState() const
GrAppliedClip(const SkISize &logicalRTDims, const SkISize &backingStoreDims)
GrAppliedClip(GrAppliedClip &&that)=default
int hasCoverageFragmentProcessor() const
bool doesClip() const
void addCoverageFP(std::unique_ptr< GrFragmentProcessor > fp)
void setScissor(const SkIRect &irect)
Definition: GrAppliedClip.h:55
bool addScissor(const SkIRect &irect, SkRect *clippedDrawBounds)
Definition: GrAppliedClip.h:51
bool operator!=(const GrAppliedHardClip &that) const
Definition: GrAppliedClip.h:83
bool doesClip() const
Definition: GrAppliedClip.h:74
void addWindowRectangles(const GrWindowRectsState &windowState)
Definition: GrAppliedClip.h:59
static const GrAppliedHardClip & Disabled()
Definition: GrAppliedClip.h:24
const GrScissorState & scissorState() const
Definition: GrAppliedClip.h:41
bool hasStencilClip() const
Definition: GrAppliedClip.h:44
bool operator==(const GrAppliedHardClip &that) const
Definition: GrAppliedClip.h:78
void addWindowRectangles(const GrWindowRectangles &windows, GrWindowRectsState::Mode mode)
Definition: GrAppliedClip.h:64
GrAppliedHardClip(const SkISize &logicalRTDims, const SkISize &backingStoreDims)
Definition: GrAppliedClip.h:33
GrAppliedHardClip(const SkISize &rtDims)
Definition: GrAppliedClip.h:32
GrAppliedHardClip(GrAppliedHardClip &&that)=default
GrAppliedHardClip(const GrAppliedHardClip &)=default
const GrWindowRectsState & windowRectsState() const
Definition: GrAppliedClip.h:42
uint32_t stencilStackID() const
Definition: GrAppliedClip.h:43
void addStencilClip(uint32_t stencilStackID)
Definition: GrAppliedClip.h:69
static std::unique_ptr< GrFragmentProcessor > Compose(std::unique_ptr< GrFragmentProcessor > f, std::unique_ptr< GrFragmentProcessor > g)
bool enabled() const
bool set(const SkIRect &rect)
bool intersect(const SkIRect &rect)
void set(const GrWindowRectangles &windows, Mode mode)
static const uint32_t kInvalidGenID
Definition: SkClipStack.h:383
const uint32_t fp
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
Definition: SkRect.h:32
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66
Definition: SkSize.h:16
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
bool intersect(const SkRect &r)
Definition: SkRect.cpp:114