blob: 1c9835389e733ef5a6bc994baa3afc9e8d89af70 [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)
Robert Phillipsc7635fa2016-10-28 13:25:24 -040033 : INHERITED(rtp, auditTrail)
bsalomonfd8d0132016-08-11 11:25:33 -070034 , fGpu(SkRef(gpu))
csmartdalton7cdda992016-11-01 07:03:03 -070035 , 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}
73#endif
74
Brian Salomon742e31d2016-12-07 17:06:19 -050075void GrRenderTargetOpList::prepareOps(GrOpFlushState* flushState) {
Robert Phillipsf2361d22016-10-25 14:20:06 -040076 // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh
77 // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed
78 // but need to be flushed anyway. Closing such GrOpLists here will mean new
79 // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again.
robertphillipsa106c622015-10-16 09:07:06 -070080 this->makeClosed();
81
Brian Salomon1e41f4a2016-12-07 15:05:04 -050082 // Loop over the ops that haven't yet been prepared.
83 for (int i = 0; i < fRecordedOps.count(); ++i) {
84 if (fRecordedOps[i].fOp) {
85 fRecordedOps[i].fOp->prepare(flushState);
bsalomonaecc0182016-03-07 11:50:44 -080086 }
bsalomon512be532015-09-10 10:42:55 -070087 }
csmartdaltona7f29642016-07-07 08:49:11 -070088
89 if (fInstancedRendering) {
90 fInstancedRendering->beginFlush(flushState->resourceProvider());
91 }
robertphillipsa13e2022015-11-11 12:01:09 -080092}
bsalomon512be532015-09-10 10:42:55 -070093
Brian Salomon25a88092016-12-01 09:36:50 -050094// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -050095// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -050096// Ops and instantiate them here.
Brian Salomon742e31d2016-12-07 17:06:19 -050097bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050098 if (0 == fRecordedOps.count()) {
bsalomondc438982016-08-31 11:53:49 -070099 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700100 }
bsalomon512be532015-09-10 10:42:55 -0700101 // Draw all the generated geometry.
bsalomon6dea83f2015-12-03 12:58:06 -0800102 SkRandom random;
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500103 const GrRenderTarget* currentRenderTarget = nullptr;
Ben Wagner145dbcd2016-11-03 14:40:50 -0400104 std::unique_ptr<GrGpuCommandBuffer> commandBuffer;
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500105 for (int i = 0; i < fRecordedOps.count(); ++i) {
106 if (!fRecordedOps[i].fOp) {
bsalomonaecc0182016-03-07 11:50:44 -0800107 continue;
108 }
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500109 if (fRecordedOps[i].fRenderTarget.get() != currentRenderTarget) {
egdaniel9cb63402016-06-23 08:37:05 -0700110 if (commandBuffer) {
111 commandBuffer->end();
Greg Daniel36a77ee2016-10-18 10:33:25 -0400112 commandBuffer->submit();
egdaniel9cb63402016-06-23 08:37:05 -0700113 commandBuffer.reset();
114 }
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500115 currentRenderTarget = fRecordedOps[i].fRenderTarget.get();
116 if (currentRenderTarget) {
egdaniel9cb63402016-06-23 08:37:05 -0700117 static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo
118 { GrGpuCommandBuffer::LoadOp::kLoad,GrGpuCommandBuffer::StoreOp::kStore,
119 GrColor_ILLEGAL };
Brian Salomonc293a292016-11-30 13:38:32 -0500120 commandBuffer.reset(fGpu->createCommandBuffer(kBasicLoadStoreInfo, // Color
egdaniel9cb63402016-06-23 08:37:05 -0700121 kBasicLoadStoreInfo)); // Stencil
122 }
Ben Wagner145dbcd2016-11-03 14:40:50 -0400123 flushState->setCommandBuffer(commandBuffer.get());
egdaniel9cb63402016-06-23 08:37:05 -0700124 }
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500125 fRecordedOps[i].fOp->execute(flushState);
bsalomon512be532015-09-10 10:42:55 -0700126 }
egdaniel9cb63402016-06-23 08:37:05 -0700127 if (commandBuffer) {
128 commandBuffer->end();
Greg Daniel36a77ee2016-10-18 10:33:25 -0400129 commandBuffer->submit();
egdaniel9cb63402016-06-23 08:37:05 -0700130 flushState->setCommandBuffer(nullptr);
131 }
ethannicholas22793252016-01-30 09:59:10 -0800132
Robert Phillipsf2361d22016-10-25 14:20:06 -0400133 fGpu->finishOpList();
bsalomondc438982016-08-31 11:53:49 -0700134 return true;
bsalomona73239a2015-04-28 13:35:17 -0700135}
136
Robert Phillipsf2361d22016-10-25 14:20:06 -0400137void GrRenderTargetOpList::reset() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500138 fLastFullClearOp = nullptr;
Brian Salomon69868af2016-12-22 15:42:51 -0500139 fLastFullClearRenderTargetID.makeInvalid();
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500140 fRecordedOps.reset();
csmartdaltona7f29642016-07-07 08:49:11 -0700141 if (fInstancedRendering) {
142 fInstancedRendering->endFlush();
143 }
bsalomon512be532015-09-10 10:42:55 -0700144}
145
Robert Phillipsf2361d22016-10-25 14:20:06 -0400146void GrRenderTargetOpList::abandonGpuResources() {
Brian Salomon467921e2017-03-06 16:17:12 -0500147 if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
Robert Phillipsf2361d22016-10-25 14:20:06 -0400148 InstancedRendering* ir = this->instancedRendering();
149 ir->resetGpuResources(InstancedRendering::ResetType::kAbandon);
150 }
151}
152
153void GrRenderTargetOpList::freeGpuResources() {
Brian Salomon467921e2017-03-06 16:17:12 -0500154 if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
Robert Phillipsf2361d22016-10-25 14:20:06 -0400155 InstancedRendering* ir = this->instancedRendering();
156 ir->resetGpuResources(InstancedRendering::ResetType::kDestroy);
157 }
158}
159
Brian Salomon69868af2016-12-22 15:42:51 -0500160void GrRenderTargetOpList::fullClear(GrRenderTargetContext* renderTargetContext, GrColor color) {
161 GrRenderTarget* renderTarget = renderTargetContext->accessRenderTarget();
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500162 // Currently this just inserts or updates the last clear op. However, once in MDB this can
163 // remove all the previously recorded ops and change the load op to clear with supplied
bsalomonfd8d0132016-08-11 11:25:33 -0700164 // color.
Robert Phillips294870f2016-11-11 12:38:40 -0500165 // TODO: this needs to be updated to use GrSurfaceProxy::UniqueID
Brian Salomon69868af2016-12-22 15:42:51 -0500166 if (fLastFullClearRenderTargetID == renderTarget->uniqueID()) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500167 // As currently implemented, fLastFullClearOp should be the last op because we would
168 // have cleared it when another op was recorded.
169 SkASSERT(fRecordedOps.back().fOp.get() == fLastFullClearOp);
170 fLastFullClearOp->setColor(color);
bsalomonfd8d0132016-08-11 11:25:33 -0700171 return;
172 }
Brian Salomonf8334782017-01-03 09:42:58 -0500173 std::unique_ptr<GrClearOp> op(GrClearOp::Make(GrFixedClip::Disabled(), color, renderTarget));
Brian Salomon69868af2016-12-22 15:42:51 -0500174 if (GrOp* clearOp = this->recordOp(std::move(op), renderTargetContext)) {
Brian Salomon2790c522016-12-09 16:32:23 -0500175 // This is either the clear op we just created or another one that it combined with.
Brian Salomon7dae46a2016-12-14 16:21:37 -0500176 fLastFullClearOp = static_cast<GrClearOp*>(clearOp);
Brian Salomon69868af2016-12-22 15:42:51 -0500177 fLastFullClearRenderTargetID = renderTarget->uniqueID();
bsalomonfd8d0132016-08-11 11:25:33 -0700178 }
bsalomon9f129de2016-08-10 16:31:05 -0700179}
180
Brian Salomon69868af2016-12-22 15:42:51 -0500181void GrRenderTargetOpList::discard(GrRenderTargetContext* renderTargetContext) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500182 // Currently this just inserts a discard op. However, once in MDB this can remove all the
183 // previously recorded ops and change the load op to discard.
bsalomon53469832015-08-18 09:20:09 -0700184 if (this->caps()->discardRenderTargetSupport()) {
Brian Salomon69868af2016-12-22 15:42:51 -0500185 this->recordOp(GrDiscardOp::Make(renderTargetContext->accessRenderTarget()),
186 renderTargetContext);
bsalomon63b21962014-11-05 07:05:34 -0800187 }
188}
189
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000190////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000191
Robert Phillipsf2361d22016-10-25 14:20:06 -0400192bool GrRenderTargetOpList::copySurface(GrSurface* dst,
193 GrSurface* src,
194 const SkIRect& srcRect,
195 const SkIPoint& dstPoint) {
Brian Salomonf8334782017-01-03 09:42:58 -0500196 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500197 if (!op) {
bsalomonb8fea972016-02-16 07:34:17 -0800198 return false;
199 }
robertphillips498d7ac2015-10-30 10:11:30 -0700200#ifdef ENABLE_MDB
bsalomonb8fea972016-02-16 07:34:17 -0800201 this->addDependency(src);
robertphillips498d7ac2015-10-30 10:11:30 -0700202#endif
203
Brian Salomon69868af2016-12-22 15:42:51 -0500204 // Copy surface doesn't work through a GrGpuCommandBuffer. By passing nullptr for the context we
205 // force this to occur between command buffers and execute directly on GrGpu. This workaround
206 // goes away with MDB.
207 this->recordOp(std::move(op), nullptr);
bsalomonb8fea972016-02-16 07:34:17 -0800208 return true;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000209}
210
bsalomon6cc90062016-07-08 11:31:22 -0700211static inline bool can_reorder(const SkRect& a, const SkRect& b) {
bsalomon88cf17d2016-07-08 06:40:56 -0700212 return a.fRight <= b.fLeft || a.fBottom <= b.fTop ||
213 b.fRight <= a.fLeft || b.fBottom <= a.fTop;
214}
215
Brian Salomonf8334782017-01-03 09:42:58 -0500216GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500217 GrRenderTargetContext* renderTargetContext) {
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500218 GrRenderTarget* renderTarget =
219 renderTargetContext ? renderTargetContext->accessRenderTarget()
220 : nullptr;
Brian Salomon69868af2016-12-22 15:42:51 -0500221
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500222 // A closed GrOpList should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700223 SkASSERT(!this->isClosed());
robertphillipsa106c622015-10-16 09:07:06 -0700224
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500225 // Check if there is an op we can combine with by linearly searching back until we either
226 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700227 // 2) intersect with something
228 // 3) find a 'blocker'
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500229 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTarget->uniqueID());
Brian Salomon199fb872017-02-06 09:41:10 -0500230 GrOP_INFO("Recording (%s, B%u)\n"
Brian Salomon25a88092016-12-01 09:36:50 -0500231 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500232 op->name(),
233 op->uniqueID(),
234 op->bounds().fLeft, op->bounds().fRight,
235 op->bounds().fTop, op->bounds().fBottom);
236 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500237 GrOP_INFO("\tClipped Bounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", op->bounds().fLeft,
238 op->bounds().fTop, op->bounds().fRight, op->bounds().fBottom);
Brian Salomon25a88092016-12-01 09:36:50 -0500239 GrOP_INFO("\tOutcome:\n");
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500240 int maxCandidates = SkTMin(fMaxOpLookback, fRecordedOps.count());
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500241 // If we don't have a valid destination render target then we cannot reorder.
242 if (maxCandidates && renderTarget) {
bsalomon512be532015-09-10 10:42:55 -0700243 int i = 0;
244 while (true) {
Brian Salomon69868af2016-12-22 15:42:51 -0500245 const RecordedOp& candidate = fRecordedOps.fromBack(i);
bsalomon512be532015-09-10 10:42:55 -0700246 // We cannot continue to search backwards if the render target changes
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500247 if (candidate.fRenderTarget.get() != renderTarget) {
Brian Salomon69868af2016-12-22 15:42:51 -0500248 GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(),
249 candidate.fOp->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700250 break;
251 }
Brian Salomon69868af2016-12-22 15:42:51 -0500252 if (candidate.fOp->combineIfPossible(op.get(), *this->caps())) {
253 GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(),
254 candidate.fOp->uniqueID());
Brian Salomon199fb872017-02-06 09:41:10 -0500255 GrOP_INFO("\t\t\tCombined op info:\n");
256 GrOP_INFO(SkTabString(candidate.fOp->dumpInfo(), 4).c_str());
Brian Salomon69868af2016-12-22 15:42:51 -0500257 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, candidate.fOp.get(), op.get());
Brian Salomon69868af2016-12-22 15:42:51 -0500258 return candidate.fOp.get();
bsalomon512be532015-09-10 10:42:55 -0700259 }
260 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500261 if (!can_reorder(fRecordedOps.fromBack(i).fOp->bounds(), op->bounds())) {
Brian Salomon69868af2016-12-22 15:42:51 -0500262 GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(),
263 candidate.fOp->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700264 break;
265 }
266 ++i;
267 if (i == maxCandidates) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500268 GrOP_INFO("\t\tReached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -0700269 break;
270 }
271 }
272 } else {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500273 GrOP_INFO("\t\tFirstOp\n");
bsalomon512be532015-09-10 10:42:55 -0700274 }
Brian Salomon42ad83a2016-12-20 16:14:45 -0500275 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op);
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500276 fRecordedOps.emplace_back(std::move(op), renderTarget);
Brian Salomond543e0a2017-03-06 16:36:49 -0500277 fRecordedOps.back().fOp->wasRecorded();
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500278 fLastFullClearOp = nullptr;
Brian Salomon69868af2016-12-22 15:42:51 -0500279 fLastFullClearRenderTargetID.makeInvalid();
Brian Salomon2790c522016-12-09 16:32:23 -0500280 return fRecordedOps.back().fOp.get();
bsalomon512be532015-09-10 10:42:55 -0700281}
282
Robert Phillipsf2361d22016-10-25 14:20:06 -0400283void GrRenderTargetOpList::forwardCombine() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500284 if (fMaxOpLookahead <= 0) {
bsalomondb27fc52016-08-29 12:43:27 -0700285 return;
286 }
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500287 for (int i = 0; i < fRecordedOps.count() - 2; ++i) {
288 GrOp* op = fRecordedOps[i].fOp.get();
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500289 GrRenderTarget* renderTarget = fRecordedOps[i].fRenderTarget.get();
Brian Salomon69868af2016-12-22 15:42:51 -0500290 // If we don't have a valid destination render target ID then we cannot reorder.
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500291 if (!renderTarget) {
Brian Salomon69868af2016-12-22 15:42:51 -0500292 continue;
293 }
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500294 int maxCandidateIdx = SkTMin(i + fMaxOpLookahead, fRecordedOps.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -0800295 int j = i + 1;
296 while (true) {
Brian Salomon69868af2016-12-22 15:42:51 -0500297 const RecordedOp& candidate = fRecordedOps[j];
bsalomonaecc0182016-03-07 11:50:44 -0800298 // We cannot continue to search if the render target changes
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500299 if (candidate.fRenderTarget.get() != renderTarget) {
Brian Salomon69868af2016-12-22 15:42:51 -0500300 GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(),
301 candidate.fOp->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800302 break;
303 }
304 if (j == i +1) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500305 // We assume op would have combined with candidate when the candidate was added
306 // via backwards combining in recordOp.
Mike Reeda1361362017-03-07 09:37:29 -0500307
Mike Reedd519d482017-02-16 11:04:52 -0500308 // not sure why this fires with device-clipping in gm/complexclip4.cpp
Mike Reeda1361362017-03-07 09:37:29 -0500309// SkASSERT(!op->combineIfPossible(candidate.fOp.get(), *this->caps()));
310
Brian Salomon69868af2016-12-22 15:42:51 -0500311 } else if (op->combineIfPossible(candidate.fOp.get(), *this->caps())) {
312 GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(),
313 candidate.fOp->uniqueID());
314 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get());
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500315 fRecordedOps[j].fOp = std::move(fRecordedOps[i].fOp);
bsalomonaecc0182016-03-07 11:50:44 -0800316 break;
317 }
318 // Stop going traversing if we would cause a painter's order violation.
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500319 if (!can_reorder(fRecordedOps[j].fOp->bounds(), op->bounds())) {
Brian Salomon69868af2016-12-22 15:42:51 -0500320 GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(),
321 candidate.fOp->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800322 break;
323 }
324 ++j;
325 if (j > maxCandidateIdx) {
Brian Salomon09d994e2016-12-21 11:14:46 -0500326 GrOP_INFO("\t\tReached max lookahead or end of op array %d\n", i);
bsalomonaecc0182016-03-07 11:50:44 -0800327 break;
328 }
329 }
330 }
331}
332
egdaniele36914c2015-02-13 09:00:33 -0800333///////////////////////////////////////////////////////////////////////////////
334
Robert Phillipsf2361d22016-10-25 14:20:06 -0400335void GrRenderTargetOpList::clearStencilClip(const GrFixedClip& clip,
336 bool insideStencilMask,
Brian Salomon69868af2016-12-22 15:42:51 -0500337 GrRenderTargetContext* renderTargetContext) {
338 this->recordOp(GrClearStencilClipOp::Make(clip, insideStencilMask,
339 renderTargetContext->accessRenderTarget()),
340 renderTargetContext);
bsalomon5ea03632015-08-18 10:33:30 -0700341}