[EWK_REFACTOR] bringup GetSnapshotAsync and GetSnapShotForRect
authorKarol Furmaniak <k.furmaniak@samsung.com>
Thu, 7 May 2015 07:35:18 +0000 (09:35 +0200)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
EWK_REFACTOR guards are removed, GetSnapshotAsync implementation
is moved from eweb_view to RenderWidgetHostViewEfl.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=12687
Reviewed by: Antonio Gomes, Hyunhak Kim, Piotr Grad, Piotr Tworek

Change-Id: Iabe107094dc00a7846c5433e4a86eecc0d0ea09e
Signed-off-by: Karol Furmaniak <k.furmaniak@samsung.com>
tizen_src/chromium_impl/content/browser/renderer_host/render_widget_host_view_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/render_widget_host_view_efl.h
tizen_src/chromium_impl/ui/base/selection/selection_magnifier_efl.cc
tizen_src/ewk/efl_integration/browser/web_view_browser_message_filter.cc
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/public/ewk_view.cc

index 793607d..ba1356a 100644 (file)
@@ -79,6 +79,20 @@ bool IsShiftKey(const char * key) {
   return !strcmp(key, "Shift_L") || !strcmp(key, "Shift_R");
 }
 
+class ScreenshotCapturedCallback {
+ public:
+      ScreenshotCapturedCallback(Screenshot_Captured_Callback func, void *user_data)
+          : func_(func), user_data_(user_data) {}
+  void Run(Evas_Object* image) {
+    if (func_ != NULL)
+      (func_)(image, user_data_);
+  }
+
+ private:
+  Screenshot_Captured_Callback func_;
+  void *user_data_;
+};
+
 void RenderWidgetHostViewBase::GetDefaultScreenInfo(
     blink::WebScreenInfo* results) {
   const gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
@@ -502,6 +516,7 @@ bool RenderWidgetHostViewEfl::OnMessageReceived(const IPC::Message& message) {
     IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, OnTextInputStateChanged)
     IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputInFormStateChanged, OnTextInputInFormStateChanged)
     IPC_MESSAGE_HANDLER(ViewHostMsg_HitTestAsyncReply, OnHitTestAsyncReply)
+    IPC_MESSAGE_HANDLER(ViewHostMsg_SnapshotDataReceived, OnSnapshotDataReceived)
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
   return handled;
@@ -520,6 +535,24 @@ void RenderWidgetHostViewEfl::OnHitTestAsyncReply(
           params, request_id);
 }
 
+void RenderWidgetHostViewEfl::OnSnapshotDataReceived(
+    SkBitmap bitmap,
+    int snapshotId) {
+  Evas_Object* image = NULL;
+  if (!bitmap.empty()) {
+    image = evas_object_image_filled_add(evas_);
+    evas_object_image_size_set(image, bitmap.width(), bitmap.height());
+    evas_object_image_data_copy_set(image, bitmap.getPixels());
+  }
+
+  ScreenshotCapturedCallback* callback = screen_capture_cb_map_.Lookup(snapshotId);
+  if (!callback) {
+    return;
+  }
+  callback->Run(image);
+  screen_capture_cb_map_.Remove(snapshotId);
+}
+
 void RenderWidgetHostViewEfl::InitAsPopup(RenderWidgetHostView*, const gfx::Rect&) {
   NOTIMPLEMENTED();
 }
@@ -923,6 +956,52 @@ void RenderWidgetHostViewEfl::CopyFromCompositingSurface(
   NOTIMPLEMENTED();
 }
 
+void RenderWidgetHostViewEfl::GetSnapshotAsync(const gfx::Rect& snapshot_area, int request_id) {
+  if (!IsDelegatedRendererEnabled())
+    Send(new ViewMsg_GetSnapshotFromRender(host_->GetRoutingID(), snapshot_area, request_id));
+  else {
+    // TODO: Add alternative way after porting delegated rendering
+    // http://107.108.218.239/bugzilla/show_bug.cgi?id=9858
+    NOTIMPLEMENTED();
+  }
+}
+
+bool RenderWidgetHostViewEfl::RequestSnapshotAsync(const Eina_Rectangle rect,
+    Screenshot_Captured_Callback callback,
+    void* user_data) {
+  int width = rect.w;
+  int height = rect.h;
+  int x = rect.x;
+  int y = rect.y;
+
+  int device_x, device_y;
+  int view_x, view_y;
+
+  evas_object_geometry_get(smart_parent(),
+                           &device_x,
+                           &device_y,
+                           NULL,
+                           NULL);
+
+  if (width > device_x + GetViewBoundsInPix().width() - rect.x)
+    width = device_x + GetViewBoundsInPix().width() - rect.x;
+  if (height > device_y + GetViewBoundsInPix().height() - rect.y)
+    height = device_y + GetViewBoundsInPix().height() - rect.y;
+
+  EvasToBlinkCords(x, y, &view_x, &view_y);
+
+  width /= device_scale_factor_;
+  height /= device_scale_factor_;
+
+  ScreenshotCapturedCallback* cb =
+      new ScreenshotCapturedCallback(callback, user_data);
+
+  int cbId = screen_capture_cb_map_.Add(cb);
+
+  GetSnapshotAsync(gfx::Rect(view_x, view_y, width, height), cbId);
+  return true;
+}
+
 // CopyFromCompositingSurfaceToVideoFrame implementation borrowed from Aura port
 bool RenderWidgetHostViewEfl::CanSubscribeFrame() const {
   return true;
index 81cf4b0..d827606 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "base/basictypes.h"
 #include "base/format_macros.h"
+#include "base/id_map.h"
 #include "content/browser/renderer_host/render_widget_host_view_base.h"
 #include "content/browser/renderer_host/evas_event_handler.h"
 #include "content/browser/web_contents/web_contents_impl.h"
@@ -63,6 +64,8 @@ struct WebScreenInfo;
 
 namespace content {
 
+typedef void (*Screenshot_Captured_Callback)(Evas_Object* image, void* user_data);
+
 class DisambiguationPopupEfl;
 class EdgeEffect;
 class IMContextEfl;
@@ -70,6 +73,7 @@ class RenderWidgetHostImpl;
 class RenderWidgetHostView;
 class ReadbackYUVInterface;
 class WebContents;
+class ScreenshotCapturedCallback;
 
 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
 class RenderWidgetHostViewEfl
@@ -215,6 +219,11 @@ class RenderWidgetHostViewEfl
   bool IsIMEShow() const;
   gfx::Rect GetIMERect() const;
   void ExecuteEditCommand(const char* command, const char* value);
+  void GetSnapshotAsync(const gfx::Rect& snapshot_area, int request_id);
+  bool RequestSnapshotAsync(const Eina_Rectangle rect,
+    Screenshot_Captured_Callback callback,
+    void* user_data);
+  void OnSnapshotDataReceived(SkBitmap bitmap, int snapshotId);
 
  protected:
   friend class RenderWidgetHostView;
@@ -366,6 +375,8 @@ class RenderWidgetHostViewEfl
   // is saved and restored when gesture will end.
   scoped_ptr<bool> restore_showing_large_handle_on_gesture_end_;
 
+  IDMap<ScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
+
   DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEfl);
 };
 
index bc0089e..676232b 100644 (file)
@@ -169,11 +169,10 @@ void SelectionMagnifierEfl::UpdateLocation(const gfx::Point& location) {
   rect.w = content_rect.width();
   rect.h = content_rect.height();
 
-#if defined(EWK_REFACTOR)
-  controller_->GetParentView()->GetSnapshotAsync(rect,
-      evas_object_evas_get(controller_->GetParentView()->evas_object()),
-      MagnifierGetSnapshotCb, this);
-#endif
+  RenderWidgetHostViewEfl* rwhv =
+      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
+  if (rwhv)
+    rwhv->RequestSnapshotAsync(rect, MagnifierGetSnapshotCb, this);
 }
 
 void SelectionMagnifierEfl::Move(const gfx::Point& location) {
index a23c4e1..cd0de5c 100644 (file)
@@ -134,11 +134,6 @@ class WebViewBrowserMessageFilterPrivate
       web_view_->DidChangePageScaleRange(min_scale, max_scale);
   }
 
-  void OnSnapshot(const std::vector<unsigned char> pixData, int snapshotId, const gfx::Size& size) {
-    if (web_view_)
-      web_view_->OnSnapshot(pixData, size.width(), size.height(), snapshotId);
-  }
-
   void OnDidChangeMaxScrollOffset(int maxScrollX, int maxScrollY) {
     if (web_view_)
       web_view_->GetScrollDetector()->SetMaxScroll(maxScrollX, maxScrollY);
@@ -237,10 +232,6 @@ bool WebViewBrowserMessageFilter::OnMessageReceived(
         WebViewBrowserMessageFilterPrivate::OnFormSubmit)
     IPC_MESSAGE_FORWARD(ViewHostMsg_StartContentIntent, private_,
         WebViewBrowserMessageFilterPrivate::OnStartContentIntent)
-#if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
-    IPC_MESSAGE_FORWARD(ViewHostMsg_SnapshotDataReceived, private_,
-        WebViewBrowserMessageFilterPrivate::OnSnapshot)
-#endif
 
     IPC_MESSAGE_UNHANDLED(handled = false)
   IPC_END_MESSAGE_MAP()
index 42ae64d..babb209 100644 (file)
@@ -1463,64 +1463,13 @@ void EWebView::SetLinkMagnifierEnabled(bool enabled) {
   web_contents_->GetRenderViewHost()->SyncRendererPrefs();
 }
 
-void EWebView::OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId) {
-  WebAppScreenshotCapturedCallback* callback = screen_capture_cb_map_.Lookup(snapshotId);
-  if (!callback) {
-    return;
-  }
-
-  Evas_Object* image = evas_object_image_filled_add(rwhv()->evas());
-  evas_object_image_size_set(image, width, height);
-  evas_object_image_data_copy_set(image, const_cast<unsigned char*>(&pixData[0]));
-
-  callback->Run(image);
-  screen_capture_cb_map_.Remove(snapshotId);
-}
-
 bool EWebView::GetSnapshotAsync(Eina_Rectangle rect,
-    Evas* canvas,
     Ewk_Web_App_Screenshot_Captured_Callback callback,
     void* user_data) {
-#if defined(OS_TIZEN) && defined(EWK_REFACTOR)
   if (!rwhv())
     return false;
-  int width = rect.w;
-  int height = rect.h;
-  int x = rect.x;
-  int y = rect.y;
-
-  int device_x, device_y;
-  int view_x, view_y;
 
-  evas_object_geometry_get(evas_object(),
-                           &device_x,
-                           &device_y,
-                           NULL,
-                           NULL);
-
-  if (width > device_x + rwhv()->GetViewBoundsInPix().width() - rect.x)
-    width = device_x + rwhv()->GetViewBoundsInPix().width() - rect.x;
-  if (height > device_y + rwhv()->GetViewBoundsInPix().height() - rect.y)
-    height = device_y + rwhv()->GetViewBoundsInPix().height() - rect.y;
-
-  EvasToBlinkCords(x, y, &view_x, &view_y);
-
-  width /= gfx::Screen::GetNativeScreen()->
-      GetPrimaryDisplay().device_scale_factor();
-  height /= gfx::Screen::GetNativeScreen()->
-      GetPrimaryDisplay().device_scale_factor();
-
-  WebAppScreenshotCapturedCallback* cb =
-      new WebAppScreenshotCapturedCallback(callback, user_data, canvas);
-
-  int cbId = screen_capture_cb_map_.Add(cb);
-
-  rwhv()->GetSnapshotAsync(gfx::Rect(view_x, view_y, width, height), cbId);
-  return true;
-#else
-  NOTIMPLEMENTED();
-  return false;
-#endif
+  return rwhv()->RequestSnapshotAsync(rect, callback, user_data);
 }
 
 void EWebView::GetSnapShotForRect(gfx::Rect& rect) {
index 0394ea3..82b6453 100644 (file)
@@ -72,21 +72,6 @@ class Ewk_Context;
 class WebViewEvasEventHandler;
 class _Ewk_Quota_Permission_Request;
 
-class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
- public:
-      WebAppScreenshotCapturedCallback(Ewk_Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
-          : func_(func), user_data_(user_data), canvas_(canvas) {}
-  void Run(Evas_Object* image) {
-    if (func_ != NULL)
-      (func_)(image, user_data_);
-  }
-
- private:
-  Ewk_Web_App_Screenshot_Captured_Callback func_;
-  void *user_data_;
-  Evas* canvas_;
-};
-
 class EwkViewPlainTextGetCallback {
  public:
   EwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
@@ -347,7 +332,7 @@ class EWebView {
   */
   Evas_Object* GetSnapshot(Eina_Rectangle rect);
 
-  bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
+  bool GetSnapshotAsync(Eina_Rectangle rect, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
   void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
   void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
       NavigationPolicyParams params, bool* handled);
@@ -425,7 +410,6 @@ class EWebView {
   void DismissColorPicker();
   bool SetColorPickerColor(int r, int g, int b, int a);
   void InputPickerShow(ui::TextInputType input_type, double input_value);
-  void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
 
   void ShowContentsDetectedPopup(const char*);
 
@@ -544,7 +528,6 @@ class EWebView {
   IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
   IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
   IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
-  IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
   scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
   content::DevToolsDelegateEfl* inspector_server_;
   scoped_ptr<ScrollDetector> scroll_detector_;
index e86ea1e..8ee217e 100644 (file)
@@ -426,7 +426,7 @@ Eina_Bool ewk_view_screenshot_contents_get_async(const Evas_Object* view, Eina_R
                << "Scaling option will be supported after hardware acceleration is enabled.";
     return EINA_FALSE;
   }
-  return impl->GetSnapshotAsync(view_area, canvas, callback, user_data) ? EINA_TRUE : EINA_FALSE;
+  return impl->GetSnapshotAsync(view_area, callback, user_data) ? EINA_TRUE : EINA_FALSE;
 }
 
 unsigned int ewk_view_inspector_server_start(Evas_Object* ewkView, unsigned int port)