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 GrDrawOp_DEFINED 9 #define GrDrawOp_DEFINED 10 11 #include <functional> 12 #include "src/core/SkAAClip.h" 13 #include "src/core/SkIPoint16.h" 14 #include "src/gpu/ganesh/GrDeferredUpload.h" 15 #include "src/gpu/ganesh/GrPipeline.h" 16 #include "src/gpu/ganesh/ops/GrOp.h" 17 18 class GrAppliedClip; 19 namespace skgpu { namespace v1 { class SurfaceDrawContext; }} 20 class GrShape; 21 22 /** 23 * Base class for GrOps that draw. These ops can draw into an op list's GrRenderTarget. 24 */ 25 class GrDrawOp : public GrOp { 26 public: GrDrawOp(uint32_t classID)27 GrDrawOp(uint32_t classID) : INHERITED(classID) {} 28 29 /** 30 * Called before setting up the GrAppliedClip and before finalize. This information is required 31 * to determine how to compute a GrAppliedClip from a GrClip for this op. 32 */ usesMSAA()33 virtual bool usesMSAA() const { 34 return this->fixedFunctionFlags() & FixedFunctionFlags::kUsesHWAA; 35 } 36 37 /** 38 * Specifies the effect of clipToShape(). 39 */ 40 enum class ClipResult { 41 // No clip was applied. 42 kFail, 43 // The clip was applied to the op's actual geometry. The clip stack is free to disable the 44 // scissor test. 45 kClippedGeometrically, 46 // The clip was applied via shader coverage. The clip stack will still use a scissor test 47 // in order to reduce overdraw of transparent pixels. 48 kClippedInShader, 49 // The op can be thrown out entirely. 50 kClippedOut 51 }; 52 53 /** 54 * This is called while the clip is being computed, before finalize(), and before any attempts 55 * to combine with other ops. If the op knows how to clip its own geometry then it will 56 * generally be much faster than a generalized clip method. 57 */ clipToShape(skgpu::v1::SurfaceDrawContext *,SkClipOp,const SkMatrix &,const GrShape &,GrAA)58 virtual ClipResult clipToShape(skgpu::v1::SurfaceDrawContext*, 59 SkClipOp, 60 const SkMatrix& /* clipMatrix */, 61 const GrShape&, 62 GrAA) { 63 return ClipResult::kFail; 64 } 65 66 /** 67 * This is called after the GrAppliedClip has been computed and just prior to recording the op 68 * or combining it with a previously recorded op. The op should convert any proxies or resources 69 * it owns to "pending io" status so that resource allocation can be more optimal. Additionally, 70 * at this time the op must report whether a copy of the destination (or destination texture 71 * itself) needs to be provided to the GrXferProcessor when this op executes. 72 */ 73 virtual GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) = 0; 74 75 /** 76 * Called after finalize, at which point every op should know whether it will need stencil. 77 */ usesStencil()78 virtual bool usesStencil() const { 79 return this->fixedFunctionFlags() & FixedFunctionFlags::kUsesStencil; 80 } 81 82 #ifdef SK_DEBUG 83 bool fAddDrawOpCalled = false; 84 validate()85 void validate() const override { 86 SkASSERT(fAddDrawOpCalled); 87 } 88 #endif 89 90 #if GR_TEST_UTILS 91 // This is really only intended for TextureOp and FillRectOp to override numQuads()92 virtual int numQuads() const { return -1; } 93 #endif 94 95 protected: 96 /** 97 * DEPRECATED: This is a legacy implementation for usesMSAA() and usesStencil(). Newer ops 98 * should override those methods directly. 99 */ 100 enum class FixedFunctionFlags : uint32_t { 101 kNone = 0x0, 102 /** Indices that the op will enable MSAA. */ 103 kUsesHWAA = 0x1, 104 /** Indices that the op reads and/or writes the stencil buffer */ 105 kUsesStencil = 0x2, 106 }; 107 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(FixedFunctionFlags); fixedFunctionFlags()108 virtual FixedFunctionFlags fixedFunctionFlags() const { 109 // Override usesMSAA() and usesStencil() instead. 110 SK_ABORT("fixedFunctionFlags() not implemented."); 111 } 112 113 private: 114 friend class GrSimpleMeshDrawOpHelper; // For FixedFunctionFlags. 115 friend class GrSimpleMeshDrawOpHelperWithStencil; // For FixedFunctionFlags. 116 117 using INHERITED = GrOp; 118 }; 119 120 GR_MAKE_BITFIELD_CLASS_OPS(GrDrawOp::FixedFunctionFlags) 121 122 #endif 123