reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 8 | #include "GrRenderTargetOpList.h" |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 9 | #include "GrAuditTrail.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 11 | #include "GrGpu.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 12 | #include "GrGpuCommandBuffer.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 13 | #include "GrMemoryPool.h" |
Brian Salomon | a4677b5 | 2017-05-04 12:39:56 -0400 | [diff] [blame] | 14 | #include "GrRect.h" |
Brian Salomon | 467921e | 2017-03-06 16:17:12 -0500 | [diff] [blame] | 15 | #include "GrRenderTargetContext.h" |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 16 | #include "GrResourceAllocator.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 17 | #include "ops/GrClearOp.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 18 | #include "ops/GrCopySurfaceOp.h" |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 19 | #include "SkTraceEvent.h" |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 20 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 21 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | //////////////////////////////////////////////////////////////////////////////// |
| 23 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 24 | // Experimentally we have found that most combining occurs within the first 10 comparisons. |
Robert Phillips | 8185f59 | 2017-04-26 08:31:08 -0400 | [diff] [blame] | 25 | static const int kMaxOpLookback = 10; |
| 26 | static const int kMaxOpLookahead = 10; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 27 | |
Robert Phillips | 3a9710b | 2018-03-27 17:51:55 -0400 | [diff] [blame] | 28 | GrRenderTargetOpList::GrRenderTargetOpList(GrResourceProvider* resourceProvider, |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 29 | sk_sp<GrOpMemoryPool> opMemoryPool, |
Robert Phillips | 3a9710b | 2018-03-27 17:51:55 -0400 | [diff] [blame] | 30 | GrRenderTargetProxy* proxy, |
Robert Phillips | 8185f59 | 2017-04-26 08:31:08 -0400 | [diff] [blame] | 31 | GrAuditTrail* auditTrail) |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 32 | : INHERITED(resourceProvider, std::move(opMemoryPool), proxy, auditTrail) |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 33 | , fLastClipStackGenID(SK_InvalidUniqueID) |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 34 | SkDEBUGCODE(, fNumClips(0)) { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 37 | void GrRenderTargetOpList::RecordedOp::deleteOp(GrOpMemoryPool* opMemoryPool) { |
| 38 | opMemoryPool->release(std::move(fOp)); |
| 39 | } |
| 40 | |
| 41 | void GrRenderTargetOpList::deleteOps() { |
| 42 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 43 | if (fRecordedOps[i].fOp) { |
| 44 | fRecordedOps[i].deleteOp(fOpMemoryPool.get()); |
| 45 | } |
| 46 | } |
| 47 | fRecordedOps.reset(); |
| 48 | } |
| 49 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 50 | GrRenderTargetOpList::~GrRenderTargetOpList() { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 51 | this->deleteOps(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | //////////////////////////////////////////////////////////////////////////////// |
| 55 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 56 | #ifdef SK_DEBUG |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 57 | void GrRenderTargetOpList::dump(bool printDependencies) const { |
| 58 | INHERITED::dump(printDependencies); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 59 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 60 | SkDebugf("ops (%d):\n", fRecordedOps.count()); |
| 61 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 62 | SkDebugf("*******************************\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 63 | if (!fRecordedOps[i].fOp) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 64 | SkDebugf("%d: <combined forward or failed instantiation>\n", i); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 65 | } else { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 66 | SkDebugf("%d: %s\n", i, fRecordedOps[i].fOp->name()); |
| 67 | SkString str = fRecordedOps[i].fOp->dumpInfo(); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 68 | SkDebugf("%s\n", str.c_str()); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 69 | const SkRect& bounds = fRecordedOps[i].fOp->bounds(); |
| 70 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 71 | bounds.fTop, bounds.fRight, bounds.fBottom); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 72 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 75 | |
| 76 | void GrRenderTargetOpList::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const { |
| 77 | for (const RecordedOp& recordedOp : fRecordedOps) { |
| 78 | recordedOp.visitProxies(func); |
| 79 | } |
| 80 | } |
Brian Salomon | c525d4f | 2018-09-17 15:48:20 -0400 | [diff] [blame^] | 81 | |
| 82 | static void assert_chain_bounds(const GrOp* op) { |
| 83 | SkASSERT(op->isChainHead()); |
| 84 | auto headBounds = op->bounds(); |
| 85 | while ((op = op->nextInChain())) { |
| 86 | SkASSERT(headBounds.contains(op->bounds())); |
| 87 | } |
| 88 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 89 | #endif |
| 90 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 91 | void GrRenderTargetOpList::onPrepare(GrOpFlushState* flushState) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 92 | SkASSERT(fTarget.get()->peekRenderTarget()); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 93 | SkASSERT(this->isClosed()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 94 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 95 | TRACE_EVENT0("skia", TRACE_FUNC); |
| 96 | #endif |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 97 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 98 | // Loop over the ops that haven't yet been prepared. |
| 99 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 100 | if (fRecordedOps[i].fOp && fRecordedOps[i].fOp->isChainHead()) { |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 101 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 102 | TRACE_EVENT0("skia", fRecordedOps[i].fOp->name()); |
| 103 | #endif |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 104 | GrOpFlushState::OpArgs opArgs = { |
| 105 | fRecordedOps[i].fOp.get(), |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 106 | fTarget.get()->asRenderTargetProxy(), |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 107 | fRecordedOps[i].fAppliedClip, |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 108 | fRecordedOps[i].fDstProxy |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 109 | }; |
Brian Salomon | c525d4f | 2018-09-17 15:48:20 -0400 | [diff] [blame^] | 110 | SkDEBUGCODE(assert_chain_bounds(opArgs.fOp)); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 111 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 112 | fRecordedOps[i].fOp->prepare(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 113 | flushState->setOpArgs(nullptr); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 114 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 115 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 116 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 117 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 118 | static GrGpuRTCommandBuffer* create_command_buffer(GrGpu* gpu, |
| 119 | GrRenderTarget* rt, |
| 120 | GrSurfaceOrigin origin, |
| 121 | GrLoadOp colorLoadOp, |
| 122 | GrColor loadClearColor, |
| 123 | GrLoadOp stencilLoadOp) { |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 124 | const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 125 | colorLoadOp, |
| 126 | GrStoreOp::kStore, |
| 127 | loadClearColor |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 128 | }; |
| 129 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 130 | // TODO: |
| 131 | // We would like to (at this level) only ever clear & discard. We would need |
| 132 | // to stop splitting up higher level opLists for copyOps to achieve that. |
| 133 | // Note: we would still need SB loads and stores but they would happen at a |
| 134 | // lower level (inside the VK command buffer). |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 135 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo stencilLoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 136 | stencilLoadOp, |
| 137 | GrStoreOp::kStore, |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 138 | }; |
| 139 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 140 | return gpu->getCommandBuffer(rt, origin, kColorLoadStoreInfo, stencilLoadAndStoreInfo); |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 143 | // TODO: this is where GrOp::renderTarget is used (which is fine since it |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 144 | // is at flush time). However, we need to store the RenderTargetProxy in the |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 145 | // Ops and instantiate them here. |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 146 | bool GrRenderTargetOpList::onExecute(GrOpFlushState* flushState) { |
Greg Daniel | dbdba60 | 2018-04-20 11:52:43 -0400 | [diff] [blame] | 147 | // TODO: Forcing the execution of the discard here isn't ideal since it will cause us to do a |
| 148 | // discard and then store the data back in memory so that the load op on future draws doesn't |
| 149 | // think the memory is unitialized. Ideally we would want a system where we are tracking whether |
| 150 | // the proxy itself has valid data or not, and then use that as a signal on whether we should be |
| 151 | // loading or discarding. In that world we wouldni;t need to worry about executing oplists with |
| 152 | // no ops just to do a discard. |
| 153 | if (0 == fRecordedOps.count() && GrLoadOp::kClear != fColorLoadOp && |
| 154 | GrLoadOp::kDiscard != fColorLoadOp) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 155 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 156 | } |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 157 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 158 | SkASSERT(fTarget.get()->peekRenderTarget()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 159 | TRACE_EVENT0("skia", TRACE_FUNC); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 160 | |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 161 | // TODO: at the very least, we want the stencil store op to always be discard (at this |
| 162 | // level). In Vulkan, sub-command buffers would still need to load & store the stencil buffer. |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 163 | GrGpuRTCommandBuffer* commandBuffer = create_command_buffer( |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 164 | flushState->gpu(), |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 165 | fTarget.get()->peekRenderTarget(), |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 166 | fTarget.get()->origin(), |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 167 | fColorLoadOp, |
| 168 | fLoadClearColor, |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 169 | fStencilLoadOp); |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 170 | flushState->setCommandBuffer(commandBuffer); |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 171 | commandBuffer->begin(); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 172 | |
| 173 | // Draw all the generated geometry. |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 174 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 175 | if (!fRecordedOps[i].fOp || !fRecordedOps[i].fOp->isChainHead()) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 176 | continue; |
| 177 | } |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 178 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 179 | TRACE_EVENT0("skia", fRecordedOps[i].fOp->name()); |
| 180 | #endif |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 181 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 182 | GrOpFlushState::OpArgs opArgs { |
| 183 | fRecordedOps[i].fOp.get(), |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 184 | fTarget.get()->asRenderTargetProxy(), |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 185 | fRecordedOps[i].fAppliedClip, |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 186 | fRecordedOps[i].fDstProxy |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 187 | }; |
| 188 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 189 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 190 | fRecordedOps[i].fOp->execute(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 191 | flushState->setOpArgs(nullptr); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 192 | } |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 193 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 194 | commandBuffer->end(); |
| 195 | flushState->gpu()->submit(commandBuffer); |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 196 | flushState->setCommandBuffer(nullptr); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 197 | |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 198 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 201 | void GrRenderTargetOpList::endFlush() { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 202 | fLastClipStackGenID = SK_InvalidUniqueID; |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 203 | this->deleteOps(); |
Chris Dalton | c82dd4e | 2017-11-20 18:20:28 -0700 | [diff] [blame] | 204 | fClipAllocator.reset(); |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 205 | INHERITED::endFlush(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 208 | void GrRenderTargetOpList::discard() { |
| 209 | // Discard calls to in-progress opLists are ignored. Calls at the start update the |
| 210 | // opLists' color & stencil load ops. |
| 211 | if (this->isEmpty()) { |
| 212 | fColorLoadOp = GrLoadOp::kDiscard; |
| 213 | fStencilLoadOp = GrLoadOp::kDiscard; |
| 214 | } |
| 215 | } |
| 216 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 217 | void GrRenderTargetOpList::fullClear(GrContext* context, GrColor color) { |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 218 | |
| 219 | // This is conservative. If the opList is marked as needing a stencil buffer then there |
| 220 | // may be a prior op that writes to the stencil buffer. Although the clear will ignore the |
| 221 | // stencil buffer, following draw ops may not so we can't get rid of all the preceding ops. |
| 222 | // Beware! If we ever add any ops that have a side effect beyond modifying the stencil |
| 223 | // buffer we will need a more elaborate tracking system (skbug.com/7002). |
| 224 | if (this->isEmpty() || !fTarget.get()->asRenderTargetProxy()->needsStencil()) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 225 | this->deleteOps(); |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 226 | fDeferredProxies.reset(); |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 227 | fColorLoadOp = GrLoadOp::kClear; |
| 228 | fLoadClearColor = color; |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 229 | return; |
| 230 | } |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 231 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 232 | std::unique_ptr<GrClearOp> op(GrClearOp::Make(context, GrFixedClip::Disabled(), |
| 233 | color, fTarget.get())); |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 234 | if (!op) { |
| 235 | return; |
| 236 | } |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 237 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 238 | this->recordOp(std::move(op), *context->contextPriv().caps()); |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 239 | } |
| 240 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 241 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 242 | |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame] | 243 | // This closely parallels GrTextureOpList::copySurface but renderTargetOpLists |
| 244 | // also store the applied clip and dest proxy with the op |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 245 | bool GrRenderTargetOpList::copySurface(GrContext* context, |
Robert Phillips | a16f6cb | 2017-06-01 11:06:13 -0400 | [diff] [blame] | 246 | GrSurfaceProxy* dst, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 247 | GrSurfaceProxy* src, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 248 | const SkIRect& srcRect, |
| 249 | const SkIPoint& dstPoint) { |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 250 | SkASSERT(dst->asRenderTargetProxy() == fTarget.get()); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 251 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(context, dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 252 | if (!op) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 253 | return false; |
| 254 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 255 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 256 | this->addOp(std::move(op), *context->contextPriv().caps()); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 257 | return true; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 260 | void GrRenderTargetOpList::purgeOpsWithUninstantiatedProxies() { |
| 261 | bool hasUninstantiatedProxy = false; |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 262 | auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p) { |
| 263 | if (!p->isInstantiated()) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 264 | hasUninstantiatedProxy = true; |
| 265 | } |
| 266 | }; |
| 267 | for (RecordedOp& recordedOp : fRecordedOps) { |
| 268 | hasUninstantiatedProxy = false; |
Robert Phillips | ed1205a | 2018-07-13 11:44:53 -0400 | [diff] [blame] | 269 | if (recordedOp.fOp) { |
| 270 | recordedOp.visitProxies(checkInstantiation); |
| 271 | } |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 272 | if (hasUninstantiatedProxy) { |
| 273 | // When instantiation of the proxy fails we drop the Op |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 274 | recordedOp.deleteOp(fOpMemoryPool.get()); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 279 | void GrRenderTargetOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 280 | unsigned int cur = alloc->numOps(); |
| 281 | |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 282 | for (int i = 0; i < fDeferredProxies.count(); ++i) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 283 | SkASSERT(!fDeferredProxies[i]->isInstantiated()); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 284 | // We give all the deferred proxies a write usage at the very start of flushing. This |
| 285 | // locks them out of being reused for the entire flush until they are read - and then |
| 286 | // they can be recycled. This is a bit unfortunate because a flush can proceed in waves |
| 287 | // with sub-flushes. The deferred proxies only need to be pinned from the start of |
| 288 | // the sub-flush in which they appear. |
| 289 | alloc->addInterval(fDeferredProxies[i], 0, 0); |
| 290 | } |
| 291 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 292 | // Add the interval for all the writes to this opList's target |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 293 | if (fRecordedOps.count()) { |
| 294 | alloc->addInterval(fTarget.get(), cur, cur+fRecordedOps.count()-1); |
| 295 | } else { |
| 296 | // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we |
| 297 | // still need to add an interval for the destination so we create a fake op# for |
| 298 | // the missing clear op. |
| 299 | alloc->addInterval(fTarget.get()); |
| 300 | alloc->incOps(); |
| 301 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 302 | |
Chris Dalton | 8816b93 | 2017-11-29 16:48:25 -0700 | [diff] [blame] | 303 | auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p) { |
| 304 | alloc->addInterval(p SkDEBUGCODE(, fTarget.get() == p)); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 305 | }; |
Chris Dalton | 8816b93 | 2017-11-29 16:48:25 -0700 | [diff] [blame] | 306 | for (const RecordedOp& recordedOp : fRecordedOps) { |
| 307 | recordedOp.visitProxies(gather); // only diff from the GrTextureOpList version |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 308 | |
| 309 | // Even though the op may have been moved we still need to increment the op count to |
| 310 | // keep all the math consistent. |
| 311 | alloc->incOps(); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Brian Salomon | a4677b5 | 2017-05-04 12:39:56 -0400 | [diff] [blame] | 315 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); } |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 316 | |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 317 | GrOp::CombineResult GrRenderTargetOpList::combineIfPossible(const RecordedOp& a, GrOp* b, |
| 318 | const GrAppliedClip* bClip, |
| 319 | const DstProxy* bDstProxy, |
| 320 | const GrCaps& caps) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 321 | if (a.fAppliedClip) { |
| 322 | if (!bClip) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 323 | return GrOp::CombineResult::kCannotCombine; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 324 | } |
| 325 | if (*a.fAppliedClip != *bClip) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 326 | return GrOp::CombineResult::kCannotCombine; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 327 | } |
| 328 | } else if (bClip) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 329 | return GrOp::CombineResult::kCannotCombine; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 330 | } |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 331 | if (bDstProxy) { |
| 332 | if (a.fDstProxy != *bDstProxy) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 333 | return GrOp::CombineResult::kCannotCombine; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 334 | } |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 335 | } else if (a.fDstProxy.proxy()) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 336 | return GrOp::CombineResult::kCannotCombine; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 337 | } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 338 | return a.fOp->combineIfPossible(b, caps); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Chris Dalton | f104fec | 2018-05-22 16:17:48 -0600 | [diff] [blame] | 341 | uint32_t GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op, |
| 342 | const GrCaps& caps, |
| 343 | GrAppliedClip* clip, |
| 344 | const DstProxy* dstProxy) { |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 345 | SkASSERT(fTarget.get()); |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 346 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 347 | // A closed GrOpList should never receive new/more ops |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 348 | SkASSERT(!this->isClosed()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 349 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 350 | // Check if there is an op we can combine with by linearly searching back until we either |
| 351 | // 1) check every op |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 352 | // 2) intersect with something |
| 353 | // 3) find a 'blocker' |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 354 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID()); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 355 | GrOP_INFO("opList: %d Recording (%s, opID: %u)\n" |
| 356 | "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n", |
| 357 | this->uniqueID(), |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 358 | op->name(), |
| 359 | op->uniqueID(), |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 360 | op->bounds().fLeft, op->bounds().fTop, |
| 361 | op->bounds().fRight, op->bounds().fBottom); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 362 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 363 | GrOP_INFO("\tOutcome:\n"); |
Robert Phillips | 8185f59 | 2017-04-26 08:31:08 -0400 | [diff] [blame] | 364 | int maxCandidates = SkTMin(kMaxOpLookback, fRecordedOps.count()); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 365 | int firstChainableIdx = -1; |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 366 | if (maxCandidates) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 367 | int i = 0; |
| 368 | while (true) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 369 | const RecordedOp& candidate = fRecordedOps.fromBack(i); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 370 | auto combineResult = this->combineIfPossible(candidate, op.get(), clip, dstProxy, caps); |
| 371 | switch (combineResult) { |
| 372 | case GrOp::CombineResult::kMayChain: |
| 373 | if (candidate.fOp->isChainTail() && firstChainableIdx < 0) { |
| 374 | GrOP_INFO("\t\tBackward: Can chain with (%s, opID: %u)\n", |
| 375 | candidate.fOp->name(), candidate.fOp->uniqueID()); |
| 376 | firstChainableIdx = i; |
| 377 | } |
| 378 | break; |
| 379 | case GrOp::CombineResult::kMerged: |
| 380 | GrOP_INFO("\t\tBackward: Combining with (%s, opID: %u)\n", |
| 381 | candidate.fOp->name(), candidate.fOp->uniqueID()); |
| 382 | GrOP_INFO("\t\t\tBackward: Combined op info:\n"); |
| 383 | GrOP_INFO(SkTabString(candidate.fOp->dumpInfo(), 4).c_str()); |
| 384 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, candidate.fOp.get(), op.get()); |
| 385 | fOpMemoryPool->release(std::move(op)); |
| 386 | return SK_InvalidUniqueID; |
| 387 | case GrOp::CombineResult::kCannotCombine: |
| 388 | break; |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 389 | } |
Brian Salomon | 764e546 | 2018-08-21 12:07:00 -0400 | [diff] [blame] | 390 | // Stop going backwards if we would cause a painter's order violation. We only need to |
| 391 | // test against chain heads as elements of a chain always draw in their chain head's |
| 392 | // slot. |
| 393 | if (candidate.fOp->isChainHead() && |
| 394 | !can_reorder(candidate.fOp->bounds(), op->bounds())) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 395 | GrOP_INFO("\t\tBackward: Intersects with (%s, opID: %u)\n", candidate.fOp->name(), |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 396 | candidate.fOp->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 397 | break; |
| 398 | } |
| 399 | ++i; |
| 400 | if (i == maxCandidates) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 401 | GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 402 | break; |
| 403 | } |
| 404 | } |
| 405 | } else { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 406 | GrOP_INFO("\t\tBackward: FirstOp\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 407 | } |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 408 | GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 409 | if (clip) { |
| 410 | clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip)); |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 411 | SkDEBUGCODE(fNumClips++;) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 412 | } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 413 | if (firstChainableIdx >= 0) { |
Brian Salomon | 764e546 | 2018-08-21 12:07:00 -0400 | [diff] [blame] | 414 | // If we chain this op it will draw in the slot of the head of the chain. We have to check |
| 415 | // that the new op's bounds don't intersect any of the other ops between firstChainableIdx |
| 416 | // and the head of that op's chain. We only need to test against chain heads as elements of |
| 417 | // a chain always draw in their chain head's slot. |
| 418 | const GrOp* chainHead = fRecordedOps.fromBack(firstChainableIdx).fOp->chainHead(); |
| 419 | int idx = firstChainableIdx; |
| 420 | bool chain = true; |
| 421 | while (fRecordedOps.fromBack(idx).fOp.get() != chainHead) { |
| 422 | // If idx is not in the same chain then we have to check against its bounds as we will |
| 423 | // draw before it (when chainHead draws). |
| 424 | const GrOp* testOp = fRecordedOps.fromBack(idx).fOp.get(); |
| 425 | if (testOp->isChainHead() && !can_reorder(testOp->bounds(), op->bounds())) { |
| 426 | GrOP_INFO("\t\tBackward: Intersects with (%s, opID: %u). Cannot chain.\n", |
| 427 | testOp->name(), testOp->uniqueID()); |
| 428 | chain = false; |
| 429 | break; |
| 430 | } |
| 431 | ++idx; |
| 432 | // We must encounter the chain head before running off the beginning of the list. |
| 433 | SkASSERT(idx < fRecordedOps.count()); |
| 434 | } |
| 435 | if (chain) { |
| 436 | GrOp* prevOp = fRecordedOps.fromBack(firstChainableIdx).fOp.get(); |
| 437 | GrOP_INFO("\t\t\tBackward: Chained to (%s, opID: %u)\n", prevOp->name(), |
| 438 | prevOp->uniqueID()); |
| 439 | prevOp->setNextInChain(op.get()); |
| 440 | } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 441 | } |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 442 | fRecordedOps.emplace_back(std::move(op), clip, dstProxy); |
Chris Dalton | f104fec | 2018-05-22 16:17:48 -0600 | [diff] [blame] | 443 | return this->uniqueID(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 446 | void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 447 | SkASSERT(!this->isClosed()); |
| 448 | |
Robert Phillips | 48567ac | 2017-06-01 08:46:00 -0400 | [diff] [blame] | 449 | GrOP_INFO("opList: %d ForwardCombine %d ops:\n", this->uniqueID(), fRecordedOps.count()); |
| 450 | |
Brian Salomon | 337432d | 2017-03-21 17:36:10 -0400 | [diff] [blame] | 451 | for (int i = 0; i < fRecordedOps.count() - 1; ++i) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 452 | GrOp* op = fRecordedOps[i].fOp.get(); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 453 | |
Robert Phillips | 8185f59 | 2017-04-26 08:31:08 -0400 | [diff] [blame] | 454 | int maxCandidateIdx = SkTMin(i + kMaxOpLookahead, fRecordedOps.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 455 | int j = i + 1; |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 456 | int firstChainableIdx = -1; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 457 | while (true) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 458 | const RecordedOp& candidate = fRecordedOps[j]; |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 459 | auto combineResult = |
| 460 | this->combineIfPossible(fRecordedOps[i], candidate.fOp.get(), |
| 461 | candidate.fAppliedClip, &candidate.fDstProxy, caps); |
| 462 | switch (combineResult) { |
| 463 | case GrOp::CombineResult::kMayChain: |
| 464 | if (firstChainableIdx < 0 && !fRecordedOps[i].fOp->isChained() && |
| 465 | !fRecordedOps[j].fOp->isChained()) { |
| 466 | GrOP_INFO("\t\tForward: Can chain with (%s, opID: %u)\n", |
| 467 | candidate.fOp->name(), candidate.fOp->uniqueID()); |
| 468 | firstChainableIdx = j; |
| 469 | } |
| 470 | break; |
| 471 | case GrOp::CombineResult::kMerged: |
| 472 | GrOP_INFO("\t\t%d: (%s opID: %u) -> Combining with (%s, opID: %u)\n", i, |
| 473 | op->name(), op->uniqueID(), candidate.fOp->name(), |
| 474 | candidate.fOp->uniqueID()); |
| 475 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get()); |
| 476 | fOpMemoryPool->release(std::move(fRecordedOps[j].fOp)); |
| 477 | fRecordedOps[j].fOp = std::move(fRecordedOps[i].fOp); |
| 478 | break; |
| 479 | case GrOp::CombineResult::kCannotCombine: |
| 480 | break; |
| 481 | } |
| 482 | if (!fRecordedOps[i].fOp) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 483 | break; |
| 484 | } |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 485 | // Stop traversing if we would cause a painter's order violation. |
Brian Salomon | 764e546 | 2018-08-21 12:07:00 -0400 | [diff] [blame] | 486 | if (candidate.fOp->isChainHead() && |
| 487 | !can_reorder(candidate.fOp->bounds(), op->bounds())) { |
Robert Phillips | 48567ac | 2017-06-01 08:46:00 -0400 | [diff] [blame] | 488 | GrOP_INFO("\t\t%d: (%s opID: %u) -> Intersects with (%s, opID: %u)\n", |
| 489 | i, op->name(), op->uniqueID(), |
| 490 | candidate.fOp->name(), candidate.fOp->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 491 | break; |
| 492 | } |
| 493 | ++j; |
| 494 | if (j > maxCandidateIdx) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 495 | if (firstChainableIdx >= 0) { |
Brian Salomon | 764e546 | 2018-08-21 12:07:00 -0400 | [diff] [blame] | 496 | GrOp* nextOp = fRecordedOps[firstChainableIdx].fOp.get(); |
| 497 | GrOP_INFO("\t\t\tForward: Chained to (%s, opID: %u)\n", nextOp->name(), |
| 498 | nextOp->uniqueID()); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 499 | // We have to chain i before firstChainableIdx in order to preserve their |
| 500 | // relative order as they may overlap. |
Brian Salomon | 764e546 | 2018-08-21 12:07:00 -0400 | [diff] [blame] | 501 | fRecordedOps[i].fOp->setNextInChain(nextOp); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 502 | // However we want to draw them *after* any ops that occur between them. So move |
| 503 | // the head of the new chain to the later slot as we only execute chain heads. |
| 504 | std::swap(fRecordedOps[i].fOp, fRecordedOps[firstChainableIdx].fOp); |
| 505 | } else { |
| 506 | GrOP_INFO("\t\t%d: (%s opID: %u) -> Reached max lookahead or end of array\n", i, |
| 507 | op->name(), op->uniqueID()); |
| 508 | } |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 509 | break; |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |