From 76f0953aeff17b4a25bbbde5f96fedb4f8e3b087 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Sat, 13 Aug 2016 00:18:58 -0700 Subject: [PATCH] Rename SkyView to RuntimeController (flutter/engine#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. --- engine/src/flutter/lib/ui/window.dart | 5 +- engine/src/flutter/lib/ui/window/window.cc | 5 - engine/src/flutter/lib/ui/window/window.h | 1 - engine/src/flutter/runtime/BUILD.gn | 8 +- .../{sky_view.cc => runtime_controller.cc} | 100 +++++++++--------- .../{sky_view.h => runtime_controller.h} | 27 +++-- .../src/flutter/runtime/runtime_delegate.cc | 15 +++ .../{sky_view_client.h => runtime_delegate.h} | 15 ++- engine/src/flutter/runtime/sky_view_client.cc | 11 -- 9 files changed, 91 insertions(+), 96 deletions(-) rename engine/src/flutter/runtime/{sky_view.cc => runtime_controller.cc} (55%) rename engine/src/flutter/runtime/{sky_view.h => runtime_controller.h} (73%) create mode 100644 engine/src/flutter/runtime/runtime_delegate.cc rename engine/src/flutter/runtime/{sky_view_client.h => runtime_delegate.h} (55%) delete mode 100644 engine/src/flutter/runtime/sky_view_client.cc diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index 714d60f1bc..873f96e7b8 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/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/engine/src/flutter/lib/ui/window/window.cc b/engine/src/flutter/lib/ui/window/window.cc index ca5c8c6a97..15cff630e7 100644 --- a/engine/src/flutter/lib/ui/window/window.cc +++ b/engine/src/flutter/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/engine/src/flutter/lib/ui/window/window.h b/engine/src/flutter/lib/ui/window/window.h index 1fd5d36f6d..f7553abb98 100644 --- a/engine/src/flutter/lib/ui/window/window.h +++ b/engine/src/flutter/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/engine/src/flutter/runtime/BUILD.gn b/engine/src/flutter/runtime/BUILD.gn index 1686253f17..4286fceb9c 100644 --- a/engine/src/flutter/runtime/BUILD.gn +++ b/engine/src/flutter/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/engine/src/flutter/runtime/sky_view.cc b/engine/src/flutter/runtime/runtime_controller.cc similarity index 55% rename from engine/src/flutter/runtime/sky_view.cc rename to engine/src/flutter/runtime/runtime_controller.cc index 7d2e91c971..071d68431b 100644 --- a/engine/src/flutter/runtime/sky_view.cc +++ b/engine/src/flutter/runtime/runtime_controller.cc @@ -2,61 +2,37 @@ // 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) { - if (metrics) { - viewport_metrics_ = metrics->Clone(); - GetWindow()->UpdateWindowMetrics(viewport_metrics_); - } else { - viewport_metrics_ = nullptr; - } -} - -void SkyView::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 SkyView::PushRoute(const std::string& route) { - GetWindow()->PushRoute(route); -} - -void SkyView::PopRoute() { - GetWindow()->PopRoute(); -} - -void SkyView::CreateView(const std::string& script_uri) { +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)))); + 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); @@ -68,40 +44,66 @@ void SkyView::CreateView(const std::string& script_uri) { GetWindow()->UpdateLocale(language_code_, country_code_); } -void SkyView::BeginFrame(ftl::TimePoint frame_time) { +void RuntimeController::SetViewportMetrics( + const sky::ViewportMetricsPtr& metrics) { + if (metrics) { + viewport_metrics_ = metrics->Clone(); + GetWindow()->UpdateWindowMetrics(viewport_metrics_); + } else { + viewport_metrics_ = nullptr; + } +} + +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::PushRoute(const std::string& route) { + GetWindow()->PushRoute(route); +} + +void RuntimeController::PopRoute() { + GetWindow()->PopRoute(); +} + +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/engine/src/flutter/runtime/sky_view.h b/engine/src/flutter/runtime/runtime_controller.h similarity index 73% rename from engine/src/flutter/runtime/sky_view.h rename to engine/src/flutter/runtime/runtime_controller.h index 5f0e7bd07d..9fbccb2b97 100644 --- a/engine/src/flutter/runtime/sky_view.h +++ b/engine/src/flutter/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/engine/src/flutter/runtime/runtime_delegate.cc b/engine/src/flutter/runtime/runtime_delegate.cc new file mode 100644 index 0000000000..6df41f0220 --- /dev/null +++ b/engine/src/flutter/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/engine/src/flutter/runtime/sky_view_client.h b/engine/src/flutter/runtime/runtime_delegate.h similarity index 55% rename from engine/src/flutter/runtime/sky_view_client.h rename to engine/src/flutter/runtime/runtime_delegate.h index e0fc129139..9baba061d7 100644 --- a/engine/src/flutter/runtime/sky_view_client.h +++ b/engine/src/flutter/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/engine/src/flutter/runtime/sky_view_client.cc b/engine/src/flutter/runtime/sky_view_client.cc deleted file mode 100644 index 0bdb61cdb3..0000000000 --- a/engine/src/flutter/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