1 /* 2 * Copyright 2024 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_DrawTask_DEFINED 9 #define skgpu_graphite_task_DrawTask_DEFINED 10 11 #include "src/gpu/graphite/ScratchResourceManager.h" 12 #include "src/gpu/graphite/task/Task.h" 13 #include "src/gpu/graphite/task/TaskList.h" 14 15 namespace skgpu::graphite { 16 17 class TextureProxy; 18 19 /** 20 * DrawTask is a collection of subtasks that are executed in order to produce some intended 21 * image in the DrawTask's target. As such, at least one of its subtasks will either be a 22 * RenderPassTask, ComputeTask or CopyXToTextureTask that directly modify the target. 23 */ 24 class DrawTask final : public Task, private ScratchResourceManager::PendingUseListener { 25 public: 26 explicit DrawTask(sk_sp<TextureProxy> target); 27 ~DrawTask() override; 28 29 Status prepareResources(ResourceProvider*, 30 ScratchResourceManager*, 31 const RuntimeEffectDictionary*) override; 32 33 Status addCommands(Context*, CommandBuffer*, ReplayTargetData) override; 34 35 private: 36 friend class DrawContext; // for "addTask" 37 38 // DrawTask is modified directly by DrawContext for efficiency, but its task list will be 39 // fixed once DrawContext snaps the task. addTask(sk_sp<Task> task)40 void addTask(sk_sp<Task> task) { fChildTasks.add(std::move(task)); } hasTasks()41 bool hasTasks() const { return fChildTasks.hasTasks(); } 42 43 void onUseCompleted(ScratchResourceManager*) override; 44 45 sk_sp<TextureProxy> fTarget; 46 TaskList fChildTasks; 47 48 // Once there is one DrawTask for a scratch device, whether or not the target is instantaited 49 // will be equivalent to whether or not prepareResources() has been called already if the task 50 // is referenced multiple times in a Recording. Right now, however, a scratch device can still 51 // produce several DrawTasks (in which case they will see an instantiated proxy so should still 52 // prepare their own resources instead of discarding themselves). 53 bool fPrepared = false; 54 }; 55 56 } // namespace skgpu::graphite 57 58 #endif // skgpu_graphite_task_DrawTask_DEFINED 59