[webkit-gtk] rendering browser on offscreen surface/window
Prasanta Sadhukhan
psadhukhan at gmail.com
Tue Aug 7 00:20:20 PDT 2012
Hi,
I have a requirement to render the webpage on an offscreen window. The
offscreen window will be added or blitted to primary/main window at a
predetermined time or after receipt of some signal and then the webpage on
main window will be shown.
In our scenario,
gtk will be intialized in the main graphics thread and the webpage would be
rendered in some other thread when the application will try to load a
webpage. So, actually gtk_initialize() in the below code will be done in
context of main graphics thread which will create the main/primary window.
The main window may have other gtk widgets and the browser will be a
somewhat smaller part of the main window
while load_webpage() will be called in context of another thread where the
webpage will be rendered in a offscreen window. We probably will have a
thread which will add/blit these offscreen window content to main window
and to render it visible (This is currently not done in below code and for
simplicity I am trying to add the offscreen content in main window in
load_webpage() function itself)
I am trying in this manner as shown below on 1.8.1 webkitgtk but I am
getting error like below and the webpage is not displayed.
Can anyone suggest if the above scenario can be achieved OR do we need to
load the webpage on the main window only?
Also, another question is since gtk_main() is a non returning call, can we
call it inside a thread as I tried to do below or do we need to call it
every time we try to load a webpage in load_webpage()?
Thanks in advance!!
==============
webkitgtktest.c: In function ‘main’:
webkitgtktest.c:56: warning: passing argument 1 of
‘gtk_offscreen_window_get_pixbuf’ from incompatible pointer type
/usr/include/gtk-2.0/gtk/gtkoffscreenwindow.h:56: note: expected ‘struct
GtkOffscreenWindow *’ but argument is of type ‘struct GtkWidget *’
(a.out:3519): Gdk-CRITICAL **: IA__gdk_offscreen_window_get_pixmap:
assertion `GDK_IS_WINDOW (window)' failed
(a.out:3519): Gtk-CRITICAL **: IA__gtk_container_add: assertion
`GTK_IS_WIDGET (widget)' failed
(a.out:3519): Gdk-CRITICAL **: IA__gdk_window_get_origin: assertion
`GDK_IS_WINDOW (window)' failed
(a.out:3519): Gdk-CRITICAL **: IA__gdk_window_get_origin: assertion
`GDK_IS_WINDOW (window)' failed
(a.out:3519): Gdk-CRITICAL **: IA__gdk_window_get_origin: assertion
`GDK_IS_WINDOW (window)' failed
(a.out:3519): Gdk-CRITICAL **: IA__gdk_window_get_origin: assertion
`GDK_IS_WINDOW (window)' failed
(a.out:3519): Gdk-CRITICAL **: IA__gdk_window_get_origin: assertion
`GDK_IS_WINDOW (window)' failed
(a.out:3519): Gdk-CRITICAL **: IA__gdk_window_get_origin: assertion
`GDK_IS_WINDOW (window)' failed
(a.out:3519): Gdk-CRITICAL **: IA__gdk_drawable_get_visual: assertion
`GDK_IS_DRAWABLE (drawable)' failed
===================
#include <gtk/gtk.h>
#include <webkit/webkit.h>
#include "libsoup/soup.h"
void setProxy()
{
const char *httpProxy = g_getenv("http_proxy");
SoupURI *soupUri = soup_uri_new(httpProxy);
g_object_set(webkit_get_default_session(), SOUP_SESSION_PROXY_URI,
soupUri, NULL);
if (soupUri)
soup_uri_free(soupUri);
}
static void *start (void *arg)
{
// gtk_main();
}
GtkWidget *gtk_initialize()
{
pthread_t thrd;
int argc = 1;
char *argv[1];
// Initialize GTK+
gtk_init(&argc, NULL);
// Create an 800x600 window that will contain the browser instance
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 1200, 800);
pthread_create(&thrd, NULL, &start, NULL);
return main_window;
}
int main(int argc, char* argv[])
{
GtkWidget *main_window = gtk_initialize();
load_webpage(main_window);
}
void load_webpage(GtkWidget *main_window)
{
// Create a browser instance
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
GtkWidget *offscreen_window = gtk_offscreen_window_new();
gtk_window_set_default_size(GTK_WINDOW(offscreen_window), 800, 600);
gtk_container_add(GTK_CONTAINER(offscreen_window), GTK_WIDGET(webView));
setProxy();
// Load a web page into the browser instance
webkit_web_view_load_uri(webView, "http://www.thewildernessdowntown.com/
");
// Make sure that when the browser area becomes visible, it will get
mouse
// and keyboard events
gtk_widget_grab_focus(GTK_WIDGET(webView));
GdkPixbuf *pixmap = gtk_offscreen_window_get_pixbuf(offscreen_window);
gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(pixmap));
// Make sure the main window and all its contents are visible
gtk_widget_show_all(main_window);
// Run the main GTK+ event loop
gtk_main();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-gtk/attachments/20120807/6105bdd1/attachment.html>
More information about the webkit-gtk
mailing list