Chromium Code Reviews| Index: ui/gfx/image/image.cc |
| diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc |
| index 2ba2eba203349c389d491da3311398c8a28e59be..70d247aac5ba95b4681baee72e1ed8dfbc8b9e49 100644 |
| --- a/ui/gfx/image/image.cc |
| +++ b/ui/gfx/image/image.cc |
| @@ -15,6 +15,7 @@ |
| #include <glib-object.h> |
| #include "ui/gfx/canvas_skia.h" |
| #include "ui/gfx/gtk_util.h" |
| +#include "ui/gfx/image/cairo_cached_surface.h" |
| #elif defined(OS_MACOSX) |
| #include "base/mac/mac_util.h" |
| #include "skia/ext/skia_utils_mac.h" |
| @@ -42,6 +43,7 @@ const SkBitmap* GdkPixbufToSkBitmap(GdkPixbuf* pixbuf) { |
| class ImageRepSkia; |
| class ImageRepGdk; |
| +class ImageRepCairoCached; |
| class ImageRepCocoa; |
| // An ImageRep is the object that holds the backing memory for an Image. Each |
| @@ -67,6 +69,11 @@ class ImageRep { |
| CHECK_EQ(type_, Image::kImageRepGdk); |
| return reinterpret_cast<ImageRepGdk*>(this); |
| } |
| + |
| + ImageRepCairoCached* AsImageRepCairo() { |
| + CHECK_EQ(type_, Image::kImageRepCairoCache); |
| + return reinterpret_cast<ImageRepCairoCached*>(this); |
| + } |
| #endif |
| #if defined(OS_MACOSX) |
| @@ -133,7 +140,29 @@ class ImageRepGdk : public ImageRep { |
| DISALLOW_COPY_AND_ASSIGN(ImageRepGdk); |
| }; |
| -#endif |
| + |
| +// Represents data that lives on the display server instead of in the client. |
| +class ImageRepCairoCached : public ImageRep { |
| + public: |
| + explicit ImageRepCairoCached(GdkPixbuf* pixbuf) |
| + : ImageRep(Image::kImageRepCairoCache), |
| + cairo_cache_(new CairoCachedSurface) { |
| + CHECK(pixbuf); |
| + cairo_cache_->UsePixbuf(pixbuf); |
| + } |
| + |
| + virtual ~ImageRepCairoCached() { |
| + delete cairo_cache_; |
| + } |
| + |
| + CairoCachedSurface* surface() const { return cairo_cache_; } |
| + |
| + private: |
| + CairoCachedSurface* cairo_cache_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ImageRepCairoCached); |
| +}; |
| +#endif // defined(TOOLKIT_USES_GTK) |
| #if defined(OS_MACOSX) |
| class ImageRepCocoa : public ImageRep { |
| @@ -156,7 +185,7 @@ class ImageRepCocoa : public ImageRep { |
| DISALLOW_COPY_AND_ASSIGN(ImageRepCocoa); |
| }; |
| -#endif |
| +#endif // defined(OS_MACOSX) |
| // The Storage class acts similarly to the pixels in a SkBitmap: the Image |
| // class holds a refptr instance of Storage, which in turn holds all the |
| @@ -244,6 +273,11 @@ GdkPixbuf* Image::ToGdkPixbuf() const { |
| internal::ImageRep* rep = GetRepresentation(Image::kImageRepGdk); |
| return rep->AsImageRepGdk()->pixbuf(); |
| } |
| + |
| +CairoCachedSurface* const Image::ToCairo() const { |
| + internal::ImageRep* rep = GetRepresentation(Image::kImageRepCairoCache); |
| + return rep->AsImageRepCairo()->surface(); |
| +} |
| #endif |
| #if defined(OS_MACOSX) |
| @@ -337,6 +371,9 @@ internal::ImageRep* Image::GetRepresentation( |
| rep = new internal::ImageRepSkia( |
| internal::GdkPixbufToSkBitmap(pixbuf_rep->pixbuf())); |
| } |
| + // We don't do conversions from CairoCachedSurfaces to Skia because the |
| + // data lives on the display server and we'll always have a GdkPixbuf if we |
| + // have a CairoCachedSurface. |
| #elif defined(OS_MACOSX) |
| if (storage_->default_representation_type() == Image::kImageRepCocoa) { |
| internal::ImageRepCocoa* nsimage_rep = default_rep->AsImageRepCocoa(); |
| @@ -349,6 +386,18 @@ internal::ImageRep* Image::GetRepresentation( |
| AddRepresentation(rep); |
| return rep; |
| } |
| +#if defined(TOOLKIT_USES_GTK) |
| + else if (rep_type == Image::kImageRepCairoCache) { |
|
Robert Sesek
2011/12/02 16:36:16
// Handle to-Cairo conversion. This may recursivel
|
| + // Send the data that we have in process right now to the display server. |
| + internal::ImageRep* rep = GetRepresentation(Image::kImageRepGdk); |
| + internal::ImageRepCairoCached* native_rep = |
| + new internal::ImageRepCairoCached(rep->AsImageRepGdk()->pixbuf()); |
| + |
| + CHECK(native_rep); |
| + AddRepresentation(native_rep); |
| + return native_rep; |
| + } |
| +#endif |
| // Handle Skia-to-native conversions. |
| if (default_rep->type() == Image::kImageRepSkia) { |