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