Hello again Julien. I've created my own widget from GtkWidget and set the "load-finished" signal from webkit to a callback which then uses the webkit_web_frame_show() function from clutter. The problem is when I save the surface to a PNG image and open it, there's only black color. I've attached the sources.
Could you please take a quick look at the sources. I really don't know what I'm doing wrong. I've looked into the clutter code and nothing special was there that could hint why this is happening to me. Greets, Luka Dne 23.05.2008 (pet) ob 14:11 +0200 je Julien Sanchez zapisal(a): > Hello Luka, > > I used the following path from clutter repository: > http://svn.o-hand.com/view/clutter/trunk/clutter-webkit/webkit-frame-show-cairo.patch?rev=2031&view=markup > > As a rough prototype, I adapted an "OffscreenWebkit" class inspired from > the ClutterWebkitClass from clutter-webkit > (http://svn.o-hand.com/view/clutter/trunk/clutter-webkit/clutter-webkit.c?rev=2030&view=markup) > > and more especially in load_finished_cb: > > static void load_finished_cb (WebKitWebView *web_view, > WebKitWebFrame *frame, > OffscreenWebkit *webkit) > { > g_print ("load_finished_cb\n"); > OffscreenWebkitPrivate *priv = OFFSCREEN_WEBKIT_GET_PRIVATE(webkit); > cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_RGB24, > priv->width, priv->height); > cairo_t* cr_surf = cairo_create(surf); > cairo_rectangle (cr_surf, 0, 0, priv->width, priv->height); > webkit_web_frame_show (frame, cr_surf); > cairo_surface_write_to_png(surf, "webkitsurf.png"); > cairo_surface_destroy(surf); > > surf = > cairo_pdf_surface_create("webkitsurf.pdf", priv->width, priv->height); > cr_surf = cairo_create(surf); > cairo_rectangle (cr_surf, 0, 0, priv->width, priv->height); > webkit_web_frame_show (frame, cr_surf); > cairo_surface_show_page(surf); > > cairo_surface_finish(surf); > cairo_surface_destroy(surf); > > g_main_loop_quit(loop); > } > > It works but I wonder if it is possible to to the same without an X > server (I just tried with the gtk-directfb port :./configure > --enable-debug --with-target=directfb but it does not work. I don't know > how to use directfb and if it will be efficient. > > Julien > > Le vendredi 23 mai 2008 à 13:32 +0200, Luka Napotnik a écrit : > > Hello Julien. > > > > So you didn't draw the webkitview widget at all but stil managed to get > > a cairo drawing from the engine? If so, could you please tell me how did > > you do that? > > > > Greets, > > Luka > > > > Dne 23.05.2008 (pet) ob 12:58 +0200 je Julien Sanchez zapisal(a): > > > Hello, > > > > > > I'm interested too in such a port because I'm trying to render simple > > > html (no plugins or widgets) into image and pdf backends. > > > For the moment, I made a simple hack (inspired from Clutter project) to > > > render into a cairo surface. It works from the command line but it still > > > depends from X (and GTK) and I don't know where to begin to get rid of > > > these dependencies. > > > > > > Julien > > > > > > Le jeudi 22 mai 2008 à 09:30 -0700, Mike Emmel a écrit : > > > > Luka I don't think it makes a difference if your running a lot of > > > > thumbnails you would want to use gpu's some sort of render > > > > farm arrangement. My port does it as a result of the design not > > > > because of a strong desire to render with the cpu. > > > > Also for real world web pages your going to have problems with plugins > > > > which depend on X11 and native widget libraries. > > > > > > > > So although its possible with my port I can't see a single real > > > > problem that can be solved with this approach. > > > > Gtk/DirectFB will work for most pages if you have a flash port. Thats > > > > the number one stumbling block. > > > > I did my headless version of DirectFB for example to use the DirectFB > > > > video provider for the media tags. > > > > You can take other approaches but you would need to consider at a > > > > minimum flash and the media tags. > > > > For complete font support your going to have to use pango or go with > > > > the QT port but the QT port gets you back > > > > to the plugin issues if you don't use X11 and a lot of plugins use GTK > > > > so.... > > > > > > > > > > > > As far as releasing I'm not in control of the release cycle except for > > > > creating delays as I work on stuff :( > > > > It should be released however some time this year. > > > > > > > > I obviously don't disagree with your idea in fact I worked hard to > > > > ensure my approach was adaptable so it could be used for these types > > > > of use cases so someday we will have what your looking for if things > > > > go well. I actually designed it to work > > > > with all the legacy use cases I mentioned but be flexible enough to > > > > transparently drop them when replacements without the legacy X11/Gtk > > > > dependencies become available. So soon a framework will be available > > > > to allow you to reverse software > > > > bloat but I've got no idea if software developers will accept it. I > > > > built it to deal with the problems that occur with our new embedded > > > > devices that have capabilities rivaling desktops where bloat is a huge > > > > problem. The fact it can do what your asking makes me confident the > > > > design is correct in fact it solves problems your not considering. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Thu, May 22, 2008 at 8:41 AM, Luka Napotnik <[EMAIL PROTECTED]> > > > > wrote: > > > > > Wow really? Could you share the port please. I've been looking for > > > > > such > > > > > a port to save the cairo painting to a PNG image. > > > > > > > > > > Greets, > > > > > Luka > > > > > > > > > > Dne 22.05.2008 (čet) ob 07:41 -0700 je Mike Emmel zapisal(a): > > > > >> I actually have a WebKit port with no dependencies but Cairo. > > > > >> > > > > >> > > > > >> > > > > >> On Thu, May 22, 2008 at 7:02 AM, Luka Napotnik <[EMAIL PROTECTED]> > > > > >> wrote: > > > > >> > Hello Mike. > > > > >> > > > > > >> > What I need is a WebKit port that is independent of any display > > > > >> > server > > > > >> > (X or a framebuffer). I only want to render the page to an image. > > > > >> > And > > > > >> > since cairo is a great graphics library I think It's a good start. > > > > >> > > > > > >> > Greets, > > > > >> > Luka > > > > >> > > > > > >> > Dne 22.05.2008 (čet) ob 06:49 -0700 je Mike Emmel zapisal(a): > > > > >> >> Use the GTK DirectFB backend. > > > > >> >> > > > > >> >> I have a memory only system that I really need to get into the > > > > >> >> trunk. > > > > >> >> But if you have a graphics card in the system the fb0 will work. > > > > >> >> > > > > >> >> Its on my TODO to get the mem only system checked in and I can > > > > >> >> give > > > > >> >> you a patch in the mean time if its a issue. Also you can use the > > > > >> >> vnc driver > > > > >> >> as a virtual framebuffer. > > > > >> >> > > > > >> >> Also some of the XServers should work in a similar way so you can > > > > >> >> probably > > > > >> >> play the same trick with the right X11 server. > > > > >> >> > > > > >> >> > > > > >> >> On Thu, May 22, 2008 at 4:21 AM, Luka Napotnik <[EMAIL > > > > >> >> PROTECTED]> wrote: > > > > >> >> > Hello. > > > > >> >> > > > > > >> >> > I am interested in porting webkit to cairo for off-screen > > > > >> >> > rendering > > > > >> >> > without a X server. As I cannot find any documents about > > > > >> >> > porting to > > > > >> >> > other platform I would really appreciate if you could help me > > > > >> >> > with some > > > > >> >> > hints about porting webkit. > > > > >> >> > > > > > >> >> > Greets, > > > > >> >> > Luka > > > > >> >> > > > > > >> >> > _______________________________________________ > > > > >> >> > webkit-dev mailing list > > > > >> >> > [email protected] > > > > >> >> > http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev > > > > >> >> > > > > > >> >> > > > > > >> > > > > > > > > > > _______________________________________________ > > > > webkit-dev mailing list > > > > [email protected] > > > > http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev > > > > > > > >
#include <gtk/gtk.h>
#include "offscreen-webkit.h"
int
main(int argc,
char **argv)
{
GtkWidget *offscreen;
gtk_init(&argc, &argv);
offscreen = offscreen_webkit_new();
offscreen_webkit_open(OFFSCREEN_WEBKIT(offscreen), "http://web.wt.net/~cbenton/relativity.htm");
while (gtk_events_pending ())
gtk_main_iteration ();
return 0;
}
#include <gtk/gtk.h>
#include <cairo.h>
#include "offscreen-webkit.h"
G_DEFINE_TYPE (OffscreenWebkit, offscreen_webkit, GTK_TYPE_WIDGET);
static void
offscreen_webkit_class_init(OffscreenWebkitClass *class)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS(class);
//widget_class->expose_event = offscreen_webkit_expose;
g_type_class_add_private(class, sizeof(OffscreenWebkitPrivate));
}
static void
offscreen_webkit_draw(OffscreenWebkit *offscreen,
WebKitWebFrame *frame)
{
OffscreenWebkitPrivate *priv = OFFSCREEN_WEBKIT_GET_PRIVATE(offscreen);
priv->c = cairo_create(priv->surface);
cairo_set_source_rgb (priv->c, 1.0, 0.0, 0.0);
cairo_rectangle (priv->c, 0, 0, OFFSCREEN_SCREEN_WIDTH, OFFSCREEN_SCREEN_HEIGHT);
webkit_web_frame_show (frame, priv->c);
cairo_destroy(priv->c);
}
static void
offscreen_webkit_load_finished(WebKitWebView *web_view,
WebKitWebFrame *frame,
OffscreenWebkit *offscreen)
{
OffscreenWebkitPrivate *priv = OFFSCREEN_WEBKIT_GET_PRIVATE(offscreen);
offscreen_webkit_draw(offscreen, frame);
cairo_surface_write_to_png(priv->surface, "/home/luka/Desktop/test.png");
}
static void
offscreen_webkit_init(OffscreenWebkit *offscreen)
{
OffscreenWebkitPrivate *priv = OFFSCREEN_WEBKIT_GET_PRIVATE(offscreen);
GtkAllocation alloc = {0, 0, OFFSCREEN_SCREEN_WIDTH, OFFSCREEN_SCREEN_HEIGHT};
priv->web_view = (WebKitWebView *)webkit_web_view_new();
gtk_widget_size_allocate(GTK_WIDGET (priv->web_view), &alloc);
gtk_widget_size_allocate(GTK_WIDGET (offscreen), &alloc);
g_signal_connect(G_OBJECT(priv->web_view), "load-finished",
G_CALLBACK(offscreen_webkit_load_finished), offscreen);
g_object_ref_sink(priv->web_view);
priv->surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
OFFSCREEN_SCREEN_WIDTH,
OFFSCREEN_SCREEN_HEIGHT);
}
GtkWidget *
offscreen_webkit_new()
{
return g_object_new(OFFSCREEN_TYPE_WEBKIT, NULL);
}
static gboolean
offscreen_webkit_expose(GtkWidget *offscreen, GdkEventExpose *e)
{
return FALSE;
}
void
offscreen_webkit_open(OffscreenWebkit *offscreen,
char *address)
{
OffscreenWebkitPrivate *priv = OFFSCREEN_WEBKIT_GET_PRIVATE(offscreen);
webkit_web_view_open(priv->web_view, address);
}
WebKitWebView *
offscreen_webkit_get_web_view(OffscreenWebkit *offscreen)
{
OffscreenWebkitPrivate *priv = OFFSCREEN_WEBKIT_GET_PRIVATE(offscreen);
WebKitWebView *web_view;
web_view = priv->web_view;
return web_view;
}
#ifndef __OFFSCREEN_WEBKIT_H_
#define __OFFSCREEN_WEBKIT_H_
#include <gtk/gtk.h>
#include <cairo.h>
#include <webkit/webkit.h>
typedef struct _OffscreenWebkit OffscreenWebkit;
typedef struct _OffscreenWebkitClass OffscreenWebkitClass;
typedef struct _OffscreenWebkitPrivate OffscreenWebkitPrivate;
struct _OffscreenWebkit {
GtkWidget parent;
};
struct _OffscreenWebkitClass {
GtkWidgetClass parent_class;
};
struct _OffscreenWebkitPrivate {
WebKitWebView *web_view;
cairo_surface_t *surface;
cairo_t *c;
};
#define OFFSCREEN_TYPE_WEBKIT (offscreen_webkit_get_type ())
#define OFFSCREEN_WEBKIT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OFFSCREEN_TYPE_WEBKIT, OffscreenWebkit))
#define OFFSCREEN_WEBKIT_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), OFFSCREEN_WEBKIT, OffscreenWebkitClass))
#define OFFSCREEN_IS_WEBKIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OFFSCREEN_TYPE_WEBKIT))
#define OFFSCREEN_IS_WEBKIT_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), OFFSCREEN_TYPE_WEBKIT))
#define OFFSCREEN_WEBKIT_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), OFFSCREEN_TYPE_WEBKIT, OffscreenWebkitClass))
#define OFFSCREEN_WEBKIT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OFFSCREEN_TYPE_WEBKIT, OffscreenWebkitPrivate))
#define OFFSCREEN_SCREEN_WIDTH 500
#define OFFSCREEN_SCREEN_HEIGHT 500
GtkWidget *
offscreen_webkit_new();
static gboolean
offscreen_webkit_expose(GtkWidget *offscreen, GdkEventExpose *e);
void
offscreen_webkit_open(OffscreenWebkit *offscreen,
char *address);
WebKitWebView *
offscreen_webkit_get_web_view();
#endif
signature.asc
Description: To je digitalno podpisan del sporočila
_______________________________________________ webkit-dev mailing list [email protected] http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

