| Index: ui/snapshot/snapshot_mac.mm
|
| diff --git a/ui/snapshot/snapshot_mac.mm b/ui/snapshot/snapshot_mac.mm
|
| index 40cfaaf0e2fea90db89860e6482708696a5669eb..9761cb7f5086136f36de50109e04e7e0e92222eb 100644
|
| --- a/ui/snapshot/snapshot_mac.mm
|
| +++ b/ui/snapshot/snapshot_mac.mm
|
| @@ -9,6 +9,7 @@
|
| #include "base/callback.h"
|
| #include "base/logging.h"
|
| #include "base/mac/scoped_cftyperef.h"
|
| +#include "base/mac/scoped_nsobject.h"
|
| #include "base/mac/sdk_forward_declarations.h"
|
| #include "base/task_runner.h"
|
| #include "ui/gfx/geometry/rect.h"
|
| @@ -17,8 +18,8 @@
|
| namespace ui {
|
|
|
| bool GrabViewSnapshot(gfx::NativeView view,
|
| - const gfx::Rect& snapshot_bounds,
|
| - gfx::Image* image) {
|
| + std::vector<unsigned char>* png_representation,
|
| + const gfx::Rect& snapshot_bounds) {
|
| NSWindow* window = [view window];
|
| NSScreen* screen = [[NSScreen screens] firstObject];
|
| gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame]));
|
| @@ -42,6 +43,8 @@
|
| DCHECK_LE(screen_snapshot_bounds.right(), view_bounds.right());
|
| DCHECK_LE(screen_snapshot_bounds.bottom(), view_bounds.bottom());
|
|
|
| + png_representation->clear();
|
| +
|
| base::ScopedCFTypeRef<CGImageRef> windowSnapshot(
|
| CGWindowListCreateImage(screen_snapshot_bounds.ToCGRect(),
|
| kCGWindowListOptionIncludingWindow,
|
| @@ -50,19 +53,27 @@
|
| if (CGImageGetWidth(windowSnapshot) <= 0)
|
| return false;
|
|
|
| - NSImage* nsImage =
|
| - [[NSImage alloc] initWithCGImage:windowSnapshot size:NSZeroSize];
|
| - *image = gfx::Image(nsImage);
|
| + base::scoped_nsobject<NSBitmapImageRep> rep(
|
| + [[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]);
|
| + NSData* data = [rep representationUsingType:NSPNGFileType properties:@{}];
|
| + const unsigned char* buf = static_cast<const unsigned char*>([data bytes]);
|
| + NSUInteger length = [data length];
|
| + if (buf == NULL || length == 0)
|
| + return false;
|
| +
|
| + png_representation->assign(buf, buf + length);
|
| + DCHECK(!png_representation->empty());
|
| +
|
| return true;
|
| }
|
|
|
| bool GrabWindowSnapshot(gfx::NativeWindow window,
|
| - const gfx::Rect& snapshot_bounds,
|
| - gfx::Image* image) {
|
| + std::vector<unsigned char>* png_representation,
|
| + const gfx::Rect& snapshot_bounds) {
|
| // Make sure to grab the "window frame" view so we get current tab +
|
| // tabstrip.
|
| - return GrabViewSnapshot([[window contentView] superview], snapshot_bounds,
|
| - image);
|
| + return GrabViewSnapshot([[window contentView] superview], png_representation,
|
| + snapshot_bounds);
|
| }
|
|
|
| void GrabWindowSnapshotAndScaleAsync(
|
| @@ -74,17 +85,21 @@
|
| callback.Run(gfx::Image());
|
| }
|
|
|
| -void GrabViewSnapshotAsync(gfx::NativeView view,
|
| - const gfx::Rect& source_rect,
|
| - const GrabWindowSnapshotAsyncCallback& callback) {
|
| - callback.Run(gfx::Image());
|
| +void GrabViewSnapshotAsync(
|
| + gfx::NativeView view,
|
| + const gfx::Rect& source_rect,
|
| + scoped_refptr<base::TaskRunner> background_task_runner,
|
| + const GrabWindowSnapshotAsyncPNGCallback& callback) {
|
| + callback.Run(scoped_refptr<base::RefCountedBytes>());
|
| }
|
|
|
| -void GrabWindowSnapshotAsync(gfx::NativeWindow window,
|
| - const gfx::Rect& source_rect,
|
| - const GrabWindowSnapshotAsyncCallback& callback) {
|
| +void GrabWindowSnapshotAsync(
|
| + gfx::NativeWindow window,
|
| + const gfx::Rect& source_rect,
|
| + scoped_refptr<base::TaskRunner> background_task_runner,
|
| + const GrabWindowSnapshotAsyncPNGCallback& callback) {
|
| return GrabViewSnapshotAsync([[window contentView] superview], source_rect,
|
| - callback);
|
| + background_task_runner, callback);
|
| }
|
|
|
| } // namespace ui
|
|
|