1 /* 2 * Copyright 2018 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 GrFillRRectOp_DEFINED 9 #define GrFillRRectOp_DEFINED 10 11 #include "src/gpu/ops/GrDrawOp.h" 12 13 class GrRecordingContext; 14 15 class GrFillRRectOp : public GrDrawOp { 16 public: 17 DEFINE_OP_CLASS_ID 18 19 static std::unique_ptr<GrFillRRectOp> Make( 20 GrRecordingContext*, GrAAType, const SkMatrix& viewMatrix, const SkRRect&, 21 const GrCaps&, GrPaint&&); 22 name()23 const char* name() const override { return "GrFillRRectOp"; } fixedFunctionFlags()24 FixedFunctionFlags fixedFunctionFlags() const override { 25 return (GrAAType::kMSAA == fAAType) 26 ? FixedFunctionFlags::kUsesHWAA 27 : FixedFunctionFlags::kNone; 28 } 29 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, 30 bool hasMixedSampledCoverage, GrClampType) override; 31 CombineResult onCombineIfPossible(GrOp*, const GrCaps&) override; visitProxies(const VisitProxyFunc & fn)32 void visitProxies(const VisitProxyFunc& fn) const override { 33 fProcessors.visitProxies(fn); 34 } 35 void onPrepare(GrOpFlushState*) override; 36 37 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; 38 39 private: 40 enum class Flags { 41 kNone = 0, 42 kUseHWDerivatives = 1 << 0, 43 kHasPerspective = 1 << 1, 44 kHasLocalCoords = 1 << 2, 45 kWideColor = 1 << 3 46 }; 47 48 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags); 49 50 class Processor; 51 52 GrFillRRectOp(GrAAType, const SkRRect&, Flags, const SkMatrix& totalShapeMatrix, 53 GrPaint&&, const SkRect& devBounds); 54 55 // These methods are used to append data of various POD types to our internal array of instance 56 // data. The actual layout of the instance buffer can vary from Op to Op. appendInstanceData(int count)57 template <typename T> inline T* appendInstanceData(int count) { 58 static_assert(std::is_pod<T>::value, ""); 59 static_assert(4 == alignof(T), ""); 60 return reinterpret_cast<T*>(fInstanceData.push_back_n(sizeof(T) * count)); 61 } 62 63 template <typename T, typename... Args> writeInstanceData(const T & val,const Args &...remainder)64 inline void writeInstanceData(const T& val, const Args&... remainder) { 65 memcpy(this->appendInstanceData<T>(1), &val, sizeof(T)); 66 this->writeInstanceData(remainder...); 67 } 68 writeInstanceData()69 void writeInstanceData() {} // Halt condition. 70 71 const GrAAType fAAType; 72 const SkPMColor4f fOriginalColor; 73 const SkRect fLocalRect; 74 Flags fFlags; 75 GrProcessorSet fProcessors; 76 77 SkSTArray<sizeof(float) * 16 * 4, char, /*MEM_MOVE=*/ true> fInstanceData; 78 int fInstanceCount = 1; 79 int fInstanceStride = 0; 80 81 sk_sp<const GrBuffer> fInstanceBuffer; 82 int fBaseInstance; 83 84 friend class GrOpMemoryPool; 85 }; 86 87 GR_MAKE_BITFIELD_CLASS_OPS(GrFillRRectOp::Flags) 88 89 #endif 90