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