1
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
- // FLUTTER_NOLINT
5
4
6
5
#include " flutter/shell/common/engine.h"
7
6
@@ -281,38 +280,40 @@ void Engine::SetViewportMetrics(const ViewportMetrics& metrics) {
281
280
viewport_metrics_ = metrics;
282
281
runtime_controller_->SetViewportMetrics (viewport_metrics_);
283
282
if (animator_) {
284
- if (dimensions_changed)
283
+ if (dimensions_changed) {
285
284
animator_->SetDimensionChangePending ();
286
- if (have_surface_)
285
+ }
286
+ if (have_surface_) {
287
287
ScheduleFrame ();
288
+ }
288
289
}
289
290
}
290
291
291
292
void 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 ())) {
294
296
return ;
295
- } else if (message->channel () == kLocalizationChannel ) {
296
- if (HandleLocalizationPlatformMessage (message.get ()))
297
+ }
298
+ } else if (channel == kLocalizationChannel ) {
299
+ if (HandleLocalizationPlatformMessage (message.get ())) {
297
300
return ;
298
- } else if (message->channel () == kSettingsChannel ) {
301
+ }
302
+ } else if (channel == kSettingsChannel ) {
299
303
HandleSettingsPlatformMessage (message.get ());
300
304
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 ;
301
309
}
302
310
303
311
if (runtime_controller_->IsRootIsolateRunning () &&
304
312
runtime_controller_->DispatchPlatformMessage (std::move (message))) {
305
313
return ;
306
314
}
307
315
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;
316
317
}
317
318
318
319
bool Engine::HandleLifecyclePlatformMessage (PlatformMessage* message) {
@@ -345,12 +346,14 @@ bool Engine::HandleNavigationPlatformMessage(
345
346
346
347
rapidjson::Document document;
347
348
document.Parse (reinterpret_cast <const char *>(data.data ()), data.size ());
348
- if (document.HasParseError () || !document.IsObject ())
349
+ if (document.HasParseError () || !document.IsObject ()) {
349
350
return false ;
351
+ }
350
352
auto root = document.GetObject ();
351
353
auto method = root.FindMember (" method" );
352
- if (method->value != " setInitialRoute" )
354
+ if (method->value != " setInitialRoute" ) {
353
355
return false ;
356
+ }
354
357
auto route = root.FindMember (" args" );
355
358
initial_route_ = std::move (route->value .GetString ());
356
359
return true ;
@@ -361,27 +364,32 @@ bool Engine::HandleLocalizationPlatformMessage(PlatformMessage* message) {
361
364
362
365
rapidjson::Document document;
363
366
document.Parse (reinterpret_cast <const char *>(data.data ()), data.size ());
364
- if (document.HasParseError () || !document.IsObject ())
367
+ if (document.HasParseError () || !document.IsObject ()) {
365
368
return false ;
369
+ }
366
370
auto root = document.GetObject ();
367
371
auto method = root.FindMember (" method" );
368
- if (method == root.MemberEnd ())
372
+ if (method == root.MemberEnd ()) {
369
373
return false ;
374
+ }
370
375
const size_t strings_per_locale = 4 ;
371
376
if (method->value == " setLocale" ) {
372
377
// Decode and pass the list of locale data onwards to dart.
373
378
auto args = root.FindMember (" args" );
374
- if (args == root.MemberEnd () || !args->value .IsArray ())
379
+ if (args == root.MemberEnd () || !args->value .IsArray ()) {
375
380
return false ;
381
+ }
376
382
377
- if (args->value .Size () % strings_per_locale != 0 )
383
+ if (args->value .Size () % strings_per_locale != 0 ) {
378
384
return false ;
385
+ }
379
386
std::vector<std::string> locale_data;
380
387
for (size_t locale_index = 0 ; locale_index < args->value .Size ();
381
388
locale_index += strings_per_locale) {
382
389
if (!args->value [locale_index].IsString () ||
383
- !args->value [locale_index + 1 ].IsString ())
390
+ !args->value [locale_index + 1 ].IsString ()) {
384
391
return false ;
392
+ }
385
393
locale_data.push_back (args->value [locale_index].GetString ());
386
394
locale_data.push_back (args->value [locale_index + 1 ].GetString ());
387
395
locale_data.push_back (args->value [locale_index + 2 ].GetString ());
@@ -429,8 +437,9 @@ void Engine::StopAnimator() {
429
437
}
430
438
431
439
void Engine::StartAnimatorIfPossible () {
432
- if (activity_running_ && have_surface_)
440
+ if (activity_running_ && have_surface_) {
433
441
animator_->Start ();
442
+ }
434
443
}
435
444
436
445
std::string Engine::DefaultRouteName () {
@@ -445,14 +454,16 @@ void Engine::ScheduleFrame(bool regenerate_layer_tree) {
445
454
}
446
455
447
456
void Engine::Render (std::unique_ptr<flutter::LayerTree> layer_tree) {
448
- if (!layer_tree)
457
+ if (!layer_tree) {
449
458
return ;
459
+ }
450
460
451
461
// Ensure frame dimensions are sane.
452
462
if (layer_tree->frame_size ().isEmpty () ||
453
463
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 ) {
455
465
return ;
466
+ }
456
467
457
468
animator_->Render (std::move (layer_tree));
458
469
}
0 commit comments