xref: /aosp_15_r20/external/skia/src/gpu/graphite/task/SynchronizeToCpuTask.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2022 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_SynchronizeToCpuTask_DEFINED
9 #define skgpu_graphite_task_SynchronizeToCpuTask_DEFINED
10 
11 #include "src/gpu/graphite/Buffer.h"
12 #include "src/gpu/graphite/task/Task.h"
13 
14 namespace skgpu::graphite {
15 
16 class Buffer;
17 
18 /**
19  * Task that synchronizes the contents of a buffer from the GPU to the CPU. This task ensures that
20  * all modifications to the buffer made the GPU are visible from the CPU. This task may not result
21  * in any work if the underlying buffer does not require synchronization (e.g. a shared memory
22  * buffer).
23  */
24 class SynchronizeToCpuTask final : public Task {
25 public:
26     static sk_sp<SynchronizeToCpuTask> Make(sk_sp<Buffer>);
27     ~SynchronizeToCpuTask() override;
28 
prepareResources(ResourceProvider *,ScratchResourceManager *,const RuntimeEffectDictionary *)29     Status prepareResources(ResourceProvider*,
30                             ScratchResourceManager*,
31                             const RuntimeEffectDictionary*) override {
32         return Status::kSuccess;
33     }
34 
35     Status addCommands(Context*, CommandBuffer*, ReplayTargetData) override;
36 
37 private:
SynchronizeToCpuTask(sk_sp<Buffer> buffer)38     explicit SynchronizeToCpuTask(sk_sp<Buffer> buffer) : fBuffer(std::move(buffer)) {}
39 
40     sk_sp<Buffer> fBuffer;
41 };
42 
43 }  // namespace skgpu::graphite
44 
45 #endif  // skgpu_graphite_SynchronizeToCpuTask_DEFINED
46