blob: c3e759947a99f89ba93d8c1b06f4d7c5e4068d53 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/ops/GrDrawOp.h"
Chris Dalton133944a2018-11-16 23:30:29 -050012
Robert Phillipsb97da532019-02-12 15:24:12 -050013class GrRecordingContext;
14
Chris Dalton82eb9e72019-03-21 14:26:39 -060015class GrFillRRectOp : public GrDrawOp {
Chris Dalton133944a2018-11-16 23:30:29 -050016public:
17 DEFINE_OP_CLASS_ID
18
Chris Dalton0dffbab2019-03-27 13:08:50 -060019 static std::unique_ptr<GrFillRRectOp> Make(
20 GrRecordingContext*, GrAAType, const SkMatrix& viewMatrix, const SkRRect&,
21 const GrCaps&, GrPaint&&);
Chris Dalton133944a2018-11-16 23:30:29 -050022
Chris Dalton82eb9e72019-03-21 14:26:39 -060023 const char* name() const override { return "GrFillRRectOp"; }
Chris Dalton0dffbab2019-03-27 13:08:50 -060024 FixedFunctionFlags fixedFunctionFlags() const override {
25 return (GrAAType::kMSAA == fAAType)
26 ? FixedFunctionFlags::kUsesHWAA
27 : FixedFunctionFlags::kNone;
28 }
Chris Dalton6ce447a2019-06-23 18:07:38 -060029 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
30 bool hasMixedSampledCoverage, GrClampType) override;
Chris Dalton133944a2018-11-16 23:30:29 -050031 CombineResult onCombineIfPossible(GrOp*, const GrCaps&) override;
Chris Dalton1706cbf2019-05-21 19:35:29 -060032 void visitProxies(const VisitProxyFunc& fn) const override {
Chris Dalton133944a2018-11-16 23:30:29 -050033 fProcessors.visitProxies(fn);
34 }
35 void onPrepare(GrOpFlushState*) override;
36
37 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
38
39private:
40 enum class Flags {
41 kNone = 0,
42 kUseHWDerivatives = 1 << 0,
Chris Dalton0dffbab2019-03-27 13:08:50 -060043 kHasPerspective = 1 << 1,
44 kHasLocalCoords = 1 << 2,
45 kWideColor = 1 << 3
Chris Dalton133944a2018-11-16 23:30:29 -050046 };
47
Nico Weber52578162019-02-11 09:12:25 -050048 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags);
Chris Dalton133944a2018-11-16 23:30:29 -050049
50 class Processor;
51
Chris Dalton0dffbab2019-03-27 13:08:50 -060052 GrFillRRectOp(GrAAType, const SkRRect&, Flags, const SkMatrix& totalShapeMatrix,
53 GrPaint&&, const SkRect& devBounds);
Chris Dalton133944a2018-11-16 23:30:29 -050054
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.
Chris Dalton0dffbab2019-03-27 13:08:50 -060057 template <typename T> inline T* appendInstanceData(int count) {
Chris Dalton133944a2018-11-16 23:30:29 -050058 static_assert(std::is_pod<T>::value, "");
59 static_assert(4 == alignof(T), "");
Chris Dalton0dffbab2019-03-27 13:08:50 -060060 return reinterpret_cast<T*>(fInstanceData.push_back_n(sizeof(T) * count));
Chris Dalton133944a2018-11-16 23:30:29 -050061 }
62
63 template <typename T, typename... Args>
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
69 void writeInstanceData() {} // Halt condition.
70
Chris Dalton0dffbab2019-03-27 13:08:50 -060071 const GrAAType fAAType;
Chris Dalton133944a2018-11-16 23:30:29 -050072 const SkPMColor4f fOriginalColor;
73 const SkRect fLocalRect;
Chris Dalton0dffbab2019-03-27 13:08:50 -060074 Flags fFlags;
Chris Dalton133944a2018-11-16 23:30:29 -050075 GrProcessorSet fProcessors;
76
77 SkSTArray<sizeof(float) * 16 * 4, char, /*MEM_MOVE=*/ true> fInstanceData;
78 int fInstanceCount = 1;
79 int fInstanceStride = 0;
80
Brian Salomon12d22642019-01-29 14:38:50 -050081 sk_sp<const GrBuffer> fInstanceBuffer;
Greg Danielf793de12019-09-05 13:23:23 -040082 sk_sp<const GrBuffer> fVertexBuffer;
83 sk_sp<const GrBuffer> fIndexBuffer;
Chris Dalton133944a2018-11-16 23:30:29 -050084 int fBaseInstance;
Greg Danielf793de12019-09-05 13:23:23 -040085 int fIndexCount = 0;
Chris Dalton133944a2018-11-16 23:30:29 -050086
87 friend class GrOpMemoryPool;
88};
89
Chris Dalton82eb9e72019-03-21 14:26:39 -060090GR_MAKE_BITFIELD_CLASS_OPS(GrFillRRectOp::Flags)
Chris Dalton133944a2018-11-16 23:30:29 -050091
92#endif