diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 06:40:57 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 06:40:57 +0000 |
commit | 5c7293a73bdaedbe368bc26426a2345f230f2822 (patch) | |
tree | 9a5c28a66102e61536730d8335843c14ae5e0a10 /gfx/gtk_util.h | |
parent | af63c908603f8a2f58f69167129f819d5d30820c (diff) | |
download | chromium_src-5c7293a73bdaedbe368bc26426a2345f230f2822.zip chromium_src-5c7293a73bdaedbe368bc26426a2345f230f2822.tar.gz chromium_src-5c7293a73bdaedbe368bc26426a2345f230f2822.tar.bz2 |
Move some more files to toplevel gfx dir.
TBR=darin
BUG=none
TEST=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx/gtk_util.h')
-rw-r--r-- | gfx/gtk_util.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/gfx/gtk_util.h b/gfx/gtk_util.h new file mode 100644 index 0000000..a958d67 --- /dev/null +++ b/gfx/gtk_util.h @@ -0,0 +1,67 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GFX_GTK_UTIL_H_ +#define GFX_GTK_UTIL_H_ + +#include <stdint.h> +#include <vector> + +#include <glib-object.h> + +#include "base/scoped_ptr.h" + +typedef struct _GdkColor GdkColor; +typedef struct _GdkPixbuf GdkPixbuf; +typedef struct _GdkRegion GdkRegion; + +class SkBitmap; + +const int kSkiaToGDKMultiplier = 257; + +// Define a macro for creating GdkColors from RGB values. This is a macro to +// allow static construction of literals, etc. Use this like: +// GdkColor white = GDK_COLOR_RGB(0xff, 0xff, 0xff); +#define GDK_COLOR_RGB(r, g, b) {0, r * kSkiaToGDKMultiplier, \ + g * kSkiaToGDKMultiplier, b * kSkiaToGDKMultiplier} + +namespace gfx { + +class Rect; + +extern const GdkColor kGdkWhite; +extern const GdkColor kGdkBlack; +extern const GdkColor kGdkGreen; + +// Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so +// it is an expensive operation. +GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); + +// Modify the given region by subtracting the given rectangles. +void SubtractRectanglesFromRegion(GdkRegion* region, + const std::vector<Rect>& cutouts); + +} // namespace gfx + +namespace { +// A helper class that will g_object_unref |p| when it goes out of scope. +// This never adds a ref, it only unrefs. +template <typename Type> +struct GObjectUnrefer { + void operator()(Type* ptr) const { + if (ptr) + g_object_unref(ptr); + } +}; +} // namespace + +// It's not legal C++ to have a templatized typedefs, so we wrap it in a +// struct. When using this, you need to include ::Type. E.g., +// ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); +template<class T> +struct ScopedGObject { + typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; +}; + +#endif // GFX_GTK_UTIL_H_ |