Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 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 | |
Chris Dalton | 82eb9e7 | 2019-03-21 14:26:39 -0600 | [diff] [blame] | 8 | #ifndef GrFillRRectOp_DEFINED |
| 9 | #define GrFillRRectOp_DEFINED |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 10 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrProgramInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/ops/GrDrawOp.h" |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 13 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 14 | class GrRecordingContext; |
| 15 | |
Chris Dalton | 82eb9e7 | 2019-03-21 14:26:39 -0600 | [diff] [blame] | 16 | class GrFillRRectOp : public GrDrawOp { |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 17 | public: |
| 18 | DEFINE_OP_CLASS_ID |
| 19 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 20 | static std::unique_ptr<GrFillRRectOp> Make( |
| 21 | GrRecordingContext*, GrAAType, const SkMatrix& viewMatrix, const SkRRect&, |
| 22 | const GrCaps&, GrPaint&&); |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 23 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 24 | const char* name() const final { return "GrFillRRectOp"; } |
| 25 | |
| 26 | FixedFunctionFlags fixedFunctionFlags() const final { |
| 27 | return (GrAAType::kMSAA == fAAType) ? FixedFunctionFlags::kUsesHWAA |
| 28 | : FixedFunctionFlags::kNone; |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 29 | } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 30 | GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 31 | bool hasMixedSampledCoverage, GrClampType) final; |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 32 | CombineResult onCombineIfPossible(GrOp*, GrRecordingContext::Arenas*, const GrCaps&) final; |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 33 | void visitProxies(const VisitProxyFunc& fn) const override { |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 34 | if (fProgramInfo) { |
| 35 | fProgramInfo->visitProxies(fn); |
| 36 | } else { |
| 37 | fProcessors.visitProxies(fn); |
| 38 | } |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 39 | } |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 40 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 41 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView*, GrAppliedClip*, |
| 42 | const GrXferProcessor::DstProxyView&) final; |
| 43 | |
| 44 | void onPrepare(GrOpFlushState*) final; |
| 45 | |
| 46 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) final; |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | enum class Flags { |
| 50 | kNone = 0, |
| 51 | kUseHWDerivatives = 1 << 0, |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 52 | kHasPerspective = 1 << 1, |
| 53 | kHasLocalCoords = 1 << 2, |
| 54 | kWideColor = 1 << 3 |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 55 | }; |
| 56 | |
Nico Weber | 5257816 | 2019-02-11 09:12:25 -0500 | [diff] [blame] | 57 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags); |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 58 | |
| 59 | class Processor; |
| 60 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 61 | GrFillRRectOp(GrAAType, const SkRRect&, Flags, const SkMatrix& totalShapeMatrix, |
| 62 | GrPaint&&, const SkRect& devBounds); |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 63 | |
| 64 | // These methods are used to append data of various POD types to our internal array of instance |
| 65 | // data. The actual layout of the instance buffer can vary from Op to Op. |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 66 | template <typename T> inline T* appendInstanceData(int count) { |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 67 | static_assert(std::is_pod<T>::value, ""); |
| 68 | static_assert(4 == alignof(T), ""); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 69 | return reinterpret_cast<T*>(fInstanceData.push_back_n(sizeof(T) * count)); |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | template <typename T, typename... Args> |
| 73 | inline void writeInstanceData(const T& val, const Args&... remainder) { |
| 74 | memcpy(this->appendInstanceData<T>(1), &val, sizeof(T)); |
| 75 | this->writeInstanceData(remainder...); |
| 76 | } |
| 77 | |
| 78 | void writeInstanceData() {} // Halt condition. |
| 79 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 80 | // Create a GrProgramInfo object in the provided arena |
| 81 | GrProgramInfo* createProgramInfo(const GrCaps*, |
| 82 | SkArenaAlloc*, |
| 83 | const GrSurfaceProxyView* dstView, |
| 84 | GrAppliedClip&&, |
| 85 | const GrXferProcessor::DstProxyView&); |
| 86 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 87 | const GrAAType fAAType; |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 88 | const SkPMColor4f fOriginalColor; |
| 89 | const SkRect fLocalRect; |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 90 | Flags fFlags; |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 91 | GrProcessorSet fProcessors; |
| 92 | |
| 93 | SkSTArray<sizeof(float) * 16 * 4, char, /*MEM_MOVE=*/ true> fInstanceData; |
| 94 | int fInstanceCount = 1; |
| 95 | int fInstanceStride = 0; |
| 96 | |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 97 | sk_sp<const GrBuffer> fInstanceBuffer; |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 98 | sk_sp<const GrBuffer> fVertexBuffer; |
| 99 | sk_sp<const GrBuffer> fIndexBuffer; |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 100 | int fBaseInstance = 0; |
Greg Daniel | f793de1 | 2019-09-05 13:23:23 -0400 | [diff] [blame] | 101 | int fIndexCount = 0; |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 102 | |
Robert Phillips | 8053c97 | 2019-11-21 10:44:53 -0500 | [diff] [blame] | 103 | // If this op is prePrepared the created programInfo will be stored here from use in |
| 104 | // onExecute. In the prePrepared case it will have been stored in the record-time arena. |
| 105 | GrProgramInfo* fProgramInfo = nullptr; |
| 106 | |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 107 | friend class GrOpMemoryPool; |
| 108 | }; |
| 109 | |
Chris Dalton | 82eb9e7 | 2019-03-21 14:26:39 -0600 | [diff] [blame] | 110 | GR_MAKE_BITFIELD_CLASS_OPS(GrFillRRectOp::Flags) |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 111 | |
| 112 | #endif |