Flutter Engine
The Flutter Engine
platform_isolate.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <iostream>
6#include <thread>
7
8#include "flutter/fml/macros.h"
9#include "flutter/fml/task_runner.h"
10#include "flutter/lib/ui/ui_dart_state.h"
11#include "flutter/lib/ui/window/platform_isolate.h"
13
14namespace flutter {
15
17 UIDartState* current_state = UIDartState::Current();
18 FML_DCHECK(current_state != nullptr);
19 if (!current_state->IsRootIsolate()) {
20 // TODO(flutter/flutter#136314): Remove this restriction.
23 "PlatformIsolates can only be spawned on the root isolate."));
24 }
25
26 char* error = nullptr;
27 current_state->CreatePlatformIsolate(entry_point, &error);
28 if (error) {
30 Dart_Handle error_handle = tonic::ToDart<const char*>(error);
31 ::free(error);
32 Dart_ThrowException(error_handle);
33 }
34}
35
37 UIDartState* current_state = UIDartState::Current();
38 FML_DCHECK(current_state != nullptr);
39 fml::RefPtr<fml::TaskRunner> platform_task_runner =
40 current_state->GetTaskRunners().GetPlatformTaskRunner();
41 if (!platform_task_runner) {
42 return false;
43 }
44 return platform_task_runner->RunsTasksOnCurrentThread();
45}
46
47} // namespace flutter
static void Spawn(Dart_Handle entry_point)
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
Definition: task_runners.cc:30
bool IsRootIsolate() const
const TaskRunners & GetTaskRunners() const
virtual Dart_Isolate CreatePlatformIsolate(Dart_Handle entry_point, char **error)
static UIDartState * Current()
virtual bool RunsTasksOnCurrentThread()
Definition: task_runner.cc:43
DART_EXPORT void Dart_EnterScope(void)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
const uint8_t uint32_t uint32_t GError ** error
#define FML_DCHECK(condition)
Definition: logging.h:103
Dart_Handle ToDart(const T &object)