5#include "flutter/lib/ui/ui_dart_state.h"
10#include "flutter/fml/message_loop.h"
11#include "flutter/lib/ui/window/platform_configuration.h"
12#include "flutter/lib/ui/window/platform_message.h"
16#if defined(FML_OS_ANDROID)
17#include <android/log.h>
18#elif defined(FML_OS_IOS)
21extern void syslog(
int,
const char*, ...);
30 : task_runners(task_runners) {}
39 std::string advisory_script_uri,
40 std::string advisory_script_entrypoint,
41 std::shared_ptr<VolatilePathTracker> volatile_path_tracker,
42 std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
45 : task_runners(task_runners),
46 snapshot_delegate(
std::move(snapshot_delegate)),
47 io_manager(
std::move(io_manager)),
48 unref_queue(
std::move(unref_queue)),
49 image_decoder(
std::move(image_decoder)),
50 image_generator_registry(
std::move(image_generator_registry)),
51 advisory_script_uri(
std::move(advisory_script_uri)),
52 advisory_script_entrypoint(
std::move(advisory_script_entrypoint)),
53 volatile_path_tracker(
std::move(volatile_path_tracker)),
54 concurrent_task_runner(
std::move(concurrent_task_runner)),
55 enable_impeller(enable_impeller),
56 runtime_stage_backend(runtime_stage_backend) {}
64 std::shared_ptr<IsolateNameServer> isolate_name_server,
67 : add_callback_(
std::move(add_callback)),
68 remove_callback_(
std::move(remove_callback)),
70 is_root_isolate_(is_root_isolate),
72 log_message_callback_(
std::move(log_message_callback)),
73 isolate_name_server_(
std::move(isolate_name_server)),
75 AddOrRemoveTaskObserver(
true );
79 AddOrRemoveTaskObserver(
false );
94void UIDartState::DidSetIsolate() {
107 tonic::ToDart(
"UI actions are only available on root isolate."));
113 if (platform_configuration_) {
114 platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
120 return static_cast<UIDartState*
>(DartState::Current());
124 std::unique_ptr<PlatformConfiguration> platform_configuration) {
127 if (platform_configuration_) {
128 platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
134 std::weak_ptr<PlatformMessageHandler> handler) {
136 platform_message_handler_ = std::move(handler);
156std::shared_ptr<fml::ConcurrentTaskRunner>
173void UIDartState::AddOrRemoveTaskObserver(
bool add) {
180 FML_DCHECK(add_callback_ && remove_callback_);
182 add_callback_(
reinterpret_cast<intptr_t
>(
this),
185 remove_callback_(
reinterpret_cast<intptr_t
>(
this));
204 return isolate_name_server_;
216 const std::string&
message)
const {
217 if (log_message_callback_) {
218 log_message_callback_(tag,
message);
221#if defined(FML_OS_ANDROID)
222 __android_log_print(ANDROID_LOG_INFO, tag.c_str(),
"%.*s",
224#elif defined(FML_OS_IOS)
231 syslog(1 ,
"%.*s",
static_cast<int>(
log.size()),
235 std::cout << tag <<
": ";
237 std::cout <<
message << std::endl;
243 std::unique_ptr<PlatformMessage>
message) {
244 if (platform_configuration_) {
245 platform_configuration_->client()->HandlePlatformMessage(
248 std::shared_ptr<PlatformMessageHandler> handler =
249 platform_message_handler_.lock();
251 handler->HandlePlatformMessage(std::move(
message));
254 "No platform channel handler registered for background isolate.");
262 return IsRootIsolate() ?
reinterpret_cast<int64_t
>(
this) : 0;
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
fml::RefPtr< flutter::SkiaUnrefQueue > GetSkiaUnrefQueue() const
std::shared_ptr< fml::ConcurrentTaskRunner > GetConcurrentTaskRunner() const
PlatformConfiguration * platform_configuration() const
fml::WeakPtr< ImageDecoder > GetImageDecoder() const
UnhandledExceptionCallback unhandled_exception_callback() const
bool IsRootIsolate() const
void FlushMicrotasksNow()
void SetPlatformConfiguration(std::unique_ptr< PlatformConfiguration > platform_configuration)
std::shared_ptr< VolatilePathTracker > GetVolatilePathTracker() const
const std::string & logger_prefix() const
tonic::DartErrorHandleType GetLastError()
fml::WeakPtr< IOManager > GetIOManager() const
const TaskRunners & GetTaskRunners() const
fml::WeakPtr< ImageGeneratorRegistry > GetImageGeneratorRegistry() const
virtual Dart_Isolate CreatePlatformIsolate(Dart_Handle entry_point, char **error)
bool IsImpellerEnabled() const
Whether Impeller is enabled for this application.
std::shared_ptr< IsolateNameServer > GetIsolateNameServer() const
void SetDebugName(const std::string &name)
int64_t GetRootIsolateToken() const
void ScheduleMicrotask(Dart_Handle handle)
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > GetSnapshotDelegate() const
const std::string & GetAdvisoryScriptURI() const
impeller::RuntimeStageBackend GetRuntimeStageBackend() const
The expected type for runtime stage shaders.
void LogMessage(const std::string &tag, const std::string &message) const
void SetPlatformMessageHandler(std::weak_ptr< PlatformMessageHandler > handler)
static UIDartState * Current()
static void ThrowIfUIOperationsProhibited()
Dart_Handle HandlePlatformMessage(std::unique_ptr< PlatformMessage > message)
UIDartState(TaskObserverAdd add_callback, TaskObserverRemove remove_callback, std::string logger_prefix, UnhandledExceptionCallback unhandled_exception_callback, LogMessageCallback log_message_callback, std::shared_ptr< IsolateNameServer > isolate_name_server, bool is_root_isolate_, const UIDartState::Context &context)
const std::string & debug_name() const
DartErrorHandleType isolate_last_error() const
void ScheduleMicrotask(Dart_Handle callback)
DartErrorHandleType GetLastError()
DartMessageHandler & message_handler()
DART_EXPORT void Dart_EnterScope(void)
struct _Dart_Handle * Dart_Handle
struct _Dart_Isolate * Dart_Isolate
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT Dart_Port Dart_GetMainPortId(void)
DART_EXPORT bool Dart_IsClosure(Dart_Handle object)
const uint8_t uint32_t uint32_t GError ** error
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
std::function< void(intptr_t)> TaskObserverRemove
std::function< void(intptr_t, fml::closure)> TaskObserverAdd
std::function< bool(const std::string &, const std::string &)> UnhandledExceptionCallback
std::function< void(const std::string &, const std::string &)> LogMessageCallback
std::function< void()> closure
Dart_Handle ToDart(const T &object)
bool CheckAndHandleError(Dart_Handle handle)
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
fml::RefPtr< SkiaUnrefQueue > unref_queue
fml::WeakPtr< ImageGeneratorRegistry > image_generator_registry
fml::WeakPtr< IOManager > io_manager
The IO manager used by the isolate for asynchronous texture uploads.
std::string advisory_script_uri
Context(const TaskRunners &task_runners)
const TaskRunners task_runners
std::shared_ptr< VolatilePathTracker > volatile_path_tracker
Cache for tracking path volatility.
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate
bool enable_impeller
Whether Impeller is enabled or not.
impeller::RuntimeStageBackend runtime_stage_backend
The expected backend for runtime stage shaders.
fml::WeakPtr< ImageDecoder > image_decoder
The image decoder.
std::shared_ptr< fml::ConcurrentTaskRunner > concurrent_task_runner
std::string advisory_script_entrypoint