2

I am using Gtk and WebKit from gi.repository using python on X11 server (on raspbian). I have a Gtk.OffscreenWindow with a WebKit.WebView widget in it and I am looking for a way to get a reference to the actual surface data of the OffscreenWindow.

Gtk.OffscreenWindow.get_surface returns a cairo.XlibSurface object but it doesn't seem there is a way to access pixel data of the surface (get_drawable is missing).

Gtk.OffscreenWindow.get_pixbuf returns a pixel buffer but to my understanding this is a copy of the actual surface data.

I used get_snapshot method of the WebKit.WebView but it creates a new cairo.ImageSurface.

My final goal is to use the reference to draw the surface using pi3d and get any surface updates without having to get a new snapshot of the OffscreenWindow (which is quite slow).

kapetanos
  • 21
  • 1
  • *Why* do you have a WebView in an OffscreenWindow? It sounds like you want to make the content of the WebView visible somewhere... well, then why is it in an OffscreenWindow? – Uli Schlachter Apr 09 '16 at 13:03
  • I am using an OffscreenWindow because I want to make the content visible through opengl (pi3d). – kapetanos Apr 11 '16 at 07:29

2 Answers2

0

From the GTK3 developer reference,

GtkOffscreenWindow derives from GtkWindow only as an implementation detail. Applications should not use any API specific to GtkWindow to operate on this object.

GTKOffscreenWindows cannot or should not be operated on as windows, thus Cairo cannot be used on them.

oldtechaa
  • 1,463
  • 1
  • 14
  • 26
  • I do understand the documentation. The purpose of the OffscreenWindow is to get a snapshot of the contained widget. You can get the surface with OffscreenWindow.get_surface which returns a cairo.XlibSurface as stated in the documentation. I am not using anything GtkWindow specific. – kapetanos Apr 08 '16 at 12:27
  • 1
    Why are you using a `GtkOffscreenWindow` at all? Couldn't you just have a virtual `WebKit.WebView` in memory, and get the surface? A `cairo.ImageSurface` would give you the pixel data anyway. – oldtechaa Apr 08 '16 at 18:16
  • Yes this is indeed working. The problem is that get_snapshot creates a new cairo.ImageSurface every time you call it (as seen on webkit source). I am looking for a way to get a reference to a buffer that holds the pixel data, so any updates of the webkit content will be available through the same buffer. – kapetanos Apr 11 '16 at 07:43
  • I've never used WebKit before and I don't have time to look it up right now, but you do _not_ need the `GtkOffscreenWindow`. I would recommend connecting to whatever WebKit provides for a changed signal and using the pixel data provided in the `cairo.ImageSurface`. – oldtechaa Apr 11 '16 at 16:00
0

@kapetanos, You are probably familiar with the pi3d.groups conversation here https://groups.google.com/forum/#!topic/pi3d/4x0fPerYKRU and the subsequent integration into pi3d https://github.com/pi3d/pi3d_demos/blob/master/GtkCube.py and https://github.com/pi3d/pi3d_demos/blob/master/PyQtCube.py

I realize this is too late for your original question but it might help someone arriving here from a google search!

I still don't understand why the X11 drawing surface system that works on other linux implementations doesn't work on the Raspberry Pi but other developers seem to resort to using libbcm_host.so

paddyg
  • 2,153
  • 20
  • 24