Fix capturePage under accelerated mode, fixes #223.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 7 Apr 2014 07:43:15 +0000 (15:43 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 7 Apr 2014 07:43:15 +0000 (15:43 +0800)
atom/browser/native_window.cc

index 0463fdd..119ddfa 100644 (file)
@@ -271,12 +271,28 @@ base::ProcessHandle NativeWindow::GetRenderProcessHandle() {
 
 void NativeWindow::CapturePage(const gfx::Rect& rect,
                                const CapturePageCallback& callback) {
+  content::RenderViewHost* render_view_host =
+      GetWebContents()->GetRenderViewHost();
+  content::RenderWidgetHostView* render_widget_host_view =
+      render_view_host->GetView();
+
+  if (!render_widget_host_view) {
+    callback.Run(std::vector<unsigned char>());
+    return;
+  }
+
   gfx::Rect flipped_y_rect = rect;
   flipped_y_rect.set_y(-rect.y());
 
+  gfx::Size size;
+  if (flipped_y_rect.IsEmpty())
+    size = render_widget_host_view->GetViewBounds().size();
+  else
+    size = flipped_y_rect.size();
+
   GetWebContents()->GetRenderViewHost()->CopyFromBackingStore(
       flipped_y_rect,
-      gfx::Size(),
+      size,
       base::Bind(&NativeWindow::OnCapturePageDone,
                  weak_factory_.GetWeakPtr(),
                  callback));