Flutter Engine
The Flutter Engine
CopyTask.cpp
Go to the documentation of this file.
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
9
15
16namespace skgpu::graphite {
17
19 size_t srcOffset,
20 sk_sp<Buffer> dstBuffer,
21 size_t dstOffset,
22 size_t size) {
23 SkASSERT(srcBuffer);
24 SkASSERT(size <= srcBuffer->size() - srcOffset);
25 SkASSERT(dstBuffer);
26 SkASSERT(size <= dstBuffer->size() - dstOffset);
28 srcOffset,
29 std::move(dstBuffer),
30 dstOffset,
31 size));
32}
33
34CopyBufferToBufferTask::CopyBufferToBufferTask(const Buffer* srcBuffer,
35 size_t srcOffset,
36 sk_sp<Buffer> dstBuffer,
37 size_t dstOffset,
38 size_t size)
39 : fSrcBuffer(srcBuffer)
40 , fSrcOffset(srcOffset)
41 , fDstBuffer(std::move(dstBuffer))
42 , fDstOffset(dstOffset)
43 , fSize(size) {}
44
46
50 return Status::kSuccess;
51}
52
54 CommandBuffer* commandBuffer,
56 if (commandBuffer->copyBufferToBuffer(fSrcBuffer, fSrcOffset, fDstBuffer, fDstOffset, fSize)) {
57 return Status::kSuccess;
58 } else {
59 return Status::kFail;
60 }
61}
62
64 SkIRect srcRect,
66 size_t bufferOffset,
67 size_t bufferRowBytes) {
68 if (!textureProxy) {
69 return nullptr;
70 }
71 return sk_sp<CopyTextureToBufferTask>(new CopyTextureToBufferTask(std::move(textureProxy),
72 srcRect,
73 std::move(buffer),
74 bufferOffset,
75 bufferRowBytes));
76}
77
78CopyTextureToBufferTask::CopyTextureToBufferTask(sk_sp<TextureProxy> textureProxy,
79 SkIRect srcRect,
81 size_t bufferOffset,
82 size_t bufferRowBytes)
83 : fTextureProxy(std::move(textureProxy))
84 , fSrcRect(srcRect)
85 , fBuffer(std::move(buffer))
86 , fBufferOffset(bufferOffset)
87 , fBufferRowBytes(bufferRowBytes) {
88}
89
91
95 // If the source texture hasn't been instantiated yet, it means there was no prior task that
96 // could have initialized its contents so a readback to a buffer does not make sense.
97 SkASSERT(fTextureProxy->isInstantiated() || fTextureProxy->isLazy());
98 // TODO: The copy is also a consumer of the source, so it should participate in returning
99 // scratch resources like RenderPassTask does. For now, though, all copy tasks side step reuse
100 // entirely and they cannot participate until they've been moved into scoping tasks like
101 // DrawTask first.
102 return Status::kSuccess;
103}
104
106 CommandBuffer* commandBuffer,
108 if (commandBuffer->copyTextureToBuffer(fTextureProxy->refTexture(),
109 fSrcRect,
110 std::move(fBuffer),
111 fBufferOffset,
112 fBufferRowBytes)) {
113 // TODO(b/332681367): CopyTextureToBuffer is currently only used for readback operations,
114 // which are a one-time event. Should this just default to returning kDiscard?
115 return Status::kSuccess;
116 } else {
117 return Status::kFail;
118 }
119}
120
121//--------------------------------------------------------------------------------------------------
122
124 SkIRect srcRect,
125 sk_sp<TextureProxy> dstProxy,
126 SkIPoint dstPoint,
127 int dstLevel) {
128 if (!srcProxy || !dstProxy) {
129 return nullptr;
130 }
131 return sk_sp<CopyTextureToTextureTask>(new CopyTextureToTextureTask(std::move(srcProxy),
132 srcRect,
133 std::move(dstProxy),
134 dstPoint,
135 dstLevel));
136}
137
138CopyTextureToTextureTask::CopyTextureToTextureTask(sk_sp<TextureProxy> srcProxy,
139 SkIRect srcRect,
140 sk_sp<TextureProxy> dstProxy,
141 SkIPoint dstPoint,
142 int dstLevel)
143 : fSrcProxy(std::move(srcProxy))
144 , fSrcRect(srcRect)
145 , fDstProxy(std::move(dstProxy))
146 , fDstPoint(dstPoint)
147 , fDstLevel(dstLevel) {}
148
150
154 // Do not instantiate the src proxy. If the source texture hasn't been instantiated yet, it
155 // means there was no prior task that could have initialized its contents so propagating the
156 // undefined contents to the dst does not make sense.
157 // TODO(b/333729316): Assert that fSrcProxy is instantiated or lazy; right now it may not be
158 // instantatiated if this is a dst readback copy for a scratch Device. In that case, a
159 // RenderPassTask will immediately follow this copy task and instantiate the source proxy so
160 // that addCommands() has a texture to operate on. That said, the texture's contents will be
161 // undefined when the copy is executed ideally it just shouldn't happen.
162
163 // TODO: The copy is also a consumer of the source, so it should participate in returning
164 // scratch resources like RenderPassTask does. For now, though, all copy tasks side step reuse
165 // entirely and they cannot participate until they've been moved into scoping tasks like
166 // DrawTask first. In particular, for texture-to-texture copies, they should be scoped to not
167 // invoke pending listeners for a subsequent RenderPassTask.
168
169 // TODO: Use the scratch resource manager to instantiate fDstProxy, although the details of when
170 // that texture can be returned need to be worked out. While brittle, all current use cases
171 // of scratch texture-to-texture copies have the dst used immediately by the next task, so it
172 // could just add a pending listener that returns the texture w/o any read counting.
173 if (!TextureProxy::InstantiateIfNotLazy(resourceProvider, fDstProxy.get())) {
174 SKGPU_LOG_E("Could not instantiate dst texture proxy for CopyTextureToTextureTask!");
175 return Status::kFail;
176 }
177 return Status::kSuccess;
178}
179
181 CommandBuffer* commandBuffer,
183 // prepareResources() doesn't instantiate the source assuming that a prior task will have do so
184 // as part of initializing the texture contents.
185 SkASSERT(fSrcProxy->isInstantiated());
186 if (commandBuffer->copyTextureToTexture(fSrcProxy->refTexture(),
187 fSrcRect,
188 fDstProxy->refTexture(),
189 fDstPoint,
190 fDstLevel)) {
191 // TODO(b/332681367): The calling context should be able to specify whether or not this copy
192 // is a repeatable operation (e.g. dst readback copy for blending) or one time (e.g. client
193 // asked for a copy of an image or surface).
194 return Status::kSuccess;
195 } else {
196 return Status::kFail;
197 }
198}
199
200} // namespace skgpu::graphite
#define SKGPU_LOG_E(fmt,...)
Definition: Log.h:38
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool copyTextureToTexture(sk_sp< Texture > src, SkIRect srcRect, sk_sp< Texture > dst, SkIPoint dstPoint, int mipLevel)
bool copyTextureToBuffer(sk_sp< Texture >, SkIRect srcRect, sk_sp< Buffer >, size_t bufferOffset, size_t bufferRowBytes)
bool copyBufferToBuffer(const Buffer *srcBuffer, size_t srcOffset, sk_sp< Buffer > dstBuffer, size_t dstOffset, size_t size)
Status prepareResources(ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *) override
Definition: CopyTask.cpp:47
static sk_sp< CopyBufferToBufferTask > Make(const Buffer *srcBuffer, size_t srcOffset, sk_sp< Buffer > dstBuffer, size_t dstOffset, size_t size)
Definition: CopyTask.cpp:18
Status addCommands(Context *, CommandBuffer *, ReplayTargetData) override
Definition: CopyTask.cpp:53
static sk_sp< CopyTextureToBufferTask > Make(sk_sp< TextureProxy >, SkIRect srcRect, sk_sp< Buffer >, size_t bufferOffset, size_t bufferRowBytes)
Definition: CopyTask.cpp:63
Status addCommands(Context *, CommandBuffer *, ReplayTargetData) override
Definition: CopyTask.cpp:105
Status prepareResources(ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *) override
Definition: CopyTask.cpp:92
Status addCommands(Context *, CommandBuffer *, ReplayTargetData) override
Definition: CopyTask.cpp:180
static sk_sp< CopyTextureToTextureTask > Make(sk_sp< TextureProxy > srcProxy, SkIRect srcRect, sk_sp< TextureProxy > dstProxy, SkIPoint dstPoint, int dstLevel=0)
Definition: CopyTask.cpp:123
Status prepareResources(ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *) override
Definition: CopyTask.cpp:151
static bool InstantiateIfNotLazy(ResourceProvider *, TextureProxy *)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: ref_ptr.h:256
Definition: SkRect.h:32