diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 714d60f1bc0f726d5de140f8b8abe379a86e74e2..873f96e7b814cb83df73e35a2649cec80c77a0ab 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -172,15 +172,12 @@ class Window { /// graphical operations, call the [endRecording] function on the /// [PictureRecorder] to obtain the final [Picture] that represents /// the issued graphical operations. - /// + /// /// Next, create a [SceneBuilder], and add the [Picture] to it using /// [SceneBuilder.addPicture]. With the [SceneBuilder.build] method /// 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 diff --git a/lib/ui/window/window.cc b/lib/ui/window/window.cc index ca5c8c6a9755165713f2ba130610cd3e14871d62..15cff630e77203133923e20ffd31cbab97b26b0a 100644 --- a/lib/ui/window/window.cc +++ b/lib/ui/window/window.cc @@ -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}, }); } diff --git a/lib/ui/window/window.h b/lib/ui/window/window.h index 1fd5d36f6daeaa2131d4a4189d1254c610cad1a6..f7553abb981246fe67dd83804094b4a03eb1a6c6 100644 --- a/lib/ui/window/window.h +++ b/lib/ui/window/window.h @@ -20,7 +20,6 @@ class Scene; class WindowClient { public: virtual void ScheduleFrame() = 0; - virtual void FlushRealTimeEvents() = 0; virtual void Render(Scene* scene) = 0; protected: diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 1686253f171228644075e25423277b79a88c21f9..4286fceb9cafd004821d2b491b737ecdc4cfb180 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -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", ] diff --git a/runtime/sky_view.cc b/runtime/runtime_controller.cc similarity index 55% rename from runtime/sky_view.cc rename to runtime/runtime_controller.cc index 7d2e91c971de6258cda32c2f1896a2b5ecc77fa4..071d68431b110e5d0d4bb68205fb92d95df409f1 100644 --- a/runtime/sky_view.cc +++ b/runtime/runtime_controller.cc @@ -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::Create(SkyViewClient* client) { - return std::unique_ptr(new SkyView(client)); +std::unique_ptr RuntimeController::Create( + RuntimeDelegate* client) { + return std::unique_ptr(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(new Window(this)); + dart_controller_->CreateIsolateFor( + script_uri, + std::unique_ptr(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,8 +54,8 @@ void SkyView::SetViewportMetrics(const sky::ViewportMetricsPtr& metrics) { } } -void SkyView::SetLocale(const std::string& language_code, - const std::string& country_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(new Window(this)); - dart_controller_->CreateIsolateFor(script_uri, std::unique_ptr( - 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; } diff --git a/runtime/sky_view.h b/runtime/runtime_controller.h similarity index 73% rename from runtime/sky_view.h rename to runtime/runtime_controller.h index 5f0e7bd07df592f12f262853fd6394abf3db06ec..9fbccb2b9722e84e2958bd629ec755672ce38eb3 100644 --- a/runtime/sky_view.h +++ b/runtime/runtime_controller.h @@ -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 @@ -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 Create(SkyViewClient* client); - ~SkyView(); + static std::unique_ptr 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 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_ diff --git a/runtime/runtime_delegate.cc b/runtime/runtime_delegate.cc new file mode 100644 index 0000000000000000000000000000000000000000..6df41f0220c675023e600575aefa1499ba97723c --- /dev/null +++ b/runtime/runtime_delegate.cc @@ -0,0 +1,15 @@ +// 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. + +#include "flutter/runtime/runtime_delegate.h" + +namespace blink { + +RuntimeDelegate::~RuntimeDelegate() {} + +void RuntimeDelegate::DidCreateMainIsolate(Dart_Isolate isolate) {} + +void RuntimeDelegate::DidCreateSecondaryIsolate(Dart_Isolate isolate) {} + +} // namespace blink diff --git a/runtime/sky_view_client.h b/runtime/runtime_delegate.h similarity index 55% rename from runtime/sky_view_client.h rename to runtime/runtime_delegate.h index e0fc1291396c9ddf120b011d66c572ef68302a17..9baba061d710c5271fca8510c7a6758d25319107 100644 --- a/runtime/sky_view_client.h +++ b/runtime/runtime_delegate.h @@ -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 @@ -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 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_ diff --git a/runtime/sky_view_client.cc b/runtime/sky_view_client.cc deleted file mode 100644 index 0bdb61cdb39130b1b5aeaef265a0782798a7b29a..0000000000000000000000000000000000000000 --- a/runtime/sky_view_client.cc +++ /dev/null @@ -1,11 +0,0 @@ -// 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. - -#include "flutter/runtime/sky_view_client.h" - -namespace blink { - -SkyViewClient::~SkyViewClient() {} - -} // namespace blink diff --git a/sky/shell/ui/animator.cc b/sky/shell/ui/animator.cc index 5847ccbb0d7afa71ba5683dfc9d12f56dba50d71..e88d392a569bf5844d83c289cef5a97d1bdef197 100644 --- a/sky/shell/ui/animator.cc +++ b/sky/shell/ui/animator.cc @@ -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; } diff --git a/sky/shell/ui/animator.h b/sky/shell/ui/animator.h index 339f34e1ece56bffc58526fe161954ced7017443..ffe4169d8d8be2d5355120ca5d2d9e71083f0600 100644 --- a/sky/shell/ui/animator.h +++ b/sky/shell/ui/animator.h @@ -22,7 +22,6 @@ class Animator { ~Animator(); void RequestFrame(); - void FlushRealTimeEvents(); void Render(std::unique_ptr layer_tree); diff --git a/sky/shell/ui/engine.cc b/sky/shell/ui/engine.cc index 1a9d8a56c08a69ff2502907a2d6b3c12a3538c0b..51c42ffbad78a17c17353a157ea2be304f0f704f 100644 --- a/sky/shell/ui/engine.cc +++ b/sky/shell/ui/engine.cc @@ -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 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 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(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 layer_tree) { if (!layer_tree) return; diff --git a/sky/shell/ui/engine.h b/sky/shell/ui/engine.h index 4ac69e8bcb2fb1a9a297639cab6cc47f07a6da62..54e7eaaf7eba78a159db440b8c6b64a965eeafce 100644 --- a/sky/shell/ui/engine.h +++ b/sky/shell/ui/engine.h @@ -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 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_; @@ -109,7 +108,7 @@ class Engine : public UIDelegate, mojo::BindingSet service_provider_bindings_; mojo::asset_bundle::AssetBundlePtr root_bundle_; - std::unique_ptr sky_view_; + std::unique_ptr runtime_; std::unique_ptr snapshot_drainer_;