Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
device_buffer_mtl.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include "flutter/fml/logging.h"
11
12namespace impeller {
13
14DeviceBufferMTL::DeviceBufferMTL(DeviceBufferDescriptor desc,
15 id<MTLBuffer> buffer,
16 MTLStorageMode storage_mode)
17 : DeviceBuffer(desc), buffer_(buffer), storage_mode_(storage_mode) {}
18
19DeviceBufferMTL::~DeviceBufferMTL() = default;
20
21id<MTLBuffer> DeviceBufferMTL::GetMTLBuffer() const {
22 return buffer_;
23}
24
25uint8_t* DeviceBufferMTL::OnGetContents() const {
26 if (storage_mode_ != MTLStorageModeShared) {
27 return nullptr;
28 }
29 return reinterpret_cast<uint8_t*>(buffer_.contents);
30}
31
32[[nodiscard]] bool DeviceBufferMTL::OnCopyHostBuffer(const uint8_t* source,
33 Range source_range,
34 size_t offset) {
35 auto dest = static_cast<uint8_t*>(buffer_.contents);
36
37 if (!dest) {
38 return false;
39 }
40
41 if (source) {
42 ::memmove(dest + offset, source + source_range.offset, source_range.length);
43 }
44
45// MTLStorageModeManaged is never present on always returns false on iOS. But
46// the compiler is mad that `didModifyRange:` appears in a TU meant for iOS. So,
47// just compile it away.
48#if !FML_OS_IOS
49 if (storage_mode_ == MTLStorageModeManaged) {
50 [buffer_ didModifyRange:NSMakeRange(offset, source_range.length)];
51 }
52#endif
53
54 return true;
55}
56
57void DeviceBufferMTL::Flush(std::optional<Range> range) const {
58#if !FML_OS_IOS
59 auto flush_range = range.value_or(Range{0, GetDeviceBufferDescriptor().size});
60 if (storage_mode_ == MTLStorageModeManaged) {
61 [buffer_
62 didModifyRange:NSMakeRange(flush_range.offset, flush_range.length)];
63 }
64#endif
65}
66
67bool DeviceBufferMTL::SetLabel(const std::string& label) {
68 if (label.empty()) {
69 return false;
70 }
71 [buffer_ setLabel:@(label.c_str())];
72 return true;
73}
74
75bool DeviceBufferMTL::SetLabel(const std::string& label, Range range) {
76 if (label.empty()) {
77 return false;
78 }
79 [buffer_ addDebugMarker:@(label.c_str())
80 range:NSMakeRange(range.offset, range.length)];
81 return true;
82}
83
84} // namespace impeller
SkBitmap source
Definition: examples.cpp:28
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
void Flush(SkSurface *surface)
Definition: GpuTools.h:25
dest
Definition: zip.py:79
SeparatedVector2 offset