• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 ClearOp_DEFINED
9 #define ClearOp_DEFINED
10 
11 #include "include/gpu/GrTypes.h"
12 #include "src/gpu/GrScissorState.h"
13 #include "src/gpu/ops/GrOp.h"
14 
15 #ifdef SK_ENABLE_STENCIL_CULLING_OHOS
16 #include "src/gpu/GrOpFlushState.h"
17 #else
18 class GrOpFlushState;
19 #endif
20 
21 class GrRecordingContext;
22 
23 namespace skgpu::v1 {
24 
25 class ClearOp final : public GrOp {
26 public:
27     DEFINE_OP_CLASS_ID
28 
29     // A fullscreen or scissored clear, depending on the clip and proxy dimensions
30     static GrOp::Owner MakeColor(GrRecordingContext* context,
31                                  const GrScissorState& scissor,
32                                  std::array<float, 4> color);
33 
34     static GrOp::Owner MakeStencilClip(GrRecordingContext* context,
35                                        const GrScissorState& scissor,
36                                        bool insideMask);
37 #ifdef SK_ENABLE_STENCIL_CULLING_OHOS
38     static GrOp::Owner MakeStencil(GrRecordingContext* context,
39                                    const GrScissorState& scissor,
40                                    uint32_t stencilVal);
41 #endif
name()42     const char* name() const override { return "Clear"; }
43 
color()44     const std::array<float, 4>& color() const { return fColor; }
stencilInsideMask()45     bool stencilInsideMask() const { return fStencilInsideMask; }
46 private:
47     friend class GrOp; // for ctors
48 
49     enum class Buffer {
50         kColor       = 0b01,
51         kStencilClip = 0b10,
52 
53         kBoth        = 0b11,
54 #ifdef SK_ENABLE_STENCIL_CULLING_OHOS
55         kStencil        = 0b100,
56 #endif
57     };
58     GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Buffer);
59 
60     ClearOp(Buffer buffer,
61             const GrScissorState& scissor,
62             std::array<float, 4> color,
63             bool stencil);
64 #ifdef SK_ENABLE_STENCIL_CULLING_OHOS
65     ClearOp(Buffer buffer,
66             const GrScissorState& scissor,
67             uint32_t stencilVal,
68             bool stencil);
69 #endif
70 
71     CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override;
72 
onPrePrepare(GrRecordingContext *,const GrSurfaceProxyView & writeView,GrAppliedClip *,const GrDstProxyView &,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)73     void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView& writeView, GrAppliedClip*,
74                       const GrDstProxyView&, GrXferBarrierFlags renderPassXferBarriers,
75                       GrLoadOp colorLoadOp) override {}
76 
onPrepare(GrOpFlushState * flushState)77     void onPrepare(GrOpFlushState* flushState) override {
78 #ifdef SK_ENABLE_STENCIL_CULLING_OHOS
79         fShouldDisableStencilCulling = flushState->fDisableStencilCulling;
80 #endif
81     }
82 
83     void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
84 #if GR_TEST_UTILS
onDumpInfo()85     SkString onDumpInfo() const override {
86         SkString string("Scissor [ ");
87         if (fScissor.enabled()) {
88             const SkIRect& r = fScissor.rect();
89             string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
90         } else {
91             string.append("disabled");
92         }
93         string.appendf("], Color: {%g, %g, %g, %g}\n", fColor[0], fColor[1], fColor[2], fColor[3]);
94         return string;
95     }
96 #endif
97 
98     GrScissorState       fScissor;
99     std::array<float, 4> fColor;
100 #ifdef SK_ENABLE_STENCIL_CULLING_OHOS
101     uint32_t             fStencilVal;
102 #endif
103     bool                 fStencilInsideMask;
104     Buffer               fBuffer;
105 };
106 
107 GR_MAKE_BITFIELD_CLASS_OPS(ClearOp::Buffer)
108 
109 } // namespace skgpu::v1
110 
111 #endif // ClearOp_DEFINED
112