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