blob: d1c1425123d96163e84863256a584d8046313441 [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"
Brian Salomona4677b52017-05-04 12:39:56 -040013#include "GrRect.h"
Brian Salomon467921e2017-03-06 16:17:12 -050014#include "GrRenderTargetContext.h"
Brian Salomona4677b52017-05-04 12:39:56 -040015#include "instanced/InstancedRendering.h"
Brian Salomon89527432016-12-16 09:52:16 -050016#include "ops/GrClearOp.h"
Brian Salomon89527432016-12-16 09:52:16 -050017#include "ops/GrCopySurfaceOp.h"
csmartdaltona7f29642016-07-07 08:49:11 -070018
Robert Phillipsf2361d22016-10-25 14:20:06 -040019using gr_instanced::InstancedRendering;
20
reed@google.comac10a2d2010-12-22 21:39:39 +000021////////////////////////////////////////////////////////////////////////////////
22
Brian Salomon09d994e2016-12-21 11:14:46 -050023// Experimentally we have found that most combining occurs within the first 10 comparisons.
Robert Phillips8185f592017-04-26 08:31:08 -040024static const int kMaxOpLookback = 10;
25static const int kMaxOpLookahead = 10;
bsalomon489147c2015-12-14 12:13:09 -080026
Robert Phillipsb6deea82017-05-11 14:14:30 -040027GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* proxy, GrGpu* gpu,
Robert Phillips8185f592017-04-26 08:31:08 -040028 GrAuditTrail* auditTrail)
Robert Phillips5efd5ea2017-05-30 13:47:32 -040029 : INHERITED(gpu->getContext()->resourceProvider(), proxy, auditTrail)
Robert Phillipsc84c0302017-05-08 15:35:11 -040030 , fLastClipStackGenID(SK_InvalidUniqueID)
Robert Phillipsb6deea82017-05-11 14:14:30 -040031 SkDEBUGCODE(, fNumClips(0)) {
Robert Phillipsee683652017-04-26 11:53:10 -040032 if (GrCaps::InstancedSupport::kNone != gpu->caps()->instancedSupport()) {
33 fInstancedRendering.reset(gpu->createInstancedRendering());
csmartdaltone0d36292016-07-29 08:14:20 -070034 }
bsalomon4061b122015-05-29 10:26:19 -070035}
36
Robert Phillipsf2361d22016-10-25 14:20:06 -040037GrRenderTargetOpList::~GrRenderTargetOpList() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000038}
39
40////////////////////////////////////////////////////////////////////////////////
41
robertphillips4beb5c12015-10-20 07:50:00 -070042#ifdef SK_DEBUG
Robert Phillipsf2361d22016-10-25 14:20:06 -040043void GrRenderTargetOpList::dump() const {
44 INHERITED::dump();
45
Brian Salomon1e41f4a2016-12-07 15:05:04 -050046 SkDebugf("ops (%d):\n", fRecordedOps.count());
47 for (int i = 0; i < fRecordedOps.count(); ++i) {
robertphillips4beb5c12015-10-20 07:50:00 -070048 SkDebugf("*******************************\n");
Brian Salomon1e41f4a2016-12-07 15:05:04 -050049 if (!fRecordedOps[i].fOp) {
bsalomonaecc0182016-03-07 11:50:44 -080050 SkDebugf("%d: <combined forward>\n", i);
51 } else {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050052 SkDebugf("%d: %s\n", i, fRecordedOps[i].fOp->name());
53 SkString str = fRecordedOps[i].fOp->dumpInfo();
bsalomonaecc0182016-03-07 11:50:44 -080054 SkDebugf("%s\n", str.c_str());
Brian Salomon9e50f7b2017-03-06 12:02:34 -050055 const SkRect& bounds = fRecordedOps[i].fOp->bounds();
56 SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft,
57 bounds.fTop, bounds.fRight, bounds.fBottom);
bsalomonaecc0182016-03-07 11:50:44 -080058 }
robertphillips4beb5c12015-10-20 07:50:00 -070059 }
60}
61#endif
62
Brian Salomon742e31d2016-12-07 17:06:19 -050063void GrRenderTargetOpList::prepareOps(GrOpFlushState* flushState) {
Robert Phillips318c4192017-05-17 09:36:38 -040064 SkASSERT(fTarget.get()->priv().peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -040065 SkASSERT(this->isClosed());
robertphillipsa106c622015-10-16 09:07:06 -070066
Brian Salomon1e41f4a2016-12-07 15:05:04 -050067 // Loop over the ops that haven't yet been prepared.
68 for (int i = 0; i < fRecordedOps.count(); ++i) {
69 if (fRecordedOps[i].fOp) {
Robert Phillips318c4192017-05-17 09:36:38 -040070 GrOpFlushState::DrawOpArgs opArgs = {
71 fTarget.get()->priv().peekRenderTarget(),
72 fRecordedOps[i].fAppliedClip,
Robert Phillipsbb581ce2017-05-29 15:05:15 -040073 fRecordedOps[i].fDstProxy
Robert Phillips318c4192017-05-17 09:36:38 -040074 };
75
Brian Salomon54d212e2017-03-21 14:22:38 -040076 flushState->setDrawOpArgs(&opArgs);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050077 fRecordedOps[i].fOp->prepare(flushState);
Brian Salomon54d212e2017-03-21 14:22:38 -040078 flushState->setDrawOpArgs(nullptr);
bsalomonaecc0182016-03-07 11:50:44 -080079 }
bsalomon512be532015-09-10 10:42:55 -070080 }
csmartdaltona7f29642016-07-07 08:49:11 -070081
82 if (fInstancedRendering) {
83 fInstancedRendering->beginFlush(flushState->resourceProvider());
84 }
robertphillipsa13e2022015-11-11 12:01:09 -080085}
bsalomon512be532015-09-10 10:42:55 -070086
Robert Phillips178ce3e2017-04-13 09:15:47 -040087static std::unique_ptr<GrGpuCommandBuffer> create_command_buffer(GrGpu* gpu) {
88 static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo {
89 GrGpuCommandBuffer::LoadOp::kLoad,
90 GrGpuCommandBuffer::StoreOp::kStore,
91 GrColor_ILLEGAL
92 };
93
94 std::unique_ptr<GrGpuCommandBuffer> buffer(
95 gpu->createCommandBuffer(kBasicLoadStoreInfo, // Color
96 kBasicLoadStoreInfo)); // Stencil
97 return buffer;
98}
99
100static inline void finish_command_buffer(GrGpuCommandBuffer* buffer) {
101 if (!buffer) {
102 return;
103 }
104
105 buffer->end();
106 buffer->submit();
107}
108
Brian Salomon25a88092016-12-01 09:36:50 -0500109// TODO: this is where GrOp::renderTarget is used (which is fine since it
Robert Phillips294870f2016-11-11 12:38:40 -0500110// is at flush time). However, we need to store the RenderTargetProxy in the
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500111// Ops and instantiate them here.
Brian Salomon742e31d2016-12-07 17:06:19 -0500112bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500113 if (0 == fRecordedOps.count()) {
bsalomondc438982016-08-31 11:53:49 -0700114 return false;
egdanielb4021cf2016-07-28 08:53:07 -0700115 }
Robert Phillips4a395042017-04-24 16:27:17 +0000116
Robert Phillips318c4192017-05-17 09:36:38 -0400117 SkASSERT(fTarget.get()->priv().peekRenderTarget());
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400118
119 std::unique_ptr<GrGpuCommandBuffer> commandBuffer = create_command_buffer(flushState->gpu());
120 flushState->setCommandBuffer(commandBuffer.get());
121
122 // Draw all the generated geometry.
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500123 for (int i = 0; i < fRecordedOps.count(); ++i) {
124 if (!fRecordedOps[i].fOp) {
bsalomonaecc0182016-03-07 11:50:44 -0800125 continue;
126 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400127
Robert Phillips178ce3e2017-04-13 09:15:47 -0400128 if (fRecordedOps[i].fOp->needsCommandBufferIsolation()) {
129 // This op is a special snowflake and must occur between command buffers
130 // TODO: make this go through the command buffer
131 finish_command_buffer(commandBuffer.get());
Robert Phillips178ce3e2017-04-13 09:15:47 -0400132
133 commandBuffer.reset();
134 flushState->setCommandBuffer(commandBuffer.get());
Robert Phillips178ce3e2017-04-13 09:15:47 -0400135 } else if (!commandBuffer) {
Robert Phillipsee683652017-04-26 11:53:10 -0400136 commandBuffer = create_command_buffer(flushState->gpu());
Ben Wagner145dbcd2016-11-03 14:40:50 -0400137 flushState->setCommandBuffer(commandBuffer.get());
egdaniel9cb63402016-06-23 08:37:05 -0700138 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400139
140 GrOpFlushState::DrawOpArgs opArgs {
Robert Phillips318c4192017-05-17 09:36:38 -0400141 fTarget.get()->priv().peekRenderTarget(),
Robert Phillips178ce3e2017-04-13 09:15:47 -0400142 fRecordedOps[i].fAppliedClip,
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400143 fRecordedOps[i].fDstProxy
Robert Phillips178ce3e2017-04-13 09:15:47 -0400144 };
145
146 flushState->setDrawOpArgs(&opArgs);
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500147 fRecordedOps[i].fOp->execute(flushState);
Brian Salomon54d212e2017-03-21 14:22:38 -0400148 flushState->setDrawOpArgs(nullptr);
bsalomon512be532015-09-10 10:42:55 -0700149 }
Robert Phillips178ce3e2017-04-13 09:15:47 -0400150
151 finish_command_buffer(commandBuffer.get());
152 flushState->setCommandBuffer(nullptr);
ethannicholas22793252016-01-30 09:59:10 -0800153
bsalomondc438982016-08-31 11:53:49 -0700154 return true;
bsalomona73239a2015-04-28 13:35:17 -0700155}
156
Robert Phillipsf2361d22016-10-25 14:20:06 -0400157void GrRenderTargetOpList::reset() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500158 fLastFullClearOp = nullptr;
Robert Phillipsb6deea82017-05-11 14:14:30 -0400159 fLastClipStackGenID = SK_InvalidUniqueID;
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500160 fRecordedOps.reset();
csmartdaltona7f29642016-07-07 08:49:11 -0700161 if (fInstancedRendering) {
162 fInstancedRendering->endFlush();
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400163 fInstancedRendering = nullptr;
csmartdaltona7f29642016-07-07 08:49:11 -0700164 }
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400165
166 INHERITED::reset();
bsalomon512be532015-09-10 10:42:55 -0700167}
168
Robert Phillipsf2361d22016-10-25 14:20:06 -0400169void GrRenderTargetOpList::abandonGpuResources() {
Robert Phillipsee683652017-04-26 11:53:10 -0400170 if (fInstancedRendering) {
171 fInstancedRendering->resetGpuResources(InstancedRendering::ResetType::kAbandon);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400172 }
173}
174
175void GrRenderTargetOpList::freeGpuResources() {
Robert Phillipsee683652017-04-26 11:53:10 -0400176 if (fInstancedRendering) {
177 fInstancedRendering->resetGpuResources(InstancedRendering::ResetType::kDestroy);
Robert Phillipsf2361d22016-10-25 14:20:06 -0400178 }
179}
180
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400181void GrRenderTargetOpList::fullClear(const GrCaps& caps, GrColor color) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500182 // Currently this just inserts or updates the last clear op. However, once in MDB this can
183 // remove all the previously recorded ops and change the load op to clear with supplied
bsalomonfd8d0132016-08-11 11:25:33 -0700184 // color.
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400185 if (fLastFullClearOp) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500186 // As currently implemented, fLastFullClearOp should be the last op because we would
187 // have cleared it when another op was recorded.
188 SkASSERT(fRecordedOps.back().fOp.get() == fLastFullClearOp);
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400189 GrOP_INFO("opList: %d Fusing clears (opID: %d Color: 0x%08x -> 0x%08x)\n",
190 this->uniqueID(),
191 fLastFullClearOp->uniqueID(),
192 fLastFullClearOp->color(), color);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500193 fLastFullClearOp->setColor(color);
bsalomonfd8d0132016-08-11 11:25:33 -0700194 return;
195 }
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400196 std::unique_ptr<GrClearOp> op(GrClearOp::Make(GrFixedClip::Disabled(), color, fTarget.get()));
Robert Phillipsf7a72612017-03-31 10:03:45 -0400197 if (!op) {
198 return;
199 }
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400200
201 if (GrOp* clearOp = this->recordOp(std::move(op), caps)) {
Brian Salomon2790c522016-12-09 16:32:23 -0500202 // This is either the clear op we just created or another one that it combined with.
Brian Salomon7dae46a2016-12-14 16:21:37 -0500203 fLastFullClearOp = static_cast<GrClearOp*>(clearOp);
bsalomonfd8d0132016-08-11 11:25:33 -0700204 }
bsalomon9f129de2016-08-10 16:31:05 -0700205}
206
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000207////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000208
Robert Phillips81dd3e02017-06-23 11:59:24 -0400209// This closely parallels GrTextureOpList::copySurface but renderTargetOpLists
210// also store the applied clip and dest proxy with the op
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400211bool GrRenderTargetOpList::copySurface(const GrCaps& caps,
212 GrSurfaceProxy* dst,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400213 GrSurfaceProxy* src,
Robert Phillipsf2361d22016-10-25 14:20:06 -0400214 const SkIRect& srcRect,
215 const SkIPoint& dstPoint) {
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400216 SkASSERT(dst->asRenderTargetProxy() == fTarget.get());
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400217 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500218 if (!op) {
bsalomonb8fea972016-02-16 07:34:17 -0800219 return false;
220 }
robertphillips498d7ac2015-10-30 10:11:30 -0700221#ifdef ENABLE_MDB
bsalomonb8fea972016-02-16 07:34:17 -0800222 this->addDependency(src);
robertphillips498d7ac2015-10-30 10:11:30 -0700223#endif
224
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400225 this->recordOp(std::move(op), caps);
bsalomonb8fea972016-02-16 07:34:17 -0800226 return true;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000227}
228
Brian Salomona4677b52017-05-04 12:39:56 -0400229static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); }
bsalomon88cf17d2016-07-08 06:40:56 -0700230
Brian Salomon54d212e2017-03-21 14:22:38 -0400231bool GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b,
232 const GrAppliedClip* bClip,
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400233 const DstProxy* bDstProxy,
Robert Phillipsee683652017-04-26 11:53:10 -0400234 const GrCaps& caps) {
Brian Salomon54d212e2017-03-21 14:22:38 -0400235 if (a.fAppliedClip) {
236 if (!bClip) {
237 return false;
238 }
239 if (*a.fAppliedClip != *bClip) {
240 return false;
241 }
242 } else if (bClip) {
243 return false;
244 }
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400245 if (bDstProxy) {
246 if (a.fDstProxy != *bDstProxy) {
Brian Salomon54d212e2017-03-21 14:22:38 -0400247 return false;
248 }
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400249 } else if (a.fDstProxy.proxy()) {
Brian Salomon54d212e2017-03-21 14:22:38 -0400250 return false;
251 }
Robert Phillipsee683652017-04-26 11:53:10 -0400252 return a.fOp->combineIfPossible(b, caps);
Brian Salomon54d212e2017-03-21 14:22:38 -0400253}
254
Brian Salomonf8334782017-01-03 09:42:58 -0500255GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op,
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400256 const GrCaps& caps,
Brian Salomon54d212e2017-03-21 14:22:38 -0400257 GrAppliedClip* clip,
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400258 const DstProxy* dstProxy) {
Robert Phillips318c4192017-05-17 09:36:38 -0400259 SkASSERT(fTarget.get());
Robert Phillipsee683652017-04-26 11:53:10 -0400260
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500261 // A closed GrOpList should never receive new/more ops
robertphillips6a186652015-10-20 07:37:58 -0700262 SkASSERT(!this->isClosed());
robertphillipsa106c622015-10-16 09:07:06 -0700263
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500264 // Check if there is an op we can combine with by linearly searching back until we either
265 // 1) check every op
bsalomon512be532015-09-10 10:42:55 -0700266 // 2) intersect with something
267 // 3) find a 'blocker'
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400268 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400269 GrOP_INFO("opList: %d Recording (%s, opID: %u)\n"
270 "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n",
271 this->uniqueID(),
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500272 op->name(),
273 op->uniqueID(),
Robert Phillips1119dc32017-04-11 12:54:57 -0400274 op->bounds().fLeft, op->bounds().fTop,
275 op->bounds().fRight, op->bounds().fBottom);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500276 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon25a88092016-12-01 09:36:50 -0500277 GrOP_INFO("\tOutcome:\n");
Robert Phillips8185f592017-04-26 08:31:08 -0400278 int maxCandidates = SkTMin(kMaxOpLookback, fRecordedOps.count());
Brian Salomoncdcc33f2017-02-21 09:49:20 -0500279 // If we don't have a valid destination render target then we cannot reorder.
Robert Phillips318c4192017-05-17 09:36:38 -0400280 if (maxCandidates) {
bsalomon512be532015-09-10 10:42:55 -0700281 int i = 0;
282 while (true) {
Brian Salomon69868af2016-12-22 15:42:51 -0500283 const RecordedOp& candidate = fRecordedOps.fromBack(i);
Robert Phillips318c4192017-05-17 09:36:38 -0400284
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400285 if (this->combineIfPossible(candidate, op.get(), clip, dstProxy, caps)) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400286 GrOP_INFO("\t\tBackward: Combining with (%s, opID: %u)\n", candidate.fOp->name(),
Brian Salomon69868af2016-12-22 15:42:51 -0500287 candidate.fOp->uniqueID());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400288 GrOP_INFO("\t\t\tBackward: Combined op info:\n");
Brian Salomon199fb872017-02-06 09:41:10 -0500289 GrOP_INFO(SkTabString(candidate.fOp->dumpInfo(), 4).c_str());
Brian Salomon69868af2016-12-22 15:42:51 -0500290 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, candidate.fOp.get(), op.get());
Brian Salomon69868af2016-12-22 15:42:51 -0500291 return candidate.fOp.get();
bsalomon512be532015-09-10 10:42:55 -0700292 }
293 // Stop going backwards if we would cause a painter's order violation.
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500294 if (!can_reorder(fRecordedOps.fromBack(i).fOp->bounds(), op->bounds())) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400295 GrOP_INFO("\t\tBackward: Intersects with (%s, opID: %u)\n", candidate.fOp->name(),
Brian Salomon69868af2016-12-22 15:42:51 -0500296 candidate.fOp->uniqueID());
bsalomon512be532015-09-10 10:42:55 -0700297 break;
298 }
299 ++i;
300 if (i == maxCandidates) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400301 GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i);
bsalomon512be532015-09-10 10:42:55 -0700302 break;
303 }
304 }
305 } else {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400306 GrOP_INFO("\t\tBackward: FirstOp\n");
bsalomon512be532015-09-10 10:42:55 -0700307 }
Brian Salomon42ad83a2016-12-20 16:14:45 -0500308 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op);
Brian Salomon54d212e2017-03-21 14:22:38 -0400309 if (clip) {
310 clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip));
Robert Phillipsc84c0302017-05-08 15:35:11 -0400311 SkDEBUGCODE(fNumClips++;)
Brian Salomon54d212e2017-03-21 14:22:38 -0400312 }
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400313 fRecordedOps.emplace_back(std::move(op), clip, dstProxy);
Robert Phillipse3302df2017-04-24 07:31:02 -0400314 fRecordedOps.back().fOp->wasRecorded(this);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500315 fLastFullClearOp = nullptr;
Brian Salomon2790c522016-12-09 16:32:23 -0500316 return fRecordedOps.back().fOp.get();
bsalomon512be532015-09-10 10:42:55 -0700317}
318
Robert Phillipsee683652017-04-26 11:53:10 -0400319void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) {
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400320 SkASSERT(!this->isClosed());
321
Robert Phillips48567ac2017-06-01 08:46:00 -0400322 GrOP_INFO("opList: %d ForwardCombine %d ops:\n", this->uniqueID(), fRecordedOps.count());
323
Brian Salomon337432d2017-03-21 17:36:10 -0400324 for (int i = 0; i < fRecordedOps.count() - 1; ++i) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500325 GrOp* op = fRecordedOps[i].fOp.get();
Robert Phillips318c4192017-05-17 09:36:38 -0400326
Robert Phillips8185f592017-04-26 08:31:08 -0400327 int maxCandidateIdx = SkTMin(i + kMaxOpLookahead, fRecordedOps.count() - 1);
bsalomonaecc0182016-03-07 11:50:44 -0800328 int j = i + 1;
329 while (true) {
Brian Salomon69868af2016-12-22 15:42:51 -0500330 const RecordedOp& candidate = fRecordedOps[j];
Robert Phillips318c4192017-05-17 09:36:38 -0400331
Brian Salomon54d212e2017-03-21 14:22:38 -0400332 if (this->combineIfPossible(fRecordedOps[i], candidate.fOp.get(),
Robert Phillipsbb581ce2017-05-29 15:05:15 -0400333 candidate.fAppliedClip, &candidate.fDstProxy, caps)) {
Robert Phillips48567ac2017-06-01 08:46:00 -0400334 GrOP_INFO("\t\t%d: (%s opID: %u) -> Combining with (%s, opID: %u)\n",
335 i, op->name(), op->uniqueID(),
336 candidate.fOp->name(), candidate.fOp->uniqueID());
Brian Salomon69868af2016-12-22 15:42:51 -0500337 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get());
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500338 fRecordedOps[j].fOp = std::move(fRecordedOps[i].fOp);
bsalomonaecc0182016-03-07 11:50:44 -0800339 break;
340 }
Robert Phillipsc84c0302017-05-08 15:35:11 -0400341 // Stop traversing if we would cause a painter's order violation.
Brian Salomon9e50f7b2017-03-06 12:02:34 -0500342 if (!can_reorder(fRecordedOps[j].fOp->bounds(), op->bounds())) {
Robert Phillips48567ac2017-06-01 08:46:00 -0400343 GrOP_INFO("\t\t%d: (%s opID: %u) -> Intersects with (%s, opID: %u)\n",
344 i, op->name(), op->uniqueID(),
345 candidate.fOp->name(), candidate.fOp->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800346 break;
347 }
348 ++j;
349 if (j > maxCandidateIdx) {
Robert Phillips48567ac2017-06-01 08:46:00 -0400350 GrOP_INFO("\t\t%d: (%s opID: %u) -> Reached max lookahead or end of array\n",
351 i, op->name(), op->uniqueID());
bsalomonaecc0182016-03-07 11:50:44 -0800352 break;
353 }
354 }
355 }
356}
357