summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-19 19:48:35 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-19 19:48:35 +0000
commitfece3a7e17e0cd75ff3fa5a3ab88c41e94f7a923 (patch)
tree53808985c00baf5d4e4e7204ae7d5af2b6a96564
parent997aaec37d6e6197688b5a6d1541b7ace4c9f38b (diff)
downloadchromium_src-fece3a7e17e0cd75ff3fa5a3ab88c41e94f7a923.zip
chromium_src-fece3a7e17e0cd75ff3fa5a3ab88c41e94f7a923.tar.gz
chromium_src-fece3a7e17e0cd75ff3fa5a3ab88c41e94f7a923.tar.bz2
Change Clipboard::ReadImage to return a bitmap.
This allows the PNG compression to be offloaded to another thread as appropriate. BUG=75237 TEST=Local testing. Review URL: http://codereview.chromium.org/6835036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82142 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/DEPS9
-rw-r--r--content/browser/renderer_host/clipboard_message_filter.cc24
-rw-r--r--ui/base/clipboard/DEPS4
-rw-r--r--ui/base/clipboard/clipboard.h6
-rw-r--r--ui/base/clipboard/clipboard_linux.cc8
-rw-r--r--ui/base/clipboard/clipboard_mac.mm34
-rw-r--r--ui/base/clipboard/clipboard_win.cc70
-rw-r--r--webkit/tools/test_shell/DEPS1
-rw-r--r--webkit/tools/test_shell/simple_clipboard_impl.cc23
9 files changed, 92 insertions, 87 deletions
diff --git a/content/browser/renderer_host/DEPS b/content/browser/renderer_host/DEPS
index 8e154f7..0a9e14a 100644
--- a/content/browser/renderer_host/DEPS
+++ b/content/browser/renderer_host/DEPS
@@ -1,4 +1,5 @@
-include_rules = [
- "+content/renderer", # For single-process mode.
- "+chrome/browser/extensions", # temporarily, for BrowserRenderProcessHost
-]
+include_rules = [
+ "+content/renderer", # For single-process mode.
+ "+third_party/zlib",
+ "+chrome/browser/extensions", # temporarily, for BrowserRenderProcessHost
+]
diff --git a/content/browser/renderer_host/clipboard_message_filter.cc b/content/browser/renderer_host/clipboard_message_filter.cc
index 7a68e08..1b09839 100644
--- a/content/browser/renderer_host/clipboard_message_filter.cc
+++ b/content/browser/renderer_host/clipboard_message_filter.cc
@@ -4,11 +4,16 @@
#include "content/browser/renderer_host/clipboard_message_filter.h"
+#include "base/stl_util-inl.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/clipboard_dispatcher.h"
#include "content/common/clipboard_messages.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message_macros.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/zlib/zlib.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/size.h"
namespace {
@@ -140,7 +145,24 @@ void ClipboardMessageFilter::OnReadHTML(
void ClipboardMessageFilter::OnReadImage(
ui::Clipboard::Buffer buffer, std::string* data) {
- GetClipboard()->ReadImage(buffer, data);
+ SkBitmap bitmap = GetClipboard()->ReadImage(buffer);
+ if (bitmap.isNull())
+ return;
+
+ std::vector<unsigned char> png_data;
+ SkAutoLockPixels lock(bitmap);
+ if (gfx::PNGCodec::EncodeWithCompressionLevel(
+ static_cast<const unsigned char*>(bitmap.getPixels()),
+ gfx::PNGCodec::FORMAT_BGRA,
+ gfx::Size(bitmap.width(), bitmap.height()),
+ bitmap.rowBytes(),
+ false,
+ std::vector<gfx::PNGCodec::Comment>(),
+ Z_BEST_SPEED,
+ &png_data)) {
+ data->assign(reinterpret_cast<char*>(vector_as_array(&png_data)),
+ png_data.size());
+ }
}
void ClipboardMessageFilter::OnReadAvailableTypes(
diff --git a/ui/base/clipboard/DEPS b/ui/base/clipboard/DEPS
deleted file mode 100644
index 03b9e67..0000000
--- a/ui/base/clipboard/DEPS
+++ /dev/null
@@ -1,4 +0,0 @@
-include_rules = [
- "+third_party/zlib",
-]
-
diff --git a/ui/base/clipboard/clipboard.h b/ui/base/clipboard/clipboard.h
index bc8b950..744f7a6 100644
--- a/ui/base/clipboard/clipboard.h
+++ b/ui/base/clipboard/clipboard.h
@@ -20,6 +20,7 @@ class Size;
}
class FilePath;
+class SkBitmap;
#if defined(TOOLKIT_USES_GTK)
typedef struct _GtkClipboard GtkClipboard;
@@ -151,9 +152,8 @@ class Clipboard {
// Reads HTML from the clipboard, if available.
void ReadHTML(Buffer buffer, string16* markup, std::string* src_url) const;
- // Reads an image from the clipboard, if available. The returned data will be
- // encoded in PNG format.
- void ReadImage(Buffer buffer, std::string* data) const;
+ // Reads an image from the clipboard, if available.
+ SkBitmap ReadImage(Buffer buffer) const;
// Reads a bookmark from the clipboard, if available.
void ReadBookmark(string16* title, std::string* url) const;
diff --git a/ui/base/clipboard/clipboard_linux.cc b/ui/base/clipboard/clipboard_linux.cc
index e688875..3cbe7d8 100644
--- a/ui/base/clipboard/clipboard_linux.cc
+++ b/ui/base/clipboard/clipboard_linux.cc
@@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/utf_string_conversions.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/size.h"
@@ -375,13 +376,10 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup,
gtk_selection_data_free(data);
}
-void Clipboard::ReadImage(Buffer buffer, std::string* data) const {
+SkBitmap Clipboard::ReadImage(Buffer buffer) const {
// TODO(dcheng): implement this.
NOTIMPLEMENTED();
- if (!data) {
- NOTREACHED();
- return;
- }
+ return SkBitmap();
}
void Clipboard::ReadBookmark(string16* title, std::string* url) const {
diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm
index 74b73f9..63d456b 100644
--- a/ui/base/clipboard/clipboard_mac.mm
+++ b/ui/base/clipboard/clipboard_mac.mm
@@ -14,6 +14,8 @@
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#import "third_party/mozilla/NSPasteboard+Utils.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/size.h"
namespace ui {
@@ -240,26 +242,30 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup,
src_url->clear();
}
-void Clipboard::ReadImage(Buffer buffer, std::string* data) const {
+SkBitmap Clipboard::ReadImage(Buffer buffer) const {
DCHECK_EQ(buffer, BUFFER_STANDARD);
- if (!data) {
- NOTREACHED();
- return;
- }
scoped_nsobject<NSImage> image(
[[NSImage alloc] initWithPasteboard:GetPasteboard()]);
if (image.get()) {
- NSArray* reps = [image representations];
- NSData* png_data = [NSBitmapImageRep
- representationOfImageRepsInArray:reps
- usingType:NSPNGFileType
- properties:[NSDictionary dictionary]];
- if (png_data) {
- data->assign(static_cast<const char*>([png_data bytes]),
- [png_data length]);
- }
+ [image setFlipped:YES];
+ int width = [image size].width;
+ int height = [image size].height;
+
+ gfx::CanvasSkia canvas(width, height, false);
+ CGContextRef gc = canvas.beginPlatformPaint();
+ NSGraphicsContext* cocoa_gc =
+ [NSGraphicsContext graphicsContextWithGraphicsPort:gc flipped:NO];
+ [NSGraphicsContext setCurrentContext:cocoa_gc];
+ [image drawInRect:NSMakeRect(0, 0, width, height)
+ fromRect:NSZeroRect
+ operation:NSCompositeCopy
+ fraction:1.0];
+ [NSGraphicsContext restoreGraphicsState];
+ canvas.endPlatformPaint();
+ return canvas.ExtractBitmap();
}
+ return SkBitmap();
}
void Clipboard::ReadBookmark(string16* title, std::string* url) const {
diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc
index bf7399b..013da58 100644
--- a/ui/base/clipboard/clipboard_win.cc
+++ b/ui/base/clipboard/clipboard_win.cc
@@ -21,9 +21,9 @@
#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_hdc.h"
#include "base/win/wrapped_window_proc.h"
-#include "third_party/zlib/zlib.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/clipboard/clipboard_util_win.h"
-#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/size.h"
namespace ui {
@@ -430,76 +430,36 @@ void Clipboard::ReadHTML(Clipboard::Buffer buffer, string16* markup,
markup->assign(UTF8ToWide(markup_utf8));
}
-void Clipboard::ReadImage(Buffer buffer, std::string* data) const {
+SkBitmap Clipboard::ReadImage(Buffer buffer) const {
DCHECK_EQ(buffer, BUFFER_STANDARD);
- if (!data) {
- NOTREACHED();
- return;
- }
// Acquire the clipboard.
ScopedClipboard clipboard;
if (!clipboard.Acquire(GetClipboardWindow()))
- return;
+ return SkBitmap();
HBITMAP source_bitmap = static_cast<HBITMAP>(::GetClipboardData(CF_BITMAP));
if (!source_bitmap)
- return;
+ return SkBitmap();
base::win::ScopedHDC source_dc(::CreateCompatibleDC(NULL));
if (!source_dc)
- return;
+ return SkBitmap();
+ ::SelectObject(source_dc, source_bitmap);
// Get the dimensions of the bitmap.
BITMAPINFO bitmap_info = {};
bitmap_info.bmiHeader.biSize = sizeof(bitmap_info.bmiHeader);
::GetDIBits(source_dc, source_bitmap, 0, 0, 0, &bitmap_info, DIB_RGB_COLORS);
- gfx::Size size(bitmap_info.bmiHeader.biWidth,
- abs(bitmap_info.bmiHeader.biHeight));
-
-
- BITMAPINFO destination_bitmap_info = {};
- destination_bitmap_info.bmiHeader.biSize =
- sizeof(destination_bitmap_info.bmiHeader);
- destination_bitmap_info.bmiHeader.biWidth = size.width();
- // Convert to a top-down DIB.
- destination_bitmap_info.bmiHeader.biHeight = -size.height();
- destination_bitmap_info.bmiHeader.biPlanes = 1;
- destination_bitmap_info.bmiHeader.biBitCount = 32;
- destination_bitmap_info.bmiHeader.biCompression = BI_RGB;
-
- unsigned char* raw_data;
- base::win::ScopedHDC destination_dc(::CreateCompatibleDC(source_dc));
- if (!destination_dc)
- return;
- base::win::ScopedGDIObject<HBITMAP> destination_bitmap(::CreateDIBSection(
- destination_dc,
- &destination_bitmap_info,
- DIB_RGB_COLORS,
- reinterpret_cast<void**>(&raw_data),
- NULL,
- 0));
- if (!destination_bitmap)
- return;
+ int width = bitmap_info.bmiHeader.biWidth;
+ int height = bitmap_info.bmiHeader.biHeight;
- ::SelectObject(source_dc, source_bitmap);
- ::SelectObject(destination_dc, destination_bitmap);
- ::BitBlt(destination_dc, 0, 0, size.width(), size.height(), source_dc, 0, 0,
- SRCCOPY);
-
- std::vector<unsigned char> png_data;
- gfx::PNGCodec::EncodeWithCompressionLevel(
- raw_data,
- gfx::PNGCodec::FORMAT_BGRA,
- size,
- size.width() * 4,
- false,
- std::vector<gfx::PNGCodec::Comment>(),
- Z_BEST_SPEED,
- &png_data);
-
- data->assign(reinterpret_cast<char*>(vector_as_array(&png_data)),
- png_data.size());
+ gfx::CanvasSkia canvas(width, height, false);
+
+ HDC destination_dc = canvas.beginPlatformPaint();
+ ::BitBlt(destination_dc, 0, 0, width, height, source_dc, 0, 0, SRCCOPY);
+ canvas.endPlatformPaint();
+ return canvas.ExtractBitmap();
}
void Clipboard::ReadBookmark(string16* title, std::string* url) const {
diff --git a/webkit/tools/test_shell/DEPS b/webkit/tools/test_shell/DEPS
index cdb5eeb..cce3c4b 100644
--- a/webkit/tools/test_shell/DEPS
+++ b/webkit/tools/test_shell/DEPS
@@ -1,5 +1,6 @@
include_rules = [
"+mac",
"+app",
+ "+third_party/zlib",
"+ui",
]
diff --git a/webkit/tools/test_shell/simple_clipboard_impl.cc b/webkit/tools/test_shell/simple_clipboard_impl.cc
index cd12ded..2bb35df 100644
--- a/webkit/tools/test_shell/simple_clipboard_impl.cc
+++ b/webkit/tools/test_shell/simple_clipboard_impl.cc
@@ -7,10 +7,14 @@
#include <string>
#include "base/lazy_instance.h"
+#include "base/stl_util-inl.h"
#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/zlib/zlib.h"
#include "ui/base/clipboard/clipboard.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/size.h"
#include "webkit/glue/scoped_clipboard_writer_glue.h"
// Clipboard glue
@@ -60,7 +64,24 @@ void ClipboardReadHTML(ui::Clipboard::Buffer buffer, string16* markup,
}
void ClipboardReadImage(ui::Clipboard::Buffer buffer, std::string* data) {
- ClipboardGetClipboard()->ReadImage(buffer, data);
+ SkBitmap bitmap = ClipboardGetClipboard()->ReadImage(buffer);
+ if (bitmap.isNull())
+ return;
+
+ std::vector<unsigned char> png_data;
+ SkAutoLockPixels lock(bitmap);
+ if (gfx::PNGCodec::EncodeWithCompressionLevel(
+ static_cast<const unsigned char*>(bitmap.getPixels()),
+ gfx::PNGCodec::FORMAT_BGRA,
+ gfx::Size(bitmap.width(), bitmap.height()),
+ bitmap.rowBytes(),
+ false,
+ std::vector<gfx::PNGCodec::Comment>(),
+ Z_BEST_SPEED,
+ &png_data)) {
+ data->assign(reinterpret_cast<char*>(vector_as_array(&png_data)),
+ png_data.size());
+ }
}
bool ClipboardReadData(ui::Clipboard::Buffer buffer, const string16& type,