OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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_UI_GTK_CAIRO_CACHED_SURFACE_H_ | |
6 #define CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ | |
7 #pragma once | |
8 | |
9 typedef struct _GdkPixbuf GdkPixbuf; | |
10 typedef struct _cairo cairo_t; | |
11 typedef struct _cairo_surface cairo_surface_t; | |
12 | |
13 // A helper class that takes a GdkPixbuf* and renders it to the screen. Unlike | |
14 // gdk_cairo_set_source_pixbuf(), CairoCachedSurface assumes that the pixbuf is | |
15 // immutable after UsePixbuf() is called and can be sent to the X server | |
16 // once. From then on, that cached version is used so we don't upload the same | |
17 // image each and every time we expose. | |
18 // | |
19 // Most cached surfaces are owned by the GtkThemeService, which associates | |
20 // them with a certain XDisplay. Some users of surfaces (CustomDrawButtonBase, | |
21 // for example) own their surfaces instead since they interact with the | |
22 // ResourceBundle instead of the GtkThemeService. | |
23 class CairoCachedSurface { | |
24 public: | |
25 CairoCachedSurface(); | |
26 ~CairoCachedSurface(); | |
27 | |
28 // Whether this CairoCachedSurface owns a GdkPixbuf. | |
29 bool valid() const { | |
30 return pixbuf_; | |
31 } | |
32 | |
33 // Delete all our data. | |
34 void Reset(); | |
35 | |
36 // The dimensions of the underlying pixbuf/surface. (or -1 if invalid.) | |
37 int Width() const; | |
38 int Height() const; | |
39 | |
40 // Sets the pixbuf that we pass to cairo. Calling UsePixbuf() only derefs the | |
41 // current pixbuf and surface (if they exist). Actually transfering data to | |
42 // the X server occurs at SetSource() time. Calling UsePixbuf() should only | |
43 // be done once as it clears cached data from the X server. | |
44 void UsePixbuf(GdkPixbuf* pixbuf); | |
45 | |
46 // Sets our pixbuf as the active surface starting at (x, y), uploading it in | |
47 // case we don't have an X backed surface cached. | |
48 void SetSource(cairo_t* cr, int x, int y); | |
49 | |
50 // Performs a mask operation, using this surface as the alpha channel. | |
51 void MaskSource(cairo_t* cr, int x, int y); | |
52 | |
53 // Raw access to the pixbuf. May be NULL. Used for a few gdk operations | |
54 // regarding window shaping. | |
55 GdkPixbuf* pixbuf() { return pixbuf_; } | |
56 | |
57 private: | |
58 // Makes sure |surface_| is a valid thing that lives on the X server, | |
59 // uploading it if necessary. | |
60 void EnsureSurfaceValid(cairo_t* cr); | |
61 | |
62 // The source pixbuf. | |
63 GdkPixbuf* pixbuf_; | |
64 | |
65 // Our cached surface. This should be a xlib surface so the data lives on the | |
66 // server instead of on the client. | |
67 cairo_surface_t* surface_; | |
68 }; | |
69 | |
70 #endif // CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ | |
OLD | NEW |