Merge pull request #3983 from atom/fix-capture-page

Fix distorted image when calling `capturePage` with no rect
This commit is contained in:
Cheng Zhao 2016-01-04 20:52:17 +08:00
commit 88ba4fb36a

View file

@ -32,10 +32,10 @@
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/gl/gpu_switching_manager.h" #include "ui/gl/gpu_switching_manager.h"
@ -278,22 +278,22 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
} }
// Capture full page if user doesn't specify a |rect|. // Capture full page if user doesn't specify a |rect|.
const gfx::Rect view_rect = rect.IsEmpty() ? view->GetViewBounds() : const gfx::Size view_size = rect.IsEmpty() ? view->GetViewBounds().size() :
rect; rect.size();
// By default, the requested bitmap size is the view size in screen // By default, the requested bitmap size is the view size in screen
// coordinates. However, if there's more pixel detail available on the // coordinates. However, if there's more pixel detail available on the
// current system, increase the requested bitmap size to capture it all. // current system, increase the requested bitmap size to capture it all.
gfx::Size bitmap_size = view_rect.size(); gfx::Size bitmap_size = view_size;
const gfx::NativeView native_view = view->GetNativeView(); const gfx::NativeView native_view = view->GetNativeView();
gfx::Screen* const screen = gfx::Screen::GetScreenFor(native_view); gfx::Screen* const screen = gfx::Screen::GetScreenFor(native_view);
const float scale = const float scale =
screen->GetDisplayNearestWindow(native_view).device_scale_factor(); screen->GetDisplayNearestWindow(native_view).device_scale_factor();
if (scale > 1.0f) if (scale > 1.0f)
bitmap_size = gfx::ScaleToCeiledSize(view_rect.size(), scale); bitmap_size = gfx::ScaleToCeiledSize(view_size, scale);
host->CopyFromBackingStore( host->CopyFromBackingStore(
view_rect, gfx::Rect(rect.origin(), view_size),
bitmap_size, bitmap_size,
base::Bind(&NativeWindow::OnCapturePageDone, base::Bind(&NativeWindow::OnCapturePageDone,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),