| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_ | |
| 6 #define CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_ | |
| 7 | |
| 8 #include <gtk/gtk.h> | |
| 9 | |
| 10 // A helper class that takes a GdkPixbuf* and renders it to the screen. Unlike | |
| 11 // gdk_cairo_set_source_pixbuf(), CairoCachedSurface assumes that the pixbuf is | |
| 12 // immutable after UsePixbuf() is called and can be sent to the X server | |
| 13 // once. From then on, that cached version is used so we don't upload the same | |
| 14 // image each and every time we expose. | |
| 15 // | |
| 16 // Most cached surfaces are owned by the GtkThemeProvider, which associates | |
| 17 // them with a certain XDisplay. Some users of surfaces (CustomDrawButtonBase, | |
| 18 // for example) own their surfaces instead since they interact with the | |
| 19 // ResourceBundle instead of the GtkThemeProvider. | |
| 20 class CairoCachedSurface { | |
| 21 public: | |
| 22 CairoCachedSurface(); | |
| 23 ~CairoCachedSurface(); | |
| 24 | |
| 25 // Whether this CairoCachedSurface owns a GdkPixbuf. | |
| 26 bool valid() const { | |
| 27 return pixbuf_; | |
| 28 } | |
| 29 | |
| 30 // The dimensions of the underlying pixbuf/surface. (or -1 if invalid.) | |
| 31 int Width() const; | |
| 32 int Height() const; | |
| 33 | |
| 34 // Sets the pixbuf that we pass to cairo. Calling UsePixbuf() only derefs the | |
| 35 // current pixbuf and surface (if they exist). Actually transfering data to | |
| 36 // the X server occurs at SetSource() time. Calling UsePixbuf() should only | |
| 37 // be done once as it clears cached data from the X server. | |
| 38 void UsePixbuf(GdkPixbuf* pixbuf); | |
| 39 | |
| 40 // Sets our pixbuf as the active surface starting at (x, y), uploading it in | |
| 41 // case we don't have an X backed surface cached. | |
| 42 void SetSource(cairo_t* cr, int x, int y); | |
| 43 | |
| 44 // Raw access to the pixbuf. May be NULL. Used for a few gdk operations | |
| 45 // regarding window shaping. | |
| 46 GdkPixbuf* pixbuf() { return pixbuf_; } | |
| 47 | |
| 48 private: | |
| 49 // The source pixbuf. | |
| 50 GdkPixbuf* pixbuf_; | |
| 51 | |
| 52 // Our cached surface. This should be a xlib surface so the data lives on the | |
| 53 // server instead of on the client. | |
| 54 cairo_surface_t* surface_; | |
| 55 }; | |
| 56 | |
| 57 #endif // CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_ | |
| OLD | NEW |