Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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. |
| 6 | */ |
| 7 | |
| 8 | #include "GrTextureOpList.h" |
| 9 | |
| 10 | #include "GrAuditTrail.h" |
| 11 | #include "GrGpu.h" |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 12 | #include "GrResourceAllocator.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 13 | #include "GrTextureProxy.h" |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 14 | #include "SkStringUtils.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 15 | #include "ops/GrCopySurfaceOp.h" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 16 | |
| 17 | //////////////////////////////////////////////////////////////////////////////// |
| 18 | |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 19 | GrTextureOpList::GrTextureOpList(GrResourceProvider* resourceProvider, |
| 20 | GrTextureProxy* proxy, |
| 21 | GrAuditTrail* auditTrail) |
| 22 | : INHERITED(resourceProvider, proxy, auditTrail) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | GrTextureOpList::~GrTextureOpList() { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | //////////////////////////////////////////////////////////////////////////////// |
| 29 | |
| 30 | #ifdef SK_DEBUG |
| 31 | void GrTextureOpList::dump() const { |
| 32 | INHERITED::dump(); |
| 33 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 34 | SkDebugf("ops (%d):\n", fRecordedOps.count()); |
| 35 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 36 | SkDebugf("*******************************\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 37 | SkDebugf("%d: %s\n", i, fRecordedOps[i]->name()); |
| 38 | SkString str = fRecordedOps[i]->dumpInfo(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 39 | SkDebugf("%s\n", str.c_str()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 40 | const SkRect& clippedBounds = fRecordedOps[i]->bounds(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 41 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 42 | clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight, |
| 43 | clippedBounds.fBottom); |
| 44 | } |
| 45 | } |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame] | 46 | |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 47 | #endif |
| 48 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 49 | void GrTextureOpList::onPrepare(GrOpFlushState* flushState) { |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 50 | SkASSERT(this->isClosed()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 51 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 52 | // Loop over the ops that haven't yet generated their geometry |
| 53 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 54 | if (fRecordedOps[i]) { |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 55 | GrOpFlushState::OpArgs opArgs = { |
| 56 | fRecordedOps[i].get(), |
| 57 | nullptr, |
| 58 | nullptr, |
| 59 | GrXferProcessor::DstProxy() |
| 60 | }; |
| 61 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 62 | fRecordedOps[i]->prepare(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 63 | flushState->setOpArgs(nullptr); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 68 | bool GrTextureOpList::onExecute(GrOpFlushState* flushState) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 69 | if (0 == fRecordedOps.count()) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 70 | return false; |
| 71 | } |
| 72 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 73 | std::unique_ptr<GrGpuTextureCommandBuffer> commandBuffer( |
| 74 | flushState->gpu()->createCommandBuffer(fTarget.get()->priv().peekTexture(), |
| 75 | fTarget.get()->origin())); |
| 76 | flushState->setCommandBuffer(commandBuffer.get()); |
| 77 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 78 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 79 | GrOpFlushState::OpArgs opArgs = { |
| 80 | fRecordedOps[i].get(), |
| 81 | nullptr, |
| 82 | nullptr, |
| 83 | GrXferProcessor::DstProxy() |
| 84 | }; |
| 85 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 86 | fRecordedOps[i]->execute(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 87 | flushState->setOpArgs(nullptr); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 90 | commandBuffer->submit(); |
| 91 | flushState->setCommandBuffer(nullptr); |
| 92 | |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 93 | return true; |
| 94 | } |
| 95 | |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 96 | void GrTextureOpList::endFlush() { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 97 | fRecordedOps.reset(); |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 98 | INHERITED::endFlush(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | //////////////////////////////////////////////////////////////////////////////// |
| 102 | |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame] | 103 | // This closely parallels GrRenderTargetOpList::copySurface but renderTargetOpList |
| 104 | // stores extra data with the op |
Robert Phillips | a16f6cb | 2017-06-01 11:06:13 -0400 | [diff] [blame] | 105 | bool GrTextureOpList::copySurface(const GrCaps& caps, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 106 | GrSurfaceProxy* dst, |
| 107 | GrSurfaceProxy* src, |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 108 | const SkIRect& srcRect, |
| 109 | const SkIPoint& dstPoint) { |
Robert Phillips | a16f6cb | 2017-06-01 11:06:13 -0400 | [diff] [blame] | 110 | SkASSERT(dst == fTarget.get()); |
| 111 | |
| 112 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 113 | if (!op) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 114 | return false; |
| 115 | } |
Robert Phillips | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 116 | |
| 117 | auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) { |
| 118 | this->addDependency(p, caps); |
| 119 | }; |
| 120 | op->visitProxies(addDependency); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 121 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 122 | this->recordOp(std::move(op)); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 123 | return true; |
| 124 | } |
| 125 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 126 | void GrTextureOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 127 | unsigned int cur = alloc->numOps(); |
| 128 | |
| 129 | // Add the interval for all the writes to this opList's target |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame^] | 130 | if (fRecordedOps.count()) { |
| 131 | alloc->addInterval(fTarget.get(), cur, cur+fRecordedOps.count()-1); |
| 132 | } else { |
| 133 | // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we |
| 134 | // still need to add an interval for the destination so we create a fake op# for |
| 135 | // the missing clear op. |
| 136 | alloc->addInterval(fTarget.get()); |
| 137 | alloc->incOps(); |
| 138 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 139 | |
| 140 | auto gather = [ alloc ] (GrSurfaceProxy* p) { |
| 141 | alloc->addInterval(p); |
| 142 | }; |
| 143 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 144 | const GrOp* op = fRecordedOps[i].get(); // only diff from the GrRenderTargetOpList version |
Robert Phillips | 8186cbe | 2017-11-01 17:32:39 -0400 | [diff] [blame] | 145 | if (op) { |
| 146 | op->visitProxies(gather); |
Greg Daniel | 065b41d | 2017-11-08 19:58:51 +0000 | [diff] [blame] | 147 | } |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame^] | 148 | |
| 149 | // Even though the op may have been moved we still need to increment the op count to |
| 150 | // keep all the math consistent. |
| 151 | alloc->incOps(); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 155 | void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op) { |
| 156 | SkASSERT(fTarget.get()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 157 | // A closed GrOpList should never receive new/more ops |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 158 | SkASSERT(!this->isClosed()); |
| 159 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 160 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID()); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 161 | GrOP_INFO("Re-Recording (%s, opID: %u)\n" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 162 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 163 | op->name(), |
| 164 | op->uniqueID(), |
| 165 | op->bounds().fLeft, op->bounds().fRight, |
| 166 | op->bounds().fTop, op->bounds().fBottom); |
| 167 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 168 | GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 169 | |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 170 | fRecordedOps.emplace_back(std::move(op)); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 171 | } |