1 /*
2 * Copyright 2020 Google LLC
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 "src/gpu/GrDDLTask.h"
9
10 #include "include/core/SkDeferredDisplayList.h"
11 #include "src/core/SkDeferredDisplayListPriv.h"
12 #include "src/gpu/GrResourceAllocator.h"
13
GrDDLTask(GrDrawingManager * drawingMgr,sk_sp<GrRenderTargetProxy> ddlTarget,sk_sp<const SkDeferredDisplayList> ddl,SkIPoint offset)14 GrDDLTask::GrDDLTask(GrDrawingManager* drawingMgr,
15 sk_sp<GrRenderTargetProxy> ddlTarget,
16 sk_sp<const SkDeferredDisplayList> ddl,
17 SkIPoint offset)
18 : fDDL(std::move(ddl))
19 , fDDLTarget(std::move(ddlTarget))
20 , fOffset(offset) {
21 (void) fOffset; // fOffset will be used shortly
22
23 for (auto& task : fDDL->priv().renderTasks()) {
24 SkASSERT(task->isClosed());
25
26 for (int i = 0; i < task->numTargets(); ++i) {
27 drawingMgr->setLastRenderTask(task->target(i), task.get());
28 }
29 }
30
31 // The DDL task never accepts additional tasks
32 this->setFlag(kClosed_Flag);
33 }
34
~GrDDLTask()35 GrDDLTask::~GrDDLTask() { }
36
endFlush(GrDrawingManager * drawingManager)37 void GrDDLTask::endFlush(GrDrawingManager* drawingManager) {
38 for (auto& task : fDDL->priv().renderTasks()) {
39 task->endFlush(drawingManager);
40 }
41
42 INHERITED::endFlush(drawingManager);
43 }
44
disown(GrDrawingManager * drawingManager)45 void GrDDLTask::disown(GrDrawingManager* drawingManager) {
46 for (auto& task : fDDL->priv().renderTasks()) {
47 task->disown(drawingManager);
48 }
49
50 INHERITED::disown(drawingManager);
51 }
52
onIsUsed(GrSurfaceProxy * proxy) const53 bool GrDDLTask::onIsUsed(GrSurfaceProxy* proxy) const {
54 if (proxy == fDDLTarget.get()) {
55 return true;
56 }
57
58 for (auto& task : fDDL->priv().renderTasks()) {
59 if (task->isUsed(proxy)) {
60 return true;
61 }
62 }
63
64 return false;
65 }
66
gatherProxyIntervals(GrResourceAllocator * alloc) const67 void GrDDLTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
68 // We don't have any proxies, but the resource allocator will still bark
69 // if a task doesn't claim any op indices, so we oblige it.
70 alloc->incOps();
71
72 for (auto& task : fDDL->priv().renderTasks()) {
73 task->gatherProxyIntervals(alloc);
74 }
75 }
76
onMakeClosed(const GrCaps & caps,SkIRect * targetUpdateBounds)77 GrRenderTask::ExpectedOutcome GrDDLTask::onMakeClosed(const GrCaps& caps,
78 SkIRect* targetUpdateBounds) {
79 SkASSERT(0);
80 return ExpectedOutcome::kTargetUnchanged;
81 }
82
gatherIDs(SkSTArray<8,uint32_t,true> * idArray) const83 void GrDDLTask::gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const {
84 for (auto& task : fDDL->priv().renderTasks()) {
85 task->gatherIDs(idArray);
86 }
87 }
88
onPrepare(GrOpFlushState * flushState)89 void GrDDLTask::onPrepare(GrOpFlushState* flushState) {
90 for (auto& task : fDDL->priv().renderTasks()) {
91 task->prepare(flushState);
92 }
93 }
94
onExecute(GrOpFlushState * flushState)95 bool GrDDLTask::onExecute(GrOpFlushState* flushState) {
96 bool anyCommandsIssued = false;
97 for (auto& task : fDDL->priv().renderTasks()) {
98 if (task->execute(flushState)) {
99 anyCommandsIssued = true;
100 }
101 }
102
103 return anyCommandsIssued;
104 }
105
106 #if GR_TEST_UTILS
dump(const SkString & label,SkString indent,bool printDependencies,bool close) const107 void GrDDLTask::dump(const SkString& label,
108 SkString indent,
109 bool printDependencies,
110 bool close) const {
111 INHERITED::dump(label, indent, printDependencies, false);
112
113 SkDebugf("%sDDL Target: ", indent.c_str());
114 if (fDDLTarget) {
115 SkString proxyStr = fDDLTarget->dump();
116 SkDebugf("%s", proxyStr.c_str());
117 }
118 SkDebugf("\n");
119
120 SkDebugf("%s%d sub-tasks\n", indent.c_str(), fDDL->priv().numRenderTasks());
121
122 SkString subIndent(indent);
123 subIndent.append(" ");
124
125 int index = 0;
126 for (auto& task : fDDL->priv().renderTasks()) {
127 SkString subLabel;
128 subLabel.printf("sub-task %d/%d", index++, fDDL->priv().numRenderTasks());
129 task->dump(subLabel, subIndent, printDependencies, true);
130 }
131
132 if (close) {
133 SkDebugf("%s--------------------------------------------------------------\n\n",
134 indent.c_str());
135 }
136 }
137 #endif
138