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