From c6c32dee8da128970df06b74ab7fc53dee9eb6d1 Mon Sep 17 00:00:00 2001 From: "deanm@chromium.org" Date: Tue, 10 Mar 2009 13:03:19 +0000 Subject: 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 --- chrome/browser/gtk/menu_gtk.cc | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) (limited to 'chrome') 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(bitmap->getPixels()); - guchar* data = static_cast(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); -- cgit v1.1