[M42-Merge] fixup! Changed implementation of EWebView::GetSnapshot
authordhyuna.ko <dhyuna.ko@samsung.com>
Tue, 21 Jul 2015 07:12:03 +0000 (16:12 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 07:55:23 +0000 (07:55 +0000)
MakeCurrent is missing in EWebView::GetSnapshot() where Evas_GL_API is used.
This results in error below inside EvasGL when EvasGL API is called.
"Unable to retrieve Current Engine"

Static allocation of quite large amount of memory caused crash.

Query for GL_IMPLEMENTATION_COLOR_READ_FORMAT returns GL_RGBA, so to use
GL_BGRA results in GL_INVALID_OPERATION error in the case of glReadPixels.

The functionality of EWebView::GetSnapshot was verified on both mobile (Note4)
and tv (XU3).

Original Commit: http://165.213.202.130/gerrit/#/c/83886/

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=13517

Reviewed by: a1.gomes, dhyuna.ko, siba.samal, sns.park

Change-Id: Ie1dd9cf096e4fc92cde6e952f8c318a06da0e7f7
Signed-off-by: dhyuna.ko <dhyuna.ko@samsung.com>
Signed-off-by: venu.musham <venu.musham@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/ewk/efl_integration/eweb_view.cc

index 239fb0b..174f8db 100755 (executable)
@@ -448,16 +448,16 @@ void RenderWidgetHostViewEfl::initializeProgram() {
   GL_CHECK(source_texture_location_ = evas_gl_api_->glGetUniformLocation (program_id_, "s_texture" ));
 }
 
+bool RenderWidgetHostViewEfl::MakeCurrent() {
+  return evas_gl_make_current(evas_gl_, evas_gl_surface_, evas_gl_context_);
+}
+
 #if defined(TIZEN_DISABLE_GPU_THREAD)
 void RenderWidgetHostViewEfl::DoCompositeNow() {
   evas_object_image_pixels_dirty_set(content_image_, true);
   evas_render(evas_);
 }
 
-bool RenderWidgetHostViewEfl::MakeCurrent() {
-  return evas_gl_make_current(evas_gl_, evas_gl_surface_, evas_gl_context_);
-}
-
 void RenderWidgetHostViewEfl::PaintToSurface() {
   Evas_GL_API* gl_api = evasGlApi();
 
index 18c636d..3b6ae57 100755 (executable)
@@ -257,10 +257,10 @@ class CONTENT_EXPORT RenderWidgetHostViewEfl
   void DelegatedFrameHostUpdateVSyncParameters(
       const base::TimeTicks& timebase,
       const base::TimeDelta& interval) override;
+  bool MakeCurrent();
 
 #if defined(TIZEN_DISABLE_GPU_THREAD)
   void DoCompositeNow();
-  bool MakeCurrent();
 #endif
 
   SelectionControllerEfl* GetSelectionController() const {
index f5486cf..064c213 100644 (file)
 
 #include <iostream>
 
-//this constant is not defined in efl headers so we have to do it here
-#ifndef GL_BGRA
-#define GL_BGRA 0x80E1
-#endif
-
 using namespace content;
 using web_contents_utils::WebViewFromWebContents;
 
@@ -1523,6 +1518,9 @@ bool EWebView::GetSnapshotAsync(Eina_Rectangle rect,
 Evas_Object* EWebView::GetSnapshot(Eina_Rectangle rect) {
   Evas_Object* image = NULL;
 #ifdef OS_TIZEN
+  if (!rwhv() || !rwhv()->MakeCurrent())
+    return NULL;
+
   int width = rect.w;
   int height = rect.h;
 
@@ -1536,15 +1534,32 @@ Evas_Object* EWebView::GetSnapshot(Eina_Rectangle rect) {
 
   Evas_GL_API* gl_api = rwhv()->evasGlApi();
   DCHECK(gl_api);
-  int size = width * height;
+  int size = width * height *  sizeof(GLuint);
+
+  GLuint* tmp = (GLuint*)malloc(size);
+  if (!tmp)
+    return NULL;
 
-  GLubyte tmp[size*4];
-  GLubyte bits[size*4];
-  gl_api->glReadPixels(x, y, width, height, GL_BGRA, GL_UNSIGNED_BYTE, bits);
+  GLuint* bits = (GLuint*)malloc(size);
+  if (!bits) {
+    free(tmp);
+    return NULL;
+  }
+
+  gl_api->glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (GLubyte*)bits);
+
+  // flip the Y axis and change color format from RGBA to BGRA
+  int i, j, idx1, idx2;
+  GLuint d;
+  for (j = 0; j < height; j++) {
+    for (i = 0; i < width; i++) {
+      idx1 = (j * width) + i;
+      idx2 = ((height - 1) - j) * width + i;
+      d = bits[idx1];
+      tmp[idx2] = ((d & 0x000000ff) << 16) + ((d & 0x00ff0000) >> 16) + ((d & 0xff00ff00));
+    }
+  }
 
-  //flip data after reading
-  for (int i=0; i < height; i++)
-    memcpy(&tmp[i*width*4], &bits[(height-i-1)*width*4], width*4*sizeof(unsigned char));
   image = evas_object_image_filled_add(rwhv()->evas());
   if (image) {
     evas_object_image_size_set(image, width, height);