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

Unified Diff: ui/gfx/image/image.cc

Issue 8769017: GTK: Move CairoCachedSurface from being owned by GtkThemeService to gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase for commit Created 9 years 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/gfx/image/image.h ('k') | ui/gfx/image/image_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image.cc
diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc
index 2ba2eba203349c389d491da3311398c8a28e59be..f14b9ec0e2413a45db546a3955ec691e604e81e7 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,19 @@ internal::ImageRep* Image::GetRepresentation(
AddRepresentation(rep);
return rep;
}
+#if defined(TOOLKIT_USES_GTK)
+ else if (rep_type == Image::kImageRepCairoCache) {
+ // Handle any-to-Cairo conversion. This may recursively create an
+ // intermediate pixbuf before we send the data 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) {
« no previous file with comments | « ui/gfx/image/image.h ('k') | ui/gfx/image/image_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698