[M108 Migration][API] Add ewk_context_max_refresh_rate_set 07/288007/4
authorayush.k123 <ayush.k123@samsung.com>
Wed, 8 Feb 2023 09:51:41 +0000 (15:21 +0530)
committerBot Blink <blinkbot@samsung.com>
Mon, 13 Feb 2023 06:28:08 +0000 (06:28 +0000)
To reduce current consumption, some devices need to set screen FPS limitation.
This api is added to set screen FPS limitation.

If max refresh rate is set as 30, each thread will work as below.
1) With |setInterval(16ms)|.
 - Renderer main thread : 60fps
 - Renderer raster thread : 30fps
 - Renderer compositor thread : 30fps
 - UI main thread : 30fps

2) With |setInterval(20ms)|
 - Renderer main thread : 50fps
 - Renderer raster thread : 30fps
 - Renderer compositor thread : 30fps
 - UI main thread : 30fps

3) With |requestAnimationFrame|
 - Renderer main thread : 30fps
 - Renderer raster thread : 30fps
 - Renderer compositor thread : 30fps
 - UI main thread : 30fps

References:
https://review.tizen.org/gerrit/270945

Change-Id: I05d8e28afe2b12ccf1d281c7634bab380a0e5b40
Signed-off-by: Ayush Kumar <ayush.k123@samsung.com>
20 files changed:
content/browser/web_contents/web_contents_impl.cc
content/public/common/content_switches.cc
content/public/common/content_switches.h
content/renderer/agent_scheduling_group.cc
third_party/blink/common/web_preferences/web_preferences.cc
third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc
third_party/blink/public/common/web_preferences/web_preferences.h
third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h
third_party/blink/public/mojom/BUILD.gn
third_party/blink/public/mojom/webpreferences/web_preferences.mojom
third_party/blink/public/web/web_frame_widget.h
third_party/blink/renderer/core/frame/web_frame_widget_impl.cc
third_party/blink/renderer/core/frame/web_frame_widget_impl.h
third_party/blink/renderer/platform/widget/widget_base.cc
third_party/blink/renderer/platform/widget/widget_base.h
tizen_src/ewk/efl_integration/eweb_context.cc
tizen_src/ewk/efl_integration/eweb_context.h
tizen_src/ewk/efl_integration/private/ewk_context_private.cc
tizen_src/ewk/efl_integration/private/ewk_context_private.h
tizen_src/ewk/efl_integration/public/ewk_context.cc

index 2ce1e682a3cfdd39c9db9b55647bbbbcd3fbdf66..17895cb2137e67296bcf4ac70448c25f9b677ee3 100644 (file)
@@ -2872,6 +2872,16 @@ const blink::web_pref::WebPreferences WebContentsImpl::ComputeWebPreferences() {
   prefs.user_gesture_required_for_presentation = !command_line.HasSwitch(
       switches::kDisableGestureRequirementForPresentation);
 
+#if BUILDFLAG(IS_TIZEN)
+  if (command_line.HasSwitch(switches::kMaxRefreshRate)) {
+    int refresh_rate = 0;
+    base::StringToInt(
+        command_line.GetSwitchValueASCII(switches::kMaxRefreshRate),
+        &refresh_rate);
+    prefs.max_refresh_rate = refresh_rate;
+  }
+#endif
+
   if (is_overlay_content_)
     prefs.hide_download_ui = true;
 
index 310961b48553e2de0eca68e1b4f6910c6c0ceaec..cde3d1cfb160e211e02d2b8d63406d931dd3170b 100644 (file)
@@ -1068,6 +1068,10 @@ const char kGpu2StartupDialog[] = "gpu2-startup-dialog";
 const char kAudioProcessHighPriority[] = "audio-process-high-priority";
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+const char kMaxRefreshRate[] = "max-refresh-rate";
+#endif
+
 #if defined(ENABLE_IPC_FUZZER)
 // Dumps IPC messages sent from renderer processes to the browser process to
 // the given directory. Used primarily to gather samples for IPC fuzzing.
index e3e3ddf3a4c03bab2f26e564435053a8acecedfc..e04843e82a604135156c1e2f01e02f125898c2b4 100644 (file)
@@ -297,6 +297,10 @@ CONTENT_EXPORT extern const char kGpu2StartupDialog[];
 CONTENT_EXPORT extern const char kAudioProcessHighPriority[];
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+CONTENT_EXPORT extern const char kMaxRefreshRate[];
+#endif
+
 #if defined(ENABLE_IPC_FUZZER)
 extern const char kIpcDumpDirectory[];
 extern const char kIpcFuzzerTestcase[];
index dcdbc2e2b2409e33b267a5a57b27dd740d4f5078..35246108714dc1a146986e179ab93d3e74329181 100644 (file)
 #include "third_party/blink/public/web/web_view.h"
 #include "third_party/blink/public/web/web_view_client.h"
 
+#if BUILDFLAG(IS_TIZEN)
+#include "third_party/blink/public/web/web_frame_widget.h"
+#endif
+
 namespace content {
 
 using ::IPC::ChannelMojo;
@@ -329,6 +333,15 @@ blink::WebView* AgentSchedulingGroup::CreateWebView(
   GetContentClient()->renderer()->WebViewCreated(
       web_view, was_created_by_renderer,
       params->outermost_origin ? &params->outermost_origin.value() : nullptr);
+
+#if BUILDFLAG(IS_TIZEN)
+  if (web_view->MainFrame() && web_view->MainFrame()->IsWebLocalFrame()) {
+    auto* frame_widget =
+        web_view->MainFrame()->ToWebLocalFrame()->LocalRoot()->FrameWidget();
+    frame_widget->SetMaxRefreshRate(params->web_preferences.max_refresh_rate);
+  }
+#endif
+
   return web_view;
 }
 
index 2257cb2aad2f29fab0f010361b028095f521a799..67b358e9ac659da52293e339f5c5bc36832d465d 100644 (file)
@@ -205,6 +205,9 @@ WebPreferences::WebPreferences()
 #endif
       low_priority_iframes_threshold(
           EffectiveConnectionType::kEffectiveConnectionUnknownType),
+#if BUILDFLAG(IS_TIZEN)
+      max_refresh_rate(-1),
+#endif
       picture_in_picture_enabled(true),
       translate_service_available(false),
       network_quality_estimator_web_holdback(
index f8792c52abc09a8fadbd4f3a478ce29c7f49c1a7..99b78f7aa78164c34120fc77be5632160951e480 100644 (file)
@@ -159,6 +159,9 @@ bool StructTraits<blink::mojom::WebPreferencesDataView,
   out->double_tap_to_zoom_enabled = data.double_tap_to_zoom_enabled();
   out->fullscreen_supported = data.fullscreen_supported();
   out->text_autosizing_enabled = data.text_autosizing_enabled();
+#if BUILDFLAG(IS_TIZEN)
+  out->max_refresh_rate = data.max_refresh_rate();
+#endif
 #if BUILDFLAG(IS_ANDROID)
   out->font_scale_factor = data.font_scale_factor();
   out->device_scale_adjustment = data.device_scale_adjustment();
index c141ba752da6a510e5d2d78194ffb755caf4575e..21c156f7c29e1fc2444f6508041521b7a214157e 100644 (file)
@@ -296,6 +296,10 @@ struct BLINK_COMMON_EXPORT WebPreferences {
   // TODO(changwan): remove this once we no longer support Android N.
   bool do_not_update_selection_on_mutating_selection_range;
 
+#if BUILDFLAG(IS_TIZEN)
+  int max_refresh_rate;
+#endif
+
   // Defines the current autoplay policy.
   blink::mojom::AutoplayPolicy autoplay_policy =
       blink::mojom::AutoplayPolicy::kNoUserGestureRequired;
index dafe321a88941d69c19c4348cbdf6fbc60aecbe5..3f2fbaf8d4a54c3a738b92eeeaff67c13e826602 100644 (file)
@@ -528,6 +528,12 @@ struct BLINK_COMMON_EXPORT StructTraits<blink::mojom::WebPreferencesDataView,
 #if BUILDFLAG(IS_EFL)
   static bool link_effect_enabled(const blink::web_pref::WebPreferences& r) {
     return r.link_effect_enabled;
+}
+#endif
+
+#if BUILDFLAG(IS_TIZEN)
+  static uint32_t max_refresh_rate(const blink::web_pref::WebPreferences& r) {
+    return r.max_refresh_rate;
   }
 #endif
 
index 4fe39886f3dcaa7fea53b894f187badd0b928d04..01be4fe8179b74c93ea8b8dbf6ea1f0927ef807d 100644 (file)
@@ -332,6 +332,9 @@ mojom("mojom_platform") {
   if (tizen_product_tv) {
     enabled_features += [ "is_tizen_tv" ]
   }
+  if (is_tizen) {
+    enabled_features += [ "is_tizen" ]
+  }
   if (use_efl) {
     enabled_features += [ "is_efl" ]
   }
index 14fa99b0ef95953f3502dac1af3fe8d913ab6b6c..52fa0a77207db379dbd97d37cbe0b50863506b5e 100644 (file)
@@ -373,6 +373,9 @@ struct WebPreferences {
   [EnableIf=is_efl]
   uint64 tizen_version_release;
 
+  [EnableIf=is_tizen]
+  int32 max_refresh_rate;
+
   // Whether download UI should be hidden on this page.
   bool hide_download_ui;
 
index 6264d513b398cb0cc89498a6aced047da59b2eee..d98d626a7c44b6d429a6b440837223d89e6fee73 100644 (file)
@@ -219,6 +219,10 @@ class WebFrameWidget : public WebWidget {
   // UpdateAllLifecyclePhases() just before dumping pixels.
   virtual void PrepareForFinalLifecyclUpdateForTesting() = 0;
 
+#if BUILDFLAG(IS_TIZEN)
+  virtual void SetMaxRefreshRate(uint32_t max_refresh_rate) {}
+#endif
+
  private:
   // This is a private virtual method so we don't expose cc::LayerTreeHost
   // outside of this class. Friend classes may be added in order to access it.
index ba0ebb37e96369d53ddb56a6bd2d31bc3911f4f6..3cd122f2d9e8f73c74d17b47c2b998f4ae52851b 100644 (file)
@@ -4189,6 +4189,12 @@ void WebFrameWidgetImpl::SetLongPollingGlobalTimeout(uint64_t timeout) {
 }
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+void WebFrameWidgetImpl::SetMaxRefreshRate(uint32_t max_refresh_rate) {
+  widget_base_->SetMaxRefreshRate(max_refresh_rate);
+}
+#endif
+
 void WebFrameWidgetImpl::OrientationChanged() {
   local_root_->SendOrientationChangeEvent();
 }
index fa0e44548067195bb38611627210000d9c929a68..2d28000fbf579749bf72af7ec8ae36ab03552f41 100644 (file)
@@ -636,6 +636,10 @@ class CORE_EXPORT WebFrameWidgetImpl
   void NotifyKeyEvent(WebInputEvent::Type type, bool processed) override;
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+  void SetMaxRefreshRate(uint32_t max_refresh_rate) override;
+#endif
+
  protected:
   // WidgetBaseClient overrides:
   void ScheduleAnimation() override;
index c6babf98496bc8a736e6016be5486d1769fdf16a..1bc0dad2dd9e0d585a0d27a0ed858ea69752761c 100644 (file)
 
 namespace blink {
 
+#if BUILDFLAG(IS_TIZEN)
+int WidgetBase::max_refresh_rate_ = -1;
+#endif
+
 namespace {
 
 #if BUILDFLAG(IS_ANDROID)
@@ -141,6 +145,18 @@ CreateSyntheticBeginFrameSource() {
       Platform::Current()->CompositorThreadTaskRunner()
           ? Platform::Current()->CompositorThreadTaskRunner().get()
           : base::ThreadTaskRunnerHandle::Get().get();
+#if BUILDFLAG(IS_TIZEN)
+  int max_refresh_rate_ = WidgetBase::GetMaxRefreshRate();
+  if (max_refresh_rate_ >= 1 && max_refresh_rate_ <= 60) {
+    auto timer_source = std::make_unique<viz::DelayBasedTimeSource>(
+        compositor_impl_side_task_runner);
+    const base::TimeDelta interval = base::Microseconds(
+        base::Time::kMicrosecondsPerSecond / max_refresh_rate_);
+    timer_source->SetTimebaseAndInterval(base::TimeTicks(), interval);
+    return std::make_unique<viz::DelayBasedBeginFrameSource>(
+        std::move(timer_source), viz::BeginFrameSource::kNotRestartableId);
+  }
+#endif
   return std::make_unique<viz::BackToBackBeginFrameSource>(
       std::make_unique<viz::DelayBasedTimeSource>(
           compositor_impl_side_task_runner));
index 117004a024dfeec3b389544b5efa791fe8eb36f7..9759e3b16e24d39af9983744545378223a3fd440 100644 (file)
@@ -385,6 +385,14 @@ class PLATFORM_EXPORT WidgetBase : public mojom::blink::Widget,
 
   bool is_embedded() const { return is_embedded_; }
 
+#if BUILDFLAG(IS_TIZEN)
+  void SetMaxRefreshRate(uint32_t max_refresh_rate) {
+    max_refresh_rate_ = max_refresh_rate;
+  }
+
+  static int GetMaxRefreshRate() { return max_refresh_rate_; }
+#endif
+
  private:
   bool CanComposeInline();
   void UpdateTextInputStateInternal(bool show_virtual_keyboard,
@@ -559,6 +567,10 @@ class PLATFORM_EXPORT WidgetBase : public mojom::blink::Widget,
   bool text_input_is_in_form_tag_ = false;
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+  static int max_refresh_rate_;
+#endif
+
   // Delayed callback to ensure we have only one delayed ScheduleAnimation()
   // call going at a time.
   TaskRunnerTimer<WidgetBase> request_animation_after_delay_timer_;
index 4001a4ccdddbac251233f3fd5de98165eb5eef0a..980ee8101e5626f7d26ea1521549aaa39192c6a1 100644 (file)
@@ -916,3 +916,11 @@ void EWebContext::SetApplicationType(
   }
 }
 #endif
+
+void EWebContext::SetMaxRefreshRate(int max_refresh_rate) {
+#if BUILDFLAG(IS_TIZEN)
+  base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
+  command_line.AppendSwitchASCII(switches::kMaxRefreshRate,
+                                 base::NumberToString(max_refresh_rate));
+#endif
+}
index ce38dc9a1b0321f968d23a198040e6cb302e95fc..f8e944410d4ea3a5b9b02f0ae2fba4f6a41c008a 100644 (file)
@@ -194,6 +194,7 @@ class EWebContext {
 #endif
 
   void EnableAppControl(bool enabled);
+  void SetMaxRefreshRate(int max_refresh_rate);
 
  private:
   EWebContext(bool incognito);
index 50a4a3968f9864bdc038d8029b0e312d04d832b7..1433c1905a57658d78012716c989ba32a3efd38c 100644 (file)
@@ -305,3 +305,7 @@ Ewk_Application_Type Ewk_Context::GetApplicationType() const {
   return impl->GetApplicationType();
 }
 #endif
+
+void Ewk_Context::SetMaxRefreshRate(int max_refresh_rate) {
+  impl->SetMaxRefreshRate(max_refresh_rate);
+}
\ No newline at end of file
index b991e5884b28889326506398e42a1f648023483c..4306bc0357a593cdfd7f5e39e6d5f31ab0e1c2e0 100644 (file)
@@ -154,6 +154,7 @@ struct Ewk_Context : public base::RefCounted<Ewk_Context> {
 #endif
 
   void EnableAppControl(bool enabled);
+  void SetMaxRefreshRate(int max_refresh_rate);
 
  private:
   EWebContext* impl;
index 016fa3eff4e49143f08f1dcd4c9021107146b855..2fc9073ecb55d9a43a547ec8f70907fbf2856078 100644 (file)
@@ -956,7 +956,8 @@ Eina_Bool ewk_context_app_control_set(const Ewk_Context* context, void* app_cont
 
 void ewk_context_max_refresh_rate_set(Ewk_Context* context, int max_refresh_rate)
 {
-  LOG_EWK_API_MOCKUP();
+  EINA_SAFETY_ON_NULL_RETURN(context);
+  context->SetMaxRefreshRate(max_refresh_rate);
 }
 
 void ewk_context_service_worker_unregister(Ewk_Context *context, const char* scope_url, Ewk_Context_Service_Worker_Unregistration_Result_Callback result_callback, void* user_data)