提交 b2058f8b 编写于 作者: A Adam Barth 提交者: GitHub

Rename SkyView to RuntimeController (#2924)

Also, rename SkyViewClient to RuntimeDelegate. These names are more
sensible.

This patch also cleans up the RuntimeDelegate a bit, for example by
removing support for flushing real-time events, which aren't used.
上级 0a439f3f
......@@ -178,9 +178,6 @@ class Window {
/// you can then obtain a [Scene] object, which you can display to
/// the user via this [render] function.
void render(Scene scene) native "Window_render";
/// Flushes pending real-time events, executing their callbacks.
void flushRealTimeEvents() native "Scheduler_FlushRealTimeEvents";
}
/// The [Window] singleton. This object exposes the size of the display, the
......
......@@ -33,10 +33,6 @@ void Render(Dart_NativeArguments args) {
UIDartState::Current()->window()->client()->Render(scene);
}
void FlushRealTimeEvents(Dart_NativeArguments args) {
UIDartState::Current()->window()->client()->FlushRealTimeEvents();
}
} // namespace
WindowClient::~WindowClient() {}
......@@ -154,7 +150,6 @@ void Window::RegisterNatives(tonic::DartLibraryNatives* natives) {
natives->Register({
{"Window_scheduleFrame", ScheduleFrame, 1, true},
{"Window_render", Render, 2, true},
{"Scheduler_FlushRealTimeEvents", FlushRealTimeEvents, 1, true},
});
}
......
......@@ -20,7 +20,6 @@ class Scene;
class WindowClient {
public:
virtual void ScheduleFrame() = 0;
virtual void FlushRealTimeEvents() = 0;
virtual void Render(Scene* scene) = 0;
protected:
......
......@@ -46,10 +46,10 @@ source_set("runtime") {
"dart_service_isolate.h",
"embedder_resources.cc",
"embedder_resources.h",
"sky_view.cc",
"sky_view_client.cc",
"sky_view_client.h",
"sky_view.h",
"runtime_controller.cc",
"runtime_controller.h",
"runtime_delegate.cc",
"runtime_delegate.h",
"start_up.cc",
"start_up.h",
]
......
......@@ -2,28 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/runtime/sky_view.h"
#include "flutter/runtime/runtime_controller.h"
#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"
#include "flutter/runtime/sky_view_client.h"
#include "flutter/runtime/runtime_delegate.h"
using tonic::DartState;
namespace blink {
std::unique_ptr<SkyView> SkyView::Create(SkyViewClient* client) {
return std::unique_ptr<SkyView>(new SkyView(client));
std::unique_ptr<RuntimeController> RuntimeController::Create(
RuntimeDelegate* client) {
return std::unique_ptr<RuntimeController>(new RuntimeController(client));
}
SkyView::SkyView(SkyViewClient* client) : client_(client) {}
RuntimeController::RuntimeController(RuntimeDelegate* client)
: client_(client) {}
SkyView::~SkyView() {}
RuntimeController::~RuntimeController() {}
void SkyView::SetViewportMetrics(const sky::ViewportMetricsPtr& metrics) {
void RuntimeController::CreateDartController(const std::string& script_uri) {
FTL_DCHECK(!dart_controller_);
dart_controller_.reset(new DartController());
std::unique_ptr<Window> window(new Window(this));
dart_controller_->CreateIsolateFor(
script_uri,
std::unique_ptr<UIDartState>(new UIDartState(this, std::move(window))));
UIDartState* dart_state = dart_controller_->dart_state();
DartState::Scope scope(dart_state);
dart_state->window()->DidCreateIsolate();
client_->DidCreateMainIsolate(dart_state->isolate());
if (viewport_metrics_)
GetWindow()->UpdateWindowMetrics(viewport_metrics_);
GetWindow()->UpdateLocale(language_code_, country_code_);
}
void RuntimeController::SetViewportMetrics(
const sky::ViewportMetricsPtr& metrics) {
if (metrics) {
viewport_metrics_ = metrics->Clone();
GetWindow()->UpdateWindowMetrics(viewport_metrics_);
......@@ -32,7 +54,7 @@ void SkyView::SetViewportMetrics(const sky::ViewportMetricsPtr& metrics) {
}
}
void SkyView::SetLocale(const std::string& language_code,
void RuntimeController::SetLocale(const std::string& language_code,
const std::string& country_code) {
if (language_code_ == language_code && country_code_ == country_code)
return;
......@@ -42,66 +64,46 @@ void SkyView::SetLocale(const std::string& language_code,
GetWindow()->UpdateLocale(language_code_, country_code_);
}
void SkyView::PushRoute(const std::string& route) {
void RuntimeController::PushRoute(const std::string& route) {
GetWindow()->PushRoute(route);
}
void SkyView::PopRoute() {
void RuntimeController::PopRoute() {
GetWindow()->PopRoute();
}
void SkyView::CreateView(const std::string& script_uri) {
FTL_DCHECK(!dart_controller_);
dart_controller_.reset(new DartController());
std::unique_ptr<Window> window(new Window(this));
dart_controller_->CreateIsolateFor(script_uri, std::unique_ptr<UIDartState>(
new UIDartState(this, std::move(window))));
UIDartState* dart_state = dart_controller_->dart_state();
DartState::Scope scope(dart_state);
dart_state->window()->DidCreateIsolate();
client_->DidCreateMainIsolate(dart_state->isolate());
if (viewport_metrics_)
GetWindow()->UpdateWindowMetrics(viewport_metrics_);
GetWindow()->UpdateLocale(language_code_, country_code_);
}
void SkyView::BeginFrame(ftl::TimePoint frame_time) {
void RuntimeController::BeginFrame(ftl::TimePoint frame_time) {
GetWindow()->BeginFrame(frame_time);
}
void SkyView::HandlePointerPacket(const pointer::PointerPacketPtr& packet) {
TRACE_EVENT0("input", "SkyView::HandlePointerPacket");
void RuntimeController::HandlePointerPacket(
const pointer::PointerPacketPtr& packet) {
TRACE_EVENT0("input", "RuntimeController::HandlePointerPacket");
GetWindow()->DispatchPointerPacket(packet);
}
Window* SkyView::GetWindow() {
Window* RuntimeController::GetWindow() {
return dart_controller_->dart_state()->window();
}
void SkyView::ScheduleFrame() {
void RuntimeController::ScheduleFrame() {
client_->ScheduleFrame();
}
void SkyView::FlushRealTimeEvents() {
client_->FlushRealTimeEvents();
}
void SkyView::Render(Scene* scene) {
void RuntimeController::Render(Scene* scene) {
client_->Render(scene->takeLayerTree());
}
void SkyView::DidCreateSecondaryIsolate(Dart_Isolate isolate) {
void RuntimeController::DidCreateSecondaryIsolate(Dart_Isolate isolate) {
client_->DidCreateSecondaryIsolate(isolate);
}
void SkyView::OnAppLifecycleStateChanged(sky::AppLifecycleState state) {
void RuntimeController::OnAppLifecycleStateChanged(
sky::AppLifecycleState state) {
GetWindow()->OnAppLifecycleStateChanged(state);
}
Dart_Port SkyView::GetMainPort() {
Dart_Port RuntimeController::GetMainPort() {
if (!dart_controller_) {
return ILLEGAL_PORT;
}
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_RUNTIME_SKY_VIEW_H_
#define FLUTTER_RUNTIME_SKY_VIEW_H_
#ifndef FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
#define FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
#include <memory>
......@@ -18,14 +18,17 @@ namespace blink {
class DartController;
class DartLibraryProvider;
class Scene;
class SkyViewClient;
class RuntimeDelegate;
class View;
class Window;
class SkyView : public WindowClient, public IsolateClient {
class RuntimeController : public WindowClient, public IsolateClient {
public:
static std::unique_ptr<SkyView> Create(SkyViewClient* client);
~SkyView();
static std::unique_ptr<RuntimeController> Create(RuntimeDelegate* client);
~RuntimeController();
void CreateDartController(const std::string& script_uri);
DartController* dart_controller() const { return dart_controller_.get(); }
void SetViewportMetrics(const sky::ViewportMetricsPtr& metrics);
void SetLocale(const std::string& language_code,
......@@ -35,9 +38,6 @@ class SkyView : public WindowClient, public IsolateClient {
void BeginFrame(ftl::TimePoint frame_time);
void CreateView(const std::string& script_uri);
DartController* dart_controller() const { return dart_controller_.get(); }
void HandlePointerPacket(const pointer::PointerPacketPtr& packet);
void OnAppLifecycleStateChanged(sky::AppLifecycleState state);
......@@ -45,25 +45,24 @@ class SkyView : public WindowClient, public IsolateClient {
Dart_Port GetMainPort();
private:
explicit SkyView(SkyViewClient* client);
explicit RuntimeController(RuntimeDelegate* client);
Window* GetWindow();
void ScheduleFrame() override;
void FlushRealTimeEvents() override;
void Render(Scene* scene) override;
void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;
SkyViewClient* client_;
RuntimeDelegate* client_;
sky::ViewportMetricsPtr viewport_metrics_;
std::string language_code_;
std::string country_code_;
std::unique_ptr<DartController> dart_controller_;
FTL_DISALLOW_COPY_AND_ASSIGN(SkyView);
FTL_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
};
} // namespace blink
#endif // FLUTTER_RUNTIME_SKY_VIEW_H_
#endif // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
......@@ -2,10 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/runtime/sky_view_client.h"
#include "flutter/runtime/runtime_delegate.h"
namespace blink {
SkyViewClient::~SkyViewClient() {}
RuntimeDelegate::~RuntimeDelegate() {}
void RuntimeDelegate::DidCreateMainIsolate(Dart_Isolate isolate) {}
void RuntimeDelegate::DidCreateSecondaryIsolate(Dart_Isolate isolate) {}
} // namespace blink
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_RUNTIME_SKY_VIEW_CLIENT_H_
#define FLUTTER_RUNTIME_SKY_VIEW_CLIENT_H_
#ifndef FLUTTER_RUNTIME_RUNTIME_DELEGATE_H_
#define FLUTTER_RUNTIME_RUNTIME_DELEGATE_H_
#include <memory>
......@@ -12,19 +12,18 @@
namespace blink {
class SkyViewClient {
class RuntimeDelegate {
public:
virtual void ScheduleFrame() = 0;
virtual void FlushRealTimeEvents() = 0;
virtual void Render(std::unique_ptr<flow::LayerTree> layer_tree) = 0;
virtual void DidCreateMainIsolate(Dart_Isolate isolate) = 0;
virtual void DidCreateSecondaryIsolate(Dart_Isolate isolate) = 0;
virtual void DidCreateMainIsolate(Dart_Isolate isolate);
virtual void DidCreateSecondaryIsolate(Dart_Isolate isolate);
protected:
virtual ~SkyViewClient();
virtual ~RuntimeDelegate();
};
} // namespace blink
#endif // FLUTTER_RUNTIME_SKY_VIEW_CLIENT_H_
#endif // FLUTTER_RUNTIME_RUNTIME_DELEGATE_H_
......@@ -54,14 +54,6 @@ void Animator::RequestFrame() {
}
}
void Animator::FlushRealTimeEvents() {
if (outstanding_requests_ > 0)
rasterizer_.WaitForIncomingResponseWithTimeout(0);
if (engine_requested_frame_ && vsync_provider_)
vsync_provider_.WaitForIncomingResponseWithTimeout(0);
}
void Animator::Stop() {
paused_ = true;
}
......
......@@ -22,7 +22,6 @@ class Animator {
~Animator();
void RequestFrame();
void FlushRealTimeEvents();
void Render(std::unique_ptr<flow::LayerTree> layer_tree);
......
......@@ -78,8 +78,8 @@ void Engine::Init() {
void Engine::BeginFrame(ftl::TimePoint frame_time) {
TRACE_EVENT0("flutter", "Engine::BeginFrame");
if (sky_view_)
sky_view_->BeginFrame(frame_time);
if (runtime_)
runtime_->BeginFrame(frame_time);
}
void Engine::RunFromSource(const std::string& main,
......@@ -91,14 +91,14 @@ void Engine::RunFromSource(const std::string& main,
packages_path = FindPackagesPath(main);
if (!bundle.empty())
ConfigureDirectoryAssetBundle(bundle);
ConfigureView(main);
sky_view_->dart_controller()->RunFromSource(main, packages_path);
ConfigureRuntime(main);
runtime_->dart_controller()->RunFromSource(main, packages_path);
}
Dart_Port Engine::GetUIIsolateMainPort() {
if (!sky_view_)
if (!runtime_)
return ILLEGAL_PORT;
return sky_view_->GetMainPort();
return runtime_->GetMainPort();
}
void Engine::ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) {
......@@ -109,7 +109,7 @@ void Engine::OnOutputSurfaceCreated(const ftl::Closure& gpu_continuation) {
blink::Threads::Gpu()->PostTask(gpu_continuation);
have_surface_ = true;
StartAnimatorIfPossible();
if (sky_view_)
if (runtime_)
ScheduleFrame();
}
......@@ -154,16 +154,16 @@ void Engine::SetServices(ServicesDataPtr services) {
void Engine::OnViewportMetricsChanged(ViewportMetricsPtr metrics) {
viewport_metrics_ = metrics.Pass();
if (sky_view_)
sky_view_->SetViewportMetrics(viewport_metrics_);
if (runtime_)
runtime_->SetViewportMetrics(viewport_metrics_);
}
void Engine::OnLocaleChanged(const mojo::String& language_code,
const mojo::String& country_code) {
language_code_ = language_code;
country_code_ = country_code;
if (sky_view_)
sky_view_->SetLocale(language_code_, country_code_);
if (runtime_)
runtime_->SetLocale(language_code_, country_code_);
}
void Engine::OnPointerPacket(pointer::PointerPacketPtr packet) {
......@@ -175,20 +175,20 @@ void Engine::OnPointerPacket(pointer::PointerPacketPtr packet) {
(*it)->y /= viewport_metrics_->device_pixel_ratio;
}
if (sky_view_)
sky_view_->HandlePointerPacket(packet);
if (runtime_)
runtime_->HandlePointerPacket(packet);
}
void Engine::RunFromSnapshotStream(
const std::string& script_uri,
mojo::ScopedDataPipeConsumerHandle snapshot) {
TRACE_EVENT0("flutter", "Engine::RunFromSnapshotStream");
ConfigureView(script_uri);
ConfigureRuntime(script_uri);
snapshot_drainer_.reset(new glue::DrainDataPipeJob(
std::move(snapshot), [this](std::vector<char> snapshot) {
FTL_DCHECK(sky_view_);
FTL_DCHECK(sky_view_->dart_controller());
sky_view_->dart_controller()->RunFromSnapshot(
FTL_DCHECK(runtime_);
FTL_DCHECK(runtime_->dart_controller());
runtime_->dart_controller()->RunFromSnapshot(
reinterpret_cast<uint8_t*>(snapshot.data()), snapshot.size());
}));
}
......@@ -204,21 +204,21 @@ void Engine::ConfigureDirectoryAssetBundle(const std::string& path) {
blink::Threads::IO());
}
void Engine::ConfigureView(const std::string& script_uri) {
void Engine::ConfigureRuntime(const std::string& script_uri) {
snapshot_drainer_.reset();
sky_view_ = blink::SkyView::Create(this);
sky_view_->CreateView(std::move(script_uri));
sky_view_->SetViewportMetrics(viewport_metrics_);
sky_view_->SetLocale(language_code_, country_code_);
runtime_ = blink::RuntimeController::Create(this);
runtime_->CreateDartController(std::move(script_uri));
runtime_->SetViewportMetrics(viewport_metrics_);
runtime_->SetLocale(language_code_, country_code_);
if (!initial_route_.empty())
sky_view_->PushRoute(initial_route_);
runtime_->PushRoute(initial_route_);
}
void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) {
TRACE_EVENT0("flutter", "Engine::RunFromPrecompiledSnapshot");
ConfigureZipAssetBundle(bundle_path.get());
ConfigureView("http://localhost");
sky_view_->dart_controller()->RunFromPrecompiledSnapshot();
ConfigureRuntime("http://localhost");
runtime_->dart_controller()->RunFromPrecompiledSnapshot();
}
void Engine::RunFromFile(const mojo::String& main,
......@@ -252,15 +252,15 @@ void Engine::RunFromBundleAndSnapshot(const mojo::String& script_uri,
}
void Engine::PushRoute(const mojo::String& route) {
if (sky_view_)
sky_view_->PushRoute(route);
if (runtime_)
runtime_->PushRoute(route);
else
initial_route_ = route;
}
void Engine::PopRoute() {
if (sky_view_)
sky_view_->PopRoute();
if (runtime_)
runtime_->PopRoute();
}
void Engine::OnAppLifecycleStateChanged(sky::AppLifecycleState state) {
......@@ -276,8 +276,8 @@ void Engine::OnAppLifecycleStateChanged(sky::AppLifecycleState state) {
break;
}
if (sky_view_)
sky_view_->OnAppLifecycleStateChanged(state);
if (runtime_)
runtime_->OnAppLifecycleStateChanged(state);
}
void Engine::DidCreateMainIsolate(Dart_Isolate isolate) {
......@@ -324,10 +324,6 @@ void Engine::ScheduleFrame() {
animator_->RequestFrame();
}
void Engine::FlushRealTimeEvents() {
animator_->FlushRealTimeEvents();
}
void Engine::Render(std::unique_ptr<flow::LayerTree> layer_tree) {
if (!layer_tree)
return;
......
......@@ -7,8 +7,8 @@
#include "flutter/assets/zip_asset_store.h"
#include "flutter/glue/drain_data_pipe_job.h"
#include "flutter/runtime/sky_view_client.h"
#include "flutter/runtime/sky_view.h"
#include "flutter/runtime/runtime_delegate.h"
#include "flutter/runtime/runtime_controller.h"
#include "flutter/services/engine/sky_engine.mojom.h"
#include "flutter/services/rasterizer/rasterizer.mojom.h"
#include "flutter/sky/shell/ui_delegate.h"
......@@ -30,7 +30,7 @@ class Animator;
class Engine : public UIDelegate,
public SkyEngine,
public blink::SkyViewClient {
public blink::RuntimeDelegate {
public:
struct Config {
Config();
......@@ -78,9 +78,8 @@ class Engine : public UIDelegate,
void PopRoute() override;
void OnAppLifecycleStateChanged(sky::AppLifecycleState state) override;
// SkyViewClient methods:
// RuntimeDelegate methods:
void ScheduleFrame() override;
void FlushRealTimeEvents() override;
void Render(std::unique_ptr<flow::LayerTree> layer_tree) override;
void DidCreateMainIsolate(Dart_Isolate isolate) override;
void DidCreateSecondaryIsolate(Dart_Isolate isolate) override;
......@@ -98,7 +97,7 @@ class Engine : public UIDelegate,
void ConfigureZipAssetBundle(const std::string& path);
void ConfigureDirectoryAssetBundle(const std::string& path);
void ConfigureView(const std::string& script_uri);
void ConfigureRuntime(const std::string& script_uri);
Config config_;
std::unique_ptr<Animator> animator_;
......@@ -109,7 +108,7 @@ class Engine : public UIDelegate,
mojo::BindingSet<mojo::ServiceProvider> service_provider_bindings_;
mojo::asset_bundle::AssetBundlePtr root_bundle_;
std::unique_ptr<blink::SkyView> sky_view_;
std::unique_ptr<blink::RuntimeController> runtime_;
std::unique_ptr<glue::DrainDataPipeJob> snapshot_drainer_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册