blob: 8d47ffffceecd97cd45d478e2fefb55f27ca2f70 [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"
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000013#include "GrRenderTarget.h"
Brian Salomon467921e2017-03-06 16:17:12 -050014#include "GrRenderTargetContext.h"
bsalomon4061b122015-05-29 10:26:19 -070015#include "GrResourceProvider.h"
Brian Salomon89527432016-12-16 09:52:16 -050016#include "ops/GrClearOp.h"
17#include "ops/GrClearStencilClipOp.h"
18#include "ops/GrCopySurfaceOp.h"
19#include "ops/GrDiscardOp.h"
csmartdaltona7f29642016-07-07 08:49:11 -070020#include "instanced/InstancedRendering.h"
21
Robert Phillipsf2361d22016-10-25 14:20:06 -040022using gr_instanced::InstancedRendering;
23
reed@google.comac10a2d2010-12-22 21:39:39 +000024////////////////////////////////////////////////////////////////////////////////
25
Brian Salomon09d994e2016-12-21 11:14:46 -050026// Experimentally we have found that most combining occurs within the first 10 comparisons.
27static const int kDefaultMaxOpLookback = 10;
28static const int kDefaultMaxOpLookahead = 10;
bsalomon489147c2015-12-14 12:13:09 -080029
Robert Phillipsc7635fa2016-10-28 13:25:24 -040030GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* rtp, GrGpu* gpu,
Robert Phillipsf2361d22016-10-25 14:20:06 -040031 GrResourceProvider* resourceProvider,
32 GrAuditTrail* auditTrail, const Options& options)
Brian Salomonc48af932017-03-16 19:51:42 +000033 : INHERITED(rtp, auditTrail)
34 , fGpu(SkRef(gpu))
35 , fResourceProvider(resourceProvider)
36 , fLastClipStackGenID(SK_InvalidUniqueID) {
robertphillips4beb5c12015-10-20 07:50:00 -070037
Brian Salomon09d994e2016-12-21 11:14:46 -050038 fMaxOpLookback = (options.fMaxOpCombineLookback < 0) ? kDefaultMaxOpLookback
39 : options.fMaxOpCombineLookback;
40 fMaxOpLookahead = (options.fMaxOpCombineLookahead < 0) ? kDefaultMaxOpLookahead
41 : options.fMaxOpCombineLookahead;
bsalomon6dea83f2015-12-03 12:58:06 -080042
csmartdaltone0d36292016-07-29 08:14:20 -070043 if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
44 fInstancedRendering.reset(fGpu->createInstancedRendering());
45 }
bsalomon4061b122015-05-29 10:26:19 -070046}
47
Robert Phillipsf2361d22016-10-25 14:20:06 -040048GrRenderTargetOpList::~GrRenderTargetOpList() {
bsalomon4061b122015-05-29 10:26:19 -070049 fGpu->unref();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000050}
51
52////////////////////////////////////////////////////////////////////////////////
53
robertphillips4beb5c12015-10-20 07:50:00 -070054#ifdef SK_DEBUG
Robert Phillipsf2361d22016-10-25 14:20:06 -040055void GrRenderTargetOpList::dump() const {
56 INHERITED::dump();
57
Brian Salomon1e41f4a2016-12-07 15:05:04 -050058 SkDebugf("ops (%d):\n", fRecordedOps.count());
59 for (int i = 0; i < fRecordedOps.count(); ++i) {
robertphillips4beb5c12015-10-20 07:50:00 -070060 SkDebugf("*******************************\n");
Brian Salomon1e41f4a2016-12-07 15:05:04 -050061 if (!fRecordedOps[i].fOp) {
bsalomonaecc0182016-03-07 11:50:44 -080062 SkDebugf("%d: <combined forward>\n", i);
63 } else {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050064 SkDebugf("%d: %s\n", i, fRecordedOps[i].fOp->name());
65 SkString str = fRecordedOps[i].fOp->dumpInfo();
bsalomonaecc0182016-03-07 11:50:44 -080066 SkDebugf("%s\n", str.c_str());
Brian Salomon9e50f7b2017-03-06 12:02:34 -050067 const SkRect& bounds = fRecordedOps[i].fOp->bounds();
68 SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
69 bounds.fTop, bounds.fRight, bounds.fBottom);
bsalomonaecc0182016-03-07 11:50:44 -080070 }
robertphillips4beb5c12015-10-20 07:50:00 -070071 }
72}
Robert Phillipseb35f4d2017-03-21 07:56:47 -040073
74void GrRenderTargetOpList::validateTargetsSingleRenderTarget() const {
75 GrRenderTarget* rt = nullptr;
76 for (int i = 0; i < fRecordedOps.count(); ++i) {
77 if (!fRecordedOps[i].fOp) {
78 continue; // combined forward
79 }
80
81 if (!rt) {
82 rt = fRecordedOps[i].fRenderTarget.get();
83 } else {
84 SkASSERT(fRecordedOps[i].fRenderTarget.get() == rt);
85 }
86 }
87}
robertphillips4beb5c12015-10-20 07:50:00 -070088#endif
89
Brian Salomon742e31d2016-12-07 17:06:19 -050090void GrRenderTargetOpList::prepareOps(GrOpFlushState* flushState) {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040091 // MDB TODO: add SkASSERT(this->isClosed());
robertphillipsa106c622015-10-16 09:07:06 -070092
Brian Salomon1e41f4a2016-12-07 15:05:04 -050093 // Loop over the ops that haven't yet been prepared.
94 for (int i = 0; i < fRecordedOps.count(); ++i) {
95 if (fRecordedOps[i].fOp) {
96 fRecordedOps[i].fOp->prepare(flushState);
bsalomonaecc0182016-03-07 11:50:44 -080097 }
bsalomon512be532015-09-10 10:42:55 -070098 }
csmartdaltona7f29642016-07-07 08:49:11 -070099
100 if (fInstancedRendering) {
101 fInstancedRendering->beginFlush(flushState->resourceProvider());
102 }
robertphillipsa13e2022015-11-11 12:01:09 -0800103}
bsalomon512be532015-09-10 10:42:55 -0700104
Brian Salomon25a88092016-12-01 09:36:50 -0500105// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500106// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500107// Ops and instantiate them here.
Brian Salomon742e31d2016-12-07 17:06:19 -0500108bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500109 if (0 == fRecordedOps.count()) {
bsalomondc438982016-08-31 11:53:49 -0700110 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700111 }
bsalomon512be532015-09-10 10:42:55 -0700112 // Draw all the generated geometry.
bsalomon6dea83f2015-12-03 12:58:06 -0800113 SkRandom random;
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500114 const GrRenderTarget* currentRenderTarget = nullptr;
Ben Wagner145dbcd2016-11-03 14:40:50 -0400115 std::unique_ptr<GrGpuCommandBuffer> commandBuffer;
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500116 for (int i = 0; i < fRecordedOps.count(); ++i) {
117 if (!fRecordedOps[i].fOp) {
bsalomonaecc0182016-03-07 11:50:44 -0800118 continue;
119 }
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500120 if (fRecordedOps[i].fRenderTarget.get() != currentRenderTarget) {
egdaniel9cb63402016-06-23 08:37:05 -0700121 if (commandBuffer) {
122 commandBuffer->end();
Greg Daniel36a77ee2016-10-18 10:33:25 -0400123 commandBuffer->submit();
egdaniel9cb63402016-06-23 08:37:05 -0700124 commandBuffer.reset();
125 }
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500126 currentRenderTarget = fRecordedOps[i].fRenderTarget.get();
127 if (currentRenderTarget) {
egdaniel9cb63402016-06-23 08:37:05 -0700128 static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo
129 { GrGpuCommandBuffer::LoadOp::kLoad,GrGpuCommandBuffer::StoreOp::kStore,
130 GrColor_ILLEGAL };
Brian Salomonc293a292016-11-30 13:38:32 -0500131 commandBuffer.reset(fGpu->createCommandBuffer(kBasicLoadStoreInfo, // Color
egdaniel9cb63402016-06-23 08:37:05 -0700132 kBasicLoadStoreInfo)); // Stencil
133 }
Ben Wagner145dbcd2016-11-03 14:40:50 -0400134 flushState->setCommandBuffer(commandBuffer.get());
egdaniel9cb63402016-06-23 08:37:05 -0700135 }
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500136 fRecordedOps[i].fOp->execute(flushState);
bsalomon512be532015-09-10 10:42:55 -0700137 }
egdaniel9cb63402016-06-23 08:37:05 -0700138 if (commandBuffer) {
139 commandBuffer->end();
Greg Daniel36a77ee2016-10-18 10:33:25 -0400140 commandBuffer->submit();
egdaniel9cb63402016-06-23 08:37:05 -0700141 flushState->setCommandBuffer(nullptr);
142 }
ethannicholas22793252016-01-30 09:59:10 -0800143
Robert Phillipsf2361d22016-10-25 14:20:06 -0400144 fGpu->finishOpList();
bsalomondc438982016-08-31 11:53:49 -0700145 return true;
bsalomona73239a2015-04-28 13:35:17 -0700146}
147
Robert Phillipsf2361d22016-10-25 14:20:06 -0400148void GrRenderTargetOpList::reset() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500149 fLastFullClearOp = nullptr;
Brian Salomon69868af2016-12-22 15:42:51 -0500150 fLastFullClearRenderTargetID.makeInvalid();
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500151 fRecordedOps.reset();
csmartdaltona7f29642016-07-07 08:49:11 -0700152 if (fInstancedRendering) {
153 fInstancedRendering->endFlush();
154 }
bsalomon512be532015-09-10 10:42:55 -0700155}
156
Robert Phillipsf2361d22016-10-25 14:20:06 -0400157void GrRenderTargetOpList::abandonGpuResources() {
Brian Salomon467921e2017-03-06 16:17:12 -0500158 if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
Robert Phillipsf2361d22016-10-25 14:20:06 -0400159 InstancedRendering* ir = this->instancedRendering();
160 ir->resetGpuResources(InstancedRendering::ResetType::kAbandon);
161 }
162}
163
164void GrRenderTargetOpList::freeGpuResources() {
Brian Salomon467921e2017-03-06 16:17:12 -0500165 if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
Robert Phillipsf2361d22016-10-25 14:20:06 -0400166 InstancedRendering* ir = this->instancedRendering();
167 ir->resetGpuResources(InstancedRendering::ResetType::kDestroy);
168 }
169}
170
Brian Salomon69868af2016-12-22 15:42:51 -0500171void GrRenderTargetOpList::fullClear(GrRenderTargetContext* renderTargetContext, GrColor color) {
172 GrRenderTarget* renderTarget = renderTargetContext->accessRenderTarget();
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500173 // Currently this just inserts or updates the last clear op. However, once in MDB this can
174 // remove all the previously recorded ops and change the load op to clear with supplied
bsalomonfd8d0132016-08-11 11:25:33 -0700175 // color.
Robert Phillips294870f2016-11-11 12:38:40 -0500176 // TODO: this needs to be updated to use GrSurfaceProxy::UniqueID
Brian Salomon69868af2016-12-22 15:42:51 -0500177 if (fLastFullClearRenderTargetID == renderTarget->uniqueID()) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500178 // As currently implemented, fLastFullClearOp should be the last op because we would
179 // have cleared it when another op was recorded.
180 SkASSERT(fRecordedOps.back().fOp.get() == fLastFullClearOp);
181 fLastFullClearOp->setColor(color);
bsalomonfd8d0132016-08-11 11:25:33 -0700182 return;
183 }
Brian Salomonf8334782017-01-03 09:42:58 -0500184 std::unique_ptr<GrClearOp> op(GrClearOp::Make(GrFixedClip::Disabled(), color, renderTarget));
Brian Salomon69868af2016-12-22 15:42:51 -0500185 if (GrOp* clearOp = this->recordOp(std::move(op), renderTargetContext)) {
Brian Salomon2790c522016-12-09 16:32:23 -0500186 // This is either the clear op we just created or another one that it combined with.
Brian Salomon7dae46a2016-12-14 16:21:37 -0500187 fLastFullClearOp = static_cast<GrClearOp*>(clearOp);
Brian Salomon69868af2016-12-22 15:42:51 -0500188 fLastFullClearRenderTargetID = renderTarget->uniqueID();
bsalomonfd8d0132016-08-11 11:25:33 -0700189 }
bsalomon9f129de2016-08-10 16:31:05 -0700190}
191
Brian Salomon69868af2016-12-22 15:42:51 -0500192void GrRenderTargetOpList::discard(GrRenderTargetContext* renderTargetContext) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500193 // Currently this just inserts a discard op. However, once in MDB this can remove all the
194 // previously recorded ops and change the load op to discard.
bsalomon53469832015-08-18 09:20:09 -0700195 if (this->caps()->discardRenderTargetSupport()) {
Brian Salomon69868af2016-12-22 15:42:51 -0500196 this->recordOp(GrDiscardOp::Make(renderTargetContext->accessRenderTarget()),
197 renderTargetContext);
bsalomon63b21962014-11-05 07:05:34 -0800198 }
199}
200
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000201////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000202
Robert Phillipsf2361d22016-10-25 14:20:06 -0400203bool GrRenderTargetOpList::copySurface(GrSurface* dst,
204 GrSurface* src,
205 const SkIRect& srcRect,
206 const SkIPoint& dstPoint) {
Brian Salomonf8334782017-01-03 09:42:58 -0500207 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500208 if (!op) {
bsalomonb8fea972016-02-16 07:34:17 -0800209 return false;
210 }
robertphillips498d7ac2015-10-30 10:11:30 -0700211#ifdef ENABLE_MDB
bsalomonb8fea972016-02-16 07:34:17 -0800212 this->addDependency(src);
robertphillips498d7ac2015-10-30 10:11:30 -0700213#endif
214
Brian Salomon69868af2016-12-22 15:42:51 -0500215 // Copy surface doesn't work through a GrGpuCommandBuffer. By passing nullptr for the context we
216 // force this to occur between command buffers and execute directly on GrGpu. This workaround
217 // goes away with MDB.
218 this->recordOp(std::move(op), nullptr);
bsalomonb8fea972016-02-16 07:34:17 -0800219 return true;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000220}
221
bsalomon6cc90062016-07-08 11:31:22 -0700222static inline bool can_reorder(const SkRect& a, const SkRect& b) {
bsalomon88cf17d2016-07-08 06:40:56 -0700223 return a.fRight <= b.fLeft || a.fBottom <= b.fTop ||
224 b.fRight <= a.fLeft || b.fBottom <= a.fTop;
225}
226
Brian Salomonf8334782017-01-03 09:42:58 -0500227GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
Brian Salomonc48af932017-03-16 19:51:42 +0000228 GrRenderTargetContext* renderTargetContext) {
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500229 GrRenderTarget* renderTarget =
230 renderTargetContext ? renderTargetContext->accessRenderTarget()
231 : nullptr;
Brian Salomon69868af2016-12-22 15:42:51 -0500232
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500233 // A closed GrOpList should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700234 SkASSERT(!this->isClosed());
robertphillipsa106c622015-10-16 09:07:06 -0700235
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500236 // Check if there is an op we can combine with by linearly searching back until we either
237 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700238 // 2) intersect with something
239 // 3) find a 'blocker'
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500240 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTarget->uniqueID());
Brian Salomon199fb872017-02-06 09:41:10 -0500241 GrOP_INFO("Recording (%s, B%u)\n"
Brian Salomon25a88092016-12-01 09:36:50 -0500242 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500243 op->name(),
244 op->uniqueID(),
245 op->bounds().fLeft, op->bounds().fRight,
246 op->bounds().fTop, op->bounds().fBottom);
247 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500248 GrOP_INFO("\tClipped Bounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", op->bounds().fLeft,
249 op->bounds().fTop, op->bounds().fRight, op->bounds().fBottom);
Brian Salomon25a88092016-12-01 09:36:50 -0500250 GrOP_INFO("\tOutcome:\n");
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500251 int maxCandidates = SkTMin(fMaxOpLookback, fRecordedOps.count());
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500252 // If we don't have a valid destination render target then we cannot reorder.
253 if (maxCandidates && renderTarget) {
bsalomon512be532015-09-10 10:42:55 -0700254 int i = 0;
255 while (true) {
Brian Salomon69868af2016-12-22 15:42:51 -0500256 const RecordedOp& candidate = fRecordedOps.fromBack(i);
bsalomon512be532015-09-10 10:42:55 -0700257 // We cannot continue to search backwards if the render target changes
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500258 if (candidate.fRenderTarget.get() != renderTarget) {
Brian Salomon69868af2016-12-22 15:42:51 -0500259 GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(),
260 candidate.fOp->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700261 break;
262 }
Brian Salomonc48af932017-03-16 19:51:42 +0000263 if (candidate.fOp->combineIfPossible(op.get(), *this->caps())) {
Brian Salomon69868af2016-12-22 15:42:51 -0500264 GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(),
265 candidate.fOp->uniqueID());
Brian Salomon199fb872017-02-06 09:41:10 -0500266 GrOP_INFO("\t\t\tCombined op info:\n");
267 GrOP_INFO(SkTabString(candidate.fOp->dumpInfo(), 4).c_str());
Brian Salomon69868af2016-12-22 15:42:51 -0500268 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, candidate.fOp.get(), op.get());
Brian Salomon69868af2016-12-22 15:42:51 -0500269 return candidate.fOp.get();
bsalomon512be532015-09-10 10:42:55 -0700270 }
271 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500272 if (!can_reorder(fRecordedOps.fromBack(i).fOp->bounds(), op->bounds())) {
Brian Salomon69868af2016-12-22 15:42:51 -0500273 GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(),
274 candidate.fOp->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700275 break;
276 }
277 ++i;
278 if (i == maxCandidates) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500279 GrOP_INFO("\t\tReached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -0700280 break;
281 }
282 }
283 } else {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500284 GrOP_INFO("\t\tFirstOp\n");
bsalomon512be532015-09-10 10:42:55 -0700285 }
Brian Salomon42ad83a2016-12-20 16:14:45 -0500286 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op);
Brian Salomonc48af932017-03-16 19:51:42 +0000287 fRecordedOps.emplace_back(std::move(op), renderTarget);
Brian Salomond543e0a2017-03-06 16:36:49 -0500288 fRecordedOps.back().fOp->wasRecorded();
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500289 fLastFullClearOp = nullptr;
Brian Salomon69868af2016-12-22 15:42:51 -0500290 fLastFullClearRenderTargetID.makeInvalid();
Brian Salomon2790c522016-12-09 16:32:23 -0500291 return fRecordedOps.back().fOp.get();
bsalomon512be532015-09-10 10:42:55 -0700292}
293
Robert Phillipsf2361d22016-10-25 14:20:06 -0400294void GrRenderTargetOpList::forwardCombine() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500295 if (fMaxOpLookahead <= 0) {
bsalomondb27fc52016-08-29 12:43:27 -0700296 return;
297 }
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500298 for (int i = 0; i < fRecordedOps.count() - 2; ++i) {
299 GrOp* op = fRecordedOps[i].fOp.get();
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500300 GrRenderTarget* renderTarget = fRecordedOps[i].fRenderTarget.get();
Brian Salomon69868af2016-12-22 15:42:51 -0500301 // If we don't have a valid destination render target ID then we cannot reorder.
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500302 if (!renderTarget) {
Brian Salomon69868af2016-12-22 15:42:51 -0500303 continue;
304 }
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500305 int maxCandidateIdx = SkTMin(i + fMaxOpLookahead, fRecordedOps.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -0800306 int j = i + 1;
307 while (true) {
Brian Salomon69868af2016-12-22 15:42:51 -0500308 const RecordedOp& candidate = fRecordedOps[j];
bsalomonaecc0182016-03-07 11:50:44 -0800309 // We cannot continue to search if the render target changes
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500310 if (candidate.fRenderTarget.get() != renderTarget) {
Brian Salomon69868af2016-12-22 15:42:51 -0500311 GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(),
312 candidate.fOp->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800313 break;
314 }
315 if (j == i +1) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500316 // We assume op would have combined with candidate when the candidate was added
317 // via backwards combining in recordOp.
Mike Reeda1361362017-03-07 09:37:29 -0500318
Mike Reedd519d482017-02-16 11:04:52 -0500319 // not sure why this fires with device-clipping in gm/complexclip4.cpp
Brian Salomonc48af932017-03-16 19:51:42 +0000320// SkASSERT(!op->combineIfPossible(candidate.fOp.get(), *this->caps()));
321
322 } else if (op->combineIfPossible(candidate.fOp.get(), *this->caps())) {
Brian Salomon69868af2016-12-22 15:42:51 -0500323 GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(),
324 candidate.fOp->uniqueID());
325 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get());
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500326 fRecordedOps[j].fOp = std::move(fRecordedOps[i].fOp);
bsalomonaecc0182016-03-07 11:50:44 -0800327 break;
328 }
329 // Stop going traversing if we would cause a painter's order violation.
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500330 if (!can_reorder(fRecordedOps[j].fOp->bounds(), op->bounds())) {
Brian Salomon69868af2016-12-22 15:42:51 -0500331 GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(),
332 candidate.fOp->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800333 break;
334 }
335 ++j;
336 if (j > maxCandidateIdx) {
Brian Salomon09d994e2016-12-21 11:14:46 -0500337 GrOP_INFO("\t\tReached max lookahead or end of op array %d\n", i);
bsalomonaecc0182016-03-07 11:50:44 -0800338 break;
339 }
340 }
341 }
342}
343
egdaniele36914c2015-02-13 09:00:33 -0800344///////////////////////////////////////////////////////////////////////////////
345
Robert Phillipsf2361d22016-10-25 14:20:06 -0400346void GrRenderTargetOpList::clearStencilClip(const GrFixedClip& clip,
347 bool insideStencilMask,
Brian Salomon69868af2016-12-22 15:42:51 -0500348 GrRenderTargetContext* renderTargetContext) {
349 this->recordOp(GrClearStencilClipOp::Make(clip, insideStencilMask,
350 renderTargetContext->accessRenderTarget()),
351 renderTargetContext);
bsalomon5ea03632015-08-18 10:33:30 -0700352}