Hello all!
My application need to display a video (RGB pixels buffer) from camera on Gtk4 window, after few days of research I have a list of approaches:
- Drawing video pixels buffer with Cairo.
- Use
GLArea
and create Texture to display (eitherglTexSubImage
or pixel buffer object). - Since Gtk4 have multiple backends (GL, Vulkan, software, …), we can utilize snapshot API from Gtk4 to display a
GdkTexture
for portablility.
I’ve tried all 3 approches above and this is my opinions about it:
- Approach 1 work fine, but in the end the cairo surface will need to be uploaded to GPU for displaying (in case we’re using GL, Vulkan, … backends) so I consisder this is not an optimized way to display a video (too much data transfer, and most drawing operations are in CPU side), especially for HD video or multiple videos.
- Approach 2 work fine in OpenGL backend, but Gtk4 supports other backends (software, vulkan, …), so I think writing OpenGL specific code is not a portable (I meant, it might not work on Vulkan or Software backends) and not necessary way, am I right about this?
- This is my preferred way (in my opinion) to do this but unfortunately I haven’t gotten it to work yet . The problems are:
a.Gdk.Texture
seems to be a static texture in design than a dynamic one (I don’t see any method for updatingGdk.Texture
)
b. There is aGdk.GLTexture
object seems a wrapper of OpenGL texture, I’ve try to appendGdk.GLTexture
in snapshot method and call toglTexSubImage
to update data but thewidget.queue_draw()
doesn’t redraw the updated texture at all (until resize the window), but usingGdk.GLTexture
also losing portability as it depends on OpenGL.
So my questions are:
- In Gtk4 how can we update a
Gdk.Texture
dynamically? - What is proper way to display a dynamic pixels buffer in Gtk4 in portable (and efficient) way?
Thanks for your reading!