Index: ui/snapshot/snapshot_mac.mm |
diff --git a/ui/snapshot/snapshot_mac.mm b/ui/snapshot/snapshot_mac.mm |
index 9761cb7f5086136f36de50109e04e7e0e92222eb..2c87e38889cfdc4ded160991582c1acfbb14af07 100644 |
--- a/ui/snapshot/snapshot_mac.mm |
+++ b/ui/snapshot/snapshot_mac.mm |
@@ -19,7 +19,9 @@ namespace ui { |
bool GrabViewSnapshot(gfx::NativeView view, |
std::vector<unsigned char>* png_representation, |
- const gfx::Rect& snapshot_bounds) { |
+ const gfx::Rect& snapshot_bounds, |
+ SnapshotEncoding encoding, |
+ SnapshotQuality quality) { |
NSWindow* window = [view window]; |
NSScreen* screen = [[NSScreen screens] firstObject]; |
gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame])); |
@@ -55,7 +57,23 @@ bool GrabViewSnapshot(gfx::NativeView view, |
base::scoped_nsobject<NSBitmapImageRep> rep( |
[[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]); |
- NSData* data = [rep representationUsingType:NSPNGFileType properties:@{}]; |
+ NSData* data; |
+ float compression_factor = 0; |
+ NSDictionary* options = nullptr; |
+ switch (encoding) { |
+ case SnapshotEncoding::PNG: |
+ data = [rep representationUsingType:NSPNGFileType properties:@{}]; |
+ break; |
+ case SnapshotEncoding::JPEG: |
+ compression_factor = static_cast<float>(quality) / 100; |
+ options = [NSDictionary |
+ dictionaryWithObject:[NSNumber numberWithFloat:compression_factor] |
+ forKey:NSImageCompressionFactor]; |
+ data = [rep representationUsingType:NSJPEGFileType properties:options]; |
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
const unsigned char* buf = static_cast<const unsigned char*>([data bytes]); |
NSUInteger length = [data length]; |
if (buf == NULL || length == 0) |
@@ -69,11 +87,13 @@ bool GrabViewSnapshot(gfx::NativeView view, |
bool GrabWindowSnapshot(gfx::NativeWindow window, |
std::vector<unsigned char>* png_representation, |
- const gfx::Rect& snapshot_bounds) { |
+ const gfx::Rect& snapshot_bounds, |
+ SnapshotEncoding encoding, |
+ SnapshotQuality quality) { |
// Make sure to grab the "window frame" view so we get current tab + |
// tabstrip. |
return GrabViewSnapshot([[window contentView] superview], png_representation, |
- snapshot_bounds); |
+ snapshot_bounds, encoding, quality); |
} |
void GrabWindowSnapshotAndScaleAsync( |
@@ -89,7 +109,9 @@ void GrabViewSnapshotAsync( |
gfx::NativeView view, |
const gfx::Rect& source_rect, |
scoped_refptr<base::TaskRunner> background_task_runner, |
- const GrabWindowSnapshotAsyncPNGCallback& callback) { |
+ const GrabWindowSnapshotAsyncEncodedCallback& callback, |
+ SnapshotEncoding encoding, |
+ SnapshotQuality quality) { |
callback.Run(scoped_refptr<base::RefCountedBytes>()); |
} |
@@ -97,9 +119,12 @@ void GrabWindowSnapshotAsync( |
gfx::NativeWindow window, |
const gfx::Rect& source_rect, |
scoped_refptr<base::TaskRunner> background_task_runner, |
- const GrabWindowSnapshotAsyncPNGCallback& callback) { |
+ const GrabWindowSnapshotAsyncEncodedCallback& callback, |
+ SnapshotEncoding encoding, |
+ SnapshotQuality quality) { |
return GrabViewSnapshotAsync([[window contentView] superview], source_rect, |
- background_task_runner, callback); |
+ background_task_runner, callback, encoding, |
+ quality); |
} |
} // namespace ui |