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