fix_disabling_background_throttling_in_compositor.patch 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Michal Pichlinski <[email protected]>
  3. Date: Thu, 15 Jun 2023 23:04:48 +0200
  4. Subject: allow disabling throttling in the `viz::DisplayScheduler` per
  5. `ui::Compositor`
  6. In Chromium when the `viz::DisplayScheduler` is invisible it throttles
  7. its work by dropping frame draws and swaps.
  8. This patch allows disbling this throttling by preventing transition to
  9. invisible state of the `viz::DisplayScheduler` owned
  10. by the `ui::Compositor`.
  11. diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
  12. index b505f127b2e05e347f0bc55a8e6c2e07e645fa3e..41ca5c47b656b521f8d9cbf1e5fe7bc90f3e18e9 100644
  13. --- a/ui/compositor/compositor.cc
  14. +++ b/ui/compositor/compositor.cc
  15. @@ -340,7 +340,8 @@ void Compositor::SetLayerTreeFrameSink(
  16. if (display_private_) {
  17. disabled_swap_until_resize_ = false;
  18. display_private_->Resize(size());
  19. - display_private_->SetDisplayVisible(host_->IsVisible());
  20. + // Invisible display is throttling itself.
  21. + display_private_->SetDisplayVisible(background_throttling_ ? host_->IsVisible() : true);
  22. display_private_->SetDisplayColorSpaces(display_color_spaces_);
  23. display_private_->SetDisplayColorMatrix(
  24. gfx::SkM44ToTransform(display_color_matrix_));
  25. @@ -551,7 +552,9 @@ void Compositor::SetVisible(bool visible) {
  26. // updated then. We need to call this even if the visibility hasn't changed,
  27. // for the same reason.
  28. if (display_private_)
  29. - display_private_->SetDisplayVisible(visible);
  30. + // Invisible display is throttling itself.
  31. + display_private_->SetDisplayVisible(
  32. + background_throttling_ ? visible : true);
  33. if (changed) {
  34. observer_list_.Notify(&CompositorObserver::OnCompositorVisibilityChanged,
  35. @@ -1004,6 +1007,15 @@ void Compositor::MaybeUpdateObserveBeginFrame() {
  36. host_begin_frame_observer_->GetBoundRemote());
  37. }
  38. +void Compositor::SetBackgroundThrottling(bool background_throttling_enabled) {
  39. + background_throttling_ = background_throttling_enabled;
  40. + if (display_private_) {
  41. + // Invisible display is throttling itself.
  42. + display_private_->SetDisplayVisible(
  43. + background_throttling_ ? host_->IsVisible() : true);
  44. + }
  45. +}
  46. +
  47. #if BUILDFLAG(IS_CHROMEOS)
  48. void Compositor::SetSeamlessRefreshRates(
  49. const std::vector<float>& seamless_refresh_rates) {
  50. diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h
  51. index 970768eaa311139d0b27f5be893d601e20052825..cc5c2a704e339713a796196805a2aa05206d5b2e 100644
  52. --- a/ui/compositor/compositor.h
  53. +++ b/ui/compositor/compositor.h
  54. @@ -509,6 +509,10 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  55. const cc::LayerTreeSettings& GetLayerTreeSettings() const;
  56. + // Sets |background_throttling_| responsible for suspending drawing
  57. + // and switching frames.
  58. + void SetBackgroundThrottling(bool background_throttling_enabled);
  59. +
  60. size_t saved_events_metrics_count_for_testing() const {
  61. return host_->saved_events_metrics_count_for_testing();
  62. }
  63. @@ -657,6 +661,12 @@ class COMPOSITOR_EXPORT Compositor : public base::PowerSuspendObserver,
  64. // See go/report-ux-metrics-at-painting for details.
  65. bool animation_started_ = false;
  66. + // Background throttling is a default Chromium behaviour. It occurs
  67. + // when the |display_private_| is not visible by prevent drawing and swapping
  68. + // frames. When it is disabled we are keeping |display_private_| always
  69. + // visible in order to keep generating frames.
  70. + bool background_throttling_ = true;
  71. +
  72. TrackerId next_compositor_metrics_tracker_id_ = 1u;
  73. struct TrackerState {
  74. TrackerState();