From 7c1fc3ef40dd249f39b6948d5ff1338fcfeeea16 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 23 Jul 2020 11:23:25 -0700 Subject: [PATCH 1/3] enabled linting on engine.cc --- shell/common/engine.cc | 62 +++++++++++++++++++++++++----------------- shell/common/engine.h | 5 +++- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 223bb2870229d..33730528a8dc8 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -1,7 +1,6 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// FLUTTER_NOLINT #include "flutter/shell/common/engine.h" @@ -281,23 +280,32 @@ void Engine::SetViewportMetrics(const ViewportMetrics& metrics) { viewport_metrics_ = metrics; runtime_controller_->SetViewportMetrics(viewport_metrics_); if (animator_) { - if (dimensions_changed) + if (dimensions_changed) { animator_->SetDimensionChangePending(); - if (have_surface_) + } + if (have_surface_) { ScheduleFrame(); + } } } void Engine::DispatchPlatformMessage(fml::RefPtr message) { - if (message->channel() == kLifecycleChannel) { - if (HandleLifecyclePlatformMessage(message.get())) + std::string channel = message->channel(); + if (channel == kLifecycleChannel) { + if (HandleLifecyclePlatformMessage(message.get())) { return; - } else if (message->channel() == kLocalizationChannel) { - if (HandleLocalizationPlatformMessage(message.get())) + } + } else if (channel == kLocalizationChannel) { + if (HandleLocalizationPlatformMessage(message.get())) { return; - } else if (message->channel() == kSettingsChannel) { + } + } else if (channel == kSettingsChannel) { HandleSettingsPlatformMessage(message.get()); return; + } else if (channel == kNavigationChannel) { + // If there's no runtime_, we may still need to set the initial route. + HandleNavigationPlatformMessage(std::move(message)); + return; } if (runtime_controller_->IsRootIsolateRunning() && @@ -305,14 +313,8 @@ void Engine::DispatchPlatformMessage(fml::RefPtr message) { return; } - // If there's no runtime_, we may still need to set the initial route. - if (message->channel() == kNavigationChannel) { - HandleNavigationPlatformMessage(std::move(message)); - return; - } - FML_DLOG(WARNING) << "Dropping platform message on channel: " - << message->channel(); + << channel; } bool Engine::HandleLifecyclePlatformMessage(PlatformMessage* message) { @@ -345,12 +347,14 @@ bool Engine::HandleNavigationPlatformMessage( rapidjson::Document document; document.Parse(reinterpret_cast(data.data()), data.size()); - if (document.HasParseError() || !document.IsObject()) + if (document.HasParseError() || !document.IsObject()) { return false; + } auto root = document.GetObject(); auto method = root.FindMember("method"); - if (method->value != "setInitialRoute") + if (method->value != "setInitialRoute") { return false; + } auto route = root.FindMember("args"); initial_route_ = std::move(route->value.GetString()); return true; @@ -361,27 +365,32 @@ bool Engine::HandleLocalizationPlatformMessage(PlatformMessage* message) { rapidjson::Document document; document.Parse(reinterpret_cast(data.data()), data.size()); - if (document.HasParseError() || !document.IsObject()) + if (document.HasParseError() || !document.IsObject()) { return false; + } auto root = document.GetObject(); auto method = root.FindMember("method"); - if (method == root.MemberEnd()) + if (method == root.MemberEnd()) { return false; + } const size_t strings_per_locale = 4; if (method->value == "setLocale") { // Decode and pass the list of locale data onwards to dart. auto args = root.FindMember("args"); - if (args == root.MemberEnd() || !args->value.IsArray()) + if (args == root.MemberEnd() || !args->value.IsArray()) { return false; + } - if (args->value.Size() % strings_per_locale != 0) + if (args->value.Size() % strings_per_locale != 0) { return false; + } std::vector locale_data; for (size_t locale_index = 0; locale_index < args->value.Size(); locale_index += strings_per_locale) { if (!args->value[locale_index].IsString() || - !args->value[locale_index + 1].IsString()) + !args->value[locale_index + 1].IsString()) { return false; + } locale_data.push_back(args->value[locale_index].GetString()); locale_data.push_back(args->value[locale_index + 1].GetString()); locale_data.push_back(args->value[locale_index + 2].GetString()); @@ -429,8 +438,9 @@ void Engine::StopAnimator() { } void Engine::StartAnimatorIfPossible() { - if (activity_running_ && have_surface_) + if (activity_running_ && have_surface_) { animator_->Start(); + } } std::string Engine::DefaultRouteName() { @@ -445,14 +455,16 @@ void Engine::ScheduleFrame(bool regenerate_layer_tree) { } void Engine::Render(std::unique_ptr layer_tree) { - if (!layer_tree) + if (!layer_tree) { return; + } // Ensure frame dimensions are sane. if (layer_tree->frame_size().isEmpty() || layer_tree->frame_physical_depth() <= 0.0f || - layer_tree->frame_device_pixel_ratio() <= 0.0f) + layer_tree->frame_device_pixel_ratio() <= 0.0f) { return; + } animator_->Render(std::move(layer_tree)); } diff --git a/shell/common/engine.h b/shell/common/engine.h index e92a91a955742..c4b9b0a4ba83f 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -727,7 +727,10 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { void SetAccessibilityFeatures(int32_t flags); // |RuntimeDelegate| - void ScheduleFrame(bool regenerate_layer_tree = true) override; + void ScheduleFrame(bool regenerate_layer_tree) override; + + /// Schedule a frame with the default parameter of not regenerating the layer tree. + void ScheduleFrame() { ScheduleFrame(false); } // |RuntimeDelegate| FontCollection& GetFontCollection() override; From e389846ae855caf0c2e164a29bfa9aca80d95b86 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 23 Jul 2020 11:44:11 -0700 Subject: [PATCH 2/3] ran formatter --- shell/common/engine.cc | 3 +-- shell/common/engine.h | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 33730528a8dc8..438a1945b9f50 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -313,8 +313,7 @@ void Engine::DispatchPlatformMessage(fml::RefPtr message) { return; } - FML_DLOG(WARNING) << "Dropping platform message on channel: " - << channel; + FML_DLOG(WARNING) << "Dropping platform message on channel: " << channel; } bool Engine::HandleLifecyclePlatformMessage(PlatformMessage* message) { diff --git a/shell/common/engine.h b/shell/common/engine.h index c4b9b0a4ba83f..c76ba41469000 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -729,7 +729,8 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { // |RuntimeDelegate| void ScheduleFrame(bool regenerate_layer_tree) override; - /// Schedule a frame with the default parameter of not regenerating the layer tree. + /// Schedule a frame with the default parameter of not regenerating the layer + /// tree. void ScheduleFrame() { ScheduleFrame(false); } // |RuntimeDelegate| From 28aa13c04b181e9dce334a75e60708d33ba44709 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 23 Jul 2020 11:48:16 -0700 Subject: [PATCH 3/3] oops, got my default parameter wrong --- shell/common/engine.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/common/engine.h b/shell/common/engine.h index c76ba41469000..d7e516617afc1 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -729,9 +729,9 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { // |RuntimeDelegate| void ScheduleFrame(bool regenerate_layer_tree) override; - /// Schedule a frame with the default parameter of not regenerating the layer + /// Schedule a frame with the default parameter of regenerating the layer /// tree. - void ScheduleFrame() { ScheduleFrame(false); } + void ScheduleFrame() { ScheduleFrame(true); } // |RuntimeDelegate| FontCollection& GetFontCollection() override;