Flutter Engine
The Flutter Engine
StencilClip.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 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 StencilClip_DEFINED
9#define StencilClip_DEFINED
10
13
14namespace skgpu::ganesh {
15
16/**
17 * Implements GrHardClip with the currently-existing stencil buffer contents and GrFixedClip.
18 */
19class StencilClip final : public GrHardClip {
20public:
21 explicit StencilClip(const SkISize& rtDims, uint32_t stencilStackID = SK_InvalidGenID)
22 : fFixedClip(rtDims)
23 , fStencilStackID(stencilStackID) {}
24
25 StencilClip(const SkISize& rtDims,
26 const SkIRect& scissorRect,
28 : fFixedClip(rtDims, scissorRect)
29 , fStencilStackID(stencilStackID) {}
30
31 const GrFixedClip& fixedClip() const { return fFixedClip; }
32 GrFixedClip& fixedClip() { return fFixedClip; }
33
34 uint32_t stencilStackID() const { return fStencilStackID; }
35 bool hasStencilClip() const { return SK_InvalidGenID != fStencilStackID; }
36 void setStencilClip(uint32_t stencilStackID) { fStencilStackID = stencilStackID; }
37
39 return fFixedClip.getConservativeBounds();
40 }
41
43 Effect effect = fFixedClip.apply(out, bounds);
44 if (effect == Effect::kClippedOut) {
45 // Stencil won't bring back coverage
47 }
48 if (this->hasStencilClip()) {
49 out->addStencilClip(fStencilStackID);
50 effect = Effect::kClipped;
51 }
52 return effect;
53 }
54
55 PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final {
56 if (this->hasStencilClip()) {
57 return this->INHERITED::preApply(drawBounds, aa);
58 } else {
59 return fFixedClip.preApply(drawBounds, aa);
60 }
61 }
62
63private:
64 GrFixedClip fFixedClip;
65 uint32_t fStencilStackID;
66
67 using INHERITED = GrClip;
68};
69
70} // namespace skgpu::ganesh
71
72#endif // StencilClip_DEFINED
GrAA
Definition: GrTypesPriv.h:173
static constexpr uint32_t SK_InvalidGenID
Definition: SkTypes.h:192
Definition: GrClip.h:29
virtual PreClipResult preApply(const SkRect &drawBounds, GrAA aa) const
Definition: GrClip.h:97
Effect apply(GrAppliedHardClip *, SkIRect *) const final
Definition: GrFixedClip.cpp:34
SkIRect getConservativeBounds() const final
Definition: GrFixedClip.cpp:12
PreClipResult preApply(const SkRect &drawBounds, GrAA aa) const final
Definition: GrFixedClip.cpp:16
StencilClip(const SkISize &rtDims, const SkIRect &scissorRect, uint32_t stencilStackID=SK_InvalidGenID)
Definition: StencilClip.h:25
const GrFixedClip & fixedClip() const
Definition: StencilClip.h:31
uint32_t stencilStackID() const
Definition: StencilClip.h:34
Effect apply(GrAppliedHardClip *out, SkIRect *bounds) const final
Definition: StencilClip.h:42
StencilClip(const SkISize &rtDims, uint32_t stencilStackID=SK_InvalidGenID)
Definition: StencilClip.h:21
SkIRect getConservativeBounds() const final
Definition: StencilClip.h:38
PreClipResult preApply(const SkRect &drawBounds, GrAA aa) const final
Definition: StencilClip.h:55
bool hasStencilClip() const
Definition: StencilClip.h:35
void setStencilClip(uint32_t stencilStackID)
Definition: StencilClip.h:36
GrFixedClip & fixedClip()
Definition: StencilClip.h:32
Optional< SkRect > bounds
Definition: SkRecords.h:189
Definition: SkRect.h:32
Definition: SkSize.h:16