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