blob: 3fd6d856fdf5337ead782f6ac4211e2102f43ceb [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/private/GrRecordingContext.h"
9#include "src/core/SkExchange.h"
10#include "src/core/SkRectPriv.h"
11#include "src/core/SkTraceEvent.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrCaps.h"
14#include "src/gpu/GrGpu.h"
15#include "src/gpu/GrGpuCommandBuffer.h"
16#include "src/gpu/GrMemoryPool.h"
17#include "src/gpu/GrRecordingContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrRenderTargetContext.h"
19#include "src/gpu/GrRenderTargetOpList.h"
20#include "src/gpu/GrResourceAllocator.h"
Michael Ludwig663afe52019-06-03 16:46:19 -040021#include "src/gpu/geometry/GrRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/gpu/ops/GrClearOp.h"
23#include "src/gpu/ops/GrCopySurfaceOp.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040024
reed@google.comac10a2d2010-12-22 21:39:39 +000025////////////////////////////////////////////////////////////////////////////////
26
Brian Salomon09d994e2016-12-21 11:14:46 -050027// Experimentally we have found that most combining occurs within the first 10 comparisons.
Brian Salomon588cec72018-11-14 13:56:37 -050028static const int kMaxOpMergeDistance = 10;
29static const int kMaxOpChainDistance = 10;
30
31////////////////////////////////////////////////////////////////////////////////
32
33using DstProxy = GrXferProcessor::DstProxy;
34
35////////////////////////////////////////////////////////////////////////////////
36
37static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
38
39////////////////////////////////////////////////////////////////////////////////
40
41inline GrRenderTargetOpList::OpChain::List::List(std::unique_ptr<GrOp> op)
42 : fHead(std::move(op)), fTail(fHead.get()) {
43 this->validate();
44}
45
46inline GrRenderTargetOpList::OpChain::List::List(List&& that) { *this = std::move(that); }
47
48inline GrRenderTargetOpList::OpChain::List& GrRenderTargetOpList::OpChain::List::operator=(
49 List&& that) {
50 fHead = std::move(that.fHead);
51 fTail = that.fTail;
52 that.fTail = nullptr;
53 this->validate();
54 return *this;
55}
56
57inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::popHead() {
58 SkASSERT(fHead);
59 auto temp = fHead->cutChain();
60 std::swap(temp, fHead);
61 if (!fHead) {
62 SkASSERT(fTail == temp.get());
63 fTail = nullptr;
64 }
65 return temp;
66}
67
68inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::removeOp(GrOp* op) {
69#ifdef SK_DEBUG
70 auto head = op;
71 while (head->prevInChain()) { head = head->prevInChain(); }
72 SkASSERT(head == fHead.get());
73#endif
74 auto prev = op->prevInChain();
75 if (!prev) {
76 SkASSERT(op == fHead.get());
77 return this->popHead();
78 }
79 auto temp = prev->cutChain();
80 if (auto next = temp->cutChain()) {
81 prev->chainConcat(std::move(next));
82 } else {
83 SkASSERT(fTail == op);
84 fTail = prev;
85 }
86 this->validate();
87 return temp;
88}
89
90inline void GrRenderTargetOpList::OpChain::List::pushHead(std::unique_ptr<GrOp> op) {
91 SkASSERT(op);
92 SkASSERT(op->isChainHead());
93 SkASSERT(op->isChainTail());
94 if (fHead) {
95 op->chainConcat(std::move(fHead));
96 fHead = std::move(op);
97 } else {
98 fHead = std::move(op);
99 fTail = fHead.get();
100 }
101}
102
103inline void GrRenderTargetOpList::OpChain::List::pushTail(std::unique_ptr<GrOp> op) {
104 SkASSERT(op->isChainTail());
105 fTail->chainConcat(std::move(op));
106 fTail = fTail->nextInChain();
107}
108
109inline void GrRenderTargetOpList::OpChain::List::validate() const {
110#ifdef SK_DEBUG
111 if (fHead) {
112 SkASSERT(fTail);
113 fHead->validateChain(fTail);
114 }
115#endif
116}
117
118////////////////////////////////////////////////////////////////////////////////
119
Chris Dalton945ee652019-01-23 09:10:36 -0700120GrRenderTargetOpList::OpChain::OpChain(std::unique_ptr<GrOp> op,
121 GrProcessorSet::Analysis processorAnalysis,
122 GrAppliedClip* appliedClip, const DstProxy* dstProxy)
123 : fList{std::move(op)}
124 , fProcessorAnalysis(processorAnalysis)
125 , fAppliedClip(appliedClip) {
126 if (fProcessorAnalysis.requiresDstTexture()) {
127 SkASSERT(dstProxy && dstProxy->proxy());
Brian Salomon588cec72018-11-14 13:56:37 -0500128 fDstProxy = *dstProxy;
129 }
130 fBounds = fList.head()->bounds();
131}
132
Chris Dalton1706cbf2019-05-21 19:35:29 -0600133void GrRenderTargetOpList::OpChain::visitProxies(const GrOp::VisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500134 if (fList.empty()) {
135 return;
136 }
137 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600138 op.visitProxies(func);
Brian Salomon588cec72018-11-14 13:56:37 -0500139 }
140 if (fDstProxy.proxy()) {
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600141 func(fDstProxy.proxy(), GrMipMapped::kNo);
Brian Salomon588cec72018-11-14 13:56:37 -0500142 }
143 if (fAppliedClip) {
144 fAppliedClip->visitProxies(func);
145 }
146}
147
148void GrRenderTargetOpList::OpChain::deleteOps(GrOpMemoryPool* pool) {
149 while (!fList.empty()) {
150 pool->release(fList.popHead());
151 }
152}
153
154// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
155// the two chains are chainable. Returns the new chain.
156GrRenderTargetOpList::OpChain::List GrRenderTargetOpList::OpChain::DoConcat(
157 List chainA, List chainB, const GrCaps& caps, GrOpMemoryPool* pool,
158 GrAuditTrail* auditTrail) {
159 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
160 // at chain a's tail and working toward the head. We produce one of the following outcomes:
161 // 1) b's head is merged into an op in a.
162 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
163 // 3) b's head is popped from chain a and added at the tail of a.
164 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
165 // as we assume merges were already attempted when chain b was created. So we keep track of the
166 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
167 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
168 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
169 GrOp* origATail = chainA.tail();
170 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
171 do {
172 int numMergeChecks = 0;
173 bool merged = false;
174 bool noSkip = (origATail == chainA.tail());
175 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
176 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
177 SkRect forwardMergeBounds = skipBounds;
178 GrOp* a = origATail;
179 while (a) {
180 bool canForwardMerge =
181 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
182 if (canForwardMerge || canBackwardMerge) {
183 auto result = a->combineIfPossible(chainB.head(), caps);
184 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
185 merged = (result == GrOp::CombineResult::kMerged);
Robert Phillips9548c3b422019-01-08 12:35:43 -0500186 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Brian Salomon588cec72018-11-14 13:56:37 -0500187 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
188 a->uniqueID());
Brian Salomon588cec72018-11-14 13:56:37 -0500189 }
190 if (merged) {
Brian Salomon52a6ed32018-11-26 10:30:58 -0500191 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
Brian Salomon588cec72018-11-14 13:56:37 -0500192 if (canBackwardMerge) {
193 pool->release(chainB.popHead());
194 } else {
195 // We merged the contents of b's head into a. We will replace b's head with a in
196 // chain b.
197 SkASSERT(canForwardMerge);
198 if (a == origATail) {
199 origATail = a->prevInChain();
200 }
201 std::unique_ptr<GrOp> detachedA = chainA.removeOp(a);
202 pool->release(chainB.popHead());
203 chainB.pushHead(std::move(detachedA));
204 if (chainA.empty()) {
205 // We merged all the nodes in chain a to chain b.
206 return chainB;
207 }
208 }
209 break;
210 } else {
211 if (++numMergeChecks == kMaxOpMergeDistance) {
212 break;
213 }
214 forwardMergeBounds.joinNonEmptyArg(a->bounds());
215 canBackwardMerge =
216 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
217 a = a->prevInChain();
218 }
219 }
220 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
221 // tail of a.
222 if (!merged) {
223 chainA.pushTail(chainB.popHead());
224 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
225 }
226 } while (!chainB.empty());
227 return chainA;
228}
229
Chris Dalton945ee652019-01-23 09:10:36 -0700230// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
231// whether the operation succeeded. On success, the provided list will be returned empty.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700232bool GrRenderTargetOpList::OpChain::tryConcat(
Chris Dalton945ee652019-01-23 09:10:36 -0700233 List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxy& dstProxy,
234 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
235 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700236 SkASSERT(!fList.empty());
237 SkASSERT(!list->empty());
Chris Dalton945ee652019-01-23 09:10:36 -0700238 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxy.proxy()));
239 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxy.proxy()));
Brian Salomon588cec72018-11-14 13:56:37 -0500240 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700241 if (fList.head()->classID() != list->head()->classID() ||
242 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
243 (fAppliedClip && *fAppliedClip != *appliedClip) ||
Chris Dalton945ee652019-01-23 09:10:36 -0700244 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
245 processorAnalysis.requiresNonOverlappingDraws()) ||
246 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
247 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
248 // or read back a new dst texture between draws. In either case, we can neither
249 // chain nor combine overlapping Ops.
250 GrRectsTouchOrOverlap(fBounds, bounds)) ||
251 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
252 (fProcessorAnalysis.requiresDstTexture() && fDstProxy != dstProxy)) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700253 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500254 }
Chris Daltonee21e6b2019-01-22 14:04:43 -0700255
Brian Salomon588cec72018-11-14 13:56:37 -0500256 SkDEBUGCODE(bool first = true;)
257 do {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700258 switch (fList.tail()->combineIfPossible(list->head(), caps)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500259 case GrOp::CombineResult::kCannotCombine:
260 // If an op supports chaining then it is required that chaining is transitive and
261 // that if any two ops in two different chains can merge then the two chains
262 // may also be chained together. Thus, we should only hit this on the first
263 // iteration.
264 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700265 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500266 case GrOp::CombineResult::kMayChain:
Chris Daltonee21e6b2019-01-22 14:04:43 -0700267 fList = DoConcat(std::move(fList), skstd::exchange(*list, List()), caps, pool,
268 auditTrail);
269 // The above exchange cleared out 'list'. The list needs to be empty now for the
270 // loop to terminate.
271 SkASSERT(list->empty());
272 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500273 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500274 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700275 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
276 list->head()->uniqueID());
277 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
278 pool->release(list->popHead());
Brian Salomon588cec72018-11-14 13:56:37 -0500279 break;
280 }
281 }
282 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700283 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700284
285 // The new ops were successfully merged and/or chained onto our own.
286 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700287 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500288}
289
290bool GrRenderTargetOpList::OpChain::prependChain(OpChain* that, const GrCaps& caps,
291 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Chris Dalton945ee652019-01-23 09:10:36 -0700292 if (!that->tryConcat(
293 &fList, fProcessorAnalysis, fDstProxy, fAppliedClip, fBounds, caps, pool, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500294 this->validate();
295 // append failed
296 return false;
297 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700298
Brian Salomon588cec72018-11-14 13:56:37 -0500299 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700300 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500301 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700302 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500303
304 that->fDstProxy.setProxy(nullptr);
305 if (that->fAppliedClip) {
306 for (int i = 0; i < that->fAppliedClip->numClipCoverageFragmentProcessors(); ++i) {
307 that->fAppliedClip->detachClipCoverageFragmentProcessor(i);
308 }
309 }
310 this->validate();
311 return true;
312}
313
Chris Dalton945ee652019-01-23 09:10:36 -0700314std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::appendOp(
315 std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis,
316 const DstProxy* dstProxy, const GrAppliedClip* appliedClip, const GrCaps& caps,
317 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500318 const GrXferProcessor::DstProxy noDstProxy;
319 if (!dstProxy) {
320 dstProxy = &noDstProxy;
321 }
322 SkASSERT(op->isChainHead() && op->isChainTail());
323 SkRect opBounds = op->bounds();
324 List chain(std::move(op));
Chris Dalton945ee652019-01-23 09:10:36 -0700325 if (!this->tryConcat(
326 &chain, processorAnalysis, *dstProxy, appliedClip, opBounds, caps, pool, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500327 // append failed, give the op back to the caller.
328 this->validate();
329 return chain.popHead();
330 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700331
332 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500333 this->validate();
334 return nullptr;
335}
336
337inline void GrRenderTargetOpList::OpChain::validate() const {
338#ifdef SK_DEBUG
339 fList.validate();
340 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
341 // Not using SkRect::contains because we allow empty rects.
342 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
343 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
344 }
345#endif
346}
347
348////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800349
Robert Phillips12c46292019-04-23 07:36:17 -0400350GrRenderTargetOpList::GrRenderTargetOpList(sk_sp<GrOpMemoryPool> opMemoryPool,
Robert Phillips831a2932019-04-12 17:18:39 -0400351 sk_sp<GrRenderTargetProxy> proxy,
Robert Phillips8185f592017-04-26 08:31:08 -0400352 GrAuditTrail* auditTrail)
Robert Phillips12c46292019-04-23 07:36:17 -0400353 : INHERITED(std::move(opMemoryPool), std::move(proxy), auditTrail)
Brian Salomonc3833b42018-07-09 18:23:58 +0000354 , fLastClipStackGenID(SK_InvalidUniqueID)
Robert Phillipsb6deea82017-05-11 14:14:30 -0400355 SkDEBUGCODE(, fNumClips(0)) {
bsalomon4061b122015-05-29 10:26:19 -0700356}
357
Robert Phillipsc994a932018-06-19 13:09:54 -0400358void GrRenderTargetOpList::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500359 for (auto& chain : fOpChains) {
360 chain.deleteOps(fOpMemoryPool.get());
Robert Phillipsc994a932018-06-19 13:09:54 -0400361 }
Brian Salomon588cec72018-11-14 13:56:37 -0500362 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400363}
364
Robert Phillipsf2361d22016-10-25 14:20:06 -0400365GrRenderTargetOpList::~GrRenderTargetOpList() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400366 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000367}
368
369////////////////////////////////////////////////////////////////////////////////
370
robertphillips4beb5c12015-10-20 07:50:00 -0700371#ifdef SK_DEBUG
Robert Phillips27483912018-04-20 12:43:18 -0400372void GrRenderTargetOpList::dump(bool printDependencies) const {
373 INHERITED::dump(printDependencies);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400374
Brian Salomon588cec72018-11-14 13:56:37 -0500375 SkDebugf("ops (%d):\n", fOpChains.count());
376 for (int i = 0; i < fOpChains.count(); ++i) {
robertphillips4beb5c12015-10-20 07:50:00 -0700377 SkDebugf("*******************************\n");
Brian Salomon588cec72018-11-14 13:56:37 -0500378 if (!fOpChains[i].head()) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500379 SkDebugf("%d: <combined forward or failed instantiation>\n", i);
bsalomonaecc0182016-03-07 11:50:44 -0800380 } else {
Brian Salomon588cec72018-11-14 13:56:37 -0500381 SkDebugf("%d: %s\n", i, fOpChains[i].head()->name());
382 SkRect bounds = fOpChains[i].bounds();
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500383 SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
384 bounds.fTop, bounds.fRight, bounds.fBottom);
Brian Salomon588cec72018-11-14 13:56:37 -0500385 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
386 SkString info = SkTabString(op.dumpInfo(), 1);
387 SkDebugf("%s\n", info.c_str());
388 bounds = op.bounds();
389 SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
390 bounds.fTop, bounds.fRight, bounds.fBottom);
391 }
bsalomonaecc0182016-03-07 11:50:44 -0800392 }
robertphillips4beb5c12015-10-20 07:50:00 -0700393 }
394}
Chris Dalton706a6ff2017-11-29 22:01:06 -0700395
396void GrRenderTargetOpList::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500397 for (const OpChain& chain : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600398 chain.visitProxies(func);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700399 }
400}
Brian Salomonc525d4f2018-09-17 15:48:20 -0400401
robertphillips4beb5c12015-10-20 07:50:00 -0700402#endif
403
Brian Osman407b3422017-08-22 15:01:32 -0400404void GrRenderTargetOpList::onPrepare(GrOpFlushState* flushState) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400405 SkASSERT(fTarget.get()->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400406 SkASSERT(this->isClosed());
Stan Iliev2af578d2017-08-16 13:00:28 -0400407#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
408 TRACE_EVENT0("skia", TRACE_FUNC);
409#endif
robertphillipsa106c622015-10-16 09:07:06 -0700410
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500411 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500412 for (const auto& chain : fOpChains) {
413 if (chain.head()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400414#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon588cec72018-11-14 13:56:37 -0500415 TRACE_EVENT0("skia", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400416#endif
Brian Salomon29b60c92017-10-31 14:42:10 -0400417 GrOpFlushState::OpArgs opArgs = {
Brian Salomon588cec72018-11-14 13:56:37 -0500418 chain.head(),
Robert Phillips2890fbf2017-07-26 15:48:41 -0400419 fTarget.get()->asRenderTargetProxy(),
Brian Salomon588cec72018-11-14 13:56:37 -0500420 chain.appliedClip(),
421 chain.dstProxy()
Robert Phillips318c4192017-05-17 09:36:38 -0400422 };
Brian Salomon29b60c92017-10-31 14:42:10 -0400423 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500424 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400425 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800426 }
bsalomon512be532015-09-10 10:42:55 -0700427 }
robertphillipsa13e2022015-11-11 12:01:09 -0800428}
bsalomon512be532015-09-10 10:42:55 -0700429
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000430static GrGpuRTCommandBuffer* create_command_buffer(GrGpu* gpu,
431 GrRenderTarget* rt,
432 GrSurfaceOrigin origin,
433 const SkRect& bounds,
434 GrLoadOp colorLoadOp,
435 const SkPMColor4f& loadClearColor,
436 GrLoadOp stencilLoadOp) {
Robert Phillipscb2e2352017-08-30 16:44:40 -0400437 const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400438 colorLoadOp,
439 GrStoreOp::kStore,
440 loadClearColor
Robert Phillips178ce3e2017-04-13 09:15:47 -0400441 };
442
Robert Phillips95214472017-08-08 18:00:03 -0400443 // TODO:
444 // We would like to (at this level) only ever clear & discard. We would need
445 // to stop splitting up higher level opLists for copyOps to achieve that.
446 // Note: we would still need SB loads and stores but they would happen at a
447 // lower level (inside the VK command buffer).
Greg Daniel500d58b2017-08-24 15:59:33 -0400448 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400449 stencilLoadOp,
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000450 GrStoreOp::kStore,
Robert Phillips95214472017-08-08 18:00:03 -0400451 };
452
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400453 return gpu->getCommandBuffer(rt, origin, bounds, kColorLoadStoreInfo, stencilLoadAndStoreInfo);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400454}
455
Brian Salomon25a88092016-12-01 09:36:50 -0500456// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500457// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500458// Ops and instantiate them here.
Brian Osman407b3422017-08-22 15:01:32 -0400459bool GrRenderTargetOpList::onExecute(GrOpFlushState* flushState) {
Greg Danieldbdba602018-04-20 11:52:43 -0400460 // TODO: Forcing the execution of the discard here isn't ideal since it will cause us to do a
461 // discard and then store the data back in memory so that the load op on future draws doesn't
462 // think the memory is unitialized. Ideally we would want a system where we are tracking whether
463 // the proxy itself has valid data or not, and then use that as a signal on whether we should be
464 // loading or discarding. In that world we wouldni;t need to worry about executing oplists with
465 // no ops just to do a discard.
Brian Salomon588cec72018-11-14 13:56:37 -0500466 if (fOpChains.empty() && GrLoadOp::kClear != fColorLoadOp &&
Greg Danieldbdba602018-04-20 11:52:43 -0400467 GrLoadOp::kDiscard != fColorLoadOp) {
bsalomondc438982016-08-31 11:53:49 -0700468 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700469 }
Robert Phillips4a395042017-04-24 16:27:17 +0000470
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400471 SkASSERT(fTarget.get()->peekRenderTarget());
Stan Iliev2af578d2017-08-16 13:00:28 -0400472 TRACE_EVENT0("skia", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400473
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000474 // TODO: at the very least, we want the stencil store op to always be discard (at this
475 // level). In Vulkan, sub-command buffers would still need to load & store the stencil buffer.
476
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500477 // Make sure load ops are not kClear if the GPU needs to use draws for clears
478 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
479 !flushState->gpu()->caps()->performColorClearsAsDraws());
480 SkASSERT(fStencilLoadOp != GrLoadOp::kClear ||
481 !flushState->gpu()->caps()->performStencilClearsAsDraws());
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400482 GrGpuRTCommandBuffer* commandBuffer = create_command_buffer(
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000483 flushState->gpu(),
484 fTarget.get()->peekRenderTarget(),
485 fTarget.get()->origin(),
486 fTarget.get()->getBoundsRect(),
487 fColorLoadOp,
488 fLoadClearColor,
489 fStencilLoadOp);
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400490 flushState->setCommandBuffer(commandBuffer);
Robert Phillips95214472017-08-08 18:00:03 -0400491 commandBuffer->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400492
493 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500494 for (const auto& chain : fOpChains) {
495 if (!chain.head()) {
bsalomonaecc0182016-03-07 11:50:44 -0800496 continue;
497 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400498#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon588cec72018-11-14 13:56:37 -0500499 TRACE_EVENT0("skia", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400500#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400501
Brian Salomon29b60c92017-10-31 14:42:10 -0400502 GrOpFlushState::OpArgs opArgs {
Brian Salomon588cec72018-11-14 13:56:37 -0500503 chain.head(),
Robert Phillips2890fbf2017-07-26 15:48:41 -0400504 fTarget.get()->asRenderTargetProxy(),
Brian Salomon588cec72018-11-14 13:56:37 -0500505 chain.appliedClip(),
506 chain.dstProxy()
Robert Phillips178ce3e2017-04-13 09:15:47 -0400507 };
508
Brian Salomon29b60c92017-10-31 14:42:10 -0400509 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500510 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400511 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700512 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400513
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400514 commandBuffer->end();
515 flushState->gpu()->submit(commandBuffer);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400516 flushState->setCommandBuffer(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800517
bsalomondc438982016-08-31 11:53:49 -0700518 return true;
bsalomona73239a2015-04-28 13:35:17 -0700519}
520
Chris Daltona84cacf2017-10-04 10:30:29 -0600521void GrRenderTargetOpList::endFlush() {
Brian Salomonc3833b42018-07-09 18:23:58 +0000522 fLastClipStackGenID = SK_InvalidUniqueID;
Robert Phillipsc994a932018-06-19 13:09:54 -0400523 this->deleteOps();
Chris Daltonc82dd4e2017-11-20 18:20:28 -0700524 fClipAllocator.reset();
Chris Daltona84cacf2017-10-04 10:30:29 -0600525 INHERITED::endFlush();
bsalomon512be532015-09-10 10:42:55 -0700526}
527
Robert Phillips380b90c2017-08-30 07:41:07 -0400528void GrRenderTargetOpList::discard() {
529 // Discard calls to in-progress opLists are ignored. Calls at the start update the
530 // opLists' color & stencil load ops.
531 if (this->isEmpty()) {
532 fColorLoadOp = GrLoadOp::kDiscard;
533 fStencilLoadOp = GrLoadOp::kDiscard;
534 }
535}
536
Michael Ludwig6e17f1d2019-05-15 14:00:20 +0000537void GrRenderTargetOpList::setStencilLoadOp(GrLoadOp op) {
538 fStencilLoadOp = op;
539}
540
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500541void GrRenderTargetOpList::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) {
542 fColorLoadOp = op;
543 fLoadClearColor = color;
544}
545
546bool GrRenderTargetOpList::resetForFullscreenClear() {
547 // Mark the color load op as discard (this may be followed by a clearColorOnLoad call to make
548 // the load op kClear, or it may be followed by an explicit op). In the event of an absClear()
549 // after a regular clear(), we could end up with a clear load op and a real clear op in the list
550 // if the load op were not reset here.
551 fColorLoadOp = GrLoadOp::kDiscard;
552
553 // Regardless of how the clear is implemented (native clear or a fullscreen quad), all prior ops
554 // would be overwritten, so discard them entirely. The one exception is if the opList is marked
555 // as needing a stencil buffer then there may be a prior op that writes to the stencil buffer.
556 // Although the clear will ignore the stencil buffer, following draw ops may not so we can't get
557 // rid of all the preceding ops. Beware! If we ever add any ops that have a side effect beyond
558 // modifying the stencil buffer we will need a more elaborate tracking system (skbug.com/7002).
Greg Danielcb324152019-02-25 11:36:53 -0500559 // Additionally, if we previously recorded a wait op, we cannot delete the wait op. Until we
560 // track the wait ops separately from normal ops, we have to avoid clearing out any ops.
561 if (this->isEmpty() || (!fTarget.get()->asRenderTargetProxy()->needsStencil() && !fHasWaitOp)) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400562 this->deleteOps();
Brian Osman099fa0f2017-10-02 16:38:32 -0400563 fDeferredProxies.reset();
Greg Daniel070cbaf2019-01-03 17:35:54 -0500564
565 // If the opList is using a render target which wraps a vulkan command buffer, we can't do a
566 // clear load since we cannot change the render pass that we are using. Thus we fall back to
567 // making a clear op in this case.
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500568 return !fTarget.get()->asRenderTargetProxy()->wrapsVkSecondaryCB();
bsalomonfd8d0132016-08-11 11:25:33 -0700569 }
Robert Phillips380b90c2017-08-30 07:41:07 -0400570
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500571 // Could not empty the list, so an op must be added to handle the clear
572 return false;
bsalomon9f129de2016-08-10 16:31:05 -0700573}
574
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000575////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000576
Robert Phillips81dd3e02017-06-23 11:59:24 -0400577// This closely parallels GrTextureOpList::copySurface but renderTargetOpLists
578// also store the applied clip and dest proxy with the op
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500579bool GrRenderTargetOpList::copySurface(GrRecordingContext* context,
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400580 GrSurfaceProxy* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400581 GrSurfaceProxy* src,
Robert Phillipsf2361d22016-10-25 14:20:06 -0400582 const SkIRect& srcRect,
583 const SkIPoint& dstPoint) {
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400584 SkASSERT(dst->asRenderTargetProxy() == fTarget.get());
Robert Phillips7c525e62018-06-12 10:11:12 -0400585 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(context, dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500586 if (!op) {
bsalomonb8fea972016-02-16 07:34:17 -0800587 return false;
588 }
robertphillips498d7ac2015-10-30 10:11:30 -0700589
Robert Phillips9da87e02019-02-04 13:26:26 -0500590 this->addOp(std::move(op), *context->priv().caps());
bsalomonb8fea972016-02-16 07:34:17 -0800591 return true;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000592}
593
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500594void GrRenderTargetOpList::purgeOpsWithUninstantiatedProxies() {
595 bool hasUninstantiatedProxy = false;
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600596 auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p, GrMipMapped) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400597 if (!p->isInstantiated()) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500598 hasUninstantiatedProxy = true;
599 }
600 };
Brian Salomon588cec72018-11-14 13:56:37 -0500601 for (OpChain& recordedOp : fOpChains) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500602 hasUninstantiatedProxy = false;
Chris Dalton1706cbf2019-05-21 19:35:29 -0600603 recordedOp.visitProxies(checkInstantiation);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500604 if (hasUninstantiatedProxy) {
605 // When instantiation of the proxy fails we drop the Op
Brian Salomon588cec72018-11-14 13:56:37 -0500606 recordedOp.deleteOps(fOpMemoryPool.get());
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500607 }
608 }
609}
610
Robert Phillips9313aa72019-04-09 18:41:27 -0400611bool GrRenderTargetOpList::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
612 bool used = false;
613
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600614 auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p, GrMipMapped) {
Robert Phillips9313aa72019-04-09 18:41:27 -0400615 if (p == proxyToCheck) {
616 used = true;
617 }
618 };
619 for (const OpChain& recordedOp : fOpChains) {
Chris Dalton1706cbf2019-05-21 19:35:29 -0600620 recordedOp.visitProxies(visit);
Robert Phillips9313aa72019-04-09 18:41:27 -0400621 }
622
623 return used;
624}
625
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400626void GrRenderTargetOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400627
Robert Phillips51b20f22017-12-01 15:32:35 -0500628 for (int i = 0; i < fDeferredProxies.count(); ++i) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400629 SkASSERT(!fDeferredProxies[i]->isInstantiated());
Robert Phillips51b20f22017-12-01 15:32:35 -0500630 // We give all the deferred proxies a write usage at the very start of flushing. This
631 // locks them out of being reused for the entire flush until they are read - and then
632 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
633 // with sub-flushes. The deferred proxies only need to be pinned from the start of
634 // the sub-flush in which they appear.
Robert Phillipsc73666f2019-04-24 08:49:48 -0400635 alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo);
Robert Phillips51b20f22017-12-01 15:32:35 -0500636 }
637
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400638 // Add the interval for all the writes to this opList's target
Brian Salomon588cec72018-11-14 13:56:37 -0500639 if (fOpChains.count()) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400640 unsigned int cur = alloc->curOp();
641
Robert Phillipsc73666f2019-04-24 08:49:48 -0400642 alloc->addInterval(fTarget.get(), cur, cur + fOpChains.count() - 1,
643 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500644 } else {
645 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
646 // still need to add an interval for the destination so we create a fake op# for
647 // the missing clear op.
Robert Phillipsc73666f2019-04-24 08:49:48 -0400648 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
649 GrResourceAllocator::ActualUse::kYes);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500650 alloc->incOps();
651 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400652
Chris Dalton7eb5c0f2019-05-23 15:15:47 -0600653 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p, GrMipMapped) {
Robert Phillipsc73666f2019-04-24 08:49:48 -0400654 alloc->addInterval(p, alloc->curOp(), alloc->curOp(), GrResourceAllocator::ActualUse::kYes
655 SkDEBUGCODE(, fTarget.get() == p));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400656 };
Brian Salomon588cec72018-11-14 13:56:37 -0500657 for (const OpChain& recordedOp : fOpChains) {
Brian Salomon7d94bb52018-10-12 14:37:19 -0400658 // only diff from the GrTextureOpList version
Chris Dalton1706cbf2019-05-21 19:35:29 -0600659 recordedOp.visitProxies(gather);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500660
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400661 // Even though the op may have been (re)moved we still need to increment the op count to
Robert Phillipsf8e25022017-11-08 15:24:31 -0500662 // keep all the math consistent.
663 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400664 }
665}
666
Chris Dalton945ee652019-01-23 09:10:36 -0700667void GrRenderTargetOpList::recordOp(
668 std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip,
669 const DstProxy* dstProxy, const GrCaps& caps) {
Ethan Nicholas029b22c2018-10-18 16:49:56 -0400670 SkDEBUGCODE(op->validate();)
Chris Dalton945ee652019-01-23 09:10:36 -0700671 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxy && dstProxy->proxy()));
Robert Phillips318c4192017-05-17 09:36:38 -0400672 SkASSERT(fTarget.get());
Robert Phillipsee683652017-04-26 11:53:10 -0400673
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500674 // A closed GrOpList should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700675 SkASSERT(!this->isClosed());
Brian Salomon19ec80f2018-11-16 13:27:30 -0500676 if (!op->bounds().isFinite()) {
677 fOpMemoryPool->release(std::move(op));
678 return;
679 }
robertphillipsa106c622015-10-16 09:07:06 -0700680
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500681 // Check if there is an op we can combine with by linearly searching back until we either
682 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700683 // 2) intersect with something
684 // 3) find a 'blocker'
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400685 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400686 GrOP_INFO("opList: %d Recording (%s, opID: %u)\n"
687 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
688 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500689 op->name(),
690 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400691 op->bounds().fLeft, op->bounds().fTop,
692 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500693 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500694 GrOP_INFO("\tOutcome:\n");
Brian Salomon588cec72018-11-14 13:56:37 -0500695 int maxCandidates = SkTMin(kMaxOpChainDistance, fOpChains.count());
Robert Phillips318c4192017-05-17 09:36:38 -0400696 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700697 int i = 0;
698 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500699 OpChain& candidate = fOpChains.fromBack(i);
Chris Dalton945ee652019-01-23 09:10:36 -0700700 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxy, clip, caps,
701 fOpMemoryPool.get(), fAuditTrail);
Brian Salomon588cec72018-11-14 13:56:37 -0500702 if (!op) {
703 return;
bsalomon512be532015-09-10 10:42:55 -0700704 }
Brian Salomona7682c82018-10-24 10:04:37 -0400705 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -0500706 if (!can_reorder(candidate.bounds(), op->bounds())) {
707 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
708 candidate.head()->name(), candidate.head()->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700709 break;
710 }
Brian Salomon588cec72018-11-14 13:56:37 -0500711 if (++i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400712 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -0700713 break;
714 }
715 }
716 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400717 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -0700718 }
Brian Salomon54d212e2017-03-21 14:22:38 -0400719 if (clip) {
720 clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -0400721 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400722 }
Chris Dalton945ee652019-01-23 09:10:36 -0700723 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxy);
bsalomon512be532015-09-10 10:42:55 -0700724}
725
Robert Phillipsee683652017-04-26 11:53:10 -0400726void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400727 SkASSERT(!this->isClosed());
Brian Salomon588cec72018-11-14 13:56:37 -0500728 GrOP_INFO("opList: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
Robert Phillips48567ac2017-06-01 08:46:00 -0400729
Brian Salomon588cec72018-11-14 13:56:37 -0500730 for (int i = 0; i < fOpChains.count() - 1; ++i) {
731 OpChain& chain = fOpChains[i];
732 int maxCandidateIdx = SkTMin(i + kMaxOpChainDistance, fOpChains.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -0800733 int j = i + 1;
734 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500735 OpChain& candidate = fOpChains[j];
736 if (candidate.prependChain(&chain, caps, fOpMemoryPool.get(), fAuditTrail)) {
bsalomonaecc0182016-03-07 11:50:44 -0800737 break;
738 }
Robert Phillipsc84c0302017-05-08 15:35:11 -0400739 // Stop traversing if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -0500740 if (!can_reorder(chain.bounds(), candidate.bounds())) {
741 GrOP_INFO(
742 "\t\t%d: chain (%s head opID: %u) -> "
743 "Intersects with chain (%s, head opID: %u)\n",
744 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
745 candidate.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800746 break;
747 }
Brian Salomona7682c82018-10-24 10:04:37 -0400748 if (++j > maxCandidateIdx) {
Brian Salomon588cec72018-11-14 13:56:37 -0500749 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
750 i, chain.head()->name(), chain.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800751 break;
752 }
753 }
754 }
755}
756