Commit e33c0c59 authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Android OOP-D: Don't recreate viz proc while backgrounded

If we're backgrounded, the OS may aggressively kill procs we try to
start. Avoid creating the Viz proc while backgrounded, instead wait for
us to come to foreground.

Bug: 866631
Change-Id: I01c73707bbb65dcbc87eda1b344de2ce72647b5d
Reviewed-on: https://chromium-review.googlesource.com/1239219
Commit-Queue: Eric Karl <ericrk@chromium.org>
Reviewed-by: default avatarFady Samuel <fsamuel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593350}
parent ba2cdbfe
...@@ -184,7 +184,7 @@ class CompositorDependencies { ...@@ -184,7 +184,7 @@ class CompositorDependencies {
// Set up a callback to automatically re-connect if we lose our // Set up a callback to automatically re-connect if we lose our
// connection. // connection.
host_frame_sink_manager.SetConnectionLostCallback(base::BindRepeating( host_frame_sink_manager.SetConnectionLostCallback(base::BindRepeating(
[]() { CompositorDependencies::Get().CreateVizFrameSinkManager(); })); []() { CompositorDependencies::Get().OnVizFrameSinkManagerLost(); }));
BrowserMainLoop::GetInstance() BrowserMainLoop::GetInstance()
->gpu_channel_establish_factory() ->gpu_channel_establish_factory()
...@@ -236,8 +236,8 @@ class CompositorDependencies { ...@@ -236,8 +236,8 @@ class CompositorDependencies {
CreateVizFrameSinkManager(); CreateVizFrameSinkManager();
} }
// Unretained is safe as CompositorDependencies is a static instance which // Ensure we're in the correct state at start up.
// is leaked at the end. OnApplicationStateChange(app_listener_->GetState());
} }
void OnReadyToConnectVizFrameSinkManagerOnMainThread( void OnReadyToConnectVizFrameSinkManagerOnMainThread(
...@@ -274,6 +274,21 @@ class CompositorDependencies { ...@@ -274,6 +274,21 @@ class CompositorDependencies {
} }
} }
void OnVizFrameSinkManagerLost() {
needs_recreate_viz_frame_sink_manager_ = true;
TryRecreateVizFrameSinkManagerIfNeeded();
}
void TryRecreateVizFrameSinkManagerIfNeeded() {
// We don't recreate the frame sink manager if backgrounded, as the OS may
// repeatedly kill the resulting process. Instead wait until we come to the
// foreground.
if (needs_recreate_viz_frame_sink_manager_ && application_is_foreground_) {
needs_recreate_viz_frame_sink_manager_ = false;
CreateVizFrameSinkManager();
}
}
void EnqueueLowEndBackgroundCleanup() { void EnqueueLowEndBackgroundCleanup() {
if (base::SysInfo::IsLowEndDevice()) { if (base::SysInfo::IsLowEndDevice()) {
low_end_background_cleanup_task_.Reset( low_end_background_cleanup_task_.Reset(
...@@ -317,12 +332,15 @@ class CompositorDependencies { ...@@ -317,12 +332,15 @@ class CompositorDependencies {
GpuDataManagerImpl::GetInstance()->SetApplicationVisible(true); GpuDataManagerImpl::GetInstance()->SetApplicationVisible(true);
SendOnForegroundedToGpuService(); SendOnForegroundedToGpuService();
low_end_background_cleanup_task_.Cancel(); low_end_background_cleanup_task_.Cancel();
application_is_foreground_ = true;
TryRecreateVizFrameSinkManagerIfNeeded();
break; break;
case base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES: case base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES:
case base::android::APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES: case base::android::APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES:
GpuDataManagerImpl::GetInstance()->SetApplicationVisible(false); GpuDataManagerImpl::GetInstance()->SetApplicationVisible(false);
SendOnBackgroundedToGpuService(); SendOnBackgroundedToGpuService();
EnqueueLowEndBackgroundCleanup(); EnqueueLowEndBackgroundCleanup();
application_is_foreground_ = false;
} }
} }
...@@ -332,6 +350,8 @@ class CompositorDependencies { ...@@ -332,6 +350,8 @@ class CompositorDependencies {
// An instance of Android AppListener. // An instance of Android AppListener.
std::unique_ptr<base::android::ApplicationStatusListener> app_listener_; std::unique_ptr<base::android::ApplicationStatusListener> app_listener_;
bool application_is_foreground_ = true;
bool needs_recreate_viz_frame_sink_manager_ = false;
}; };
const unsigned int kMaxDisplaySwapBuffers = 1U; const unsigned int kMaxDisplaySwapBuffers = 1U;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment