1 /*
2 * Copyright 2021 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/graphite/task/TaskList.h"
9
10 #include "src/core/SkTraceEvent.h"
11 #include "src/gpu/graphite/ScratchResourceManager.h"
12
13 namespace skgpu::graphite {
14
15 using Status = Task::Status;
16
17 template <typename Fn>
visitTasks(Fn fn)18 Status TaskList::visitTasks(Fn fn) {
19 int discardCount = 0;
20 for (sk_sp<Task>& task: fTasks) {
21 if (!task) {
22 discardCount++;
23 continue; // Skip over discarded tasks
24 }
25
26 Status status = fn(task.get());
27 if (status == Status::kFail) {
28 return Status::kFail;
29 } else if (status == Status::kDiscard) {
30 task.reset();
31 discardCount++;
32 }
33 }
34
35 return discardCount == fTasks.size() ? Status::kDiscard : Status::kSuccess;
36 }
37
prepareResources(ResourceProvider * resourceProvider,ScratchResourceManager * scratchManager,const RuntimeEffectDictionary * runtimeDict)38 Status TaskList::prepareResources(ResourceProvider* resourceProvider,
39 ScratchResourceManager* scratchManager,
40 const RuntimeEffectDictionary* runtimeDict) {
41 TRACE_EVENT1("skia.gpu", TRACE_FUNC, "# tasks", fTasks.size());
42 scratchManager->pushScope();
43 Status status = this->visitTasks([&](Task* task) {
44 return task->prepareResources(resourceProvider, scratchManager, runtimeDict);
45 });
46 scratchManager->popScope();
47 return status;
48 }
49
addCommands(Context * context,CommandBuffer * commandBuffer,Task::ReplayTargetData replayData)50 Status TaskList::addCommands(Context* context,
51 CommandBuffer* commandBuffer,
52 Task::ReplayTargetData replayData) {
53 TRACE_EVENT1("skia.gpu", TRACE_FUNC, "# tasks", fTasks.size());
54 return this->visitTasks([&](Task* task) {
55 return task->addCommands(context, commandBuffer, replayData);
56 });
57 }
58
59 } // namespace skgpu::graphite
60