| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_GFX_GTK_UTIL_H_ | |
| 6 #define BASE_GFX_GTK_UTIL_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include <glib-object.h> | |
| 12 | |
| 13 #include "base/scoped_ptr.h" | |
| 14 | |
| 15 typedef struct _GdkColor GdkColor; | |
| 16 typedef struct _GdkPixbuf GdkPixbuf; | |
| 17 typedef struct _GdkRegion GdkRegion; | |
| 18 | |
| 19 class SkBitmap; | |
| 20 | |
| 21 const int kSkiaToGDKMultiplier = 257; | |
| 22 | |
| 23 // Define a macro for creating GdkColors from RGB values. This is a macro to | |
| 24 // allow static construction of literals, etc. Use this like: | |
| 25 // GdkColor white = GDK_COLOR_RGB(0xff, 0xff, 0xff); | |
| 26 #define GDK_COLOR_RGB(r, g, b) {0, r * kSkiaToGDKMultiplier, \ | |
| 27 g * kSkiaToGDKMultiplier, b * kSkiaToGDKMultiplier} | |
| 28 | |
| 29 namespace gfx { | |
| 30 | |
| 31 class Rect; | |
| 32 | |
| 33 extern const GdkColor kGdkWhite; | |
| 34 extern const GdkColor kGdkBlack; | |
| 35 extern const GdkColor kGdkGreen; | |
| 36 | |
| 37 // Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so | |
| 38 // it is an expensive operation. | |
| 39 GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); | |
| 40 | |
| 41 // Modify the given region by subtracting the given rectangles. | |
| 42 void SubtractRectanglesFromRegion(GdkRegion* region, | |
| 43 const std::vector<Rect>& cutouts); | |
| 44 | |
| 45 } // namespace gfx | |
| 46 | |
| 47 namespace { | |
| 48 // 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 template <typename Type> | |
| 51 struct GObjectUnrefer { | |
| 52 void operator()(Type* ptr) const { | |
| 53 if (ptr) | |
| 54 g_object_unref(ptr); | |
| 55 } | |
| 56 }; | |
| 57 } // namespace | |
| 58 | |
| 59 // 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 // ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); | |
| 62 template<class T> | |
| 63 struct ScopedGObject { | |
| 64 typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; | |
| 65 }; | |
| 66 | |
| 67 #endif // BASE_GFX_GTK_UTIL_H_ | |
| OLD | NEW |