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; | |
tony
2009/09/09 21:26:21
Nit: Maybe include the implementation in the heade
| |
27 | |
28 // The dimensions of the underlying pixbuf/surface. (or -1 if invalid.) | |
29 int Width() const; | |
30 int Height() const; | |
31 | |
32 // Sets the pixbuf that we pass to cairo. Calling UsePixbuf() only derefs the | |
33 // current pixbuf and surface (if they exist). Actually transfering data to | |
34 // 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
| |
35 // be done once as it clears cached data from the X Server. | |
36 void UsePixbuf(GdkPixbuf* pixbuf); | |
37 | |
38 // Sets our pixbuf as the active surface starting at (x, y), uploading it in | |
39 // case we don't have an X backed surface cached. | |
40 void SetSource(cairo_t* cr, int x, int y); | |
41 | |
42 // Raw access to the pixbuf. May be NULL. Used for a few gdk operations | |
43 // regarding window shaping. | |
44 GdkPixbuf* pixbuf() { return pixbuf_; } | |
45 | |
46 private: | |
47 // The source pixbuf. | |
48 GdkPixbuf* pixbuf_; | |
tony
2009/09/09 21:26:21
Maybe make this a ScopedGObject (in base/gfx/gtk_u
| |
49 | |
50 // Our cached surface. This should be a xlib surface so the data lives on the | |
51 // server instead of on the client. | |
52 cairo_surface_t* surface_; | |
53 }; | |
54 | |
55 #endif // CHROME_BROWSER_GTK_CAIRO_CACHED_SURFACE_H_ | |
OLD | NEW |