Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -281,38 +280,40 @@ 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<PlatformMessage> 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() &&
runtime_controller_->DispatchPlatformMessage(std::move(message))) {
return;
}

// If there's no runtime_, we may still need to set the initial route.
if (message->channel() == kNavigationChannel) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the navigation channel check to the else if block above is now preventing the runtime_controller from receiving navigation messages. The back button on Android no longer works.

HandleNavigationPlatformMessage(std::move(message));
return;
}

FML_DLOG(WARNING) << "Dropping platform message on channel: "
<< message->channel();
FML_DLOG(WARNING) << "Dropping platform message on channel: " << channel;
}

bool Engine::HandleLifecyclePlatformMessage(PlatformMessage* message) {
Expand Down Expand Up @@ -345,12 +346,14 @@ bool Engine::HandleNavigationPlatformMessage(

rapidjson::Document document;
document.Parse(reinterpret_cast<const char*>(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;
Expand All @@ -361,27 +364,32 @@ bool Engine::HandleLocalizationPlatformMessage(PlatformMessage* message) {

rapidjson::Document document;
document.Parse(reinterpret_cast<const char*>(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<std::string> 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());
Expand Down Expand Up @@ -429,8 +437,9 @@ void Engine::StopAnimator() {
}

void Engine::StartAnimatorIfPossible() {
if (activity_running_ && have_surface_)
if (activity_running_ && have_surface_) {
animator_->Start();
}
}

std::string Engine::DefaultRouteName() {
Expand All @@ -445,14 +454,16 @@ void Engine::ScheduleFrame(bool regenerate_layer_tree) {
}

void Engine::Render(std::unique_ptr<flutter::LayerTree> 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));
}
Expand Down
6 changes: 5 additions & 1 deletion shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,11 @@ 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 regenerating the layer
/// tree.
void ScheduleFrame() { ScheduleFrame(true); }

// |RuntimeDelegate|
FontCollection& GetFontCollection() override;
Expand Down