void debug_save_widget(GtkWidget *widget) { GdkPixmap *pixmap; GdkPixbuf *pixbuf; gint w, h; pixmap = gtk_widget_get_snapshot(widget, NULL); gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &w, &h); pixbuf = gdk_pixbuf_get_from_drawable(NULL, GDK_DRAWABLE(pixmap), NULL, 0, 0, 0, 0, w, h); debug_save_pixbuf(pixbuf); gdk_pixmap_unref(pixmap); g_object_unref(pixbuf); }
PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool, bool, bool, bool drawSelectionRect) { WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); GtkWidget* viewContainer = gtk_widget_get_parent(GTK_WIDGET(view)); gint width, height; #ifdef GTK_API_VERSION_2 GdkPixmap* pixmap = gtk_widget_get_snapshot(viewContainer, 0); gdk_pixmap_get_size(pixmap, &width, &height); #else width = gtk_widget_get_allocated_width(viewContainer); height = gtk_widget_get_allocated_height(viewContainer); #endif cairo_surface_t* imageSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t* context = cairo_create(imageSurface); #ifdef GTK_API_VERSION_2 gdk_cairo_set_source_pixmap(context, pixmap, 0, 0); cairo_paint(context); g_object_unref(pixmap); #else gtk_widget_draw(viewContainer, context); #endif if (drawSelectionRect) { cairo_rectangle_int_t rectangle; DumpRenderTreeSupportGtk::rectangleForSelection(mainFrame, &rectangle); cairo_set_line_width(context, 1.0); cairo_rectangle(context, rectangle.x, rectangle.y, rectangle.width, rectangle.height); cairo_set_source_rgba(context, 1.0, 0.0, 0.0, 1.0); cairo_stroke(context); } return BitmapContext::createByAdoptingBitmapAndContext(0, context); }