| 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 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace gfx { | 29 namespace gfx { |
| 30 | 30 |
| 31 class Rect; | 31 class Rect; |
| 32 | 32 |
| 33 extern const GdkColor kGdkWhite; | 33 extern const GdkColor kGdkWhite; |
| 34 extern const GdkColor kGdkBlack; | 34 extern const GdkColor kGdkBlack; |
| 35 extern const GdkColor kGdkGreen; | 35 extern const GdkColor kGdkGreen; |
| 36 | 36 |
| 37 // Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so | 37 // Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so |
| 38 // it is an expensive operation. | 38 // it is an expensive operation. The returned GdkPixbuf will have a refcount of |
| 39 // 1, and the caller is responsible for unrefing it when done. |
| 39 GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); | 40 GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); |
| 40 | 41 |
| 41 // Modify the given region by subtracting the given rectangles. | 42 // Modify the given region by subtracting the given rectangles. |
| 42 void SubtractRectanglesFromRegion(GdkRegion* region, | 43 void SubtractRectanglesFromRegion(GdkRegion* region, |
| 43 const std::vector<Rect>& cutouts); | 44 const std::vector<Rect>& cutouts); |
| 44 | 45 |
| 45 } // namespace gfx | 46 } // namespace gfx |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 // A helper class that will g_object_unref |p| when it goes out of scope. | 49 // A helper class that will g_object_unref |p| when it goes out of scope. |
| 49 // This never adds a ref, it only unrefs. | 50 // This never adds a ref, it only unrefs. |
| 50 template <typename Type> | 51 template <typename Type> |
| 51 struct GObjectUnrefer { | 52 struct GObjectUnrefer { |
| 52 void operator()(Type* ptr) const { | 53 void operator()(Type* ptr) const { |
| 53 if (ptr) | 54 if (ptr) |
| 54 g_object_unref(ptr); | 55 g_object_unref(ptr); |
| 55 } | 56 } |
| 56 }; | 57 }; |
| 57 } // namespace | 58 } // namespace |
| 58 | 59 |
| 59 // It's not legal C++ to have a templatized typedefs, so we wrap it in a | 60 // It's not legal C++ to have a templatized typedefs, so we wrap it in a |
| 60 // struct. When using this, you need to include ::Type. E.g., | 61 // struct. When using this, you need to include ::Type. E.g., |
| 61 // ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); | 62 // ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); |
| 62 template<class T> | 63 template<class T> |
| 63 struct ScopedGObject { | 64 struct ScopedGObject { |
| 64 typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; | 65 typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 #endif // GFX_GTK_UTIL_H_ | 68 #endif // GFX_GTK_UTIL_H_ |
| OLD | NEW |