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 UI_GFX_GTK_UTIL_H_ | 5 #ifndef UI_GFX_GTK_UTIL_H_ |
6 #define UI_GFX_GTK_UTIL_H_ | 6 #define UI_GFX_GTK_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <glib-object.h> | 9 #include <glib-object.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "ui/ui_api.h" | 16 #include "ui/base/ui_export.h" |
17 | 17 |
18 typedef struct _GdkPixbuf GdkPixbuf; | 18 typedef struct _GdkPixbuf GdkPixbuf; |
19 typedef struct _GdkRegion GdkRegion; | 19 typedef struct _GdkRegion GdkRegion; |
20 typedef struct _GdkCursor GdkCursor; | 20 typedef struct _GdkCursor GdkCursor; |
21 | 21 |
22 class CommandLine; | 22 class CommandLine; |
23 class SkBitmap; | 23 class SkBitmap; |
24 | 24 |
25 namespace gfx { | 25 namespace gfx { |
26 | 26 |
27 class Rect; | 27 class Rect; |
28 | 28 |
29 // Call gtk_init() using the argc and argv from command_line. | 29 // Call gtk_init() using the argc and argv from command_line. |
30 // gtk_init() wants an argc and argv that it can mutate; we provide those, | 30 // gtk_init() wants an argc and argv that it can mutate; we provide those, |
31 // but leave the original CommandLine unaltered. | 31 // but leave the original CommandLine unaltered. |
32 UI_API void GtkInitFromCommandLine(const CommandLine& command_line); | 32 UI_EXPORT void GtkInitFromCommandLine(const CommandLine& command_line); |
33 | 33 |
34 // Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so | 34 // Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so |
35 // it is an expensive operation. The returned GdkPixbuf will have a refcount of | 35 // it is an expensive operation. The returned GdkPixbuf will have a refcount of |
36 // 1, and the caller is responsible for unrefing it when done. | 36 // 1, and the caller is responsible for unrefing it when done. |
37 UI_API GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); | 37 UI_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); |
38 | 38 |
39 // Modify the given region by subtracting the given rectangles. | 39 // Modify the given region by subtracting the given rectangles. |
40 UI_API void SubtractRectanglesFromRegion(GdkRegion* region, | 40 UI_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region, |
41 const std::vector<Rect>& cutouts); | 41 const std::vector<Rect>& cutouts); |
42 | 42 |
43 // Returns the resolution (DPI) used by pango. A negative values means the | 43 // Returns the resolution (DPI) used by pango. A negative values means the |
44 // resolution hasn't been set. | 44 // resolution hasn't been set. |
45 double GetPangoResolution(); | 45 double GetPangoResolution(); |
46 | 46 |
47 // Returns a static instance of a GdkCursor* object, sharable across the | 47 // Returns a static instance of a GdkCursor* object, sharable across the |
48 // process. Caller must gdk_cursor_ref() it if they want to assume ownership. | 48 // process. Caller must gdk_cursor_ref() it if they want to assume ownership. |
49 UI_API GdkCursor* GetCursor(int type); | 49 UI_EXPORT GdkCursor* GetCursor(int type); |
50 | 50 |
51 // Change windows accelerator style to GTK style. (GTK uses _ for | 51 // Change windows accelerator style to GTK style. (GTK uses _ for |
52 // accelerators. Windows uses & with && as an escape for &.) | 52 // accelerators. Windows uses & with && as an escape for &.) |
53 UI_API std::string ConvertAcceleratorsFromWindowsStyle( | 53 UI_EXPORT std::string ConvertAcceleratorsFromWindowsStyle( |
54 const std::string& label); | 54 const std::string& label); |
55 | 55 |
56 // Removes the "&" accelerators from a Windows label. | 56 // Removes the "&" accelerators from a Windows label. |
57 UI_API std::string RemoveWindowsStyleAccelerators(const std::string& label); | 57 UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label); |
58 | 58 |
59 // Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. | 59 // Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. |
60 // The caller is responsible for free()ing the data. If |stride| is 0, it's | 60 // The caller is responsible for free()ing the data. If |stride| is 0, it's |
61 // assumed to be 4 * |width|. | 61 // assumed to be 4 * |width|. |
62 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); | 62 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); |
63 | 63 |
64 } // namespace gfx | 64 } // namespace gfx |
65 | 65 |
66 // It's not legal C++ to have a templatized typedefs, so we wrap it in a | 66 // It's not legal C++ to have a templatized typedefs, so we wrap it in a |
67 // struct. When using this, you need to include ::Type. E.g., | 67 // struct. When using this, you need to include ::Type. E.g., |
68 // ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); | 68 // ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); |
69 template<class T> | 69 template<class T> |
70 struct ScopedGObject { | 70 struct ScopedGObject { |
71 // A helper class that will g_object_unref |p| when it goes out of scope. | 71 // A helper class that will g_object_unref |p| when it goes out of scope. |
72 // This never adds a ref, it only unrefs. | 72 // This never adds a ref, it only unrefs. |
73 template<class U> | 73 template<class U> |
74 struct GObjectUnrefer { | 74 struct GObjectUnrefer { |
75 void operator()(U* ptr) const { | 75 void operator()(U* ptr) const { |
76 if (ptr) | 76 if (ptr) |
77 g_object_unref(ptr); | 77 g_object_unref(ptr); |
78 } | 78 } |
79 }; | 79 }; |
80 | 80 |
81 typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; | 81 typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; |
82 }; | 82 }; |
83 | 83 |
84 #endif // UI_GFX_GTK_UTIL_H_ | 84 #endif // UI_GFX_GTK_UTIL_H_ |
OLD | NEW |