blob: 09bfa1698220a745ff8617000368dc8967268516 [file] [log] [blame]
Chris Dalton133944a2018-11-16 23:30:29 -05001/*
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 Dalton82eb9e72019-03-21 14:26:39 -06008#ifndef GrFillRRectOp_DEFINED
9#define GrFillRRectOp_DEFINED
Chris Dalton133944a2018-11-16 23:30:29 -050010
Robert Phillips8053c972019-11-21 10:44:53 -050011#include "src/gpu/GrProgramInfo.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/ops/GrDrawOp.h"
Chris Dalton133944a2018-11-16 23:30:29 -050013
Robert Phillipsb97da532019-02-12 15:24:12 -050014class GrRecordingContext;
15
Chris Dalton82eb9e72019-03-21 14:26:39 -060016class GrFillRRectOp : public GrDrawOp {
Chris Dalton133944a2018-11-16 23:30:29 -050017public:
18 DEFINE_OP_CLASS_ID
19
Chris Dalton0dffbab2019-03-27 13:08:50 -060020 static std::unique_ptr<GrFillRRectOp> Make(
21 GrRecordingContext*, GrAAType, const SkMatrix& viewMatrix, const SkRRect&,
22 const GrCaps&, GrPaint&&);
Chris Dalton133944a2018-11-16 23:30:29 -050023
Robert Phillips8053c972019-11-21 10:44:53 -050024 const char* name() const final { return "GrFillRRectOp"; }
25
26 FixedFunctionFlags fixedFunctionFlags() const final {
27 return (GrAAType::kMSAA == fAAType) ? FixedFunctionFlags::kUsesHWAA
28 : FixedFunctionFlags::kNone;
Chris Dalton0dffbab2019-03-27 13:08:50 -060029 }
Chris Dalton6ce447a2019-06-23 18:07:38 -060030 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
Robert Phillips8053c972019-11-21 10:44:53 -050031 bool hasMixedSampledCoverage, GrClampType) final;
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050032 CombineResult onCombineIfPossible(GrOp*, GrRecordingContext::Arenas*, const GrCaps&) final;
Chris Dalton1706cbf2019-05-21 19:35:29 -060033 void visitProxies(const VisitProxyFunc& fn) const override {
Robert Phillips8053c972019-11-21 10:44:53 -050034 if (fProgramInfo) {
35 fProgramInfo->visitProxies(fn);
36 } else {
37 fProcessors.visitProxies(fn);
38 }
Chris Dalton133944a2018-11-16 23:30:29 -050039 }
Chris Dalton133944a2018-11-16 23:30:29 -050040
Robert Phillips8053c972019-11-21 10:44:53 -050041 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 Dalton133944a2018-11-16 23:30:29 -050047
48private:
49 enum class Flags {
50 kNone = 0,
51 kUseHWDerivatives = 1 << 0,
Chris Dalton0dffbab2019-03-27 13:08:50 -060052 kHasPerspective = 1 << 1,
53 kHasLocalCoords = 1 << 2,
54 kWideColor = 1 << 3
Chris Dalton133944a2018-11-16 23:30:29 -050055 };
56
Nico Weber52578162019-02-11 09:12:25 -050057 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags);
Chris Dalton133944a2018-11-16 23:30:29 -050058
59 class Processor;
60
Chris Dalton0dffbab2019-03-27 13:08:50 -060061 GrFillRRectOp(GrAAType, const SkRRect&, Flags, const SkMatrix& totalShapeMatrix,
62 GrPaint&&, const SkRect& devBounds);
Chris Dalton133944a2018-11-16 23:30:29 -050063
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 Dalton0dffbab2019-03-27 13:08:50 -060066 template <typename T> inline T* appendInstanceData(int count) {
Chris Dalton133944a2018-11-16 23:30:29 -050067 static_assert(std::is_pod<T>::value, "");
68 static_assert(4 == alignof(T), "");
Chris Dalton0dffbab2019-03-27 13:08:50 -060069 return reinterpret_cast<T*>(fInstanceData.push_back_n(sizeof(T) * count));
Chris Dalton133944a2018-11-16 23:30:29 -050070 }
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 Phillips8053c972019-11-21 10:44:53 -050080 // 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 Dalton0dffbab2019-03-27 13:08:50 -060087 const GrAAType fAAType;
Chris Dalton133944a2018-11-16 23:30:29 -050088 const SkPMColor4f fOriginalColor;
89 const SkRect fLocalRect;
Chris Dalton0dffbab2019-03-27 13:08:50 -060090 Flags fFlags;
Chris Dalton133944a2018-11-16 23:30:29 -050091 GrProcessorSet fProcessors;
92
93 SkSTArray<sizeof(float) * 16 * 4, char, /*MEM_MOVE=*/ true> fInstanceData;
94 int fInstanceCount = 1;
95 int fInstanceStride = 0;
96
Brian Salomon12d22642019-01-29 14:38:50 -050097 sk_sp<const GrBuffer> fInstanceBuffer;
Greg Danielf793de12019-09-05 13:23:23 -040098 sk_sp<const GrBuffer> fVertexBuffer;
99 sk_sp<const GrBuffer> fIndexBuffer;
Robert Phillips8053c972019-11-21 10:44:53 -0500100 int fBaseInstance = 0;
Greg Danielf793de12019-09-05 13:23:23 -0400101 int fIndexCount = 0;
Chris Dalton133944a2018-11-16 23:30:29 -0500102
Robert Phillips8053c972019-11-21 10:44:53 -0500103 // 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 Dalton133944a2018-11-16 23:30:29 -0500107 friend class GrOpMemoryPool;
108};
109
Chris Dalton82eb9e72019-03-21 14:26:39 -0600110GR_MAKE_BITFIELD_CLASS_OPS(GrFillRRectOp::Flags)
Chris Dalton133944a2018-11-16 23:30:29 -0500111
112#endif