5#include "flutter/lib/ui/painting/immutable_buffer.h"
9#include "flutter/fml/file.h"
10#include "flutter/fml/make_copyable.h"
11#include "flutter/lib/ui/ui_dart_state.h"
12#include "flutter/lib/ui/window/platform_configuration.h"
35 tonic::Uint8List dataList = tonic::Uint8List(
data);
37 auto sk_data = MakeSkDataWithCopy(dataList.data(), dataList.num_elements());
39 auto buffer = fml::MakeRefCounted<ImmutableBuffer>(sk_data);
54 uint8_t* chars =
nullptr;
55 intptr_t asset_length = 0;
62 std::string asset_name = std::string{
reinterpret_cast<const char*
>(chars),
63 static_cast<size_t>(asset_length)};
66 auto ui_task_runner = dart_state->GetTaskRunners().GetUITaskRunner();
67 auto* buffer_callback_ptr =
69 auto* buffer_handle_ptr =
77 [buffer_callback_ptr, buffer_handle_ptr](
const sk_sp<SkData>& sk_data,
79 std::unique_ptr<tonic::DartPersistentValue> buffer_handle(
81 std::unique_ptr<tonic::DartPersistentValue> buffer_callback(
84 auto dart_state = buffer_callback->dart_state().lock();
95 auto buffer = fml::MakeRefCounted<ImmutableBuffer>(sk_data);
100 dart_state->GetConcurrentTaskRunner()->PostTask(
101 [asset_name = std::move(asset_name),
102 asset_manager = std::move(asset_manager),
103 ui_task_runner = std::move(ui_task_runner), ui_task] {
104 std::unique_ptr<fml::Mapping> mapping =
105 asset_manager->GetAsMapping(asset_name);
109 if (mapping !=
nullptr) {
111 const void* bytes =
static_cast<const void*
>(mapping->GetMapping());
114 ui_task_runner->PostTask(
115 [sk_data = std::move(sk_data), ui_task = ui_task,
buffer_size]() {
130 uint8_t* chars =
nullptr;
131 intptr_t file_path_length = 0;
138 std::string file_path = std::string{
reinterpret_cast<const char*
>(chars),
139 static_cast<size_t>(file_path_length)};
142 auto ui_task_runner = dart_state->GetTaskRunners().GetUITaskRunner();
143 auto* buffer_callback_ptr =
145 auto* buffer_handle_ptr =
149 [buffer_callback_ptr, buffer_handle_ptr](
const sk_sp<SkData>& sk_data,
151 std::unique_ptr<tonic::DartPersistentValue> buffer_handle(
153 std::unique_ptr<tonic::DartPersistentValue> buffer_callback(
154 buffer_callback_ptr);
155 auto dart_state = buffer_callback->dart_state().lock();
166 auto buffer = fml::MakeRefCounted<ImmutableBuffer>(sk_data);
171 dart_state->GetConcurrentTaskRunner()->PostTask(
172 [file_path = std::move(file_path),
173 ui_task_runner = std::move(ui_task_runner), ui_task] {
174 auto mapping = std::make_unique<fml::FileMapping>(
fml::OpenFile(
179 if (mapping->IsValid()) {
181 const void* bytes =
static_cast<const void*
>(mapping->GetMapping());
184 ui_task_runner->PostTask(
185 [sk_data = std::move(sk_data), ui_task = ui_task,
buffer_size]() {
205 size_t mapping_length =
length +
sizeof(size_t);
206 void* mapping = ::mmap(
nullptr, mapping_length, PROT_READ | PROT_WRITE,
207 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
209 if (mapping == MAP_FAILED) {
213 *
reinterpret_cast<size_t*
>(mapping) = mapping_length;
214 void* mapping_data =
reinterpret_cast<char*
>(mapping) +
sizeof(
size_t);
218 size_t* size_ptr =
reinterpret_cast<size_t*
>(context);
220 if (::munmap(
const_cast<void*
>(context), *size_ptr) == -1) {
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
void(* ReleaseProc)(const void *ptr, void *context)
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
static sk_sp< SkData > MakeEmpty()
sk_sp< SkData > data() const
Callers should not modify the returned data. This is not exposed to Dart.
static Dart_Handle initFromAsset(Dart_Handle buffer_handle, Dart_Handle asset_name_handle, Dart_Handle callback_handle)
static Dart_Handle init(Dart_Handle buffer_handle, Dart_Handle data, Dart_Handle callback_handle)
size_t length() const
The length of the data in bytes.
static Dart_Handle initFromFile(Dart_Handle buffer_handle, Dart_Handle file_path_handle, Dart_Handle callback_handle)
~ImmutableBuffer() override
PlatformConfiguration * platform_configuration() const
static UIDartState * Current()
static void ThrowIfUIOperationsProhibited()
void AssociateWithDartWrapper(Dart_Handle wrappable)
DART_EXPORT Dart_Handle Dart_TypeVoid(void)
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, uint8_t **utf8_array, intptr_t *length)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT bool Dart_IsClosure(Dart_Handle object)
#define FML_LOG(severity)
#define FML_DCHECK(condition)
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, FlutterGpuTestClass)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
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
internal::CopyableLambda< T > MakeCopyable(T lambda)
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)