blob: 5c4fe3cc06d29587923f812cdb44c8966c319a5b [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) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040036 SkDebugf("*******************************\n");
Brian Salomon1e41f4a2016-12-07 15:05:04 -050037 SkDebugf("%d: %s\n", i, fRecordedOps[i]->name());
38 SkString str = fRecordedOps[i]->dumpInfo();
Brian Osman62e7b5f2016-10-26 12:02:18 -040039 SkDebugf("%s\n", str.c_str());
Brian Salomon1e41f4a2016-12-07 15:05:04 -050040 const SkRect& clippedBounds = fRecordedOps[i]->bounds();
Brian Osman62e7b5f2016-10-26 12:02:18 -040041 SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
42 clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight,
43 clippedBounds.fBottom);
44 }
45}
Robert Phillipsc589b0b2017-04-17 07:53:07 -040046
Brian Osman62e7b5f2016-10-26 12:02:18 -040047#endif
48
Brian Osman407b3422017-08-22 15:01:32 -040049void GrTextureOpList::onPrepare(GrOpFlushState* flushState) {
Robert Phillips6cdc22c2017-05-11 16:29:14 -040050 SkASSERT(this->isClosed());
Brian Osman62e7b5f2016-10-26 12:02:18 -040051
Brian Salomon1e41f4a2016-12-07 15:05:04 -050052 // 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 Salomon29b60c92017-10-31 14:42:10 -040055 GrOpFlushState::OpArgs opArgs = {
56 fRecordedOps[i].get(),
57 nullptr,
58 nullptr,
59 GrXferProcessor::DstProxy()
60 };
61 flushState->setOpArgs(&opArgs);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050062 fRecordedOps[i]->prepare(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -040063 flushState->setOpArgs(nullptr);
Brian Osman62e7b5f2016-10-26 12:02:18 -040064 }
65 }
66}
67
Brian Osman407b3422017-08-22 15:01:32 -040068bool GrTextureOpList::onExecute(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050069 if (0 == fRecordedOps.count()) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040070 return false;
71 }
72
Greg Daniel500d58b2017-08-24 15:59:33 -040073 std::unique_ptr<GrGpuTextureCommandBuffer> commandBuffer(
74 flushState->gpu()->createCommandBuffer(fTarget.get()->priv().peekTexture(),
75 fTarget.get()->origin()));
76 flushState->setCommandBuffer(commandBuffer.get());
77
Brian Salomon1e41f4a2016-12-07 15:05:04 -050078 for (int i = 0; i < fRecordedOps.count(); ++i) {
Brian Salomon29b60c92017-10-31 14:42:10 -040079 GrOpFlushState::OpArgs opArgs = {
80 fRecordedOps[i].get(),
81 nullptr,
82 nullptr,
83 GrXferProcessor::DstProxy()
84 };
85 flushState->setOpArgs(&opArgs);
Brian Salomon9e50f7b2017-03-06 12:02:34 -050086 fRecordedOps[i]->execute(flushState);
Brian Salomon29b60c92017-10-31 14:42:10 -040087 flushState->setOpArgs(nullptr);
Brian Osman62e7b5f2016-10-26 12:02:18 -040088 }
89
Greg Daniel500d58b2017-08-24 15:59:33 -040090 commandBuffer->submit();
91 flushState->setCommandBuffer(nullptr);
92
Brian Osman62e7b5f2016-10-26 12:02:18 -040093 return true;
94}
95
Chris Daltona84cacf2017-10-04 10:30:29 -060096void GrTextureOpList::endFlush() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050097 fRecordedOps.reset();
Chris Daltona84cacf2017-10-04 10:30:29 -060098 INHERITED::endFlush();
Brian Osman62e7b5f2016-10-26 12:02:18 -040099}
100
101////////////////////////////////////////////////////////////////////////////////
102
Robert Phillips81dd3e02017-06-23 11:59:24 -0400103// This closely parallels GrRenderTargetOpList::copySurface but renderTargetOpList
104// stores extra data with the op
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400105bool GrTextureOpList::copySurface(const GrCaps& caps,
Robert Phillipsbf25d432017-04-07 10:08:53 -0400106 GrSurfaceProxy* dst,
107 GrSurfaceProxy* src,
Brian Osman62e7b5f2016-10-26 12:02:18 -0400108 const SkIRect& srcRect,
109 const SkIPoint& dstPoint) {
Robert Phillipsa16f6cb2017-06-01 11:06:13 -0400110 SkASSERT(dst == fTarget.get());
111
112 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500113 if (!op) {
Brian Osman62e7b5f2016-10-26 12:02:18 -0400114 return false;
115 }
Robert Phillips9d6c64f2017-09-14 10:56:45 -0400116
117 auto addDependency = [ &caps, this ] (GrSurfaceProxy* p) {
118 this->addDependency(p, caps);
119 };
120 op->visitProxies(addDependency);
Brian Osman62e7b5f2016-10-26 12:02:18 -0400121
Robert Phillips318c4192017-05-17 09:36:38 -0400122 this->recordOp(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400123 return true;
124}
125
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400126void 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 Phillipsf8e25022017-11-08 15:24:31 -0500130 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 Phillipsd375dbf2017-09-14 12:45:25 -0400139
140 auto gather = [ alloc ] (GrSurfaceProxy* p) {
141 alloc->addInterval(p);
142 };
143 for (int i = 0; i < fRecordedOps.count(); ++i) {
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400144 const GrOp* op = fRecordedOps[i].get(); // only diff from the GrRenderTargetOpList version
Robert Phillips8186cbe2017-11-01 17:32:39 -0400145 if (op) {
146 op->visitProxies(gather);
Greg Daniel065b41d2017-11-08 19:58:51 +0000147 }
Robert Phillipsf8e25022017-11-08 15:24:31 -0500148
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 Phillipsd375dbf2017-09-14 12:45:25 -0400152 }
153}
154
Robert Phillips318c4192017-05-17 09:36:38 -0400155void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op) {
156 SkASSERT(fTarget.get());
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500157 // A closed GrOpList should never receive new/more ops
Brian Osman62e7b5f2016-10-26 12:02:18 -0400158 SkASSERT(!this->isClosed());
159
Robert Phillips318c4192017-05-17 09:36:38 -0400160 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400161 GrOP_INFO("Re-Recording (%s, opID: %u)\n"
Brian Osman62e7b5f2016-10-26 12:02:18 -0400162 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500163 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 Salomon42ad83a2016-12-20 16:14:45 -0500168 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
Brian Osman62e7b5f2016-10-26 12:02:18 -0400169
Brian Salomon2790c522016-12-09 16:32:23 -0500170 fRecordedOps.emplace_back(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400171}