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

Unified Diff: chrome/browser/gtk/cairo_cached_surface.h

Issue 197046: Upload GdkPixbufs into cairo surfaces so they (hopefully) live on X (Closed)
Patch Set: Fix crash Created 11 years, 3 months 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
Index: chrome/browser/gtk/cairo_cached_surface.h
diff --git a/chrome/browser/gtk/cairo_cached_surface.h b/chrome/browser/gtk/cairo_cached_surface.h
new file mode 100644
index 0000000000000000000000000000000000000000..ee8b5b3599c758c2f925930a861c912d6de83184
--- /dev/null
+++ b/chrome/browser/gtk/cairo_cached_surface.h
@@ -0,0 +1,55 @@
+// 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;
tony 2009/09/09 21:26:21 Nit: Maybe include the implementation in the heade
+
+ // 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
Evan Martin 2009/09/09 21:50:34 I think "server" should be lowercase, here and bel
+ // 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_;
tony 2009/09/09 21:26:21 Maybe make this a ScopedGObject (in base/gfx/gtk_u
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698