Flutter Engine
 
Loading...
Searching...
No Matches
fml::MallocMapping Class Referencefinal

A Mapping like NonOwnedMapping, but uses Free as its release proc. More...

#include <mapping.h>

Inheritance diagram for fml::MallocMapping:
fml::Mapping

Public Member Functions

 MallocMapping ()
 
 MallocMapping (uint8_t *data, size_t size)
 
 MallocMapping (fml::MallocMapping &&mapping)
 
 ~MallocMapping () override
 
size_t GetSize () const override
 
const uint8_t * GetMapping () const override
 
bool IsDontNeedSafe () const override
 
uint8_t * Release ()
 
- Public Member Functions inherited from fml::Mapping
 Mapping ()
 
virtual ~Mapping ()
 

Static Public Member Functions

template<typename T >
static MallocMapping Copy (const T *begin, const T *end)
 
static MallocMapping Copy (const void *begin, size_t length)
 

Detailed Description

A Mapping like NonOwnedMapping, but uses Free as its release proc.

Definition at line 144 of file mapping.h.

Constructor & Destructor Documentation

◆ MallocMapping() [1/3]

fml::MallocMapping::MallocMapping ( )

Definition at line 119 of file mapping.cc.

119: data_(nullptr), size_(0) {}

Referenced by Copy().

◆ MallocMapping() [2/3]

fml::MallocMapping::MallocMapping ( uint8_t *  data,
size_t  size 
)

Creates a MallocMapping for a region of memory (without copying it). The function will abort() if the malloc fails.

Parameters
dataThe starting address of the mapping.
sizeThe size of the mapping in bytes.

Definition at line 121 of file mapping.cc.

122 : data_(data), size_(size) {}
std::shared_ptr< const fml::Mapping > data

◆ MallocMapping() [3/3]

fml::MallocMapping::MallocMapping ( fml::MallocMapping &&  mapping)

Definition at line 124 of file mapping.cc.

125 : data_(mapping.data_), size_(mapping.size_) {
126 mapping.data_ = nullptr;
127 mapping.size_ = 0;
128}

◆ ~MallocMapping()

fml::MallocMapping::~MallocMapping ( )
override

Definition at line 130 of file mapping.cc.

130 {
131 free(data_);
132 data_ = nullptr;
133}

Member Function Documentation

◆ Copy() [1/2]

template<typename T >
static MallocMapping fml::MallocMapping::Copy ( const T *  begin,
const T *  end 
)
inlinestatic

Copies the data from begin to end. It's templated since void* arithemetic isn't allowed and we want support for uint8_t and char.

Definition at line 162 of file mapping.h.

162 {
163 FML_DCHECK(end >= begin);
164 size_t length = end - begin;
165 return Copy(begin, length);
166 }
static MallocMapping Copy(const T *begin, const T *end)
Definition mapping.h:162
#define FML_DCHECK(condition)
Definition logging.h:122
size_t length
const size_t end

References Copy(), end, FML_DCHECK, and length.

Referenced by Copy(), flutter::CopyNSDataToMapping(), flutter_runner::TextDelegate::DidUpdateState(), DispatchJSONPlatformMessage(), flutter::PlatformViewAndroid::DispatchPlatformMessage(), flutter::PlatformViewAndroid::DispatchSemanticsAction(), FlutterEngineSendPlatformMessage(), FlutterEngineSendSemanticsAction(), if(), flutter::InvokePlatformMessageResponseCallback(), impeller::interop::MakeCopyableMapping(), flutter_runner::MakeLocalizationPlatformMessageData(), flutter_runner::TextDelegate::OnAction(), flutter_runner::PlatformView::OnChildViewStatus(), flutter_runner::TextDelegate::OnKeyEvent(), flutter::RunTester(), fml::TEST(), fml::TEST(), flutter::testing::TEST_F(), flutter_runner::testing::TEST_F(), flutter_runner::testing::TEST_F(), flutter_runner::testing::TEST_F(), flutter_runner::testing::TEST_F(), flutter_runner::testing::TEST_F(), and flutter_runner::testing::FakePlatformMessageResponse::WithMessage().

◆ Copy() [2/2]

MallocMapping fml::MallocMapping::Copy ( const void *  begin,
size_t  length 
)
static

Copies a region of memory into a MallocMapping. The function will abort() if the malloc fails.

Parameters
beginThe starting address of where we will copy.
lengthThe length of the region to copy in bytes.

Definition at line 135 of file mapping.cc.

135 {
136 auto result =
137 MallocMapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
138 FML_CHECK(result.GetMapping() != nullptr);
139 memcpy(const_cast<uint8_t*>(result.GetMapping()), begin, length);
140 return result;
141}
#define FML_CHECK(condition)
Definition logging.h:104

References FML_CHECK, length, and MallocMapping().

◆ GetMapping()

const uint8_t * fml::MallocMapping::GetMapping ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 147 of file mapping.cc.

147 {
148 return data_;
149}

Referenced by fml::TEST(), fml::TEST(), fml::TEST(), fml::TEST(), fml::TEST(), and fml::TEST().

◆ GetSize()

size_t fml::MallocMapping::GetSize ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 143 of file mapping.cc.

143 {
144 return size_;
145}

Referenced by fml::TEST(), fml::TEST(), fml::TEST(), fml::TEST(), fml::TEST(), and fml::TEST().

◆ IsDontNeedSafe()

bool fml::MallocMapping::IsDontNeedSafe ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 151 of file mapping.cc.

151 {
152 return false;
153}

Referenced by fml::TEST().

◆ Release()

uint8_t * fml::MallocMapping::Release ( )

Removes ownership of the data buffer. After this is called; the mapping will point to nullptr.

Definition at line 155 of file mapping.cc.

155 {
156 uint8_t* result = data_;
157 data_ = nullptr;
158 size_ = 0;
159 return result;
160}

Referenced by flutter::PlatformViewAndroidJNIImpl::FlutterViewHandlePlatformMessage(), and fml::TEST().


The documentation for this class was generated from the following files: