Robert Phillips | 02dd0ed | 2020-11-09 17:03:34 -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, |
| 16 | sk_sp<const SkDeferredDisplayList> ddl) |
| 17 | : fDDL(std::move(ddl)) |
| 18 | , fDDLTarget(std::move(ddlTarget)) { |
| 19 | for (auto& task : fDDL->priv().renderTasks()) { |
| 20 | SkASSERT(task->isClosed()); |
| 21 | |
| 22 | for (int i = 0; i < task->numTargets(); ++i) { |
| 23 | this->addTarget(drawingMgr, task->target(i)); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | // The DDL task never accepts additional tasks |
| 28 | this->setFlag(kClosed_Flag); |
| 29 | } |
| 30 | |
| 31 | GrDDLTask::~GrDDLTask() { } |
| 32 | |
| 33 | void GrDDLTask::endFlush(GrDrawingManager* drawingManager) { |
| 34 | for (auto& task : fDDL->priv().renderTasks()) { |
| 35 | task->endFlush(drawingManager); |
| 36 | } |
| 37 | |
| 38 | INHERITED::endFlush(drawingManager); |
| 39 | } |
| 40 | |
| 41 | void GrDDLTask::disown(GrDrawingManager* drawingManager) { |
| 42 | for (auto& task : fDDL->priv().renderTasks()) { |
| 43 | task->disown(drawingManager); |
| 44 | } |
| 45 | |
| 46 | INHERITED::disown(drawingManager); |
| 47 | } |
| 48 | |
| 49 | bool GrDDLTask::onIsUsed(GrSurfaceProxy* proxy) const { |
| 50 | // In the ctor we've added all the targets from the sub-renderTasks into the targets list |
| 51 | // of the this task. The base class' 'isUsed' call checks those so we don't want to check |
| 52 | // them again here. The following 'onIsUsed' methods just check the other (non-target) proxies. |
| 53 | for (auto& task : fDDL->priv().renderTasks()) { |
| 54 | if (task->onIsUsed(proxy)) { |
| 55 | return true; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | void GrDDLTask::handleInternalAllocationFailure() { |
| 63 | for (auto& task : fDDL->priv().renderTasks()) { |
| 64 | task->handleInternalAllocationFailure(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void GrDDLTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 69 | // We don't have any proxies, but the resource allocator will still bark |
| 70 | // if a task doesn't claim any op indices, so we oblige it. |
| 71 | alloc->incOps(); |
| 72 | |
| 73 | for (auto& task : fDDL->priv().renderTasks()) { |
| 74 | task->gatherProxyIntervals(alloc); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | GrRenderTask::ExpectedOutcome GrDDLTask::onMakeClosed(const GrCaps& caps, |
| 79 | SkIRect* targetUpdateBounds) { |
| 80 | SkASSERT(0); |
| 81 | return ExpectedOutcome::kTargetUnchanged; |
| 82 | } |
| 83 | |
| 84 | void GrDDLTask::gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const { |
| 85 | for (auto& task : fDDL->priv().renderTasks()) { |
| 86 | task->gatherIDs(idArray); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void GrDDLTask::onPrepare(GrOpFlushState* flushState) { |
| 91 | for (auto& task : fDDL->priv().renderTasks()) { |
| 92 | task->prepare(flushState); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | bool GrDDLTask::onExecute(GrOpFlushState* flushState) { |
| 97 | bool anyCommandsIssued = false; |
| 98 | for (auto& task : fDDL->priv().renderTasks()) { |
| 99 | if (task->execute(flushState)) { |
| 100 | anyCommandsIssued = true; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return anyCommandsIssued; |
| 105 | } |