xref: /third_party/skia/src/gpu/GrDDLTask.cpp (revision cb93a386)
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
14GrDDLTask::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
35GrDDLTask::~GrDDLTask() { }
36
37void GrDDLTask::endFlush(GrDrawingManager* drawingManager) {
38    for (auto& task : fDDL->priv().renderTasks()) {
39        task->endFlush(drawingManager);
40    }
41
42    INHERITED::endFlush(drawingManager);
43}
44
45void GrDDLTask::disown(GrDrawingManager* drawingManager) {
46    for (auto& task : fDDL->priv().renderTasks()) {
47        task->disown(drawingManager);
48    }
49
50    INHERITED::disown(drawingManager);
51}
52
53bool 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
67void 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
77GrRenderTask::ExpectedOutcome GrDDLTask::onMakeClosed(GrRecordingContext*,
78                                                      SkIRect* targetUpdateBounds) {
79    SkASSERT(0);
80    return ExpectedOutcome::kTargetUnchanged;
81}
82
83void GrDDLTask::gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const {
84    for (auto& task : fDDL->priv().renderTasks()) {
85        task->gatherIDs(idArray);
86    }
87}
88
89void GrDDLTask::onPrepare(GrOpFlushState* flushState) {
90    for (auto& task : fDDL->priv().renderTasks()) {
91        task->prepare(flushState);
92    }
93}
94
95bool 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
107void 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