[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 2ce1e68..17895cb 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 310961b..cde3d1c 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 e3e3ddf..e04843e 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 dcdbc2e..3524610 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 2257cb2..67b358e 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 f8792c5..99b78f7 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 c141ba7..21c156f 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 dafe321..3f2fbaf 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 4fe3988..01be4fe 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 14fa99b..52fa0a7 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 6264d51..d98d626 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 ba0ebb3..3cd122f 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 fa0e445..2d28000 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 c6babf9..1bc0dad 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 117004a..9759e3b 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 4001a4c..980ee81 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 ce38dc9..f8e9444 100644 (file)
@@ -194,6 +194,7 @@ class EWebContext {
 #endif
 
   void EnableAppControl(bool enabled);
+  void SetMaxRefreshRate(int max_refresh_rate);
 
  private:
   EWebContext(bool incognito);
index 50a4a39..1433c19 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 b991e58..4306bc0 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 016fa3e..2fc9073 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)