Flutter Engine
The Flutter Engine
MtlBuffer.mm
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
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
12
13namespace skgpu::graphite {
14
16 size_t size,
18 AccessPattern accessPattern) {
19 if (size <= 0) {
20 return nullptr;
21 }
22
23 NSUInteger options = 0;
24 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
25 if (accessPattern == AccessPattern::kHostVisible) {
26#ifdef SK_BUILD_FOR_MAC
27 const MtlCaps& mtlCaps = sharedContext->mtlCaps();
28 if (mtlCaps.isMac()) {
29 options |= MTLResourceStorageModeManaged;
30 } else {
31 SkASSERT(mtlCaps.isApple());
32 options |= MTLResourceStorageModeShared;
33 }
34#else
35 options |= MTLResourceStorageModeShared;
36#endif
37 } else {
38 options |= MTLResourceStorageModePrivate;
39 }
40 }
41
42 sk_cfp<id<MTLBuffer>> buffer([sharedContext->device() newBufferWithLength:size
44
45 return sk_sp<Buffer>(new MtlBuffer(sharedContext, size, std::move(buffer)));
46}
47
48MtlBuffer::MtlBuffer(const MtlSharedContext* sharedContext,
49 size_t size,
50 sk_cfp<id<MTLBuffer>> buffer)
51 : Buffer(sharedContext, size), fBuffer(std::move(buffer)) {}
52
53void MtlBuffer::onMap() {
54 SkASSERT(fBuffer);
55 SkASSERT(!this->isMapped());
56
57 if ((*fBuffer).storageMode == MTLStorageModePrivate) {
58 return;
59 }
60
61 fMapPtr = static_cast<char*>((*fBuffer).contents);
62}
63
64void MtlBuffer::onUnmap() {
65 SkASSERT(fBuffer);
66 SkASSERT(this->isMapped());
67#ifdef SK_BUILD_FOR_MAC
68 if ((*fBuffer).storageMode == MTLStorageModeManaged) {
69 [*fBuffer didModifyRange: NSMakeRange(0, this->size())];
70 }
71#endif
72 fMapPtr = nullptr;
73}
74
75void MtlBuffer::freeGpuData() {
76 fBuffer.reset();
77}
78
79void MtlBuffer::setBackendLabel(char const* label) {
80 SkASSERT(label);
81#ifdef SK_ENABLE_MTL_DEBUG_INFO
82 NSString* labelStr = @(label);
83 this->mtlBuffer().label = labelStr;
84#endif
85}
86
87} // namespace skgpu::graphite
const char * options
#define SkASSERT(cond)
Definition: SkAssert.h:116
GLenum type
size_t size() const
Definition: Buffer.h:19
bool isMapped() const
Definition: Buffer.h:30
id< MTLBuffer > mtlBuffer() const
Definition: MtlBuffer.h:24
static sk_sp< Buffer > Make(const MtlSharedContext *, size_t size, BufferType type, AccessPattern)
Definition: MtlBuffer.mm:15
bool isApple() const
Definition: MtlCaps.h:60
bool isMac() const
Definition: MtlCaps.h:59
const SharedContext * sharedContext() const
Definition: Resource.h:189
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