Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: ui/snapshot/snapshot_mac.mm

Issue 2592983002: [devtools] Support different encodings for Page.CaptureScreenshot. (Closed)
Patch Set: Disabled test on MacOS >=10.11, added ref to bug. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/snapshot/snapshot_ios.mm ('k') | ui/snapshot/snapshot_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/snapshot/snapshot_mac.mm
diff --git a/ui/snapshot/snapshot_mac.mm b/ui/snapshot/snapshot_mac.mm
index 9761cb7f5086136f36de50109e04e7e0e92222eb..40cfaaf0e2fea90db89860e6482708696a5669eb 100644
--- a/ui/snapshot/snapshot_mac.mm
+++ b/ui/snapshot/snapshot_mac.mm
@@ -9,7 +9,6 @@
#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"
@@ -18,8 +17,8 @@
namespace ui {
bool GrabViewSnapshot(gfx::NativeView view,
- std::vector<unsigned char>* png_representation,
- const gfx::Rect& snapshot_bounds) {
+ const gfx::Rect& snapshot_bounds,
+ gfx::Image* image) {
NSWindow* window = [view window];
NSScreen* screen = [[NSScreen screens] firstObject];
gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame]));
@@ -43,8 +42,6 @@ bool GrabViewSnapshot(gfx::NativeView view,
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,
@@ -53,27 +50,19 @@ bool GrabViewSnapshot(gfx::NativeView view,
if (CGImageGetWidth(windowSnapshot) <= 0)
return false;
- 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());
-
+ NSImage* nsImage =
+ [[NSImage alloc] initWithCGImage:windowSnapshot size:NSZeroSize];
+ *image = gfx::Image(nsImage);
return true;
}
bool GrabWindowSnapshot(gfx::NativeWindow window,
- std::vector<unsigned char>* png_representation,
- const gfx::Rect& snapshot_bounds) {
+ const gfx::Rect& snapshot_bounds,
+ gfx::Image* image) {
// Make sure to grab the "window frame" view so we get current tab +
// tabstrip.
- return GrabViewSnapshot([[window contentView] superview], png_representation,
- snapshot_bounds);
+ return GrabViewSnapshot([[window contentView] superview], snapshot_bounds,
+ image);
}
void GrabWindowSnapshotAndScaleAsync(
@@ -85,21 +74,17 @@ void GrabWindowSnapshotAndScaleAsync(
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 GrabViewSnapshotAsync(gfx::NativeView view,
+ const gfx::Rect& source_rect,
+ const GrabWindowSnapshotAsyncCallback& callback) {
+ callback.Run(gfx::Image());
}
-void GrabWindowSnapshotAsync(
- gfx::NativeWindow window,
- const gfx::Rect& source_rect,
- scoped_refptr<base::TaskRunner> background_task_runner,
- const GrabWindowSnapshotAsyncPNGCallback& callback) {
+void GrabWindowSnapshotAsync(gfx::NativeWindow window,
+ const gfx::Rect& source_rect,
+ const GrabWindowSnapshotAsyncCallback& callback) {
return GrabViewSnapshotAsync([[window contentView] superview], source_rect,
- background_task_runner, callback);
+ callback);
}
} // namespace ui
« no previous file with comments | « ui/snapshot/snapshot_ios.mm ('k') | ui/snapshot/snapshot_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698