diff options
-rw-r--r-- | base/gfx/bitmap_platform_device_linux.cc | 52 | ||||
-rw-r--r-- | base/gfx/bitmap_platform_device_linux.h | 13 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.cc | 33 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_gtk.cc | 9 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_mac.mm | 38 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_win.cc | 36 |
6 files changed, 85 insertions, 96 deletions
diff --git a/base/gfx/bitmap_platform_device_linux.cc b/base/gfx/bitmap_platform_device_linux.cc index c80a273..18f8ab1 100644 --- a/base/gfx/bitmap_platform_device_linux.cc +++ b/base/gfx/bitmap_platform_device_linux.cc @@ -10,6 +10,31 @@ namespace gfx { +// ----------------------------------------------------------------------------- +// These objects are reference counted and own a Cairo surface. The surface is +// the backing store for a Skia bitmap and we reference count it so that we can +// copy BitmapPlatformDeviceLinux objects without having to copy all the image +// data. +// ----------------------------------------------------------------------------- +class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData + : public base::RefCounted<BitmapPlatformDeviceLinuxData> { + public: + explicit BitmapPlatformDeviceLinuxData(cairo_surface_t* surface) + : surface_(surface) { } + + cairo_surface_t* surface() const { return surface_; } + + protected: + cairo_surface_t *const surface_; + + friend class base::RefCounted<BitmapPlatformDeviceLinuxData>; + ~BitmapPlatformDeviceLinuxData() { + cairo_surface_destroy(surface_); + } + + DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceLinuxData); +}; + // We use this static factory function instead of the regular constructor so // that we can create the pixel data before calling the constructor. This is // required so that we can call the base class' constructor with the pixel @@ -33,28 +58,37 @@ BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( #endif // The device object will take ownership of the graphics context. - return new BitmapPlatformDeviceLinux(bitmap, surface); + return new BitmapPlatformDeviceLinux + (bitmap, new BitmapPlatformDeviceLinuxData(surface)); } // The device will own the bitmap, which corresponds to also owning the pixel // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. -BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap, - cairo_surface_t* surface) +BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( + const SkBitmap& bitmap, + BitmapPlatformDeviceLinuxData* data) : PlatformDeviceLinux(bitmap), - surface_(surface) { + data_(data) { } BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( const BitmapPlatformDeviceLinux& other) : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>( - other).accessBitmap(true)) { + other).accessBitmap(true)), + data_(other.data_) { } BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() { - if (surface_) { - cairo_surface_destroy(surface_); - surface_ = NULL; - } +} + +cairo_surface_t* BitmapPlatformDeviceLinux::surface() const { + return data_->surface(); +} + +BitmapPlatformDeviceLinux& BitmapPlatformDeviceLinux::operator=( + const BitmapPlatformDeviceLinux& other) { + data_ = other.data_; + return *this; } } // namespace gfx diff --git a/base/gfx/bitmap_platform_device_linux.h b/base/gfx/bitmap_platform_device_linux.h index c029293..629fd1d 100644 --- a/base/gfx/bitmap_platform_device_linux.h +++ b/base/gfx/bitmap_platform_device_linux.h @@ -55,6 +55,9 @@ namespace gfx { // case we'll probably create the buffer from a precreated region of memory. // ----------------------------------------------------------------------------- class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { + // A reference counted cairo surface + class BitmapPlatformDeviceLinuxData; + public: /// Static constructor. I don't understand this, it's just a copy of the mac static BitmapPlatformDeviceLinux* Create(int width, int height, @@ -65,9 +68,11 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { // we ever have to share state between some native drawing UI and Skia, like // the Windows and Mac versions of this class do. // - // This object takes ownership of @surface. - BitmapPlatformDeviceLinux(const SkBitmap& other, cairo_surface_t* surface); + // This object takes ownership of @data. + BitmapPlatformDeviceLinux(const SkBitmap& other, + BitmapPlatformDeviceLinuxData* data); virtual ~BitmapPlatformDeviceLinux(); + BitmapPlatformDeviceLinux& operator=(const BitmapPlatformDeviceLinux& other); // A stub copy constructor. Needs to be properly implemented. BitmapPlatformDeviceLinux(const BitmapPlatformDeviceLinux& other); @@ -75,10 +80,10 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { // Bitmaps aren't vector graphics. virtual bool IsVectorial() { return false; } - cairo_surface_t* surface() const { return surface_; } + cairo_surface_t* surface() const; private: - cairo_surface_t* surface_; + scoped_refptr<BitmapPlatformDeviceLinuxData> data_; }; } // namespace gfx diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index cd3c2d7..551d14c 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -9,8 +9,10 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/gfx/bitmap_platform_device.h" +#include "base/gfx/png_encoder.h" #include "base/gfx/size.h" #include "base/icu_util.h" +#include "base/md5.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/stats_table.h" @@ -148,6 +150,37 @@ static void UnitTestAssertHandler(const std::string& str) { } // static +std::string TestShell::DumpImage(WebFrame* web_frame, + const std::wstring& file_name) { + scoped_ptr<gfx::BitmapPlatformDevice> device; + if (!web_frame->CaptureImage(&device, true)) + return std::string(); + + const SkBitmap& src_bmp = device->accessBitmap(false); + + // Encode image. + std::vector<unsigned char> png; + SkAutoLockPixels src_bmp_lock(src_bmp); + PNGEncoder::Encode( + reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), + PNGEncoder::FORMAT_BGRA, src_bmp.width(), src_bmp.height(), + static_cast<int>(src_bmp.rowBytes()), true, &png); + + // Write to disk. + file_util::WriteFile(file_name, reinterpret_cast<const char *>(&png[0]), + png.size()); + + // Compute MD5 sum. + MD5Context ctx; + MD5Init(&ctx); + MD5Update(&ctx, src_bmp.getPixels(), src_bmp.getSize()); + + MD5Digest digest; + MD5Final(&digest, &ctx); + return MD5DigestToBase16(digest); +} + +// static void TestShell::InitLogging(bool suppress_error_dialogs, bool running_layout_tests) { if (suppress_error_dialogs) diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc index f11b357..67d25c1 100644 --- a/webkit/tools/test_shell/test_shell_gtk.cc +++ b/webkit/tools/test_shell/test_shell_gtk.cc @@ -284,15 +284,6 @@ void TestShell::ResizeSubViews() { // GTK manages layout for us so we do nothing. } -/* static */ std::string TestShell::DumpImage( - WebFrame* web_frame, - const std::wstring& file_name) { - // Windows uses some platform specific bitmap functions here. - // TODO(agl): port - NOTIMPLEMENTED(); - return "00000000000000000000000000000000"; -} - /* static */ void TestShell::DumpBackForwardList(std::wstring* result) { result->clear(); for (WindowList::iterator iter = TestShell::windowList()->begin(); diff --git a/webkit/tools/test_shell/test_shell_mac.mm b/webkit/tools/test_shell/test_shell_mac.mm index 4d38664..f4a14c9d2 100644 --- a/webkit/tools/test_shell/test_shell_mac.mm +++ b/webkit/tools/test_shell/test_shell_mac.mm @@ -12,10 +12,8 @@ #include "base/debug_util.h" #include "base/file_util.h" #include "base/gfx/bitmap_platform_device.h" -#include "base/gfx/png_encoder.h" #include "base/gfx/size.h" #include "base/icu_util.h" -#include "base/md5.h" #include "base/memory_debug.h" #include "base/message_loop.h" #include "base/path_service.h" @@ -397,42 +395,6 @@ void TestShell::ResizeSubViews() { // handled by Cocoa for us } -/* static */ std::string TestShell::DumpImage( - WebFrame* web_frame, - const std::wstring& file_name) { - scoped_ptr<gfx::BitmapPlatformDevice> device; - if (!web_frame->CaptureImage(&device, true)) - return std::string(); - - const SkBitmap& src_bmp = device->accessBitmap(false); - - // Encode image. - std::vector<unsigned char> png; - SkAutoLockPixels src_bmp_lock(src_bmp); - PNGEncoder::Encode( - reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), - PNGEncoder::FORMAT_RGBA, src_bmp.width(), src_bmp.height(), - static_cast<int>(src_bmp.rowBytes()), true, &png); - - // Write to disk. - if (png.size() > 0) { - FILE* file = fopen(WideToUTF8(file_name).c_str(), "w"); - if (file) { - fwrite(&png[0], sizeof(unsigned char), png.size(), file); - fclose(file); - } - } - - // Compute MD5 sum. - MD5Context ctx; - MD5Init(&ctx); - MD5Update(&ctx, src_bmp.getPixels(), src_bmp.getSize()); - - MD5Digest digest; - MD5Final(&digest, &ctx); - return MD5DigestToBase16(digest); -} - /* static */ void TestShell::DumpBackForwardList(std::wstring* result) { result->clear(); for (WindowList::iterator iter = TestShell::windowList()->begin(); diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc index eb52dc9..12c2c47 100644 --- a/webkit/tools/test_shell/test_shell_win.cc +++ b/webkit/tools/test_shell/test_shell_win.cc @@ -12,8 +12,6 @@ #include "webkit/tools/test_shell/test_shell.h" #include "base/gfx/bitmap_platform_device.h" -#include "base/gfx/png_encoder.h" -#include "base/md5.h" #include "base/memory_debug.h" #include "base/message_loop.h" #include "base/path_service.h" @@ -113,40 +111,6 @@ ATOM TestShell::RegisterWindowClass() { return RegisterClassEx(&wcex); } -// static -std::string TestShell::DumpImage(WebFrame* web_frame, - const std::wstring& file_name) { - scoped_ptr<gfx::BitmapPlatformDevice> device; - if (!web_frame->CaptureImage(&device, true)) - return std::string(); - - const SkBitmap& src_bmp = device->accessBitmap(false); - - // Encode image. - std::vector<unsigned char> png; - SkAutoLockPixels src_bmp_lock(src_bmp); - PNGEncoder::Encode( - reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), - PNGEncoder::FORMAT_BGRA, src_bmp.width(), src_bmp.height(), - static_cast<int>(src_bmp.rowBytes()), true, &png); - - // Write to disk. - FILE* file = NULL; - if (_wfopen_s(&file, file_name.c_str(), L"wb") == 0) { - fwrite(&png[0], 1, png.size(), file); - fclose(file); - } - - // Compute MD5 sum. - MD5Context ctx; - MD5Init(&ctx); - MD5Update(&ctx, src_bmp.getPixels(), src_bmp.getSize()); - - MD5Digest digest; - MD5Final(&digest, &ctx); - return MD5DigestToBase16(digest); -} - void TestShell::DumpBackForwardList(std::wstring* result) { result->clear(); for (WindowList::iterator iter = TestShell::windowList()->begin(); |