| Flutter macOS Embedder |

buffer_conversions.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
5 #import "flutter/shell/platform/darwin/common/buffer_conversions.h"
6
7 #include "flutter/fml/macros.h"
8
9 static_assert(__has_feature(objc_arc), "ARC must be enabled.");
10
11 namespace flutter {
12 namespace {
13 class NSDataMapping : public fml::Mapping {
14 public:
15 explicit NSDataMapping(NSData* data) : data_(data) {}
16
17 size_t GetSize() const override { return data_.length; }
18
19 const uint8_t* GetMapping() const override { return static_cast<const uint8_t*>(data_.bytes); }
20
21 bool IsDontNeedSafe() const override { return false; }
22
23 private:
24 NSData* data_;
25 FML_DISALLOW_COPY_AND_ASSIGN(NSDataMapping);
26 };
27 } // namespace
28
29 fml::MallocMapping CopyNSDataToMapping(NSData* data) {
30 const uint8_t* bytes = static_cast<const uint8_t*>(data.bytes);
31 return fml::MallocMapping::Copy(bytes, data.length);
32 }
33
34 NSData* ConvertMappingToNSData(fml::MallocMapping buffer) {
35 size_t size = buffer.GetSize();
36 return [NSData dataWithBytesNoCopy:buffer.Release() length:size];
37 }
38
39 std::unique_ptr<fml::Mapping> ConvertNSDataToMappingPtr(NSData* data) {
40 return std::make_unique<NSDataMapping>(data);
41 }
42
43 NSData* CopyMappingPtrToNSData(std::unique_ptr<fml::Mapping> mapping) {
44 return [NSData dataWithBytes:mapping->GetMapping() length:mapping->GetSize()];
45 }
46
47 } // namespace flutter
buffer_conversions.h
flutter
Definition: AccessibilityBridgeMac.h:16
flutter::CopyMappingPtrToNSData
NSData * CopyMappingPtrToNSData(std::unique_ptr< fml::Mapping > mapping)
Definition: buffer_conversions.mm:43
flutter::CopyNSDataToMapping
fml::MallocMapping CopyNSDataToMapping(NSData *data)
Definition: buffer_conversions.mm:29
flutter::ConvertNSDataToMappingPtr
std::unique_ptr< fml::Mapping > ConvertNSDataToMappingPtr(NSData *data)
Definition: buffer_conversions.mm:39
flutter::ConvertMappingToNSData
NSData * ConvertMappingToNSData(fml::MallocMapping buffer)
Definition: buffer_conversions.mm:34