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