Commit 954dc16f authored by Maggie Chen's avatar Maggie Chen Committed by Commit Bot

Add observer for DisplayMetricsChanged

This is to notify DirectCompositionSurfaceWin if there are display
metrics change(s) such as desktop resolution on the monitor(s).
DirectCompositionSurfaceWin needs the current monitor size.

Bug: 1027046
Change-Id: I0df02aa4a566723468219d9333b5f26379688700
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523903Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarMaggie Chen <magchen@chromium.org>
Commit-Queue: Maggie Chen <magchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826499}
parent a5532a28
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "components/viz/host/host_gpu_memory_buffer_manager.h" #include "components/viz/host/host_gpu_memory_buffer_manager.h"
#include <string>
#include <utility> #include <utility>
#include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
...@@ -163,6 +165,8 @@ class TestGpuService : public mojom::GpuService { ...@@ -163,6 +165,8 @@ class TestGpuService : public mojom::GpuService {
void DisplayRemoved() override {} void DisplayRemoved() override {}
void DisplayMetricsChanged() override {}
void DestroyAllChannels() override {} void DestroyAllChannels() override {}
void OnBackgroundCleanup() override {} void OnBackgroundCleanup() override {}
......
...@@ -996,6 +996,19 @@ void GpuServiceImpl::DisplayRemoved() { ...@@ -996,6 +996,19 @@ void GpuServiceImpl::DisplayRemoved() {
ui::GpuSwitchingManager::GetInstance()->NotifyDisplayRemoved(); ui::GpuSwitchingManager::GetInstance()->NotifyDisplayRemoved();
} }
void GpuServiceImpl::DisplayMetricsChanged() {
if (io_runner_->BelongsToCurrentThread()) {
main_runner_->PostTask(
FROM_HERE,
base::BindOnce(&GpuServiceImpl::DisplayMetricsChanged, weak_ptr_));
return;
}
DVLOG(1) << "GPU: Display Metrics changed";
if (!in_host_process())
ui::GpuSwitchingManager::GetInstance()->NotifyDisplayMetricsChanged();
}
void GpuServiceImpl::DestroyAllChannels() { void GpuServiceImpl::DestroyAllChannels() {
if (io_runner_->BelongsToCurrentThread()) { if (io_runner_->BelongsToCurrentThread()) {
main_runner_->PostTask( main_runner_->PostTask(
......
...@@ -175,6 +175,7 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate, ...@@ -175,6 +175,7 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
void GpuSwitched(gl::GpuPreference active_gpu_heuristic) override; void GpuSwitched(gl::GpuPreference active_gpu_heuristic) override;
void DisplayAdded() override; void DisplayAdded() override;
void DisplayRemoved() override; void DisplayRemoved() override;
void DisplayMetricsChanged() override;
void DestroyAllChannels() override; void DestroyAllChannels() override;
void OnBackgroundCleanup() override; void OnBackgroundCleanup() override;
void OnBackgrounded() override; void OnBackgrounded() override;
......
...@@ -369,6 +369,13 @@ void GpuDataManagerImpl::OnDisplayRemoved(const display::Display& old_display) { ...@@ -369,6 +369,13 @@ void GpuDataManagerImpl::OnDisplayRemoved(const display::Display& old_display) {
private_->OnDisplayRemoved(old_display); private_->OnDisplayRemoved(old_display);
} }
void GpuDataManagerImpl::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t changed_metrics) {
base::AutoLock auto_lock(lock_);
private_->OnDisplayMetricsChanged(display, changed_metrics);
}
// static // static
void GpuDataManagerImpl::BindReceiver( void GpuDataManagerImpl::BindReceiver(
mojo::PendingReceiver<blink::mojom::GpuDataManager> receiver) { mojo::PendingReceiver<blink::mojom::GpuDataManager> receiver) {
......
...@@ -178,6 +178,8 @@ class CONTENT_EXPORT GpuDataManagerImpl : public GpuDataManager, ...@@ -178,6 +178,8 @@ class CONTENT_EXPORT GpuDataManagerImpl : public GpuDataManager,
// DisplayObserver overrides. // DisplayObserver overrides.
void OnDisplayAdded(const display::Display& new_display) override; void OnDisplayAdded(const display::Display& new_display) override;
void OnDisplayRemoved(const display::Display& old_display) override; void OnDisplayRemoved(const display::Display& old_display) override;
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override;
// Binds a new Mojo receiver to handle requests from a renderer. // Binds a new Mojo receiver to handle requests from a renderer.
static void BindReceiver( static void BindReceiver(
......
...@@ -1335,6 +1335,32 @@ void GpuDataManagerImplPrivate::OnDisplayRemoved( ...@@ -1335,6 +1335,32 @@ void GpuDataManagerImplPrivate::OnDisplayRemoved(
})); }));
} }
void GpuDataManagerImplPrivate::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t changed_metrics) {
#if defined(OS_WIN)
if (gpu_info_dx_diag_requested_) {
// Reset DxDiag flags so the data can be updated again
gpu_info_dx_diag_requested_ = false;
gpu_info_.dx_diagnostics = gpu::DxDiagNode();
// This DxDiag request goes to the unsandboxed GPU info collection GPU
// process while the notification below goes to the sandboxed GPU process.
RequestDxDiagNodeData();
}
#endif
base::AutoUnlock unlock(owner_->lock_);
// Notify observers in the browser process.
ui::GpuSwitchingManager::GetInstance()->NotifyDisplayMetricsChanged();
// Pass the notification to the GPU process to notify observers there.
GpuProcessHost::CallOnIO(GPU_PROCESS_KIND_SANDBOXED, false /* force_create */,
base::BindOnce([](GpuProcessHost* host) {
if (host)
host->gpu_service()->DisplayMetricsChanged();
}));
}
bool GpuDataManagerImplPrivate::UpdateActiveGpu(uint32_t vendor_id, bool GpuDataManagerImplPrivate::UpdateActiveGpu(uint32_t vendor_id,
uint32_t device_id) { uint32_t device_id) {
// Heuristics for dual-GPU detection. // Heuristics for dual-GPU detection.
......
...@@ -129,6 +129,8 @@ class CONTENT_EXPORT GpuDataManagerImplPrivate { ...@@ -129,6 +129,8 @@ class CONTENT_EXPORT GpuDataManagerImplPrivate {
void OnDisplayAdded(const display::Display& new_display); void OnDisplayAdded(const display::Display& new_display);
void OnDisplayRemoved(const display::Display& old_display); void OnDisplayRemoved(const display::Display& old_display);
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics);
private: private:
friend class GpuDataManagerImplPrivateTest; friend class GpuDataManagerImplPrivateTest;
......
...@@ -107,6 +107,7 @@ class TestGpuService : public viz::mojom::GpuService { ...@@ -107,6 +107,7 @@ class TestGpuService : public viz::mojom::GpuService {
void GpuSwitched(gl::GpuPreference active_gpu_heuristic) override {} void GpuSwitched(gl::GpuPreference active_gpu_heuristic) override {}
void DisplayAdded() override {} void DisplayAdded() override {}
void DisplayRemoved() override {} void DisplayRemoved() override {}
void DisplayMetricsChanged() override {}
void DestroyAllChannels() override {} void DestroyAllChannels() override {}
void OnBackgroundCleanup() override {} void OnBackgroundCleanup() override {}
void OnBackgrounded() override {} void OnBackgrounded() override {}
......
...@@ -124,6 +124,9 @@ interface GpuService { ...@@ -124,6 +124,9 @@ interface GpuService {
// Tells GPU that host has seen a monitor being unplugged. // Tells GPU that host has seen a monitor being unplugged.
DisplayRemoved(); DisplayRemoved();
// Tells GPU that host has seen the display metrics changed.
DisplayMetricsChanged();
// Tells GPU that all GPU channels are to be destroyed. // Tells GPU that all GPU channels are to be destroyed.
DestroyAllChannels(); DestroyAllChannels();
......
...@@ -849,6 +849,8 @@ void DirectCompositionSurfaceWin::OnDisplayRemoved() { ...@@ -849,6 +849,8 @@ void DirectCompositionSurfaceWin::OnDisplayRemoved() {
RunOverlayHdrGpuInfoUpdateCallback(); RunOverlayHdrGpuInfoUpdateCallback();
} }
void DirectCompositionSurfaceWin::OnDisplayMetricsChanged() {}
scoped_refptr<base::TaskRunner> scoped_refptr<base::TaskRunner>
DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() {
return child_window_.GetTaskRunnerForTesting(); return child_window_.GetTaskRunnerForTesting();
......
...@@ -145,6 +145,7 @@ class GL_EXPORT DirectCompositionSurfaceWin : public GLSurfaceEGL, ...@@ -145,6 +145,7 @@ class GL_EXPORT DirectCompositionSurfaceWin : public GLSurfaceEGL,
void OnGpuSwitched(gl::GpuPreference active_gpu_heuristic) override; void OnGpuSwitched(gl::GpuPreference active_gpu_heuristic) override;
void OnDisplayAdded() override; void OnDisplayAdded() override;
void OnDisplayRemoved() override; void OnDisplayRemoved() override;
void OnDisplayMetricsChanged() override;
HWND window() const { return window_; } HWND window() const { return window_; }
......
...@@ -39,4 +39,9 @@ void GpuSwitchingManager::NotifyDisplayRemoved() { ...@@ -39,4 +39,9 @@ void GpuSwitchingManager::NotifyDisplayRemoved() {
observer.OnDisplayRemoved(); observer.OnDisplayRemoved();
} }
void GpuSwitchingManager::NotifyDisplayMetricsChanged() {
for (GpuSwitchingObserver& observer : observer_list_)
observer.OnDisplayMetricsChanged();
}
} // namespace ui } // namespace ui
...@@ -40,6 +40,10 @@ class GL_EXPORT GpuSwitchingManager { ...@@ -40,6 +40,10 @@ class GL_EXPORT GpuSwitchingManager {
// Called when a monitor is unplugged. Only Windows is supported for now. // Called when a monitor is unplugged. Only Windows is supported for now.
void NotifyDisplayRemoved(); void NotifyDisplayRemoved();
// Called when the display metrics changed. Only Windows is supported for
// now.
void NotifyDisplayMetricsChanged();
private: private:
friend struct base::DefaultSingletonTraits<GpuSwitchingManager>; friend struct base::DefaultSingletonTraits<GpuSwitchingManager>;
......
...@@ -20,6 +20,9 @@ class GL_EXPORT GpuSwitchingObserver { ...@@ -20,6 +20,9 @@ class GL_EXPORT GpuSwitchingObserver {
// Called for any observer when a monitor is unplugged. // Called for any observer when a monitor is unplugged.
virtual void OnDisplayRemoved() {} virtual void OnDisplayRemoved() {}
// Called for any observer when the display metrics changed.
virtual void OnDisplayMetricsChanged() {}
}; };
} // namespace ui } // namespace ui
......
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