summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/cairo_cached_surface.h
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-10 18:16:15 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-10 18:16:15 +0000
commiteafb5b7bf242e8ebd9c947012ca404dd904bc1bd (patch)
tree697b1e9468e78b390233af5e8c696ff14f65fa72 /chrome/browser/gtk/cairo_cached_surface.h
parente28b0fbbcde1c08e4dfbff7d4bd8e1f292892b9c (diff)
downloadchromium_src-eafb5b7bf242e8ebd9c947012ca404dd904bc1bd.zip
chromium_src-eafb5b7bf242e8ebd9c947012ca404dd904bc1bd.tar.gz
chromium_src-eafb5b7bf242e8ebd9c947012ca404dd904bc1bd.tar.bz2
Reapplies the GdkPixbuf -> cairo surface patch.
Only difference is explicitly calling a FreePerDisplaySurfaces() function from ~GtkThemeProvider() because vtables are set to base class during destructor calling. BUG=http://crbug.com/10499 Original Review URL: http://codereview.chromium.org/197046 Review URL: http://codereview.chromium.org/199077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/cairo_cached_surface.h')
-rw-r--r--chrome/browser/gtk/cairo_cached_surface.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/chrome/browser/gtk/cairo_cached_surface.h b/chrome/browser/gtk/cairo_cached_surface.h
new file mode 100644
index 0000000..2c0b4d3
--- /dev/null
+++ b/chrome/browser/gtk/cairo_cached_surface.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_
+#define CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_
+
+#include <gtk/gtk.h>
+
+// A helper class that takes a GdkPixbuf* and renders it to the screen. Unlike
+// gdk_cairo_set_source_pixbuf(), CairoCachedSurface assumes that the pixbuf is
+// immutable after UsePixbuf() is called and can be sent to the X server
+// once. From then on, that cached version is used so we don't upload the same
+// image each and every time we expose.
+//
+// Most cached surfaces are owned by the GtkThemeProvider, which associates
+// them with a certain XDisplay. Some users of surfaces (CustomDrawButtonBase,
+// for example) own their surfaces instead since they interact with the
+// ResourceBundle instead of the GtkThemeProvider.
+class CairoCachedSurface {
+ public:
+ CairoCachedSurface();
+ ~CairoCachedSurface();
+
+ // Whether this CairoCachedSurface owns a GdkPixbuf.
+ bool valid() const {
+ return pixbuf_;
+ }
+
+ // The dimensions of the underlying pixbuf/surface. (or -1 if invalid.)
+ int Width() const;
+ int Height() const;
+
+ // Sets the pixbuf that we pass to cairo. Calling UsePixbuf() only derefs the
+ // current pixbuf and surface (if they exist). Actually transfering data to
+ // the X server occurs at SetSource() time. Calling UsePixbuf() should only
+ // be done once as it clears cached data from the X server.
+ void UsePixbuf(GdkPixbuf* pixbuf);
+
+ // Sets our pixbuf as the active surface starting at (x, y), uploading it in
+ // case we don't have an X backed surface cached.
+ void SetSource(cairo_t* cr, int x, int y);
+
+ // Raw access to the pixbuf. May be NULL. Used for a few gdk operations
+ // regarding window shaping.
+ GdkPixbuf* pixbuf() { return pixbuf_; }
+
+ private:
+ // The source pixbuf.
+ GdkPixbuf* pixbuf_;
+
+ // Our cached surface. This should be a xlib surface so the data lives on the
+ // server instead of on the client.
+ cairo_surface_t* surface_;
+};
+
+#endif // CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_