diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-10 13:03:19 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-10 13:03:19 +0000 |
commit | c6c32dee8da128970df06b74ab7fc53dee9eb6d1 (patch) | |
tree | a0a25f443991e8f13906fd359a89fccd77ba7043 /chrome/browser/gtk | |
parent | f09c718082535c0de7f066cb63f95809070f35a6 (diff) | |
download | chromium_src-c6c32dee8da128970df06b74ab7fc53dee9eb6d1.zip chromium_src-c6c32dee8da128970df06b74ab7fc53dee9eb6d1.tar.gz chromium_src-c6c32dee8da128970df06b74ab7fc53dee9eb6d1.tar.bz2 |
Move GdkPixbufFromSkBitmap to gtk_util so it can easily be shared.
Review URL: http://codereview.chromium.org/38009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11327 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 42 |
1 files changed, 2 insertions, 40 deletions
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 8937a3a..3f8f7a9 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -4,6 +4,7 @@ #include "chrome/browser/gtk/menu_gtk.h" +#include "base/gfx/gtk_util.h" #include "base/logging.h" #include "base/string_util.h" #include "chrome/common/l10n_util.h" @@ -31,45 +32,6 @@ std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) { return ret; } -void FreePixels(guchar* pixels, gpointer data) { - free(data); -} - -// We have to copy the pixels and reverse their order manually. -GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) { - bitmap->lockPixels(); - int width = bitmap->width(); - int height = bitmap->height(); - int stride = bitmap->rowBytes(); - const guchar* orig_data = static_cast<guchar*>(bitmap->getPixels()); - guchar* data = static_cast<guchar*>(malloc(height * stride)); - - // Swap from BGRA to RGBA. - for (int i = 0; i < height; ++i) { - for (int j = 0; j < width; ++j) { - int idx = i * stride + j * 4; - data[idx] = orig_data[idx + 2]; - data[idx + 1] = orig_data[idx + 1]; - data[idx + 2] = orig_data[idx]; - data[idx + 3] = orig_data[idx + 3]; - } - } - - // This pixbuf takes ownership of our malloc()ed data and will - // free it for us when it is destroyed. - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data( - data, - GDK_COLORSPACE_RGB, // the only colorspace gtk supports - true, // there is an alpha channel - 8, - width, height, stride, &FreePixels, data); - - // Assume ownership of pixbuf. - g_object_ref_sink(pixbuf); - bitmap->unlockPixels(); - return pixbuf; -} - } // namespace MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, @@ -203,7 +165,7 @@ void MenuGtk::BuildMenuFromDelegate() { menu_item = gtk_image_menu_item_new_with_label( delegate_->GetLabel(i).c_str()); const SkBitmap* icon = delegate_->GetIcon(i); - GdkPixbuf* pixbuf = GdkPixbufFromSkBitmap(icon); + GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(icon); GtkWidget* widget = gtk_image_new_from_pixbuf(pixbuf); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), widget); g_object_unref(pixbuf); |