Debian Codegraph @

src/gpu/graphite/task/CopyTask.h

raw
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_CopyTask_DEFINED
9 #define skgpu_graphite_task_CopyTask_DEFINED
10
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "src/gpu/graphite/task/Task.h"
15
16 #include <cstddef>
17 #include <functional>
18
19 namespace skgpu::graphite {
20
21 class Buffer;
22 class CommandBuffer;
23 class Context;
24 class ResourceProvider;
25 class RuntimeEffectDictionary;
26 class ScratchResourceManager;
27 class TextureProxy;
28
29 class CopyBufferToBufferTask final : public Task {
30 public:
31 // The srcBuffer for this Task is always a transfer buffer which is owned by the
32 // UploadBufferManager. Thus we don't have to take a ref to it as the UploadBufferManager will
33 // handle its refs and passing them to the Recording.
34 static sk_sp<CopyBufferToBufferTask> Make(const Buffer* srcBuffer,
35 size_t srcOffset,
36 sk_sp<Buffer> dstBuffer,
37 size_t dstOffset,
38 size_t size);
39
40 ~CopyBufferToBufferTask() override;
41
42 Status prepareResources(ResourceProvider*,
43 ScratchResourceManager*,
44 sk_sp<const RuntimeEffectDictionary>) override;
45
46 Status addCommands(Context*, CommandBuffer*, ReplayTargetData) override;
47
48 #if defined(SK_DUMP_TASKS)
49 void dump(int index, const char* prefix) const override {
50 if (index >= 0) {
51 SkDebugf("%s%d: Copy BtoB Task: Src=%p Dst=%p\n", prefix, index, fSrcBuffer,
52 fDstBuffer.get());
53 } else {
54 SkDebugf("%sCopy BtoB Task: Src=%p Dst=%p\n", prefix, fSrcBuffer, fDstBuffer.get());
55 }
56 }
57 #endif
58
59 private:
60 CopyBufferToBufferTask(const Buffer* srcBuffer,
61 size_t srcOffset,
62 sk_sp<Buffer> dstBuffer,
63 size_t dstOffset,
64 size_t size);
65
66 const Buffer* fSrcBuffer;
67 size_t fSrcOffset;
68 sk_sp<Buffer> fDstBuffer;
69 size_t fDstOffset;
70 size_t fSize;
71 };
72
73 class CopyTextureToBufferTask final : public Task {
74 public:
75 static sk_sp<CopyTextureToBufferTask> Make(sk_sp<TextureProxy>,
76 SkIRect srcRect,
77 sk_sp<Buffer>,
78 size_t bufferOffset,
79 size_t bufferRowBytes);
80
81 ~CopyTextureToBufferTask() override;
82
83 Status prepareResources(ResourceProvider*,
84 ScratchResourceManager*,
85 sk_sp<const RuntimeEffectDictionary>) override;
86
87 Status addCommands(Context*, CommandBuffer*, ReplayTargetData) override;
88
89 bool visitProxies(const std::function<bool(const TextureProxy*)>& visitor,
90 bool readsOnly) override {
91 // The texture is the source of the copy, so it's always read
92 return visitor(fTextureProxy.get());
93 }
94
95 #if defined(SK_DUMP_TASKS)
96 void dump(int index, const char* prefix) const override {
97 if (index >= 0) {
98 SkDebugf("%s%d: Copy TtoB Task: Texture=%p Buffer=%p\n", prefix, index,
99 fTextureProxy.get(), fBuffer.get());
100 } else {
101 SkDebugf("%sCopy TtoB Task: Texture=%p Buffer=%p\n", prefix, fTextureProxy.get(),
102 fBuffer.get());
103 }
104 }
105 #endif
106
107 private:
108 CopyTextureToBufferTask(sk_sp<TextureProxy>,
109 SkIRect srcRect,
110 sk_sp<Buffer>,
111 size_t bufferOffset,
112 size_t bufferRowBytes);
113
114 sk_sp<TextureProxy> fTextureProxy;
115 SkIRect fSrcRect;
116 sk_sp<Buffer> fBuffer;
117 size_t fBufferOffset;
118 size_t fBufferRowBytes;
119 };
120
121 class CopyTextureToTextureTask final : public Task {
122 public:
123 static sk_sp<CopyTextureToTextureTask> Make(sk_sp<TextureProxy> srcProxy,
124 SkIRect srcRect,
125 sk_sp<TextureProxy> dstProxy,
126 SkIPoint dstPoint,
127 int dstLevel = 0);
128
129 ~CopyTextureToTextureTask() override;
130
131 Status prepareResources(ResourceProvider*,
132 ScratchResourceManager*,
133 sk_sp<const RuntimeEffectDictionary>) override;
134
135 Status addCommands(Context*, CommandBuffer*, ReplayTargetData) override;
136
137 bool visitProxies(const std::function<bool(const TextureProxy*)>& visitor,
138 bool readsOnly) override {
139 // Only visit fDstProxy if readsOnly is false; fSrcProxy is the only texture being read.
140 return visitor(fSrcProxy.get()) && (readsOnly || visitor(fDstProxy.get()));
141 }
142
143 #if defined(SK_DUMP_TASKS)
144 void dump(int index, const char* prefix) const override {
145 if (index >= 0) {
146 SkDebugf("%s%d: Copy TtoT Task: Src=%p Dst=%p\n", prefix, index, fSrcProxy.get(),
147 fDstProxy.get());
148 } else {
149 SkDebugf("%sCopy TtoT Task: Src=%p Dst=%p\n", prefix, fSrcProxy.get(), fDstProxy.get());
150 }
151 }
152 #endif
153
154 private:
155 CopyTextureToTextureTask(sk_sp<TextureProxy> srcProxy,
156 SkIRect srcRect,
157 sk_sp<TextureProxy> dstProxy,
158 SkIPoint dstPoint,
159 int dstLevel);
160
161 sk_sp<TextureProxy> fSrcProxy;
162 SkIRect fSrcRect;
163 sk_sp<TextureProxy> fDstProxy;
164 SkIPoint fDstPoint;
165 int fDstLevel;
166 };
167
168 } // namespace skgpu::graphite
169
170 #endif // skgpu_graphite_task_CopyTask_DEFINED