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