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 class GrOpFlushState; 16 class GrRecordingContext; 17 18 namespace skgpu::v1 { 19 20 class ClearOp final : public GrOp { 21 public: 22 DEFINE_OP_CLASS_ID 23 24 // A fullscreen or scissored clear, depending on the clip and proxy dimensions 25 static GrOp::Owner MakeColor(GrRecordingContext* context, 26 const GrScissorState& scissor, 27 std::array<float, 4> color); 28 29 static GrOp::Owner MakeStencilClip(GrRecordingContext* context, 30 const GrScissorState& scissor, 31 bool insideMask); 32 name()33 const char* name() const override { return "Clear"; } 34 color()35 const std::array<float, 4>& color() const { return fColor; } stencilInsideMask()36 bool stencilInsideMask() const { return fStencilInsideMask; } 37 private: 38 friend class GrOp; // for ctors 39 40 enum class Buffer { 41 kColor = 0b01, 42 kStencilClip = 0b10, 43 44 kBoth = 0b11, 45 }; 46 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Buffer); 47 48 ClearOp(Buffer buffer, 49 const GrScissorState& scissor, 50 std::array<float, 4> color, 51 bool stencil); 52 53 CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override; 54 onPrePrepare(GrRecordingContext *,const GrSurfaceProxyView & writeView,GrAppliedClip *,const GrDstProxyView &,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)55 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView& writeView, GrAppliedClip*, 56 const GrDstProxyView&, GrXferBarrierFlags renderPassXferBarriers, 57 GrLoadOp colorLoadOp) override {} 58 onPrepare(GrOpFlushState *)59 void onPrepare(GrOpFlushState*) override {} 60 61 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override; 62 #if GR_TEST_UTILS onDumpInfo()63 SkString onDumpInfo() const override { 64 SkString string("Scissor [ "); 65 if (fScissor.enabled()) { 66 const SkIRect& r = fScissor.rect(); 67 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom); 68 } else { 69 string.append("disabled"); 70 } 71 string.appendf("], Color: {%g, %g, %g, %g}\n", fColor[0], fColor[1], fColor[2], fColor[3]); 72 return string; 73 } 74 #endif 75 76 GrScissorState fScissor; 77 std::array<float, 4> fColor; 78 bool fStencilInsideMask; 79 Buffer fBuffer; 80 }; 81 82 GR_MAKE_BITFIELD_CLASS_OPS(ClearOp::Buffer) 83 84 } // namespace skgpu::v1 85 86 #endif // ClearOp_DEFINED 87