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

Prevent gpu channel timeout when application not visible

We appear to frequently time-out the GPU channel when the appliction
backgrounds (or is already backgrounded) during an attempt to establish
a GPU channel.

This change causes timeouts to be surpressed while the application is
backgrounded

Bug: 897272
Change-Id: I3bc6307f737b0847d54525071ea946ce4a92b38c
Reviewed-on: https://chromium-review.googlesource.com/c/1292519Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Eric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601813}
parent 3358dabd
...@@ -351,6 +351,21 @@ BrowserGpuChannelHostFactory::GetGpuMemoryBufferManager() { ...@@ -351,6 +351,21 @@ BrowserGpuChannelHostFactory::GetGpuMemoryBufferManager() {
return gpu_memory_buffer_manager_.get(); return gpu_memory_buffer_manager_.get();
} }
// Ensures that any pending timeout is cancelled when we are backgrounded.
// Restarts the timeout when we return to the foreground.
void BrowserGpuChannelHostFactory::SetApplicationVisible(bool is_visible) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (is_visible_ == is_visible)
return;
is_visible_ = is_visible;
if (is_visible_) {
RestartTimeout();
} else {
timeout_.Stop();
}
}
gpu::GpuChannelHost* BrowserGpuChannelHostFactory::GetGpuChannel() { gpu::GpuChannelHost* BrowserGpuChannelHostFactory::GetGpuChannel() {
if (gpu_channel_.get() && !gpu_channel_->IsLost()) if (gpu_channel_.get() && !gpu_channel_->IsLost())
return gpu_channel_.get(); return gpu_channel_.get();
...@@ -377,7 +392,9 @@ void BrowserGpuChannelHostFactory::RestartTimeout() { ...@@ -377,7 +392,9 @@ void BrowserGpuChannelHostFactory::RestartTimeout() {
return; return;
} }
if (!pending_request_) // Don't restart the timeout if we aren't visible. This function will be
// re-called when we become visible again.
if (!pending_request_ || !is_visible_)
return; return;
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
......
...@@ -41,6 +41,10 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory ...@@ -41,6 +41,10 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
// thread stops. // thread stops.
void CloseChannel(); void CloseChannel();
// Notify the BrowserGpuChannelHostFactory of visibility, used to prevent
// timeouts while backgrounded.
void SetApplicationVisible(bool is_visible);
// Overridden from gpu::GpuChannelEstablishFactory: // Overridden from gpu::GpuChannelEstablishFactory:
// The factory will return a null GpuChannelHost in the callback during // The factory will return a null GpuChannelHost in the callback during
// shutdown. // shutdown.
...@@ -69,6 +73,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory ...@@ -69,6 +73,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
std::unique_ptr<gpu::GpuMemoryBufferManager, BrowserThread::DeleteOnIOThread> std::unique_ptr<gpu::GpuMemoryBufferManager, BrowserThread::DeleteOnIOThread>
gpu_memory_buffer_manager_; gpu_memory_buffer_manager_;
scoped_refptr<EstablishRequest> pending_request_; scoped_refptr<EstablishRequest> pending_request_;
bool is_visible_ = true;
base::OneShotTimer timeout_; base::OneShotTimer timeout_;
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h" #include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
#include "content/browser/browser_main_loop.h" #include "content/browser/browser_main_loop.h"
#include "content/browser/compositor/surface_utils.h" #include "content/browser/compositor/surface_utils.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
#include "content/browser/gpu/compositor_util.h" #include "content/browser/gpu/compositor_util.h"
#include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_process_host.h"
...@@ -133,6 +134,14 @@ void SendOnForegroundedToGpuService() { ...@@ -133,6 +134,14 @@ void SendOnForegroundedToGpuService() {
})); }));
} }
void BrowserGpuChannelHostFactorySetApplicationVisible(bool is_visible) {
// This code relies on the browser's GpuChannelEstablishFactory being the
// BrowserGpuChannelHostFactory.
DCHECK_EQ(BrowserMainLoop::GetInstance()->gpu_channel_establish_factory(),
BrowserGpuChannelHostFactory::instance());
BrowserGpuChannelHostFactory::instance()->SetApplicationVisible(is_visible);
}
// The client_id used here should not conflict with the client_id generated // The client_id used here should not conflict with the client_id generated
// from RenderWidgetHostImpl. // from RenderWidgetHostImpl.
constexpr uint32_t kDefaultClientId = 0u; constexpr uint32_t kDefaultClientId = 0u;
...@@ -238,6 +247,9 @@ class CompositorDependencies { ...@@ -238,6 +247,9 @@ class CompositorDependencies {
base::Unretained(this)))) { base::Unretained(this)))) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Ensure we're in the correct state at start up.
OnApplicationStateChange(app_listener_->GetState());
bool enable_viz = bool enable_viz =
base::FeatureList::IsEnabled(features::kVizDisplayCompositor); base::FeatureList::IsEnabled(features::kVizDisplayCompositor);
if (!enable_viz) { if (!enable_viz) {
...@@ -250,9 +262,6 @@ class CompositorDependencies { ...@@ -250,9 +262,6 @@ class CompositorDependencies {
} else { } else {
CreateVizFrameSinkManager(); CreateVizFrameSinkManager();
} }
// Ensure we're in the correct state at start up.
OnApplicationStateChange(app_listener_->GetState());
} }
void OnReadyToConnectVizFrameSinkManagerOnMainThread( void OnReadyToConnectVizFrameSinkManagerOnMainThread(
...@@ -340,18 +349,24 @@ class CompositorDependencies { ...@@ -340,18 +349,24 @@ class CompositorDependencies {
case base::android::APPLICATION_STATE_UNKNOWN: case base::android::APPLICATION_STATE_UNKNOWN:
case base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES: case base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES:
case base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES: case base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES:
if (application_is_foreground_)
return;
application_is_foreground_ = true;
GpuDataManagerImpl::GetInstance()->SetApplicationVisible(true); GpuDataManagerImpl::GetInstance()->SetApplicationVisible(true);
BrowserGpuChannelHostFactorySetApplicationVisible(true);
SendOnForegroundedToGpuService(); SendOnForegroundedToGpuService();
low_end_background_cleanup_task_.Cancel(); low_end_background_cleanup_task_.Cancel();
application_is_foreground_ = true;
TryEstablishVizConnectionIfNeeded(); TryEstablishVizConnectionIfNeeded();
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:
if (!application_is_foreground_)
return;
application_is_foreground_ = false;
GpuDataManagerImpl::GetInstance()->SetApplicationVisible(false); GpuDataManagerImpl::GetInstance()->SetApplicationVisible(false);
BrowserGpuChannelHostFactorySetApplicationVisible(false);
SendOnBackgroundedToGpuService(); SendOnBackgroundedToGpuService();
EnqueueLowEndBackgroundCleanup(); EnqueueLowEndBackgroundCleanup();
application_is_foreground_ = false;
} }
} }
......
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