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

Side by Side Diff: ui/gfx/image/cairo_cached_surface.h

Issue 8769017: GTK: Move CairoCachedSurface from being owned by GtkThemeService to gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years 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 unified diff | Download patch
OLDNEW
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 UI_GFX_IMAGE_CAIRO_CACHED_SURFACE_H_
6 #define CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ 6 #define UI_GFX_IMAGE_CAIRO_CACHED_SURFACE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector>
10
11 #include "ui/base/ui_export.h"
12
13 typedef struct _GdkDisplay GdkDisplay;
9 typedef struct _GdkPixbuf GdkPixbuf; 14 typedef struct _GdkPixbuf GdkPixbuf;
15 typedef struct _GtkWidget GtkWidget;
10 typedef struct _cairo cairo_t; 16 typedef struct _cairo cairo_t;
11 typedef struct _cairo_surface cairo_surface_t; 17 typedef struct _cairo_surface cairo_surface_t;
12 18
19 namespace gfx {
20
13 // A helper class that takes a GdkPixbuf* and renders it to the screen. Unlike 21 // 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 22 // 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 23 // immutable after UsePixbuf() is called and can be sent to the display server
16 // once. From then on, that cached version is used so we don't upload the same 24 // once. From then on, that cached version is used so we don't upload the same
17 // image each and every time we expose. 25 // image each and every time we expose.
18 // 26 //
19 // Most cached surfaces are owned by the GtkThemeService, which associates 27 // Most cached surfaces are owned by the GtkThemeService, which associates
20 // them with a certain XDisplay. Some users of surfaces (CustomDrawButtonBase, 28 // them with a certain XDisplay. Some users of surfaces (CustomDrawButtonBase,
21 // for example) own their surfaces instead since they interact with the 29 // for example) own their surfaces instead since they interact with the
22 // ResourceBundle instead of the GtkThemeService. 30 // ResourceBundle instead of the GtkThemeService.
23 class CairoCachedSurface { 31 class UI_EXPORT CairoCachedSurface {
24 public: 32 public:
25 CairoCachedSurface(); 33 CairoCachedSurface();
26 ~CairoCachedSurface(); 34 ~CairoCachedSurface();
27 35
28 // Whether this CairoCachedSurface owns a GdkPixbuf. 36 // Whether this CairoCachedSurface owns a GdkPixbuf.
29 bool valid() const { 37 bool valid() const {
30 return pixbuf_; 38 return pixbuf_;
31 } 39 }
32 40
33 // Delete all our data. 41 // Delete all our data.
34 void Reset(); 42 void Reset();
35 43
36 // The dimensions of the underlying pixbuf/surface. (or -1 if invalid.) 44 // The dimensions of the underlying pixbuf/surface. (or -1 if invalid.)
37 int Width() const; 45 int Width() const;
38 int Height() const; 46 int Height() const;
39 47
40 // Sets the pixbuf that we pass to cairo. Calling UsePixbuf() only derefs the 48 // 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 49 // current pixbuf and surface (if they exist). Actually transfering data to
42 // the X server occurs at SetSource() time. Calling UsePixbuf() should only 50 // the X server occurs at SetSource() time. Calling UsePixbuf() should only
43 // be done once as it clears cached data from the X server. 51 // be done once as it clears cached data from the X server.
44 void UsePixbuf(GdkPixbuf* pixbuf); 52 void UsePixbuf(GdkPixbuf* pixbuf);
45 53
46 // Sets our pixbuf as the active surface starting at (x, y), uploading it in 54 // 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. 55 // case we don't have an X backed surface cached.
48 void SetSource(cairo_t* cr, int x, int y); 56 void SetSource(cairo_t* cr, GtkWidget* widget, int x, int y) const;
57 void SetSource(cairo_t* cr, GdkDisplay* display, int x, int y) const;
49 58
50 // Performs a mask operation, using this surface as the alpha channel. 59 // Performs a mask operation, using this surface as the alpha channel.
51 void MaskSource(cairo_t* cr, int x, int y); 60 void MaskSource(cairo_t* cr, GtkWidget* widget, int x, int y) const;
61 void MaskSource(cairo_t* cr, GdkDisplay* display, int x, int y) const;
52 62
53 // Raw access to the pixbuf. May be NULL. Used for a few gdk operations 63 // Raw access to the pixbuf. May be NULL. Used for a few gdk operations
54 // regarding window shaping. 64 // regarding window shaping.
55 GdkPixbuf* pixbuf() { return pixbuf_; } 65 GdkPixbuf* pixbuf() { return pixbuf_; }
56 66
57 private: 67 private:
58 // Makes sure |surface_| is a valid thing that lives on the X server, 68 typedef std::vector<std::pair<GdkDisplay*, cairo_surface_t*> > SurfaceVector;
59 // uploading it if necessary. 69
60 void EnsureSurfaceValid(cairo_t* cr); 70 // Returns a surface . Caches results so only one copy of the image data
71 // lives on the display server.
72 cairo_surface_t* GetSurfaceFor(cairo_t* cr, GdkDisplay* display) const;
61 73
62 // The source pixbuf. 74 // The source pixbuf.
63 GdkPixbuf* pixbuf_; 75 GdkPixbuf* pixbuf_;
64 76
65 // Our cached surface. This should be a xlib surface so the data lives on the 77 // Our list of cached surfaces. 99% of the time, this will only contain a
66 // server instead of on the client. 78 // single entry. At most two. We need to get this right for multiple displays
67 cairo_surface_t* surface_; 79 // to work correct, since each GdkDisplay is a different display server.
80 mutable SurfaceVector surface_map_;
68 }; 81 };
69 82
70 #endif // CHROME_BROWSER_UI_GTK_CAIRO_CACHED_SURFACE_H_ 83 } // namespace gfx
84
85 #endif // UI_GFX_IMAGE_CAIRO_CACHED_SURFACE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698