10 #include "flutter/fml/logging.h"
34 const auto reserved = npot ? ReserveNPOT(length) : Reserve(length);
58 bool Allocation::ReserveNPOT(
size_t reserved) {
60 reserved = std::max<size_t>(4096u, reserved);
64 bool Allocation::Reserve(
size_t reserved) {
65 if (reserved <= reserved_) {
69 auto new_allocation = ::realloc(buffer_, reserved);
70 if (!new_allocation) {
78 buffer_ =
static_cast<uint8_t*
>(new_allocation);
86 if (contents ==
nullptr) {
90 auto allocation = std::make_shared<Allocation>();
91 if (!allocation->Truncate(length)) {
95 std::memmove(allocation->GetBuffer(), contents, length);
101 const std::shared_ptr<Allocation>& allocation) {
105 return std::make_shared<fml::NonOwnedMapping>(
106 reinterpret_cast<const uint8_t*
>(allocation->GetBuffer()),
107 allocation->GetLength(),
108 [allocation](
auto,
auto) {}
113 auto buffer = std::make_shared<std::string>(std::move(
string));
114 return std::make_unique<fml::NonOwnedMapping>(
115 reinterpret_cast<const uint8_t*
>(buffer->c_str()), buffer->length(),
116 [buffer](
auto,
auto) {});