OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ | 5 #ifndef CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ |
6 #define CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ | 6 #define CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 typedef struct _GdkPixbuf GdkPixbuf; | 9 typedef struct _GdkPixbuf GdkPixbuf; |
10 typedef struct _cairo cairo_t; | 10 typedef struct _cairo cairo_t; |
(...skipping 12 matching lines...) Expand all Loading... |
23 class CairoCachedSurface { | 23 class CairoCachedSurface { |
24 public: | 24 public: |
25 CairoCachedSurface(); | 25 CairoCachedSurface(); |
26 ~CairoCachedSurface(); | 26 ~CairoCachedSurface(); |
27 | 27 |
28 // Whether this CairoCachedSurface owns a GdkPixbuf. | 28 // Whether this CairoCachedSurface owns a GdkPixbuf. |
29 bool valid() const { | 29 bool valid() const { |
30 return pixbuf_; | 30 return pixbuf_; |
31 } | 31 } |
32 | 32 |
| 33 // Delete all our data. |
| 34 void Reset(); |
| 35 |
33 // The dimensions of the underlying pixbuf/surface. (or -1 if invalid.) | 36 // The dimensions of the underlying pixbuf/surface. (or -1 if invalid.) |
34 int Width() const; | 37 int Width() const; |
35 int Height() const; | 38 int Height() const; |
36 | 39 |
37 // Sets the pixbuf that we pass to cairo. Calling UsePixbuf() only derefs the | 40 // Sets the pixbuf that we pass to cairo. Calling UsePixbuf() only derefs the |
38 // current pixbuf and surface (if they exist). Actually transfering data to | 41 // current pixbuf and surface (if they exist). Actually transfering data to |
39 // the X server occurs at SetSource() time. Calling UsePixbuf() should only | 42 // the X server occurs at SetSource() time. Calling UsePixbuf() should only |
40 // be done once as it clears cached data from the X server. | 43 // be done once as it clears cached data from the X server. |
41 void UsePixbuf(GdkPixbuf* pixbuf); | 44 void UsePixbuf(GdkPixbuf* pixbuf); |
42 | 45 |
43 // Sets our pixbuf as the active surface starting at (x, y), uploading it in | 46 // Sets our pixbuf as the active surface starting at (x, y), uploading it in |
44 // case we don't have an X backed surface cached. | 47 // case we don't have an X backed surface cached. |
45 void SetSource(cairo_t* cr, int x, int y); | 48 void SetSource(cairo_t* cr, int x, int y); |
46 | 49 |
| 50 // Performs a mask operation, using this surface as the alpha channel. |
| 51 void MaskSource(cairo_t* cr, int x, int y); |
| 52 |
47 // Raw access to the pixbuf. May be NULL. Used for a few gdk operations | 53 // Raw access to the pixbuf. May be NULL. Used for a few gdk operations |
48 // regarding window shaping. | 54 // regarding window shaping. |
49 GdkPixbuf* pixbuf() { return pixbuf_; } | 55 GdkPixbuf* pixbuf() { return pixbuf_; } |
50 | 56 |
51 private: | 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 |
52 // The source pixbuf. | 62 // The source pixbuf. |
53 GdkPixbuf* pixbuf_; | 63 GdkPixbuf* pixbuf_; |
54 | 64 |
55 // Our cached surface. This should be a xlib surface so the data lives on the | 65 // Our cached surface. This should be a xlib surface so the data lives on the |
56 // server instead of on the client. | 66 // server instead of on the client. |
57 cairo_surface_t* surface_; | 67 cairo_surface_t* surface_; |
58 }; | 68 }; |
59 | 69 |
60 #endif // CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ | 70 #endif // CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ |
OLD | NEW |