11// Copyright 2013 The Flutter Authors. All rights reserved.
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
4- // FLUTTER_NOLINT
54
65#include " flutter/shell/common/engine.h"
76
@@ -281,38 +280,40 @@ void Engine::SetViewportMetrics(const ViewportMetrics& metrics) {
281280 viewport_metrics_ = metrics;
282281 runtime_controller_->SetViewportMetrics (viewport_metrics_);
283282 if (animator_) {
284- if (dimensions_changed)
283+ if (dimensions_changed) {
285284 animator_->SetDimensionChangePending ();
286- if (have_surface_)
285+ }
286+ if (have_surface_) {
287287 ScheduleFrame ();
288+ }
288289 }
289290}
290291
291292void Engine::DispatchPlatformMessage (fml::RefPtr<PlatformMessage> message) {
292- if (message->channel () == kLifecycleChannel ) {
293- if (HandleLifecyclePlatformMessage (message.get ()))
293+ std::string channel = message->channel ();
294+ if (channel == kLifecycleChannel ) {
295+ if (HandleLifecyclePlatformMessage (message.get ())) {
294296 return ;
295- } else if (message->channel () == kLocalizationChannel ) {
296- if (HandleLocalizationPlatformMessage (message.get ()))
297+ }
298+ } else if (channel == kLocalizationChannel ) {
299+ if (HandleLocalizationPlatformMessage (message.get ())) {
297300 return ;
298- } else if (message->channel () == kSettingsChannel ) {
301+ }
302+ } else if (channel == kSettingsChannel ) {
299303 HandleSettingsPlatformMessage (message.get ());
300304 return ;
305+ } else if (channel == kNavigationChannel ) {
306+ // If there's no runtime_, we may still need to set the initial route.
307+ HandleNavigationPlatformMessage (std::move (message));
308+ return ;
301309 }
302310
303311 if (runtime_controller_->IsRootIsolateRunning () &&
304312 runtime_controller_->DispatchPlatformMessage (std::move (message))) {
305313 return ;
306314 }
307315
308- // If there's no runtime_, we may still need to set the initial route.
309- if (message->channel () == kNavigationChannel ) {
310- HandleNavigationPlatformMessage (std::move (message));
311- return ;
312- }
313-
314- FML_DLOG (WARNING) << " Dropping platform message on channel: "
315- << message->channel ();
316+ FML_DLOG (WARNING) << " Dropping platform message on channel: " << channel;
316317}
317318
318319bool Engine::HandleLifecyclePlatformMessage (PlatformMessage* message) {
@@ -345,12 +346,14 @@ bool Engine::HandleNavigationPlatformMessage(
345346
346347 rapidjson::Document document;
347348 document.Parse (reinterpret_cast <const char *>(data.data ()), data.size ());
348- if (document.HasParseError () || !document.IsObject ())
349+ if (document.HasParseError () || !document.IsObject ()) {
349350 return false ;
351+ }
350352 auto root = document.GetObject ();
351353 auto method = root.FindMember (" method" );
352- if (method->value != " setInitialRoute" )
354+ if (method->value != " setInitialRoute" ) {
353355 return false ;
356+ }
354357 auto route = root.FindMember (" args" );
355358 initial_route_ = std::move (route->value .GetString ());
356359 return true ;
@@ -361,27 +364,32 @@ bool Engine::HandleLocalizationPlatformMessage(PlatformMessage* message) {
361364
362365 rapidjson::Document document;
363366 document.Parse (reinterpret_cast <const char *>(data.data ()), data.size ());
364- if (document.HasParseError () || !document.IsObject ())
367+ if (document.HasParseError () || !document.IsObject ()) {
365368 return false ;
369+ }
366370 auto root = document.GetObject ();
367371 auto method = root.FindMember (" method" );
368- if (method == root.MemberEnd ())
372+ if (method == root.MemberEnd ()) {
369373 return false ;
374+ }
370375 const size_t strings_per_locale = 4 ;
371376 if (method->value == " setLocale" ) {
372377 // Decode and pass the list of locale data onwards to dart.
373378 auto args = root.FindMember (" args" );
374- if (args == root.MemberEnd () || !args->value .IsArray ())
379+ if (args == root.MemberEnd () || !args->value .IsArray ()) {
375380 return false ;
381+ }
376382
377- if (args->value .Size () % strings_per_locale != 0 )
383+ if (args->value .Size () % strings_per_locale != 0 ) {
378384 return false ;
385+ }
379386 std::vector<std::string> locale_data;
380387 for (size_t locale_index = 0 ; locale_index < args->value .Size ();
381388 locale_index += strings_per_locale) {
382389 if (!args->value [locale_index].IsString () ||
383- !args->value [locale_index + 1 ].IsString ())
390+ !args->value [locale_index + 1 ].IsString ()) {
384391 return false ;
392+ }
385393 locale_data.push_back (args->value [locale_index].GetString ());
386394 locale_data.push_back (args->value [locale_index + 1 ].GetString ());
387395 locale_data.push_back (args->value [locale_index + 2 ].GetString ());
@@ -429,8 +437,9 @@ void Engine::StopAnimator() {
429437}
430438
431439void Engine::StartAnimatorIfPossible () {
432- if (activity_running_ && have_surface_)
440+ if (activity_running_ && have_surface_) {
433441 animator_->Start ();
442+ }
434443}
435444
436445std::string Engine::DefaultRouteName () {
@@ -445,14 +454,16 @@ void Engine::ScheduleFrame(bool regenerate_layer_tree) {
445454}
446455
447456void Engine::Render (std::unique_ptr<flutter::LayerTree> layer_tree) {
448- if (!layer_tree)
457+ if (!layer_tree) {
449458 return ;
459+ }
450460
451461 // Ensure frame dimensions are sane.
452462 if (layer_tree->frame_size ().isEmpty () ||
453463 layer_tree->frame_physical_depth () <= 0 .0f ||
454- layer_tree->frame_device_pixel_ratio () <= 0 .0f )
464+ layer_tree->frame_device_pixel_ratio () <= 0 .0f ) {
455465 return ;
466+ }
456467
457468 animator_->Render (std::move (layer_tree));
458469}
0 commit comments