Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-land "Buffer lifecycle in WindowData" #8032

Merged
merged 3 commits into from
Mar 6, 2019
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
4 changes: 4 additions & 0 deletions lib/stub_ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ void _updateUserSettingsData(String jsonData) {
_updateAlwaysUse24HourFormat(data['alwaysUse24HourFormat']);
}

void _updateLifecycleState(String state) {
window._initialLifecycleState ??= state;
}

void _updateTextScaleFactor(double textScaleFactor) {
window._textScaleFactor = textScaleFactor;
_invoke(window.onTextScaleFactorChanged, window._onTextScaleFactorChangedZone);
Expand Down
9 changes: 9 additions & 0 deletions lib/stub_ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,15 @@ class Window {
_onLocaleChangedZone = Zone.current;
}

/// The lifecycle state immediately after dart isolate initialization.
///
/// This property will not be updated as the lifecycle changes.
///
/// It is used to initialize [SchedulerBinding.lifecycleState] at startup
/// with any buffered lifecycle state events.
String get initialLifecycleState => _initialLifecycleState;
String _initialLifecycleState;

/// The setting indicating the current brightness mode of the host platform.
/// If the platform has no preference, [platformBrightness] defaults to [Brightness.light].
Brightness get platformBrightness => _platformBrightness;
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ void _updateUserSettingsData(String jsonData) {
_updatePlatformBrightness(data['platformBrightness']);
}

@pragma('vm:entry-point')
// ignore: unused_element
void _updateLifecycleState(String state) {
window._initialLifecycleState ??= state;
}


void _updateTextScaleFactor(double textScaleFactor) {
window._textScaleFactor = textScaleFactor;
_invoke(window.onTextScaleFactorChanged, window._onTextScaleFactorChangedZone);
Expand Down
9 changes: 9 additions & 0 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,15 @@ class Window {
_onLocaleChangedZone = Zone.current;
}

/// The lifecycle state immediately after dart isolate initialization.
///
/// This property will not be updated as the lifecycle changes.
///
/// It is used to initialize [SchedulerBinding.lifecycleState] at startup
/// with any buffered lifecycle state events.
String get initialLifecycleState => _initialLifecycleState;
String _initialLifecycleState;

/// The system-reported text scale.
///
/// This establishes the text scaling factor to use when rendering text,
Expand Down
12 changes: 12 additions & 0 deletions lib/ui/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ void Window::UpdateUserSettingsData(const std::string& data) {
}));
}

void Window::UpdateLifecycleState(const std::string& data) {
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
if (!dart_state)
return;
tonic::DartState::Scope scope(dart_state);
tonic::LogIfError(tonic::DartInvokeField(library_.value(),
"_updateLifecycleState",
{
tonic::StdStringToDart(data),
}));
}

void Window::UpdateSemanticsEnabled(bool enabled) {
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
if (!dart_state)
Expand Down
1 change: 1 addition & 0 deletions lib/ui/window/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Window final {
void UpdateWindowMetrics(const ViewportMetrics& metrics);
void UpdateLocales(const std::vector<std::string>& locales);
void UpdateUserSettingsData(const std::string& data);
void UpdateLifecycleState(const std::string& data);
void UpdateSemanticsEnabled(bool enabled);
void UpdateAccessibilityFeatures(int32_t flags);
void DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
Expand Down
14 changes: 13 additions & 1 deletion runtime/runtime_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ bool RuntimeController::FlushRuntimeStateToIsolate() {
SetLocales(window_data_.locale_data) &&
SetSemanticsEnabled(window_data_.semantics_enabled) &&
SetAccessibilityFeatures(window_data_.accessibility_feature_flags_) &&
SetUserSettingsData(window_data_.user_settings_data);
SetUserSettingsData(window_data_.user_settings_data) &&
SetLifecycleState(window_data_.lifecycle_state);
}

bool RuntimeController::SetViewportMetrics(const ViewportMetrics& metrics) {
Expand Down Expand Up @@ -164,6 +165,17 @@ bool RuntimeController::SetUserSettingsData(const std::string& data) {
return false;
}

bool RuntimeController::SetLifecycleState(const std::string& data) {
window_data_.lifecycle_state = data;

if (auto* window = GetWindowIfAvailable()) {
window->UpdateLifecycleState(window_data_.lifecycle_state);
return true;
}

return false;
}

bool RuntimeController::SetSemanticsEnabled(bool enabled) {
window_data_.semantics_enabled = enabled;

Expand Down
3 changes: 3 additions & 0 deletions runtime/runtime_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class RuntimeController final : public WindowClient {

bool SetUserSettingsData(const std::string& data);

bool SetLifecycleState(const std::string& data);

bool SetSemanticsEnabled(bool enabled);

bool SetAccessibilityFeatures(int32_t flags);
Expand Down Expand Up @@ -111,6 +113,7 @@ class RuntimeController final : public WindowClient {
std::string variant_code;
std::vector<std::string> locale_data;
std::string user_settings_data = "{}";
std::string lifecycle_state;
bool semantics_enabled = false;
bool assistive_technology_enabled = false;
int32_t accessibility_feature_flags_ = 0;
Expand Down
2 changes: 2 additions & 0 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ bool Engine::HandleLifecyclePlatformMessage(blink::PlatformMessage* message) {
if (state == "AppLifecycleState.resumed" && have_surface_) {
ScheduleFrame();
}
runtime_controller_->SetLifecycleState(state);
// Always forward these messages to the framework by returning false.
return false;
}

Expand Down