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_Task_DEFINED 9 #define skgpu_graphite_task_Task_DEFINED 10 11 #include "include/core/SkPoint.h" 12 #include "include/core/SkRefCnt.h" 13 14 namespace skgpu::graphite { 15 16 class CommandBuffer; 17 class Context; 18 class ResourceProvider; 19 class RuntimeEffectDictionary; 20 class ScratchResourceManager; 21 class Texture; 22 23 class Task : public SkRefCnt { 24 public: 25 // Holds a render target and translation to use in the task's work, if necessary. 26 struct ReplayTargetData { 27 const Texture* fTarget; 28 SkIVector fTranslation; 29 }; 30 31 enum class Status { 32 // The task step (prepareResources or addCommands) succeeded, proceed to the next task. 33 // If the Recording is replayed, this task should be executed again. 34 kSuccess, 35 // The task step succeeded, but it was a one-time-only operation and should be removed from 36 // the task list. If this is returned from prepareResources(), the task is removed before 37 // addCommands() will ever be called. If this is returned from addCommands(), it will not 38 // be part of any replayed Recording, but any added commands from the first call will be 39 // executed once. 40 // 41 // NOTE: If a task step needs to be conditionally processed but repeatable, it should 42 // internally skip work and still return kSuccess instead of kDiscard. 43 kDiscard, 44 // The step failed and cannot be recovered so the Recording is invalidated. 45 kFail 46 }; 47 48 // Instantiate and prepare any Resources that must happen while the Task is still on the 49 // Recorder. 50 virtual Status prepareResources(ResourceProvider*, 51 ScratchResourceManager*, 52 const RuntimeEffectDictionary*) = 0; 53 54 // Returns true on success; false on failure. 55 virtual Status addCommands(Context*, CommandBuffer*, ReplayTargetData) = 0; 56 }; 57 58 } // namespace skgpu::graphite 59 60 #endif // skgpu_graphite_task_Task_DEFINED 61