allow_disabling_blink_scheduler_throttling_per_renderview.patch 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: deepak1556 <[email protected]>
  3. Date: Mon, 18 May 2020 11:12:26 -0700
  4. Subject: allow disabling blink scheduler throttling per RenderView
  5. This allows us to disable throttling for hidden windows.
  6. diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc
  7. index ce54ce5ee0d4f421e34e2ad7c35334b5f608609f..8193988e5e9312dada93a00d38f50931acc57ee9 100644
  8. --- a/content/browser/renderer_host/render_view_host_impl.cc
  9. +++ b/content/browser/renderer_host/render_view_host_impl.cc
  10. @@ -628,6 +628,11 @@ void RenderViewHostImpl::SetBackgroundOpaque(bool opaque) {
  11. GetWidget()->GetAssociatedFrameWidget()->SetBackgroundOpaque(opaque);
  12. }
  13. +void RenderViewHostImpl::SetSchedulerThrottling(bool allowed) {
  14. + if (auto& broadcast = GetAssociatedPageBroadcast())
  15. + broadcast->SetSchedulerThrottling(allowed);
  16. +}
  17. +
  18. bool RenderViewHostImpl::IsMainFrameActive() {
  19. return is_active();
  20. }
  21. diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h
  22. index 43fb3715553154f261a10bdc2133e66f456f9cd6..7950cc266c525d6e6e12282ac48311e4da1fc418 100644
  23. --- a/content/browser/renderer_host/render_view_host_impl.h
  24. +++ b/content/browser/renderer_host/render_view_host_impl.h
  25. @@ -137,6 +137,7 @@ class CONTENT_EXPORT RenderViewHostImpl
  26. bool IsRenderViewLive() override;
  27. void WriteIntoTrace(perfetto::TracedValue context) override;
  28. + void SetSchedulerThrottling(bool allowed) override;
  29. void SendWebPreferencesToRenderer();
  30. void SendRendererPreferencesToRenderer(
  31. const blink::RendererPreferences& preferences);
  32. diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
  33. index 740d1c322b740d374dd0287d99daebc1fe39ceda..f6ed1402120c0d8b30356c87a52d88fe39ed08d9 100644
  34. --- a/content/public/browser/render_view_host.h
  35. +++ b/content/public/browser/render_view_host.h
  36. @@ -90,6 +90,9 @@ class CONTENT_EXPORT RenderViewHost {
  37. // Write a representation of this object into a trace.
  38. virtual void WriteIntoTrace(perfetto::TracedValue context) = 0;
  39. + // Disable/Enable scheduler throttling.
  40. + virtual void SetSchedulerThrottling(bool allowed) = 0;
  41. +
  42. private:
  43. // This interface should only be implemented inside content.
  44. friend class RenderViewHostImpl;
  45. diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
  46. index a4e38fd9825fdb2c16f728d8012bb2392cb31dfe..2239f82411d0ba73b95020e18d3838507521dd1c 100644
  47. --- a/content/renderer/render_view_impl.h
  48. +++ b/content/renderer/render_view_impl.h
  49. @@ -154,6 +154,8 @@ class CONTENT_EXPORT RenderViewImpl : public blink::WebViewClient,
  50. static WindowOpenDisposition NavigationPolicyToDisposition(
  51. blink::WebNavigationPolicy policy);
  52. + void OnSetSchedulerThrottling(bool allowed);
  53. +
  54. // ---------------------------------------------------------------------------
  55. // ADDING NEW FUNCTIONS? Please keep private functions alphabetized and put
  56. // it in the same order in the .cc file as it was in the header.
  57. diff --git a/third_party/blink/public/mojom/page/page.mojom b/third_party/blink/public/mojom/page/page.mojom
  58. index 8521520bb9ea48686096480700966dabae1de777..a9ef1a5f2ad6882308790cf571a3099815e68f80 100644
  59. --- a/third_party/blink/public/mojom/page/page.mojom
  60. +++ b/third_party/blink/public/mojom/page/page.mojom
  61. @@ -80,4 +80,7 @@ interface PageBroadcast {
  62. // Sent to whole page, but should only be used by the main frame.
  63. SetPageBaseBackgroundColor(skia.mojom.SkColor? color);
  64. +
  65. + // Whether to enable the Renderer scheduler background throttling.
  66. + SetSchedulerThrottling(bool allowed);
  67. };
  68. diff --git a/third_party/blink/public/web/web_view.h b/third_party/blink/public/web/web_view.h
  69. index f54b993e9fb9fedcedef327290c2e5d706c699a7..73874e124e2810f07b72fc094f57c85c0fcf1dbb 100644
  70. --- a/third_party/blink/public/web/web_view.h
  71. +++ b/third_party/blink/public/web/web_view.h
  72. @@ -366,6 +366,7 @@ class WebView {
  73. // Scheduling -----------------------------------------------------------
  74. virtual PageScheduler* Scheduler() const = 0;
  75. + virtual void SetSchedulerThrottling(bool allowed) = 0;
  76. // Visibility -----------------------------------------------------------
  77. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
  78. index 2f9022d37ab989ea5bc2946ff6f0aeff22bf9fab..c493aa8366366da89f642d77838169deda8b210a 100644
  79. --- a/third_party/blink/renderer/core/exported/web_view_impl.cc
  80. +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
  81. @@ -3594,6 +3594,13 @@ PageScheduler* WebViewImpl::Scheduler() const {
  82. return GetPage()->GetPageScheduler();
  83. }
  84. +void WebViewImpl::SetSchedulerThrottling(bool allowed) {
  85. + DCHECK(GetPage());
  86. + scheduler_throttling_allowed_ = allowed;
  87. + GetPage()->GetPageScheduler()->SetPageVisible(allowed ?
  88. + (GetVisibilityState() == mojom::blink::PageVisibilityState::kVisible) : true);
  89. +}
  90. +
  91. void WebViewImpl::SetVisibilityState(
  92. mojom::blink::PageVisibilityState visibility_state,
  93. bool is_initial_state) {
  94. @@ -3605,7 +3612,8 @@ void WebViewImpl::SetVisibilityState(
  95. }
  96. GetPage()->SetVisibilityState(visibility_state, is_initial_state);
  97. GetPage()->GetPageScheduler()->SetPageVisible(
  98. - visibility_state == mojom::blink::PageVisibilityState::kVisible);
  99. + scheduler_throttling_allowed_ ?
  100. + (visibility_state == mojom::blink::PageVisibilityState::kVisible) : true);
  101. }
  102. mojom::blink::PageVisibilityState WebViewImpl::GetVisibilityState() {
  103. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.h b/third_party/blink/renderer/core/exported/web_view_impl.h
  104. index 97e3d30f1427b56d4711ca358bef74397affa480..faf957547df2a80f4fa267733f6145776a865853 100644
  105. --- a/third_party/blink/renderer/core/exported/web_view_impl.h
  106. +++ b/third_party/blink/renderer/core/exported/web_view_impl.h
  107. @@ -414,6 +414,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  108. LocalDOMWindow* PagePopupWindow() const;
  109. PageScheduler* Scheduler() const override;
  110. + void SetSchedulerThrottling(bool allowed) override;
  111. void SetVisibilityState(mojom::blink::PageVisibilityState visibility_state,
  112. bool is_initial_state) override;
  113. mojom::blink::PageVisibilityState GetVisibilityState() override;
  114. @@ -845,6 +846,8 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  115. // If true, we send IPC messages when |preferred_size_| changes.
  116. bool send_preferred_size_changes_ = false;
  117. + bool scheduler_throttling_allowed_ = true;
  118. +
  119. // Whether the preferred size may have changed and |UpdatePreferredSize| needs
  120. // to be called.
  121. bool needs_preferred_size_update_ = true;