Flutter Engine
flutter::UIDartState Class Reference

#include <ui_dart_state.h>

Inheritance diagram for flutter::UIDartState:
tonic::DartState flutter::DartIsolate

Public Member Functions

Dart_Port main_port () const
 
bool IsRootIsolate () const
 
void SetDebugName (const std::string name)
 
const std::string & debug_name () const
 
const std::string & logger_prefix () const
 
PlatformConfigurationplatform_configuration () const
 
const TaskRunnersGetTaskRunners () const
 
void ScheduleMicrotask (Dart_Handle handle)
 
void FlushMicrotasksNow ()
 
fml::WeakPtr< IOManagerGetIOManager () const
 
fml::RefPtr< flutter::SkiaUnrefQueueGetSkiaUnrefQueue () const
 
fml::WeakPtr< SnapshotDelegateGetSnapshotDelegate () const
 
fml::WeakPtr< HintFreedDelegateGetHintFreedDelegate () const
 
fml::WeakPtr< GrDirectContext > GetResourceContext () const
 
fml::WeakPtr< ImageDecoderGetImageDecoder () const
 
std::shared_ptr< IsolateNameServerGetIsolateNameServer () const
 
tonic::DartErrorHandleType GetLastError ()
 
void ReportUnhandledException (const std::string &error, const std::string &stack_trace)
 
- Public Member Functions inherited from tonic::DartState
 DartState (int dirfd=-1, std::function< void(Dart_Handle)> message_epilogue=nullptr)
 
virtual ~DartState ()
 
std::weak_ptr< DartStateGetWeakPtr ()
 
Dart_Isolate isolate ()
 
void SetIsolate (Dart_Isolate isolate)
 
Dart_PersistentHandle private_constructor_name ()
 
DartClassLibraryclass_library ()
 
DartMessageHandlermessage_handler ()
 
FileLoaderfile_loader ()
 
void MessageEpilogue (Dart_Handle message_result)
 
void SetReturnCode (uint32_t return_code)
 
void SetReturnCodeCallback (std::function< void(uint32_t)> callback)
 
bool has_set_return_code () const
 

Static Public Member Functions

static UIDartStateCurrent ()
 
static void ThrowIfUIOperationsProhibited ()
 
template<class T >
static flutter::SkiaGPUObject< T > CreateGPUObject (sk_sp< T > object)
 
- Static Public Member Functions inherited from tonic::DartState
static DartStateFrom (Dart_Isolate isolate)
 
static DartStateCurrent ()
 
static Dart_Handle HandleLibraryTag (Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
 

Protected Member Functions

 UIDartState (TaskRunners task_runners, TaskObserverAdd add_callback, TaskObserverRemove remove_callback, fml::WeakPtr< SnapshotDelegate > snapshot_delegate, fml::WeakPtr< HintFreedDelegate > hint_freed_delegate, fml::WeakPtr< IOManager > io_manager, fml::RefPtr< SkiaUnrefQueue > skia_unref_queue, fml::WeakPtr< ImageDecoder > image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, std::string logger_prefix, UnhandledExceptionCallback unhandled_exception_callback, std::shared_ptr< IsolateNameServer > isolate_name_server, bool is_root_isolate_)
 
 ~UIDartState () override
 
void SetPlatformConfiguration (std::unique_ptr< PlatformConfiguration > platform_configuration)
 
const std::string & GetAdvisoryScriptURI () const
 
const std::string & GetAdvisoryScriptEntrypoint () const
 
- Protected Member Functions inherited from tonic::DartState
 TONIC_DISALLOW_COPY_AND_ASSIGN (DartState)
 

Detailed Description

Definition at line 33 of file ui_dart_state.h.

Constructor & Destructor Documentation

◆ UIDartState()

flutter::UIDartState::UIDartState ( TaskRunners  task_runners,
TaskObserverAdd  add_callback,
TaskObserverRemove  remove_callback,
fml::WeakPtr< SnapshotDelegate snapshot_delegate,
fml::WeakPtr< HintFreedDelegate hint_freed_delegate,
fml::WeakPtr< IOManager io_manager,
fml::RefPtr< SkiaUnrefQueue skia_unref_queue,
fml::WeakPtr< ImageDecoder image_decoder,
std::string  advisory_script_uri,
std::string  advisory_script_entrypoint,
std::string  logger_prefix,
UnhandledExceptionCallback  unhandled_exception_callback,
std::shared_ptr< IsolateNameServer isolate_name_server,
bool  is_root_isolate_ 
)
protected

Definition at line 16 of file ui_dart_state.cc.

Referenced by CreateGPUObject(), and flutter::DartIsolate::CreateRunningRootIsolate().

31  : task_runners_(std::move(task_runners)),
32  add_callback_(std::move(add_callback)),
33  remove_callback_(std::move(remove_callback)),
34  snapshot_delegate_(std::move(snapshot_delegate)),
35  hint_freed_delegate_(std::move(hint_freed_delegate)),
36  io_manager_(std::move(io_manager)),
37  skia_unref_queue_(std::move(skia_unref_queue)),
38  image_decoder_(std::move(image_decoder)),
39  advisory_script_uri_(std::move(advisory_script_uri)),
40  advisory_script_entrypoint_(std::move(advisory_script_entrypoint)),
41  logger_prefix_(std::move(logger_prefix)),
42  is_root_isolate_(is_root_isolate),
43  unhandled_exception_callback_(unhandled_exception_callback),
44  isolate_name_server_(std::move(isolate_name_server)) {
45  AddOrRemoveTaskObserver(true /* add */);
46 }
const std::string & logger_prefix() const
Definition: ui_dart_state.h:46

◆ ~UIDartState()

flutter::UIDartState::~UIDartState ( )
overrideprotected

Definition at line 48 of file ui_dart_state.cc.

Referenced by CreateGPUObject().

48  {
49  AddOrRemoveTaskObserver(false /* remove */);
50 }

Member Function Documentation

◆ CreateGPUObject()

template<class T >
static flutter::SkiaGPUObject<T> flutter::UIDartState::CreateGPUObject ( sk_sp< T >  object)
inlinestatic

Definition at line 78 of file ui_dart_state.h.

References Current(), FML_DCHECK, GetAdvisoryScriptEntrypoint(), GetAdvisoryScriptURI(), logger_prefix(), platform_configuration(), SetPlatformConfiguration(), UIDartState(), and ~UIDartState().

Referenced by flutter::SceneBuilder::addPicture(), flutter::PictureRecorder::endRecording(), flutter::CanvasGradient::initLinear(), flutter::CanvasGradient::initRadial(), flutter::CanvasGradient::initSweep(), flutter::CanvasGradient::initTwoPointConical(), and flutter::ImageShader::initWithImage().

78  {
79  if (!object) {
80  return {};
81  }
82  auto* state = UIDartState::Current();
83  FML_DCHECK(state);
84  auto queue = state->GetSkiaUnrefQueue();
85  return {std::move(object), std::move(queue)};
86  };
#define FML_DCHECK(condition)
Definition: logging.h:86
static UIDartState * Current()

◆ Current()

UIDartState * flutter::UIDartState::Current ( )
static

Definition at line 84 of file ui_dart_state.cc.

Referenced by flutter::PlatformConfiguration::BeginFrame(), flutter::ComputePlatformResolvedLocale(), flutter::Scene::create(), CreateGPUObject(), flutter::decodeStrut(), flutter::CanvasImage::dispose(), flutter::Canvas::drawShadow(), flutter::EncodeImage(), flutter::MultiFrameCodec::getNextFrame(), flutter::SingleFrameCodec::getNextFrame(), flutter::Logger_PrintString(), flutter::IsolateNameServerNatives::LookupPortByName(), flutter::Picture::RasterizeToImage(), flutter::IsolateNameServerNatives::RegisterPortWithName(), flutter::IsolateNameServerNatives::RemovePortNameMapping(), flutter::ScheduleMicrotask(), flutter::testing::TEST_F(), and ThrowIfUIOperationsProhibited().

84  {
85  return static_cast<UIDartState*>(DartState::Current());
86 }
UIDartState(TaskRunners task_runners, TaskObserverAdd add_callback, TaskObserverRemove remove_callback, fml::WeakPtr< SnapshotDelegate > snapshot_delegate, fml::WeakPtr< HintFreedDelegate > hint_freed_delegate, fml::WeakPtr< IOManager > io_manager, fml::RefPtr< SkiaUnrefQueue > skia_unref_queue, fml::WeakPtr< ImageDecoder > image_decoder, std::string advisory_script_uri, std::string advisory_script_entrypoint, std::string logger_prefix, UnhandledExceptionCallback unhandled_exception_callback, std::shared_ptr< IsolateNameServer > isolate_name_server, bool is_root_isolate_)

◆ debug_name()

const std::string& flutter::UIDartState::debug_name ( ) const
inline

Definition at line 44 of file ui_dart_state.h.

Referenced by GetAdvisoryScriptEntrypoint(), and SetDebugName().

44 { return debug_name_; }

◆ FlushMicrotasksNow()

void flutter::UIDartState::FlushMicrotasksNow ( )

◆ GetAdvisoryScriptEntrypoint()

const std::string & flutter::UIDartState::GetAdvisoryScriptEntrypoint ( ) const
protected

Definition at line 56 of file ui_dart_state.cc.

References debug_name(), and SetDebugName().

Referenced by CreateGPUObject().

56  {
57  return advisory_script_entrypoint_;
58 }

◆ GetAdvisoryScriptURI()

const std::string & flutter::UIDartState::GetAdvisoryScriptURI ( ) const
protected

Definition at line 52 of file ui_dart_state.cc.

Referenced by CreateGPUObject(), and flutter::DartIsolate::GetMessageHandlingTaskRunner().

52  {
53  return advisory_script_uri_;
54 }

◆ GetHintFreedDelegate()

fml::WeakPtr< HintFreedDelegate > flutter::UIDartState::GetHintFreedDelegate ( ) const

Definition at line 141 of file ui_dart_state.cc.

Referenced by flutter::CanvasImage::dispose(), and platform_configuration().

141  {
142  return hint_freed_delegate_;
143 }

◆ GetImageDecoder()

fml::WeakPtr< ImageDecoder > flutter::UIDartState::GetImageDecoder ( ) const

Definition at line 152 of file ui_dart_state.cc.

Referenced by platform_configuration().

152  {
153  return image_decoder_;
154 }

◆ GetIOManager()

fml::WeakPtr< IOManager > flutter::UIDartState::GetIOManager ( ) const

Definition at line 101 of file ui_dart_state.cc.

Referenced by flutter::EncodeImage(), and platform_configuration().

101  {
102  return io_manager_;
103 }

◆ GetIsolateNameServer()

std::shared_ptr< IsolateNameServer > flutter::UIDartState::GetIsolateNameServer ( ) const

◆ GetLastError()

tonic::DartErrorHandleType flutter::UIDartState::GetLastError ( )

Definition at line 160 of file ui_dart_state.cc.

References error, tonic::DartMicrotaskQueue::GetLastError(), tonic::DartMessageHandler::isolate_last_error(), tonic::kNoError, and tonic::DartState::message_handler().

Referenced by platform_configuration().

160  {
162  if (error == tonic::kNoError) {
163  error = microtask_queue_.GetLastError();
164  }
165  return error;
166 }
FlMethodResponse GError ** error
DartErrorHandleType isolate_last_error() const
DartErrorHandleType
Definition: dart_error.h:18
DartMessageHandler & message_handler()
Definition: dart_state.h:59
DartErrorHandleType GetLastError()

◆ GetResourceContext()

fml::WeakPtr< GrDirectContext > flutter::UIDartState::GetResourceContext ( ) const

Definition at line 145 of file ui_dart_state.cc.

Referenced by platform_configuration().

145  {
146  if (!io_manager_) {
147  return {};
148  }
149  return io_manager_->GetResourceContext();
150 }

◆ GetSkiaUnrefQueue()

fml::RefPtr< flutter::SkiaUnrefQueue > flutter::UIDartState::GetSkiaUnrefQueue ( ) const

Definition at line 105 of file ui_dart_state.cc.

Referenced by platform_configuration().

105  {
106  return skia_unref_queue_;
107 }

◆ GetSnapshotDelegate()

fml::WeakPtr< SnapshotDelegate > flutter::UIDartState::GetSnapshotDelegate ( ) const

Definition at line 137 of file ui_dart_state.cc.

Referenced by flutter::EncodeImage(), and platform_configuration().

137  {
138  return snapshot_delegate_;
139 }

◆ GetTaskRunners()

const TaskRunners & flutter::UIDartState::GetTaskRunners ( ) const

◆ IsRootIsolate()

bool flutter::UIDartState::IsRootIsolate ( ) const
inline

◆ logger_prefix()

const std::string& flutter::UIDartState::logger_prefix ( ) const
inline

Definition at line 46 of file ui_dart_state.h.

Referenced by CreateGPUObject(), and flutter::Logger_PrintString().

46 { return logger_prefix_; }

◆ main_port()

Dart_Port flutter::UIDartState::main_port ( ) const
inline

Definition at line 37 of file ui_dart_state.h.

37 { return main_port_; }

◆ platform_configuration()

◆ ReportUnhandledException()

void flutter::UIDartState::ReportUnhandledException ( const std::string &  error,
const std::string &  stack_trace 
)

Definition at line 168 of file ui_dart_state.cc.

References FML_LOG.

Referenced by platform_configuration().

169  {
170  if (unhandled_exception_callback_ &&
171  unhandled_exception_callback_(error, stack_trace)) {
172  return;
173  }
174 
175  // Either the exception handler was not set or it could not handle the error,
176  // just log the exception.
177  FML_LOG(ERROR) << "Unhandled Exception: " << error << std::endl
178  << stack_trace;
179 }
FlMethodResponse GError ** error
#define FML_LOG(severity)
Definition: logging.h:65

◆ ScheduleMicrotask()

void flutter::UIDartState::ScheduleMicrotask ( Dart_Handle  handle)

Definition at line 109 of file ui_dart_state.cc.

References tonic::LogIfError(), and tonic::DartMicrotaskQueue::ScheduleMicrotask().

Referenced by platform_configuration(), and flutter::ScheduleMicrotask().

109  {
110  if (tonic::LogIfError(closure) || !Dart_IsClosure(closure)) {
111  return;
112  }
113 
114  microtask_queue_.ScheduleMicrotask(closure);
115 }
void ScheduleMicrotask(Dart_Handle callback)
std::function< void()> closure
Definition: closure.h:14
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ SetDebugName()

void flutter::UIDartState::SetDebugName ( const std::string  name)

Definition at line 76 of file ui_dart_state.cc.

References debug_name().

Referenced by GetAdvisoryScriptEntrypoint(), and IsRootIsolate().

76  {
77  debug_name_ = debug_name;
78  if (platform_configuration_) {
79  platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
80  main_port_);
81  }
82 }
const std::string & debug_name() const
Definition: ui_dart_state.h:44

◆ SetPlatformConfiguration()

void flutter::UIDartState::SetPlatformConfiguration ( std::unique_ptr< PlatformConfiguration platform_configuration)
protected

Definition at line 88 of file ui_dart_state.cc.

Referenced by CreateGPUObject().

89  {
90  platform_configuration_ = std::move(platform_configuration);
91  if (platform_configuration_) {
92  platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
93  main_port_);
94  }
95 }
PlatformConfiguration * platform_configuration() const
Definition: ui_dart_state.h:48

◆ ThrowIfUIOperationsProhibited()


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