Files
engine/runtime/runtime_controller.cc
T

193 lines
5.5 KiB
C++
Raw Normal View History

2015-05-18 14:48:27 -07:00
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
2016-08-13 00:18:58 -07:00
#include "flutter/runtime/runtime_controller.h"
2015-05-18 14:48:27 -07:00
2016-08-09 12:48:29 -07:00
#include "flutter/glue/trace_event.h"
#include "flutter/lib/ui/compositing/scene.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/runtime/dart_controller.h"
2016-08-13 00:18:58 -07:00
#include "flutter/runtime/runtime_delegate.h"
#include "lib/tonic/dart_message_handler.h"
2015-05-19 10:55:07 -07:00
2016-08-12 12:05:48 -07:00
using tonic::DartState;
2015-05-18 14:48:27 -07:00
namespace blink {
2016-08-13 00:18:58 -07:00
std::unique_ptr<RuntimeController> RuntimeController::Create(
RuntimeDelegate* client) {
return std::unique_ptr<RuntimeController>(new RuntimeController(client));
2015-05-18 14:48:27 -07:00
}
2016-08-13 00:18:58 -07:00
RuntimeController::RuntimeController(RuntimeDelegate* client)
: client_(client) {}
2015-05-18 14:48:27 -07:00
2016-08-13 00:18:58 -07:00
RuntimeController::~RuntimeController() {}
2015-05-18 14:48:27 -07:00
2017-04-11 14:53:14 -07:00
void RuntimeController::CreateDartController(
const std::string& script_uri,
const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instr) {
FXL_DCHECK(!dart_controller_);
2015-08-27 16:58:44 -07:00
dart_controller_.reset(new DartController());
2016-08-13 00:18:58 -07:00
dart_controller_->CreateIsolateFor(
2017-04-11 14:53:14 -07:00
script_uri, isolate_snapshot_data, isolate_snapshot_instr,
2016-10-11 13:27:11 -07:00
std::make_unique<UIDartState>(this, std::make_unique<Window>(this)));
2016-08-12 20:38:01 -07:00
UIDartState* dart_state = dart_controller_->dart_state();
DartState::Scope scope(dart_state);
dart_state->window()->DidCreateIsolate();
client_->DidCreateMainIsolate(dart_state->isolate());
2015-08-27 16:58:44 -07:00
2016-10-11 13:27:11 -07:00
Window* window = GetWindow();
window->UpdateLocale(language_code_, country_code_);
if (semantics_enabled_)
window->UpdateSemanticsEnabled(semantics_enabled_);
2015-08-27 16:58:44 -07:00
}
void RuntimeController::SetViewportMetrics(const ViewportMetrics& metrics) {
GetWindow()->UpdateWindowMetrics(metrics);
2016-08-13 00:18:58 -07:00
}
void RuntimeController::SetLocale(const std::string& language_code,
const std::string& country_code) {
if (language_code_ == language_code && country_code_ == country_code)
return;
language_code_ = language_code;
country_code_ = country_code;
GetWindow()->UpdateLocale(language_code_, country_code_);
}
void RuntimeController::SetUserSettingsData(const std::string& data) {
if (user_settings_data_ == data)
return;
user_settings_data_ = data;
GetWindow()->UpdateUserSettingsData(user_settings_data_);
}
void RuntimeController::SetSemanticsEnabled(bool enabled) {
if (semantics_enabled_ == enabled)
return;
semantics_enabled_ = enabled;
2016-10-11 13:27:11 -07:00
GetWindow()->UpdateSemanticsEnabled(semantics_enabled_);
}
void RuntimeController::BeginFrame(fxl::TimePoint frame_time) {
GetWindow()->BeginFrame(frame_time);
2015-05-18 14:48:27 -07:00
}
void RuntimeController::NotifyIdle(int64_t deadline) {
UIDartState* dart_state = dart_controller_->dart_state();
if (!dart_state) {
return;
}
DartState::Scope scope(dart_state);
Dart_NotifyIdle(deadline);
}
2016-10-14 15:51:25 -07:00
void RuntimeController::DispatchPlatformMessage(
fxl::RefPtr<PlatformMessage> message) {
TRACE_EVENT1("flutter", "RuntimeController::DispatchPlatformMessage", "mode",
"basic");
2016-10-14 15:51:25 -07:00
GetWindow()->DispatchPlatformMessage(std::move(message));
}
void RuntimeController::DispatchPointerDataPacket(
const PointerDataPacket& packet) {
TRACE_EVENT1("flutter", "RuntimeController::DispatchPointerDataPacket",
"mode", "basic");
GetWindow()->DispatchPointerDataPacket(packet);
}
void RuntimeController::DispatchSemanticsAction(int32_t id,
SemanticsAction action) {
TRACE_EVENT1("flutter", "RuntimeController::DispatchSemanticsAction", "mode",
"basic");
GetWindow()->DispatchSemanticsAction(id, action);
}
2016-08-13 00:18:58 -07:00
Window* RuntimeController::GetWindow() {
return dart_controller_->dart_state()->window();
2015-05-18 14:48:27 -07:00
}
2017-06-06 10:59:41 +02:00
std::string RuntimeController::DefaultRouteName() {
return client_->DefaultRouteName();
}
2016-08-13 00:18:58 -07:00
void RuntimeController::ScheduleFrame() {
2015-05-21 11:22:17 -07:00
client_->ScheduleFrame();
2015-05-19 14:20:04 -07:00
}
2016-08-13 00:18:58 -07:00
void RuntimeController::Render(Scene* scene) {
client_->Render(scene->takeLayerTree());
}
void RuntimeController::UpdateSemantics(SemanticsUpdate* update) {
if (semantics_enabled_)
client_->UpdateSemantics(update->takeNodes());
}
void RuntimeController::HandlePlatformMessage(
fxl::RefPtr<PlatformMessage> message) {
client_->HandlePlatformMessage(std::move(message));
}
2016-08-13 00:18:58 -07:00
void RuntimeController::DidCreateSecondaryIsolate(Dart_Isolate isolate) {
client_->DidCreateSecondaryIsolate(isolate);
}
void RuntimeController::DidShutdownMainIsolate() {
client_->DidShutdownMainIsolate();
}
2016-08-13 00:18:58 -07:00
Dart_Port RuntimeController::GetMainPort() {
if (!dart_controller_) {
return ILLEGAL_PORT;
}
if (!dart_controller_->dart_state()) {
return ILLEGAL_PORT;
}
return dart_controller_->dart_state()->main_port();
}
std::string RuntimeController::GetIsolateName() {
if (!dart_controller_) {
return "";
}
if (!dart_controller_->dart_state()) {
return "";
}
return dart_controller_->dart_state()->debug_name();
}
bool RuntimeController::HasLivePorts() {
if (!dart_controller_) {
return false;
}
UIDartState* dart_state = dart_controller_->dart_state();
if (!dart_state) {
return false;
}
DartState::Scope scope(dart_state);
return Dart_HasLivePorts();
}
tonic::DartErrorHandleType RuntimeController::GetLastError() {
if (!dart_controller_) {
return tonic::kNoError;
}
UIDartState* dart_state = dart_controller_->dart_state();
if (!dart_state) {
return tonic::kNoError;
}
return dart_state->message_handler().isolate_last_error();
}
2016-08-01 15:11:56 -07:00
} // namespace blink