Now that we have gdk_gl_context_get_memory_flags() and code can use that
function, make the code do that.
Remove support checks from gdk_memory_format_gl_format().
This is an initial naive port that doesn't try to make use of the finer-grained
flags yet.
Make gdk_memory_format_gl_format take the GdkGLContext,
instead of just a gles boolean. This will let us
check for extensions that may be needed for certain
formats.
Update all callers.
Texture downloads can be initiated due to the weirdest reasons - and if
they cause a GL context to be changed, it'd be basically unpredictable
when the GL context changes.
An example is the Cairo renderer - if it needs to draw a GL texture, it
will download it.
Now that no longer changes the GL context.
For non-gles, make it handle unpremultiplied formats,
and everything else, by downloading the texture in its
preferred format and, in most cases, doing a
gdk_memory_convert afterwards.
For gles, keep using glReadPixels, but handle cases
where the gl read format doesn't match the texture
format by doing the necessary swizzling before calling
gdk_memory_convert.
Make the callers of this function check for
straight alpha themselves, and only do the
version compatibility check here. This makes
the function usable in contexts where straight
alpha is acceptable.
Add a new function to TextureBuilder that takes a GLsync that
requires internal code to wait on before using the texture.
Somewhat sneakily, we don't take the sync if syncs are not supported by
the current GL context.
As public API has no code to query the sync for the destroy notify, this
is fine and it means we don't have to do the check every time we want to
call gdk_texture_get_sync() internally.
Make GdkGLTexture determine if the texture has
a mipmap, and provide private API to query this
information.
This check is done in gdkgltexture.c instead of
gskgldriver.c, since we're already binding the
texture here for other reasons, so it is easy
to query a few more things.
The API docs outline why quite well.
This should make it possible to do saving of textures to image files
without any private API with the same featureset that GTK uses.
Also remove the gsktextureprivate.h include where
gdk_texture_get_format() was the only reason for it.
When checking characteristics of the context
for downloading, we were using self->context,
even though we are using a possibly different
context for downloading.
Pass the right context along and use it.
WebKit's GTK 4 port can give us textures with an internal format of
GL_RGBA with GL_UNSIGNED_NORMALIZED and a bit-depth of 8. This fixes
warnings for every GdkGLTexture created/delivered to the GskGLRenderer.
The format is essentially the same as GL_RGBA8 since it is normalized
between 0.0..1.0 for 8-bit components.
Fixes#4783
Close widget-factory and observe:
Thread 1:
* acquire main loop
* handle close button
* close window
* dispose video and media stream
* stop GstPlayer
WAIT on pipeline stopping
Thread 2:
* prepare next image in pipeline
* hand image to GtkGstSink
* create GdkTexture from image
* gdk_gl_texture_new() determines format
WAIT on acquiring main loop
Sounds like a deadlock?
Indeed, so don't do that.
It turns out glReadPixels() cannot convert pixels and you are only
allowed to pass a single value into the function arguments. You need to
know which ones or things will explode.
GL is great.
Pass a format do GdkTextureClass::download(). That way we can download
data in any format.
Also replace gdk_texture_download_texture() with
gdk_memory_texture_from_texture() which again takes a format.
The old functionality is still there for code that wants it: Just pass
gdk_texture_get_format (texture) as the format argument.
For MemoryTexture, this is a simple change.
For GLTexture, we need to query the format at texture creation. This
sounds like a bad idea and extra work until one realizes that we'd
need to do that anyway when using the texure the first time - either
when downloading, or when trying to use it in a rendernode, where we
will soon need that information to determine if the texture prefers high
depth.
Also, now make gdk_memory_convert() the only conversion functions
and allow conversions between any 2 formats by going via a float[4].
This could be optimized via fast-paths, but so far it isn't.
GLES only allows downloading float if the texture matches specific
criteria and I'm too lazy to determine them, so always fall back.
And the custom stride fallback code isn't necessary, because falling
back does exactly that step already.
This happens in the real world when using the inspector to look at a
node recording of a GStreamer video while the video is still playing.
GStreamer will use the GL context in a different thread while we are
busy trying to download it.
A test is included.
1. The download via gdk_cairo_draw_from_gl() was broken sometimes
2. We get easy conversion on fallback by chaining up and using
download_texture().
3. One more place where Cairo is no longer necessary.
1. It avoids Cairo, and in particular conversion to Cairo.
2. Keeping a texture allows easy chaining in the vfuncs.
3. Using a texture means releasing will work for HDR formats
too, once we add them.
A private vfunc that downloads a texture as a GdkMemoryTexture in
whatever format the texture deems best.
There are multiple reasons for this:
* GLES cannot download the Cairo format. But it can download some
format and then just delegate to the GdkMemoryTexture implementation.
* All the other download vfuncs (including the ones still coming) can
be implemented via download_texture() and delegation, making the
interface easier.
* We want to implement image loading and saving support. By using
download_texture(), we can save in the actual format of the texture.
* A potential GdkCompressedTexture could be implemented by just
providing this one vfunc as a compress() step.