blob: 66300df8d90edb7bfee2dc899737ebae8c12d9da [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#include "GrRenderTargetOpList.h"
joshualitt086cee12016-01-12 06:45:24 -08009#include "GrAuditTrail.h"
bsalomoneb1cb5c2015-05-22 08:01:09 -070010#include "GrCaps.h"
bsalomon4061b122015-05-29 10:26:19 -070011#include "GrGpu.h"
egdaniel9cb63402016-06-23 08:37:05 -070012#include "GrGpuCommandBuffer.h"
Robert Phillips7c525e62018-06-12 10:11:12 -040013#include "GrMemoryPool.h"
Robert Phillipsbe9aff22019-02-15 11:33:22 -050014#include "GrRecordingContext.h"
15#include "GrRecordingContextPriv.h"
Brian Salomona4677b52017-05-04 12:39:56 -040016#include "GrRect.h"
Brian Salomon467921e2017-03-06 16:17:12 -050017#include "GrRenderTargetContext.h"
Robert Phillipsd375dbf2017-09-14 12:45:25 -040018#include "GrResourceAllocator.h"
Chris Daltonee21e6b2019-01-22 14:04:43 -070019#include "SkExchange.h"
Brian Salomon588cec72018-11-14 13:56:37 -050020#include "SkRectPriv.h"
21#include "SkTraceEvent.h"
Brian Salomon89527432016-12-16 09:52:16 -050022#include "ops/GrClearOp.h"
Brian Salomon89527432016-12-16 09:52:16 -050023#include "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
133void GrRenderTargetOpList::OpChain::visitProxies(const GrOp::VisitProxyFunc& func,
134 GrOp::VisitorType visitor) const {
135 if (fList.empty()) {
136 return;
137 }
138 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
139 op.visitProxies(func, visitor);
140 }
141 if (fDstProxy.proxy()) {
142 func(fDstProxy.proxy());
143 }
144 if (fAppliedClip) {
145 fAppliedClip->visitProxies(func);
146 }
147}
148
149void GrRenderTargetOpList::OpChain::deleteOps(GrOpMemoryPool* pool) {
150 while (!fList.empty()) {
151 pool->release(fList.popHead());
152 }
153}
154
155// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that
156// the two chains are chainable. Returns the new chain.
157GrRenderTargetOpList::OpChain::List GrRenderTargetOpList::OpChain::DoConcat(
158 List chainA, List chainB, const GrCaps& caps, GrOpMemoryPool* pool,
159 GrAuditTrail* auditTrail) {
160 // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting
161 // at chain a's tail and working toward the head. We produce one of the following outcomes:
162 // 1) b's head is merged into an op in a.
163 // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.)
164 // 3) b's head is popped from chain a and added at the tail of a.
165 // After result 3 we don't want to attempt to merge the next head of b with the new tail of a,
166 // as we assume merges were already attempted when chain b was created. So we keep track of the
167 // original tail of a and start our iteration of a there. We also track the bounds of the nodes
168 // appended to chain a that will be skipped for bounds testing. If the original tail of a is
169 // merged into an op in b (case 2) then we advance the "original tail" towards the head of a.
170 GrOp* origATail = chainA.tail();
171 SkRect skipBounds = SkRectPriv::MakeLargestInverted();
172 do {
173 int numMergeChecks = 0;
174 bool merged = false;
175 bool noSkip = (origATail == chainA.tail());
176 SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted()));
177 bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds);
178 SkRect forwardMergeBounds = skipBounds;
179 GrOp* a = origATail;
180 while (a) {
181 bool canForwardMerge =
182 (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds);
183 if (canForwardMerge || canBackwardMerge) {
184 auto result = a->combineIfPossible(chainB.head(), caps);
185 SkASSERT(result != GrOp::CombineResult::kCannotCombine);
186 merged = (result == GrOp::CombineResult::kMerged);
Robert Phillips9548c3b422019-01-08 12:35:43 -0500187 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Brian Salomon588cec72018-11-14 13:56:37 -0500188 chainB.head()->name(), chainB.head()->uniqueID(), a->name(),
189 a->uniqueID());
Brian Salomon588cec72018-11-14 13:56:37 -0500190 }
191 if (merged) {
Brian Salomon52a6ed32018-11-26 10:30:58 -0500192 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
Brian Salomon588cec72018-11-14 13:56:37 -0500193 if (canBackwardMerge) {
194 pool->release(chainB.popHead());
195 } else {
196 // We merged the contents of b's head into a. We will replace b's head with a in
197 // chain b.
198 SkASSERT(canForwardMerge);
199 if (a == origATail) {
200 origATail = a->prevInChain();
201 }
202 std::unique_ptr<GrOp> detachedA = chainA.removeOp(a);
203 pool->release(chainB.popHead());
204 chainB.pushHead(std::move(detachedA));
205 if (chainA.empty()) {
206 // We merged all the nodes in chain a to chain b.
207 return chainB;
208 }
209 }
210 break;
211 } else {
212 if (++numMergeChecks == kMaxOpMergeDistance) {
213 break;
214 }
215 forwardMergeBounds.joinNonEmptyArg(a->bounds());
216 canBackwardMerge =
217 canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds());
218 a = a->prevInChain();
219 }
220 }
221 // If we weren't able to merge b's head then pop b's head from chain b and make it the new
222 // tail of a.
223 if (!merged) {
224 chainA.pushTail(chainB.popHead());
225 skipBounds.joinNonEmptyArg(chainA.tail()->bounds());
226 }
227 } while (!chainB.empty());
228 return chainA;
229}
230
Chris Dalton945ee652019-01-23 09:10:36 -0700231// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns
232// whether the operation succeeded. On success, the provided list will be returned empty.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700233bool GrRenderTargetOpList::OpChain::tryConcat(
Chris Dalton945ee652019-01-23 09:10:36 -0700234 List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxy& dstProxy,
235 const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps,
236 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700237 SkASSERT(!fList.empty());
238 SkASSERT(!list->empty());
Chris Dalton945ee652019-01-23 09:10:36 -0700239 SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxy.proxy()));
240 SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxy.proxy()));
Brian Salomon588cec72018-11-14 13:56:37 -0500241 // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700242 if (fList.head()->classID() != list->head()->classID() ||
243 SkToBool(fAppliedClip) != SkToBool(appliedClip) ||
244 (fAppliedClip && *fAppliedClip != *appliedClip) ||
Chris Dalton945ee652019-01-23 09:10:36 -0700245 (fProcessorAnalysis.requiresNonOverlappingDraws() !=
246 processorAnalysis.requiresNonOverlappingDraws()) ||
247 (fProcessorAnalysis.requiresNonOverlappingDraws() &&
248 // Non-overlaping draws are only required when Ganesh will either insert a barrier,
249 // or read back a new dst texture between draws. In either case, we can neither
250 // chain nor combine overlapping Ops.
251 GrRectsTouchOrOverlap(fBounds, bounds)) ||
252 (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) ||
253 (fProcessorAnalysis.requiresDstTexture() && fDstProxy != dstProxy)) {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700254 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500255 }
Chris Daltonee21e6b2019-01-22 14:04:43 -0700256
Brian Salomon588cec72018-11-14 13:56:37 -0500257 SkDEBUGCODE(bool first = true;)
258 do {
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700259 switch (fList.tail()->combineIfPossible(list->head(), caps)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500260 case GrOp::CombineResult::kCannotCombine:
261 // If an op supports chaining then it is required that chaining is transitive and
262 // that if any two ops in two different chains can merge then the two chains
263 // may also be chained together. Thus, we should only hit this on the first
264 // iteration.
265 SkASSERT(first);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700266 return false;
Brian Salomon588cec72018-11-14 13:56:37 -0500267 case GrOp::CombineResult::kMayChain:
Chris Daltonee21e6b2019-01-22 14:04:43 -0700268 fList = DoConcat(std::move(fList), skstd::exchange(*list, List()), caps, pool,
269 auditTrail);
270 // The above exchange cleared out 'list'. The list needs to be empty now for the
271 // loop to terminate.
272 SkASSERT(list->empty());
273 break;
Brian Salomon588cec72018-11-14 13:56:37 -0500274 case GrOp::CombineResult::kMerged: {
Robert Phillips9548c3b422019-01-08 12:35:43 -0500275 GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700276 list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
277 list->head()->uniqueID());
278 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
279 pool->release(list->popHead());
Brian Salomon588cec72018-11-14 13:56:37 -0500280 break;
281 }
282 }
283 SkDEBUGCODE(first = false);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700284 } while (!list->empty());
Chris Daltonee21e6b2019-01-22 14:04:43 -0700285
286 // The new ops were successfully merged and/or chained onto our own.
287 fBounds.joinPossiblyEmptyRect(bounds);
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700288 return true;
Brian Salomon588cec72018-11-14 13:56:37 -0500289}
290
291bool GrRenderTargetOpList::OpChain::prependChain(OpChain* that, const GrCaps& caps,
292 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Chris Dalton945ee652019-01-23 09:10:36 -0700293 if (!that->tryConcat(
294 &fList, fProcessorAnalysis, fDstProxy, fAppliedClip, fBounds, caps, pool, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500295 this->validate();
296 // append failed
297 return false;
298 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700299
Brian Salomon588cec72018-11-14 13:56:37 -0500300 // 'that' owns the combined chain. Move it into 'this'.
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700301 SkASSERT(fList.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500302 fList = std::move(that->fList);
Chris Daltonee21e6b2019-01-22 14:04:43 -0700303 fBounds = that->fBounds;
Brian Salomon588cec72018-11-14 13:56:37 -0500304
305 that->fDstProxy.setProxy(nullptr);
306 if (that->fAppliedClip) {
307 for (int i = 0; i < that->fAppliedClip->numClipCoverageFragmentProcessors(); ++i) {
308 that->fAppliedClip->detachClipCoverageFragmentProcessor(i);
309 }
310 }
311 this->validate();
312 return true;
313}
314
Chris Dalton945ee652019-01-23 09:10:36 -0700315std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::appendOp(
316 std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis,
317 const DstProxy* dstProxy, const GrAppliedClip* appliedClip, const GrCaps& caps,
318 GrOpMemoryPool* pool, GrAuditTrail* auditTrail) {
Brian Salomon588cec72018-11-14 13:56:37 -0500319 const GrXferProcessor::DstProxy noDstProxy;
320 if (!dstProxy) {
321 dstProxy = &noDstProxy;
322 }
323 SkASSERT(op->isChainHead() && op->isChainTail());
324 SkRect opBounds = op->bounds();
325 List chain(std::move(op));
Chris Dalton945ee652019-01-23 09:10:36 -0700326 if (!this->tryConcat(
327 &chain, processorAnalysis, *dstProxy, appliedClip, opBounds, caps, pool, auditTrail)) {
Brian Salomon588cec72018-11-14 13:56:37 -0500328 // append failed, give the op back to the caller.
329 this->validate();
330 return chain.popHead();
331 }
Chris Dalton6f6ae6a2019-01-18 12:10:36 -0700332
333 SkASSERT(chain.empty());
Brian Salomon588cec72018-11-14 13:56:37 -0500334 this->validate();
335 return nullptr;
336}
337
338inline void GrRenderTargetOpList::OpChain::validate() const {
339#ifdef SK_DEBUG
340 fList.validate();
341 for (const auto& op : GrOp::ChainRange<>(fList.head())) {
342 // Not using SkRect::contains because we allow empty rects.
343 SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop &&
344 fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom);
345 }
346#endif
347}
348
349////////////////////////////////////////////////////////////////////////////////
bsalomon489147c2015-12-14 12:13:09 -0800350
Robert Phillips3a9710b2018-03-27 17:51:55 -0400351GrRenderTargetOpList::GrRenderTargetOpList(GrResourceProvider* resourceProvider,
Robert Phillipsc994a932018-06-19 13:09:54 -0400352 sk_sp<GrOpMemoryPool> opMemoryPool,
Robert Phillips3a9710b2018-03-27 17:51:55 -0400353 GrRenderTargetProxy* proxy,
Robert Phillips8185f592017-04-26 08:31:08 -0400354 GrAuditTrail* auditTrail)
Robert Phillipsc994a932018-06-19 13:09:54 -0400355 : INHERITED(resourceProvider, std::move(opMemoryPool), proxy, auditTrail)
Brian Salomonc3833b42018-07-09 18:23:58 +0000356 , fLastClipStackGenID(SK_InvalidUniqueID)
Robert Phillipsb6deea82017-05-11 14:14:30 -0400357 SkDEBUGCODE(, fNumClips(0)) {
bsalomon4061b122015-05-29 10:26:19 -0700358}
359
Robert Phillipsc994a932018-06-19 13:09:54 -0400360void GrRenderTargetOpList::deleteOps() {
Brian Salomon588cec72018-11-14 13:56:37 -0500361 for (auto& chain : fOpChains) {
362 chain.deleteOps(fOpMemoryPool.get());
Robert Phillipsc994a932018-06-19 13:09:54 -0400363 }
Brian Salomon588cec72018-11-14 13:56:37 -0500364 fOpChains.reset();
Robert Phillipsc994a932018-06-19 13:09:54 -0400365}
366
Robert Phillipsf2361d22016-10-25 14:20:06 -0400367GrRenderTargetOpList::~GrRenderTargetOpList() {
Robert Phillipsc994a932018-06-19 13:09:54 -0400368 this->deleteOps();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000369}
370
371////////////////////////////////////////////////////////////////////////////////
372
robertphillips4beb5c12015-10-20 07:50:00 -0700373#ifdef SK_DEBUG
Robert Phillips27483912018-04-20 12:43:18 -0400374void GrRenderTargetOpList::dump(bool printDependencies) const {
375 INHERITED::dump(printDependencies);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400376
Brian Salomon588cec72018-11-14 13:56:37 -0500377 SkDebugf("ops (%d):\n", fOpChains.count());
378 for (int i = 0; i < fOpChains.count(); ++i) {
robertphillips4beb5c12015-10-20 07:50:00 -0700379 SkDebugf("*******************************\n");
Brian Salomon588cec72018-11-14 13:56:37 -0500380 if (!fOpChains[i].head()) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500381 SkDebugf("%d: <combined forward or failed instantiation>\n", i);
bsalomonaecc0182016-03-07 11:50:44 -0800382 } else {
Brian Salomon588cec72018-11-14 13:56:37 -0500383 SkDebugf("%d: %s\n", i, fOpChains[i].head()->name());
384 SkRect bounds = fOpChains[i].bounds();
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500385 SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
386 bounds.fTop, bounds.fRight, bounds.fBottom);
Brian Salomon588cec72018-11-14 13:56:37 -0500387 for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) {
388 SkString info = SkTabString(op.dumpInfo(), 1);
389 SkDebugf("%s\n", info.c_str());
390 bounds = op.bounds();
391 SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
392 bounds.fTop, bounds.fRight, bounds.fBottom);
393 }
bsalomonaecc0182016-03-07 11:50:44 -0800394 }
robertphillips4beb5c12015-10-20 07:50:00 -0700395 }
396}
Chris Dalton706a6ff2017-11-29 22:01:06 -0700397
398void GrRenderTargetOpList::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const {
Brian Salomon588cec72018-11-14 13:56:37 -0500399 for (const OpChain& chain : fOpChains) {
400 chain.visitProxies(func, GrOp::VisitorType::kOther);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700401 }
402}
Brian Salomonc525d4f2018-09-17 15:48:20 -0400403
robertphillips4beb5c12015-10-20 07:50:00 -0700404#endif
405
Brian Osman407b3422017-08-22 15:01:32 -0400406void GrRenderTargetOpList::onPrepare(GrOpFlushState* flushState) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400407 SkASSERT(fTarget.get()->peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400408 SkASSERT(this->isClosed());
Stan Iliev2af578d2017-08-16 13:00:28 -0400409#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
410 TRACE_EVENT0("skia", TRACE_FUNC);
411#endif
robertphillipsa106c622015-10-16 09:07:06 -0700412
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500413 // Loop over the ops that haven't yet been prepared.
Brian Salomon588cec72018-11-14 13:56:37 -0500414 for (const auto& chain : fOpChains) {
415 if (chain.head()) {
Stan Iliev2af578d2017-08-16 13:00:28 -0400416#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon588cec72018-11-14 13:56:37 -0500417 TRACE_EVENT0("skia", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400418#endif
Brian Salomon29b60c92017-10-31 14:42:10 -0400419 GrOpFlushState::OpArgs opArgs = {
Brian Salomon588cec72018-11-14 13:56:37 -0500420 chain.head(),
Robert Phillips2890fbf2017-07-26 15:48:41 -0400421 fTarget.get()->asRenderTargetProxy(),
Brian Salomon588cec72018-11-14 13:56:37 -0500422 chain.appliedClip(),
423 chain.dstProxy()
Robert Phillips318c4192017-05-17 09:36:38 -0400424 };
Brian Salomon29b60c92017-10-31 14:42:10 -0400425 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500426 chain.head()->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -0400427 flushState->setOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -0800428 }
bsalomon512be532015-09-10 10:42:55 -0700429 }
robertphillipsa13e2022015-11-11 12:01:09 -0800430}
bsalomon512be532015-09-10 10:42:55 -0700431
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400432static GrGpuRTCommandBuffer* create_command_buffer(GrGpu* gpu,
433 GrRenderTarget* rt,
434 GrSurfaceOrigin origin,
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400435 const SkRect& bounds,
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400436 GrLoadOp colorLoadOp,
Brian Osman9a9baae2018-11-05 15:06:26 -0500437 const SkPMColor4f& loadClearColor,
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400438 GrLoadOp stencilLoadOp) {
Robert Phillipscb2e2352017-08-30 16:44:40 -0400439 const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400440 colorLoadOp,
441 GrStoreOp::kStore,
442 loadClearColor
Robert Phillips178ce3e2017-04-13 09:15:47 -0400443 };
444
Robert Phillips95214472017-08-08 18:00:03 -0400445 // TODO:
446 // We would like to (at this level) only ever clear & discard. We would need
447 // to stop splitting up higher level opLists for copyOps to achieve that.
448 // Note: we would still need SB loads and stores but they would happen at a
449 // lower level (inside the VK command buffer).
Greg Daniel500d58b2017-08-24 15:59:33 -0400450 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo stencilLoadAndStoreInfo {
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400451 stencilLoadOp,
452 GrStoreOp::kStore,
Robert Phillips95214472017-08-08 18:00:03 -0400453 };
454
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400455 return gpu->getCommandBuffer(rt, origin, bounds, kColorLoadStoreInfo, stencilLoadAndStoreInfo);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400456}
457
Brian Salomon25a88092016-12-01 09:36:50 -0500458// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500459// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500460// Ops and instantiate them here.
Brian Osman407b3422017-08-22 15:01:32 -0400461bool GrRenderTargetOpList::onExecute(GrOpFlushState* flushState) {
Greg Danieldbdba602018-04-20 11:52:43 -0400462 // TODO: Forcing the execution of the discard here isn't ideal since it will cause us to do a
463 // discard and then store the data back in memory so that the load op on future draws doesn't
464 // think the memory is unitialized. Ideally we would want a system where we are tracking whether
465 // the proxy itself has valid data or not, and then use that as a signal on whether we should be
466 // loading or discarding. In that world we wouldni;t need to worry about executing oplists with
467 // no ops just to do a discard.
Brian Salomon588cec72018-11-14 13:56:37 -0500468 if (fOpChains.empty() && GrLoadOp::kClear != fColorLoadOp &&
Greg Danieldbdba602018-04-20 11:52:43 -0400469 GrLoadOp::kDiscard != fColorLoadOp) {
bsalomondc438982016-08-31 11:53:49 -0700470 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700471 }
Robert Phillips4a395042017-04-24 16:27:17 +0000472
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400473 SkASSERT(fTarget.get()->peekRenderTarget());
Stan Iliev2af578d2017-08-16 13:00:28 -0400474 TRACE_EVENT0("skia", TRACE_FUNC);
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400475
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400476 // TODO: at the very least, we want the stencil store op to always be discard (at this
477 // level). In Vulkan, sub-command buffers would still need to load & store the stencil buffer.
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500478
479 // Make sure load ops are not kClear if the GPU needs to use draws for clears
480 SkASSERT(fColorLoadOp != GrLoadOp::kClear ||
481 !flushState->gpu()->caps()->performColorClearsAsDraws());
482 SkASSERT(fStencilLoadOp != GrLoadOp::kClear ||
483 !flushState->gpu()->caps()->performStencilClearsAsDraws());
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400484 GrGpuRTCommandBuffer* commandBuffer = create_command_buffer(
Robert Phillips95214472017-08-08 18:00:03 -0400485 flushState->gpu(),
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400486 fTarget.get()->peekRenderTarget(),
Robert Phillips95214472017-08-08 18:00:03 -0400487 fTarget.get()->origin(),
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400488 fTarget.get()->getBoundsRect(),
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400489 fColorLoadOp,
490 fLoadClearColor,
Robert Phillips6b47c7d2017-08-29 07:24:09 -0400491 fStencilLoadOp);
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400492 flushState->setCommandBuffer(commandBuffer);
Robert Phillips95214472017-08-08 18:00:03 -0400493 commandBuffer->begin();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400494
495 // Draw all the generated geometry.
Brian Salomon588cec72018-11-14 13:56:37 -0500496 for (const auto& chain : fOpChains) {
497 if (!chain.head()) {
bsalomonaecc0182016-03-07 11:50:44 -0800498 continue;
499 }
Stan Iliev2af578d2017-08-16 13:00:28 -0400500#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Brian Salomon588cec72018-11-14 13:56:37 -0500501 TRACE_EVENT0("skia", chain.head()->name());
Stan Iliev2af578d2017-08-16 13:00:28 -0400502#endif
Robert Phillips178ce3e2017-04-13 09:15:47 -0400503
Brian Salomon29b60c92017-10-31 14:42:10 -0400504 GrOpFlushState::OpArgs opArgs {
Brian Salomon588cec72018-11-14 13:56:37 -0500505 chain.head(),
Robert Phillips2890fbf2017-07-26 15:48:41 -0400506 fTarget.get()->asRenderTargetProxy(),
Brian Salomon588cec72018-11-14 13:56:37 -0500507 chain.appliedClip(),
508 chain.dstProxy()
Robert Phillips178ce3e2017-04-13 09:15:47 -0400509 };
510
Brian Salomon29b60c92017-10-31 14:42:10 -0400511 flushState->setOpArgs(&opArgs);
Brian Salomon588cec72018-11-14 13:56:37 -0500512 chain.head()->execute(flushState, chain.bounds());
Brian Salomon29b60c92017-10-31 14:42:10 -0400513 flushState->setOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700514 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400515
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400516 commandBuffer->end();
517 flushState->gpu()->submit(commandBuffer);
Robert Phillips178ce3e2017-04-13 09:15:47 -0400518 flushState->setCommandBuffer(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800519
bsalomondc438982016-08-31 11:53:49 -0700520 return true;
bsalomona73239a2015-04-28 13:35:17 -0700521}
522
Chris Daltona84cacf2017-10-04 10:30:29 -0600523void GrRenderTargetOpList::endFlush() {
Brian Salomonc3833b42018-07-09 18:23:58 +0000524 fLastClipStackGenID = SK_InvalidUniqueID;
Robert Phillipsc994a932018-06-19 13:09:54 -0400525 this->deleteOps();
Chris Daltonc82dd4e2017-11-20 18:20:28 -0700526 fClipAllocator.reset();
Chris Daltona84cacf2017-10-04 10:30:29 -0600527 INHERITED::endFlush();
bsalomon512be532015-09-10 10:42:55 -0700528}
529
Robert Phillips380b90c2017-08-30 07:41:07 -0400530void GrRenderTargetOpList::discard() {
531 // Discard calls to in-progress opLists are ignored. Calls at the start update the
532 // opLists' color & stencil load ops.
533 if (this->isEmpty()) {
534 fColorLoadOp = GrLoadOp::kDiscard;
535 fStencilLoadOp = GrLoadOp::kDiscard;
536 }
537}
538
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500539void GrRenderTargetOpList::setStencilLoadOp(GrLoadOp op) {
540 fStencilLoadOp = op;
541}
Robert Phillips380b90c2017-08-30 07:41:07 -0400542
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500543void GrRenderTargetOpList::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) {
544 fColorLoadOp = op;
545 fLoadClearColor = color;
546}
547
548bool GrRenderTargetOpList::resetForFullscreenClear() {
549 // Mark the color load op as discard (this may be followed by a clearColorOnLoad call to make
550 // the load op kClear, or it may be followed by an explicit op). In the event of an absClear()
551 // after a regular clear(), we could end up with a clear load op and a real clear op in the list
552 // if the load op were not reset here.
553 fColorLoadOp = GrLoadOp::kDiscard;
554
555 // Regardless of how the clear is implemented (native clear or a fullscreen quad), all prior ops
556 // would be overwritten, so discard them entirely. The one exception is if the opList is marked
557 // as needing a stencil buffer then there may be a prior op that writes to the stencil buffer.
558 // Although the clear will ignore the stencil buffer, following draw ops may not so we can't get
559 // rid of all the preceding ops. Beware! If we ever add any ops that have a side effect beyond
560 // modifying the stencil buffer we will need a more elaborate tracking system (skbug.com/7002).
Greg Danielcb324152019-02-25 11:36:53 -0500561 // Additionally, if we previously recorded a wait op, we cannot delete the wait op. Until we
562 // track the wait ops separately from normal ops, we have to avoid clearing out any ops.
563 if (this->isEmpty() || (!fTarget.get()->asRenderTargetProxy()->needsStencil() && !fHasWaitOp)) {
Robert Phillipsc994a932018-06-19 13:09:54 -0400564 this->deleteOps();
Brian Osman099fa0f2017-10-02 16:38:32 -0400565 fDeferredProxies.reset();
Greg Daniel070cbaf2019-01-03 17:35:54 -0500566
567 // If the opList is using a render target which wraps a vulkan command buffer, we can't do a
568 // clear load since we cannot change the render pass that we are using. Thus we fall back to
569 // making a clear op in this case.
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500570 return !fTarget.get()->asRenderTargetProxy()->wrapsVkSecondaryCB();
bsalomonfd8d0132016-08-11 11:25:33 -0700571 }
Robert Phillips380b90c2017-08-30 07:41:07 -0400572
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500573 // Could not empty the list, so an op must be added to handle the clear
574 return false;
bsalomon9f129de2016-08-10 16:31:05 -0700575}
576
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000577////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000578
Robert Phillips81dd3e02017-06-23 11:59:24 -0400579// This closely parallels GrTextureOpList::copySurface but renderTargetOpLists
580// also store the applied clip and dest proxy with the op
Robert Phillipsbe9aff22019-02-15 11:33:22 -0500581bool GrRenderTargetOpList::copySurface(GrRecordingContext* context,
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400582 GrSurfaceProxy* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400583 GrSurfaceProxy* src,
Robert Phillipsf2361d22016-10-25 14:20:06 -0400584 const SkIRect& srcRect,
585 const SkIPoint& dstPoint) {
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400586 SkASSERT(dst->asRenderTargetProxy() == fTarget.get());
Robert Phillips7c525e62018-06-12 10:11:12 -0400587 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(context, dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500588 if (!op) {
bsalomonb8fea972016-02-16 07:34:17 -0800589 return false;
590 }
robertphillips498d7ac2015-10-30 10:11:30 -0700591
Robert Phillips9da87e02019-02-04 13:26:26 -0500592 this->addOp(std::move(op), *context->priv().caps());
bsalomonb8fea972016-02-16 07:34:17 -0800593 return true;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000594}
595
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500596void GrRenderTargetOpList::purgeOpsWithUninstantiatedProxies() {
597 bool hasUninstantiatedProxy = false;
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400598 auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p) {
599 if (!p->isInstantiated()) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500600 hasUninstantiatedProxy = true;
601 }
602 };
Brian Salomon588cec72018-11-14 13:56:37 -0500603 for (OpChain& recordedOp : fOpChains) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500604 hasUninstantiatedProxy = false;
Brian Salomon588cec72018-11-14 13:56:37 -0500605 recordedOp.visitProxies(checkInstantiation, GrOp::VisitorType::kOther);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500606 if (hasUninstantiatedProxy) {
607 // When instantiation of the proxy fails we drop the Op
Brian Salomon588cec72018-11-14 13:56:37 -0500608 recordedOp.deleteOps(fOpMemoryPool.get());
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500609 }
610 }
611}
612
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400613void GrRenderTargetOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400614
Robert Phillips51b20f22017-12-01 15:32:35 -0500615 for (int i = 0; i < fDeferredProxies.count(); ++i) {
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400616 SkASSERT(!fDeferredProxies[i]->isInstantiated());
Robert Phillips51b20f22017-12-01 15:32:35 -0500617 // We give all the deferred proxies a write usage at the very start of flushing. This
618 // locks them out of being reused for the entire flush until they are read - and then
619 // they can be recycled. This is a bit unfortunate because a flush can proceed in waves
620 // with sub-flushes. The deferred proxies only need to be pinned from the start of
621 // the sub-flush in which they appear.
622 alloc->addInterval(fDeferredProxies[i], 0, 0);
623 }
624
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400625 // Add the interval for all the writes to this opList's target
Brian Salomon588cec72018-11-14 13:56:37 -0500626 if (fOpChains.count()) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400627 unsigned int cur = alloc->curOp();
628
Brian Salomon588cec72018-11-14 13:56:37 -0500629 alloc->addInterval(fTarget.get(), cur, cur + fOpChains.count() - 1);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500630 } else {
631 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
632 // still need to add an interval for the destination so we create a fake op# for
633 // the missing clear op.
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400634 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp());
Robert Phillipsf8e25022017-11-08 15:24:31 -0500635 alloc->incOps();
636 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400637
Chris Dalton8816b932017-11-29 16:48:25 -0700638 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p) {
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400639 alloc->addInterval(p, alloc->curOp(), alloc->curOp() SkDEBUGCODE(, fTarget.get() == p));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400640 };
Brian Salomon588cec72018-11-14 13:56:37 -0500641 for (const OpChain& recordedOp : fOpChains) {
Brian Salomon7d94bb52018-10-12 14:37:19 -0400642 // only diff from the GrTextureOpList version
643 recordedOp.visitProxies(gather, GrOp::VisitorType::kAllocatorGather);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500644
Robert Phillips3bf3d4a2019-03-27 07:09:09 -0400645 // 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 -0500646 // keep all the math consistent.
647 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400648 }
649}
650
Chris Dalton945ee652019-01-23 09:10:36 -0700651void GrRenderTargetOpList::recordOp(
652 std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip,
653 const DstProxy* dstProxy, const GrCaps& caps) {
Ethan Nicholas029b22c2018-10-18 16:49:56 -0400654 SkDEBUGCODE(op->validate();)
Chris Dalton945ee652019-01-23 09:10:36 -0700655 SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxy && dstProxy->proxy()));
Robert Phillips318c4192017-05-17 09:36:38 -0400656 SkASSERT(fTarget.get());
Robert Phillipsee683652017-04-26 11:53:10 -0400657
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500658 // A closed GrOpList should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700659 SkASSERT(!this->isClosed());
Brian Salomon19ec80f2018-11-16 13:27:30 -0500660 if (!op->bounds().isFinite()) {
661 fOpMemoryPool->release(std::move(op));
662 return;
663 }
robertphillipsa106c622015-10-16 09:07:06 -0700664
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500665 // Check if there is an op we can combine with by linearly searching back until we either
666 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700667 // 2) intersect with something
668 // 3) find a 'blocker'
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400669 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400670 GrOP_INFO("opList: %d Recording (%s, opID: %u)\n"
671 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
672 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500673 op->name(),
674 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400675 op->bounds().fLeft, op->bounds().fTop,
676 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500677 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500678 GrOP_INFO("\tOutcome:\n");
Brian Salomon588cec72018-11-14 13:56:37 -0500679 int maxCandidates = SkTMin(kMaxOpChainDistance, fOpChains.count());
Robert Phillips318c4192017-05-17 09:36:38 -0400680 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700681 int i = 0;
682 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500683 OpChain& candidate = fOpChains.fromBack(i);
Chris Dalton945ee652019-01-23 09:10:36 -0700684 op = candidate.appendOp(std::move(op), processorAnalysis, dstProxy, clip, caps,
685 fOpMemoryPool.get(), fAuditTrail);
Brian Salomon588cec72018-11-14 13:56:37 -0500686 if (!op) {
687 return;
bsalomon512be532015-09-10 10:42:55 -0700688 }
Brian Salomona7682c82018-10-24 10:04:37 -0400689 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -0500690 if (!can_reorder(candidate.bounds(), op->bounds())) {
691 GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n",
692 candidate.head()->name(), candidate.head()->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700693 break;
694 }
Brian Salomon588cec72018-11-14 13:56:37 -0500695 if (++i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400696 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -0700697 break;
698 }
699 }
700 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400701 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -0700702 }
Brian Salomon54d212e2017-03-21 14:22:38 -0400703 if (clip) {
704 clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -0400705 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400706 }
Chris Dalton945ee652019-01-23 09:10:36 -0700707 fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxy);
bsalomon512be532015-09-10 10:42:55 -0700708}
709
Robert Phillipsee683652017-04-26 11:53:10 -0400710void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400711 SkASSERT(!this->isClosed());
Brian Salomon588cec72018-11-14 13:56:37 -0500712 GrOP_INFO("opList: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count());
Robert Phillips48567ac2017-06-01 08:46:00 -0400713
Brian Salomon588cec72018-11-14 13:56:37 -0500714 for (int i = 0; i < fOpChains.count() - 1; ++i) {
715 OpChain& chain = fOpChains[i];
716 int maxCandidateIdx = SkTMin(i + kMaxOpChainDistance, fOpChains.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -0800717 int j = i + 1;
718 while (true) {
Brian Salomon588cec72018-11-14 13:56:37 -0500719 OpChain& candidate = fOpChains[j];
720 if (candidate.prependChain(&chain, caps, fOpMemoryPool.get(), fAuditTrail)) {
bsalomonaecc0182016-03-07 11:50:44 -0800721 break;
722 }
Robert Phillipsc84c0302017-05-08 15:35:11 -0400723 // Stop traversing if we would cause a painter's order violation.
Brian Salomon588cec72018-11-14 13:56:37 -0500724 if (!can_reorder(chain.bounds(), candidate.bounds())) {
725 GrOP_INFO(
726 "\t\t%d: chain (%s head opID: %u) -> "
727 "Intersects with chain (%s, head opID: %u)\n",
728 i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(),
729 candidate.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800730 break;
731 }
Brian Salomona7682c82018-10-24 10:04:37 -0400732 if (++j > maxCandidateIdx) {
Brian Salomon588cec72018-11-14 13:56:37 -0500733 GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n",
734 i, chain.head()->name(), chain.head()->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800735 break;
736 }
737 }
738 }
739}
740