Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CommandBuffer.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
19
20namespace skgpu::graphite {
21
23
25 this->releaseResources();
26}
27
28void CommandBuffer::releaseResources() {
29 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
30
31 fTrackedUsageResources.clear();
32 fCommandBufferResources.clear();
33}
34
36 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
37
38 this->releaseResources();
40 fBuffersToAsyncMap.clear();
41}
42
44 fTrackedUsageResources.push_back(std::move(resource));
45}
46
48 fCommandBufferResources.push_back(std::move(resource));
49}
50
52 fFinishedProcs.push_back(std::move(finishedProc));
53}
54
56 if (!success) {
57 for (int i = 0; i < fFinishedProcs.size(); ++i) {
58 fFinishedProcs[i]->setFailureResult();
59 }
60 }
61 fFinishedProcs.clear();
62}
63
65 for (size_t i = 0; i < buffers.size(); ++i) {
66 SkASSERT(buffers[i]);
67 fBuffersToAsyncMap.push_back(buffers[i]);
68 }
69}
70
72 return fBuffersToAsyncMap;
73}
74
76 sk_sp<Texture> colorTexture,
77 sk_sp<Texture> resolveTexture,
78 sk_sp<Texture> depthStencilTexture,
79 SkRect viewport,
80 const DrawPassList& drawPasses) {
81 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
82
83 fRenderPassSize = colorTexture->dimensions();
84 if (!this->onAddRenderPass(renderPassDesc,
85 colorTexture.get(),
86 resolveTexture.get(),
87 depthStencilTexture.get(),
88 viewport,
89 drawPasses)) {
90 return false;
91 }
92
93 if (colorTexture) {
94 this->trackCommandBufferResource(std::move(colorTexture));
95 }
96 if (resolveTexture) {
97 this->trackCommandBufferResource(std::move(resolveTexture));
98 }
99 if (depthStencilTexture) {
100 this->trackCommandBufferResource(std::move(depthStencilTexture));
101 }
102 // We just assume if you are adding a render pass that the render pass will actually do work. In
103 // theory we could have a discard load that doesn't submit any draws, clears, etc. But hopefully
104 // something so trivial would be caught before getting here.
105 SkDEBUGCODE(fHasWork = true;)
106
107 return true;
108}
109
111 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
112
113 if (!this->onAddComputePass(dispatchGroups)) {
114 return false;
115 }
116
117 SkDEBUGCODE(fHasWork = true;)
118
119 return true;
120}
121
123 size_t srcOffset,
124 sk_sp<Buffer> dstBuffer,
125 size_t dstOffset,
126 size_t size) {
127 SkASSERT(srcBuffer);
128 SkASSERT(dstBuffer);
129
130 if (!this->onCopyBufferToBuffer(srcBuffer, srcOffset, dstBuffer.get(), dstOffset, size)) {
131 return false;
132 }
133
134 this->trackResource(std::move(dstBuffer));
135
136 SkDEBUGCODE(fHasWork = true;)
137
138 return true;
139}
140
142 SkIRect srcRect,
144 size_t bufferOffset,
145 size_t bufferRowBytes) {
148
149 if (!this->onCopyTextureToBuffer(texture.get(), srcRect, buffer.get(), bufferOffset,
150 bufferRowBytes)) {
151 return false;
152 }
153
154 this->trackCommandBufferResource(std::move(texture));
155 this->trackResource(std::move(buffer));
156
157 SkDEBUGCODE(fHasWork = true;)
158
159 return true;
160}
161
164 const BufferTextureCopyData* copyData,
165 int count) {
168 SkASSERT(count > 0 && copyData);
169
170 if (!this->onCopyBufferToTexture(buffer, texture.get(), copyData, count)) {
171 return false;
172 }
173
174 this->trackCommandBufferResource(std::move(texture));
175
176 SkDEBUGCODE(fHasWork = true;)
177
178 return true;
179}
180
182 SkIRect srcRect,
184 SkIPoint dstPoint,
185 int mipLevel) {
186 SkASSERT(src);
187 SkASSERT(dst);
188 if (src->textureInfo().isProtected() == Protected::kYes &&
189 dst->textureInfo().isProtected() != Protected::kYes) {
190 SKGPU_LOG_E("Can't copy from protected memory to non-protected");
191 return false;
192 }
193
194 if (!this->onCopyTextureToTexture(src.get(), srcRect, dst.get(), dstPoint, mipLevel)) {
195 return false;
196 }
197
198 this->trackCommandBufferResource(std::move(src));
199 this->trackCommandBufferResource(std::move(dst));
200
201 SkDEBUGCODE(fHasWork = true;)
202
203 return true;
204}
205
208
209 bool didResultInWork = false;
210 if (!this->onSynchronizeBufferToCpu(buffer.get(), &didResultInWork)) {
211 return false;
212 }
213
214 if (didResultInWork) {
215 this->trackResource(std::move(buffer));
216 SkDEBUGCODE(fHasWork = true;)
217 }
218
219 return true;
220}
221
222bool CommandBuffer::clearBuffer(const Buffer* buffer, size_t offset, size_t size) {
224
225 if (!this->onClearBuffer(buffer, offset, size)) {
226 return false;
227 }
228
229 SkDEBUGCODE(fHasWork = true;)
230
231 return true;
232}
233
234} // namespace skgpu::graphite
int count
Definition: FontMgrTest.cpp:50
#define SKGPU_LOG_E(fmt,...)
Definition: Log.h:38
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkString resource(SkPDFResourceType type, int index)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
T * get() const
Definition: SkRefCnt.h:303
virtual bool onClearBuffer(const Buffer *, size_t offset, size_t size)=0
virtual bool onAddComputePass(DispatchGroupSpan dispatchGroups)=0
virtual bool onSynchronizeBufferToCpu(const Buffer *, bool *outDidResultInWork)=0
bool clearBuffer(const Buffer *buffer, size_t offset, size_t size)
bool addRenderPass(const RenderPassDesc &, sk_sp< Texture > colorTexture, sk_sp< Texture > resolveTexture, sk_sp< Texture > depthStencilTexture, SkRect viewport, const DrawPassList &drawPasses)
bool copyBufferToTexture(const Buffer *, sk_sp< Texture >, const BufferTextureCopyData *, int count)
void addBuffersToAsyncMapOnSubmit(SkSpan< const sk_sp< Buffer > >)
bool addComputePass(DispatchGroupSpan dispatchGroups)
virtual bool onCopyTextureToBuffer(const Texture *, SkIRect srcRect, const Buffer *, size_t bufferOffset, size_t bufferRowBytes)=0
SkSpan< const sk_sp< Buffer > > buffersToAsyncMapOnSubmit() const
virtual bool onAddRenderPass(const RenderPassDesc &, const Texture *colorTexture, const Texture *resolveTexture, const Texture *depthStencilTexture, SkRect viewport, const DrawPassList &drawPasses)=0
virtual bool onCopyBufferToBuffer(const Buffer *srcBuffer, size_t srcOffset, const Buffer *dstBuffer, size_t dstOffset, size_t size)=0
bool copyTextureToTexture(sk_sp< Texture > src, SkIRect srcRect, sk_sp< Texture > dst, SkIPoint dstPoint, int mipLevel)
virtual void onResetCommandBuffer()=0
bool copyTextureToBuffer(sk_sp< Texture >, SkIRect srcRect, sk_sp< Buffer >, size_t bufferOffset, size_t bufferRowBytes)
void trackResource(sk_sp< Resource > resource)
virtual bool onCopyTextureToTexture(const Texture *src, SkIRect srcRect, const Texture *dst, SkIPoint dstPoint, int mipLevel)=0
void addFinishedProc(sk_sp< RefCntedCallback > finishedProc)
bool synchronizeBufferToCpu(sk_sp< Buffer >)
virtual bool onCopyBufferToTexture(const Buffer *, const Texture *, const BufferTextureCopyData *, int count)=0
void callFinishedProcs(bool success)
bool copyBufferToBuffer(const Buffer *srcBuffer, size_t srcOffset, sk_sp< Buffer > dstBuffer, size_t dstOffset, size_t size)
void trackCommandBufferResource(sk_sp< Resource > resource)
FlTexture * texture
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
dst
Definition: cp.py:12
SeparatedVector2 offset
Definition: SkRect.h:32
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131