blob: ad00d95a00ecc85f361786288cc9ce4ce4f3d539 [file] [log] [blame]
Brian Osman62e7b5f2016-10-26 12:02:18 -04001/*
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 Phillipsd375dbf2017-09-14 12:45:25 -040012#include "GrResourceAllocator.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040013#include "GrTextureProxy.h"
Brian Salomon69868af2016-12-22 15:42:51 -050014#include "SkStringUtils.h"
Brian Salomon89527432016-12-16 09:52:16 -050015#include "ops/GrCopySurfaceOp.h"
Brian Osman62e7b5f2016-10-26 12:02:18 -040016
17////////////////////////////////////////////////////////////////////////////////
18
Robert Phillips5efd5ea2017-05-30 13:47:32 -040019GrTextureOpList::GrTextureOpList(GrResourceProvider* resourceProvider,
20 GrTextureProxy* proxy,
21 GrAuditTrail* auditTrail)
22 : INHERITED(resourceProvider, proxy, auditTrail) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040023}
24
25GrTextureOpList::~GrTextureOpList() {
Brian Osman62e7b5f2016-10-26 12:02:18 -040026}
27
28////////////////////////////////////////////////////////////////////////////////
29
30#ifdef SK_DEBUG
31void GrTextureOpList::dump() const {
32 INHERITED::dump();
33
Brian Salomon1e41f4a2016-12-07 15:05:04 -050034 SkDebugf("ops (%d):\n", fRecordedOps.count());
35 for (int i = 0; i < fRecordedOps.count(); ++i) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -050036 if (!fRecordedOps[i]) {
37 SkDebugf("%d: <failed instantiation>\n", i);
38 } else {
39 SkDebugf("*******************************\n");
40 SkDebugf("%d: %s\n", i, fRecordedOps[i]->name());
41 SkString str = fRecordedOps[i]->dumpInfo();
42 SkDebugf("%s\n", str.c_str());
43 const SkRect& clippedBounds = fRecordedOps[i]->bounds();
44 SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
45 clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight,
46 clippedBounds.fBottom);
47 }
Brian Osman62e7b5f2016-10-26 12:02:18 -040048 }
49}
Robert Phillipsc589b0b2017-04-17 07:53:07 -040050
Brian Osman62e7b5f2016-10-26 12:02:18 -040051#endif
52
Brian Osman407b3422017-08-22 15:01:32 -040053void GrTextureOpList::onPrepare(GrOpFlushState* flushState) {
Robert Phillips6cdc22c2017-05-11 16:29:14 -040054 SkASSERT(this->isClosed());
Brian Osman62e7b5f2016-10-26 12:02:18 -040055
Brian Salomon1e41f4a2016-12-07 15:05:04 -050056 // Loop over the ops that haven't yet generated their geometry
57 for (int i = 0; i < fRecordedOps.count(); ++i) {
58 if (fRecordedOps[i]) {
Brian Salomon29b60c92017-10-31 14:42:10 -040059 GrOpFlushState::OpArgs opArgs = {
60 fRecordedOps[i].get(),
61 nullptr,
62 nullptr,
63 GrXferProcessor::DstProxy()
64 };
65 flushState->setOpArgs(&opArgs);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050066 fRecordedOps[i]->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -040067 flushState->setOpArgs(nullptr);
Brian Osman62e7b5f2016-10-26 12:02:18 -040068 }
69 }
70}
71
Brian Osman407b3422017-08-22 15:01:32 -040072bool GrTextureOpList::onExecute(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050073 if (0 == fRecordedOps.count()) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040074 return false;
75 }
76
Greg Daniel500d58b2017-08-24 15:59:33 -040077 std::unique_ptr<GrGpuTextureCommandBuffer> commandBuffer(
78 flushState->gpu()->createCommandBuffer(fTarget.get()->priv().peekTexture(),
79 fTarget.get()->origin()));
80 flushState->setCommandBuffer(commandBuffer.get());
81
Brian Salomon1e41f4a2016-12-07 15:05:04 -050082 for (int i = 0; i < fRecordedOps.count(); ++i) {
Brian Salomon29b60c92017-10-31 14:42:10 -040083 GrOpFlushState::OpArgs opArgs = {
84 fRecordedOps[i].get(),
85 nullptr,
86 nullptr,
87 GrXferProcessor::DstProxy()
88 };
89 flushState->setOpArgs(&opArgs);
Brian Salomon9e50f7b2017-03-06 12:02:34 -050090 fRecordedOps[i]->execute(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -040091 flushState->setOpArgs(nullptr);
Brian Osman62e7b5f2016-10-26 12:02:18 -040092 }
93
Greg Daniel500d58b2017-08-24 15:59:33 -040094 commandBuffer->submit();
95 flushState->setCommandBuffer(nullptr);
96
Brian Osman62e7b5f2016-10-26 12:02:18 -040097 return true;
98}
99
Chris Daltona84cacf2017-10-04 10:30:29 -0600100void GrTextureOpList::endFlush() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500101 fRecordedOps.reset();
Chris Daltona84cacf2017-10-04 10:30:29 -0600102 INHERITED::endFlush();
Brian Osman62e7b5f2016-10-26 12:02:18 -0400103}
104
105////////////////////////////////////////////////////////////////////////////////
106
Robert Phillips81dd3e02017-06-23 11:59:24 -0400107// This closely parallels GrRenderTargetOpList::copySurface but renderTargetOpList
108// stores extra data with the op
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400109bool GrTextureOpList::copySurface(const GrCaps& caps,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400110 GrSurfaceProxy* dst,
111 GrSurfaceProxy* src,
Brian Osman62e7b5f2016-10-26 12:02:18 -0400112 const SkIRect& srcRect,
113 const SkIPoint& dstPoint) {
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400114 SkASSERT(dst == fTarget.get());
115
116 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500117 if (!op) {
Brian Osman62e7b5f2016-10-26 12:02:18 -0400118 return false;
119 }
Robert Phillips9d6c64f2017-09-14 10:56:45 -0400120
121 auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) {
122 this->addDependency(p, caps);
123 };
124 op->visitProxies(addDependency);
Brian Osman62e7b5f2016-10-26 12:02:18 -0400125
Robert Phillips318c4192017-05-17 09:36:38 -0400126 this->recordOp(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400127 return true;
128}
129
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500130void GrTextureOpList::purgeOpsWithUninstantiatedProxies() {
131 bool hasUninstantiatedProxy = false;
132 auto checkInstantiation = [ &hasUninstantiatedProxy ] (GrSurfaceProxy* p) {
133 if (!p->priv().isInstantiated()) {
134 hasUninstantiatedProxy = true;
135 }
136 };
137 for (int i = 0; i < fRecordedOps.count(); ++i) {
138 const GrOp* op = fRecordedOps[i].get(); // only diff from the GrRenderTargetOpList version
139 hasUninstantiatedProxy = false;
140 if (op) {
141 op->visitProxies(checkInstantiation);
142 }
143 if (hasUninstantiatedProxy) {
144 // When instantiation of the proxy fails we drop the Op
145 fRecordedOps[i] = nullptr;
146 }
147 }
148}
149
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400150void GrTextureOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const {
151 unsigned int cur = alloc->numOps();
152
153 // Add the interval for all the writes to this opList's target
Robert Phillipsf8e25022017-11-08 15:24:31 -0500154 if (fRecordedOps.count()) {
155 alloc->addInterval(fTarget.get(), cur, cur+fRecordedOps.count()-1);
156 } else {
157 // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we
158 // still need to add an interval for the destination so we create a fake op# for
159 // the missing clear op.
160 alloc->addInterval(fTarget.get());
161 alloc->incOps();
162 }
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400163
Chris Dalton8816b932017-11-29 16:48:25 -0700164 auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p) {
165 alloc->addInterval(p SkDEBUGCODE(, p == fTarget.get()));
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400166 };
167 for (int i = 0; i < fRecordedOps.count(); ++i) {
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400168 const GrOp* op = fRecordedOps[i].get(); // only diff from the GrRenderTargetOpList version
Robert Phillips8186cbe2017-11-01 17:32:39 -0400169 if (op) {
170 op->visitProxies(gather);
Greg Daniel065b41d2017-11-08 19:58:51 +0000171 }
Robert Phillipsf8e25022017-11-08 15:24:31 -0500172
173 // Even though the op may have been moved we still need to increment the op count to
174 // keep all the math consistent.
175 alloc->incOps();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400176 }
177}
178
Robert Phillips318c4192017-05-17 09:36:38 -0400179void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op) {
180 SkASSERT(fTarget.get());
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500181 // A closed GrOpList should never receive new/more ops
Brian Osman62e7b5f2016-10-26 12:02:18 -0400182 SkASSERT(!this->isClosed());
183
Robert Phillips318c4192017-05-17 09:36:38 -0400184 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400185 GrOP_INFO("Re-Recording (%s, opID: %u)\n"
Brian Osman62e7b5f2016-10-26 12:02:18 -0400186 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500187 op->name(),
188 op->uniqueID(),
189 op->bounds().fLeft, op->bounds().fRight,
190 op->bounds().fTop, op->bounds().fBottom);
191 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon42ad83a2016-12-20 16:14:45 -0500192 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
Brian Osman62e7b5f2016-10-26 12:02:18 -0400193
Brian Salomon2790c522016-12-09 16:32:23 -0500194 fRecordedOps.emplace_back(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400195}