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 #ifndef skgpu_graphite_task_TaskList_DEFINED 9 #define skgpu_graphite_task_TaskList_DEFINED 10 11 #include "include/private/base/SkTArray.h" 12 #include "src/gpu/graphite/task/Task.h" 13 14 namespace skgpu::graphite { 15 16 class CommandBuffer; 17 class Context; 18 class ResourceProvider; 19 class ScratchResourceManager; 20 21 class TaskList { 22 public: 23 TaskList() = default; 24 add(TaskList && tasks)25 void add(TaskList&& tasks) { fTasks.move_back(tasks.fTasks); } add(sk_sp<Task> task)26 void add(sk_sp<Task> task) { fTasks.emplace_back(std::move(task)); } reset()27 void reset() { fTasks.clear(); } 28 size()29 int size() const { return fTasks.size(); } hasTasks()30 bool hasTasks() const { return !fTasks.empty(); } 31 32 // Returns kSuccess if no child task failed and at least one child didn't return kDiscard. 33 // Returns kDiscard if all children were discarded. 34 // Returns kFail if any child failed. 35 // Automatically removes tasks from its list if they return kDiscard. 36 Task::Status prepareResources(ResourceProvider*, 37 ScratchResourceManager*, 38 const RuntimeEffectDictionary*); 39 Task::Status addCommands(Context*, CommandBuffer*, Task::ReplayTargetData); 40 41 private: 42 template <typename Fn> // (Task*)->Status 43 Task::Status visitTasks(Fn); 44 45 skia_private::TArray<sk_sp<Task>> fTasks; 46 }; 47 48 } // namespace skgpu::graphite 49 50 #endif // skgpu_graphite_task_TaskList_DEFINED 51