blob: 5d80cfa1a7cf3fea5000588f04970abb55581af7 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
Robert Phillipsf2361d22016-10-25 14:20:06 -04008#ifndef GrRenderTargetOpList_DEFINED
9#define GrRenderTargetOpList_DEFINED
reed@google.comac10a2d2010-12-22 21:39:39 +000010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkMatrix.h"
12#include "include/core/SkStrokeRec.h"
13#include "include/core/SkTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/private/SkTArray.h"
Ben Wagner729a23f2019-05-17 16:29:34 -040015#include "src/core/SkArenaAlloc.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/core/SkClipStack.h"
17#include "src/core/SkStringUtils.h"
18#include "src/core/SkTLazy.h"
19#include "src/gpu/GrAppliedClip.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040020#include "src/gpu/GrOpList.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/gpu/GrPathRendering.h"
22#include "src/gpu/GrPrimitiveProcessor.h"
23#include "src/gpu/ops/GrDrawOp.h"
24#include "src/gpu/ops/GrOp.h"
Scroggo97c88c22011-05-11 14:05:25 +000025
joshualitt086cee12016-01-12 06:45:24 -080026class GrAuditTrail;
Brian Salomon7dae46a2016-12-14 16:21:37 -050027class GrClearOp;
bsalomon4b91f762015-05-19 09:29:46 -070028class GrCaps;
Robert Phillipsc7635fa2016-10-28 13:25:24 -040029class GrRenderTargetProxy;
sugoi@google.com12b4e272012-12-06 20:13:11 +000030
Robert Phillipsf2361d22016-10-25 14:20:06 -040031class GrRenderTargetOpList final : public GrOpList {
Brian Salomon54d212e2017-03-21 14:22:38 -040032private:
Robert Phillipsbb581ce2017-05-29 15:05:15 -040033 using DstProxy = GrXferProcessor::DstProxy;
Brian Salomon54d212e2017-03-21 14:22:38 -040034
bsalomon@google.comf6601872012-08-28 21:11:35 +000035public:
Robert Phillips12c46292019-04-23 07:36:17 -040036 GrRenderTargetOpList(sk_sp<GrOpMemoryPool>, sk_sp<GrRenderTargetProxy>, GrAuditTrail*);
bsalomona73239a2015-04-28 13:35:17 -070037
Robert Phillipsf2361d22016-10-25 14:20:06 -040038 ~GrRenderTargetOpList() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000039
Robert Phillipsee683652017-04-26 11:53:10 -040040 void makeClosed(const GrCaps& caps) override {
Robert Phillipsf5442bb2017-04-17 14:18:34 -040041 if (this->isClosed()) {
42 return;
43 }
Robert Phillipsf2361d22016-10-25 14:20:06 -040044
Robert Phillipsee683652017-04-26 11:53:10 -040045 this->forwardCombine(caps);
Robert Phillipsf5442bb2017-04-17 14:18:34 -040046
Robert Phillipsee683652017-04-26 11:53:10 -040047 INHERITED::makeClosed(caps);
robertphillipsa106c622015-10-16 09:07:06 -070048 }
bsalomonaecc0182016-03-07 11:50:44 -080049
Brian Salomon588cec72018-11-14 13:56:37 -050050 bool isEmpty() const { return fOpChains.empty(); }
Robert Phillipsf5442bb2017-04-17 14:18:34 -040051
reed@google.comac10a2d2010-12-22 21:39:39 +000052 /**
bsalomona73239a2015-04-28 13:35:17 -070053 * Empties the draw buffer of any queued up draws.
54 */
Chris Daltona84cacf2017-10-04 10:30:29 -060055 void endFlush() override;
Robert Phillipsf2361d22016-10-25 14:20:06 -040056
bsalomona73239a2015-04-28 13:35:17 -070057 /**
bsalomondc438982016-08-31 11:53:49 -070058 * Together these two functions flush all queued up draws to GrCommandBuffer. The return value
Brian Salomon1e41f4a2016-12-07 15:05:04 -050059 * of executeOps() indicates whether any commands were actually issued to the GPU.
bsalomona73239a2015-04-28 13:35:17 -070060 */
Brian Osman407b3422017-08-22 15:01:32 -040061 void onPrepare(GrOpFlushState* flushState) override;
62 bool onExecute(GrOpFlushState* flushState) override;
bsalomona73239a2015-04-28 13:35:17 -070063
Chris Dalton08755122019-08-05 16:13:47 -060064 void addOp(std::unique_ptr<GrOp> op, GrTextureResolveManager textureResolveManager,
65 const GrCaps& caps) {
66 auto addDependency = [ textureResolveManager, &caps, this ] (
67 GrSurfaceProxy* p, GrMipMapped mipmapped) {
68 this->addDependency(p, mipmapped, textureResolveManager, caps);
Robert Phillipsb493eeb2017-09-13 13:10:52 -040069 };
70
71 op->visitProxies(addDependency);
72
Chris Dalton945ee652019-01-23 09:10:36 -070073 this->recordOp(std::move(op), GrProcessorSet::EmptySetAnalysis(), nullptr, nullptr, caps);
Brian Salomon54d212e2017-03-21 14:22:38 -040074 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -040075
Chris Dalton08755122019-08-05 16:13:47 -060076 void addWaitOp(std::unique_ptr<GrOp> op, GrTextureResolveManager textureResolveManager,
77 const GrCaps& caps) {
78 fHasWaitOp = true;
79 this->addOp(std::move(op), textureResolveManager, caps);
Greg Danielcb324152019-02-25 11:36:53 -050080 }
81
Chris Dalton945ee652019-01-23 09:10:36 -070082 void addDrawOp(std::unique_ptr<GrDrawOp> op, const GrProcessorSet::Analysis& processorAnalysis,
Chris Dalton08755122019-08-05 16:13:47 -060083 GrAppliedClip&& clip, const DstProxy& dstProxy,
84 GrTextureResolveManager textureResolveManager, const GrCaps& caps) {
85 auto addDependency = [ textureResolveManager, &caps, this ] (
86 GrSurfaceProxy* p, GrMipMapped mipmapped) {
87 this->addDependency(p, mipmapped, textureResolveManager, caps);
Robert Phillipsb493eeb2017-09-13 13:10:52 -040088 };
89
90 op->visitProxies(addDependency);
91 clip.visitProxies(addDependency);
Robert Phillips2739ab02018-07-27 07:35:55 -040092 if (dstProxy.proxy()) {
Chris Dalton7eb5c0f2019-05-23 15:15:47 -060093 addDependency(dstProxy.proxy(), GrMipMapped::kNo);
Robert Phillips2739ab02018-07-27 07:35:55 -040094 }
Robert Phillipsb493eeb2017-09-13 13:10:52 -040095
Chris Dalton945ee652019-01-23 09:10:36 -070096 this->recordOp(std::move(op), processorAnalysis, clip.doesClip() ? &clip : nullptr,
97 &dstProxy, caps);
Brian Salomon69868af2016-12-22 15:42:51 -050098 }
robertphillips9199a9f2016-07-13 07:48:43 -070099
Robert Phillips380b90c2017-08-30 07:41:07 -0400100 void discard();
101
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500102 bool copySurface(GrRecordingContext*,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400103 GrSurfaceProxy* src,
bsalomonf90a02b2014-11-26 12:28:00 -0800104 const SkIRect& srcRect,
Robert Phillips2de8cfa2017-06-28 10:33:41 -0400105 const SkIPoint& dstPoint) override;
robertphillips@google.comff175842012-05-14 19:31:39 +0000106
Brian Salomon4d2d6f42019-07-26 14:15:11 -0400107 void transferFrom(GrRecordingContext*,
108 const SkIRect& srcRect,
Brian Salomonf77c1462019-08-01 15:19:29 -0400109 GrColorType surfaceColorType,
Brian Salomon4d2d6f42019-07-26 14:15:11 -0400110 GrColorType dstColorType,
111 sk_sp<GrGpuBuffer> dst,
112 size_t dstOffset) override;
113
Brian Osman45580d32016-11-23 09:37:01 -0500114 GrRenderTargetOpList* asRenderTargetOpList() override { return this; }
115
Robert Phillips27483912018-04-20 12:43:18 -0400116 SkDEBUGCODE(void dump(bool printDependencies) const override;)
Robert Phillipsc84c0302017-05-08 15:35:11 -0400117 SkDEBUGCODE(int numClips() const override { return fNumClips; })
Chris Dalton706a6ff2017-11-29 22:01:06 -0700118 SkDEBUGCODE(void visitProxies_debugOnly(const GrOp::VisitProxyFunc&) const;)
Robert Phillipsc84c0302017-05-08 15:35:11 -0400119
Brian Salomon13540482018-07-09 10:31:47 -0400120private:
Brian Salomonc3833b42018-07-09 18:23:58 +0000121 friend class GrRenderTargetContextPriv; // for stencil clip state. TODO: this is invasive
122
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500123 // The RTC and RTOpList have to work together to handle buffer clears. In most cases, buffer
124 // clearing can be done natively, in which case the op list's load ops are sufficient. In other
125 // cases, draw ops must be used, which makes the RTC the best place for those decisions. This,
126 // however, requires that the RTC be able to coordinate with the op list to achieve similar ends
127 friend class GrRenderTargetContext;
128
Robert Phillips9313aa72019-04-09 18:41:27 -0400129 bool onIsUsed(GrSurfaceProxy*) const override;
130
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000131 // Must only be called if native stencil buffer clearing is enabled
Chris Dalton6b982802019-06-27 13:53:46 -0600132 void setStencilLoadOp(GrLoadOp op) { fStencilLoadOp = op; }
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500133 // Must only be called if native color buffer clearing is enabled.
134 void setColorLoadOp(GrLoadOp op, const SkPMColor4f& color);
135 // Sets the clear color to transparent black
136 void setColorLoadOp(GrLoadOp op) {
137 static const SkPMColor4f kDefaultClearColor = {0.f, 0.f, 0.f, 0.f};
138 this->setColorLoadOp(op, kDefaultClearColor);
139 }
140
Chris Dalton6b982802019-06-27 13:53:46 -0600141 enum class CanDiscardPreviousOps : bool {
142 kYes = true,
143 kNo = false
144 };
145
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500146 // Perform book-keeping for a fullscreen clear, regardless of how the clear is implemented later
147 // (i.e. setColorLoadOp(), adding a ClearOp, or adding a GrFillRectOp that covers the device).
148 // Returns true if the clear can be converted into a load op (barring device caps).
Chris Dalton6b982802019-06-27 13:53:46 -0600149 bool resetForFullscreenClear(CanDiscardPreviousOps);
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500150
Robert Phillipsc994a932018-06-19 13:09:54 -0400151 void deleteOps();
152
Brian Salomon588cec72018-11-14 13:56:37 -0500153 class OpChain {
154 public:
155 OpChain(const OpChain&) = delete;
156 OpChain& operator=(const OpChain&) = delete;
Chris Dalton945ee652019-01-23 09:10:36 -0700157 OpChain(std::unique_ptr<GrOp>, GrProcessorSet::Analysis, GrAppliedClip*, const DstProxy*);
Brian Salomon588cec72018-11-14 13:56:37 -0500158
159 ~OpChain() {
160 // The ops are stored in a GrMemoryPool and must be explicitly deleted via the pool.
161 SkASSERT(fList.empty());
Brian Salomon54d212e2017-03-21 14:22:38 -0400162 }
Chris Dalton8816b932017-11-29 16:48:25 -0700163
Chris Dalton1706cbf2019-05-21 19:35:29 -0600164 void visitProxies(const GrOp::VisitProxyFunc&) const;
Robert Phillipsc994a932018-06-19 13:09:54 -0400165
Brian Salomon588cec72018-11-14 13:56:37 -0500166 GrOp* head() const { return fList.head(); }
Robert Phillips7c525e62018-06-12 10:11:12 -0400167
Brian Salomon588cec72018-11-14 13:56:37 -0500168 GrAppliedClip* appliedClip() const { return fAppliedClip; }
169 const DstProxy& dstProxy() const { return fDstProxy; }
170 const SkRect& bounds() const { return fBounds; }
Chris Dalton8816b932017-11-29 16:48:25 -0700171
Brian Salomon588cec72018-11-14 13:56:37 -0500172 // Deletes all the ops in the chain via the pool.
173 void deleteOps(GrOpMemoryPool* pool);
174
175 // Attempts to move the ops from the passed chain to this chain at the head. Also attempts
176 // to merge ops between the chains. Upon success the passed chain is empty.
177 // Fails when the chains aren't of the same op type, have different clips or dst proxies.
178 bool prependChain(OpChain*, const GrCaps&, GrOpMemoryPool*, GrAuditTrail*);
179
180 // Attempts to add 'op' to this chain either by merging or adding to the tail. Returns
181 // 'op' to the caller upon failure, otherwise null. Fails when the op and chain aren't of
182 // the same op type, have different clips or dst proxies.
Chris Dalton945ee652019-01-23 09:10:36 -0700183 std::unique_ptr<GrOp> appendOp(std::unique_ptr<GrOp> op, GrProcessorSet::Analysis,
184 const DstProxy*, const GrAppliedClip*, const GrCaps&,
185 GrOpMemoryPool*, GrAuditTrail*);
Brian Salomon588cec72018-11-14 13:56:37 -0500186
187 private:
188 class List {
189 public:
190 List() = default;
191 List(std::unique_ptr<GrOp>);
192 List(List&&);
193 List& operator=(List&& that);
194
195 bool empty() const { return !SkToBool(fHead); }
196 GrOp* head() const { return fHead.get(); }
197 GrOp* tail() const { return fTail; }
198
199 std::unique_ptr<GrOp> popHead();
200 std::unique_ptr<GrOp> removeOp(GrOp* op);
201 void pushHead(std::unique_ptr<GrOp> op);
202 void pushTail(std::unique_ptr<GrOp>);
203
204 void validate() const;
205
206 private:
207 std::unique_ptr<GrOp> fHead;
208 GrOp* fTail = nullptr;
209 };
210
211 void validate() const;
212
Chris Dalton945ee652019-01-23 09:10:36 -0700213 bool tryConcat(List*, GrProcessorSet::Analysis, const DstProxy&, const GrAppliedClip*,
214 const SkRect& bounds, const GrCaps&, GrOpMemoryPool*, GrAuditTrail*);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700215 static List DoConcat(List, List, const GrCaps&, GrOpMemoryPool*, GrAuditTrail*);
Brian Salomon588cec72018-11-14 13:56:37 -0500216
217 List fList;
Chris Dalton945ee652019-01-23 09:10:36 -0700218 GrProcessorSet::Analysis fProcessorAnalysis;
Brian Salomon588cec72018-11-14 13:56:37 -0500219 DstProxy fDstProxy;
220 GrAppliedClip* fAppliedClip;
221 SkRect fBounds;
Brian Salomon54d212e2017-03-21 14:22:38 -0400222 };
223
Chris Dalton6b498102019-08-01 14:14:52 -0600224 void handleInternalAllocationFailure() override;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500225
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400226 void gatherProxyIntervals(GrResourceAllocator*) const override;
227
Chris Dalton945ee652019-01-23 09:10:36 -0700228 void recordOp(std::unique_ptr<GrOp>, GrProcessorSet::Analysis, GrAppliedClip*, const DstProxy*,
229 const GrCaps& caps);
Brian Salomon2790c522016-12-09 16:32:23 -0500230
Robert Phillipsee683652017-04-26 11:53:10 -0400231 void forwardCombine(const GrCaps&);
bsalomonad792c12015-09-10 11:10:50 -0700232
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000233 uint32_t fLastClipStackGenID;
234 SkIRect fLastDevClipBounds;
235 int fLastClipNumAnalyticFPs;
csmartdalton7cdda992016-11-01 07:03:03 -0700236
Greg Danielcb324152019-02-25 11:36:53 -0500237 // We must track if we have a wait op so that we don't delete the op when we have a full clear.
238 bool fHasWaitOp = false;;
239
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400240 // For ops/opList we have mean: 5 stdDev: 28
Brian Salomon588cec72018-11-14 13:56:37 -0500241 SkSTArray<25, OpChain, true> fOpChains;
Brian Salomon54d212e2017-03-21 14:22:38 -0400242
Robert Phillipsf6d7eb12017-04-26 14:55:34 -0400243 // MDB TODO: 4096 for the first allocation of the clip space will be huge overkill.
244 // Gather statistics to determine the correct size.
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000245 SkArenaAlloc fClipAllocator{4096};
246 SkDEBUGCODE(int fNumClips;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400247
Robert Phillipsf2361d22016-10-25 14:20:06 -0400248 typedef GrOpList INHERITED;
joshualitt6db519c2014-10-29 08:48:18 -0700249};
250
reed@google.comac10a2d2010-12-22 21:39:39 +0000251#endif