summaryrefslogtreecommitdiffstats
path: root/chrome/common/gtk_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common/gtk_util.cc')
-rw-r--r--chrome/common/gtk_util.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc
index f0d5ea1..d246ccc 100644
--- a/chrome/common/gtk_util.cc
+++ b/chrome/common/gtk_util.cc
@@ -16,6 +16,10 @@ void RemoveWidget(GtkWidget* widget, gpointer container) {
gtk_container_remove(GTK_CONTAINER(container), widget);
}
+void FreePixels(guchar* pixels, gpointer data) {
+ free(data);
+}
+
} // namespace
namespace event_utils {
@@ -33,7 +37,28 @@ WindowOpenDisposition DispositionFromEventFlags(guint event_flags) {
} // namespace event_utils
-namespace gtk_util {
+namespace gfx {
+
+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 = base::BGRAToRGBA(orig_data, width, height, stride);
+
+ // 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);
+
+ bitmap->unlockPixels();
+ return pixbuf;
+}
GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,
int top, int bottom, int left, int right) {
@@ -54,4 +79,4 @@ void RemoveAllChildren(GtkWidget* container) {
gtk_container_foreach(GTK_CONTAINER(container), RemoveWidget, container);
}
-} // namespace gtk_util
+} // namespace gfx