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