Debian Codegraph @

src/gpu/ganesh/StencilClip.h

raw
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
11 #include "src/gpu/ganesh/GrAppliedClip.h"
12 #include "src/gpu/ganesh/GrFixedClip.h"
13
14 namespace skgpu::ganesh {
15
16 /**
17 * Implements GrHardClip with the currently-existing stencil buffer contents and GrFixedClip.
18 */
19 class StencilClip final : public GrHardClip {
20 public:
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,
27 uint32_t stencilStackID = SK_InvalidGenID)
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
38 SkIRect getConservativeBounds() const final {
39 return fFixedClip.getConservativeBounds();
40 }
41
42 Effect apply(GrAppliedHardClip* out, SkIRect* bounds) const final {
43 Effect effect = fFixedClip.apply(out, bounds);
44 if (effect == Effect::kClippedOut) {
45 // Stencil won't bring back coverage
46 return Effect::kClippedOut;
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
63 private:
64 GrFixedClip fFixedClip;
65 uint32_t fStencilStackID;
66
67 using INHERITED = GrClip;
68 };
69
70 } // namespace skgpu::ganesh
71
72 #endif // StencilClip_DEFINED