This is a port of the fix in the quartz backend to the new macOS backend.
From the original commit:
In macOS-12.sdk CGContextConverSizeToDeviceSpace returns a negative
height and passing that to CGContextScaleCTM in turn causes the cairo
surface to draw outside the window where it can't be seen. Passing the
absolute values of the scale factors fixes the display on macOS 12 without
affecting earlier macOS versions.
Don't pass texture + rect, but instead have
gdk_memory_texture_new_subtexture()
and use it to generate subtextures and pass them.
This has the advantage of downloading the a too large texture only once
instead of N times.
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 does not belong in GdkGLContext, it's a renderer thing.
It's also the only user of that API.
Introduce gdk_gl_context_check_version() private API to make version
checks simpler.
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.
Broadway is the only GTK+ backend that throws an error on stderr for a
"display server" connection failure.
This causes problems when gtk_init_check() is used and unexpected error
output is generated such as with hotdoc, which fails when generating a
GTK plugin's documentation instead of overlooking the issue.
"Unable to init server: Could not connect: Connection refused"
Broadway is the only GTK+ backend that throws an error on stderr when
failing to initialise, which causes problems when gtk_init_check() is
used and unexpected error output is generated.
This causes hotdoc to fail when generating a GTK plugin's documentation
instead of failing quietly.
"Unable to init server: Could not connect: Connection refused"
Otherwise if we hide and show a window we recreate a new surface,
breaking the compositor's association, but potentially not resend this
data for the new surface.
This matches what we do for input_region.
Add gdk_gl_context_is_api_allowed() for backends and make them use it.
Finally, have them return the final API as the return value (or 0 on
error).
And then use that api instead of a use_es boolean flag.
Fixes#4221
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.
The term "hdr" is so overloaded, we shouldn't use them anywhere, except
from maybe describing all of this work in blog posts and other marketing
materials.
So do renames:
* hdr => high_depth
* request_hdr => prefers_high_depth
This more accurately describes what is going on.
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.
If EGL supports:
* no-config contexts
* >8bits pixel formats
* (optionally) floating point pixel formats
Then select such a profile as the HDR format and use it when HDR is
requested.
Forces request_hdr = TRUE for all requests.
Backends should also use this when choosing whether to honor HDR
requests for low quality compositors - as long as the compositor
pretends to support HDR, shovel HDR at it.
Unify the X11 and Wayland EGL contexts.
This is a bit ugly to implement, because I don't want to create an
interface and I can't make them inherit from the same object, because
one needs to inherit from X11GLContext and the other from
WaylandGLContext.
So we have to put the code in GdkGLContext and make sure non-EGL
contexts can't accidentally run it. This is rather easy because we can
just check for priv->egl_context != NULL.
We have a global GdkGLBackendType now, just set it.
This way, using the variable forces the backend type, and we don't need
special code handling the env vars in the backends.
It also means setting the env var will now "work" on GDK backends that
don't even support that GL backend and simualte another GDK backend
having registered that GL backend already. So you can run
GDK_DEBUG=gl-wgl gtk4-demo
on test what Wayland will do when WGL is in use.
Print the extensions one per line, and sort them
alphabetically, so it is actually possible to find
something in the list.
Also print a short description of the chosen config.
Print the extensions one per line, and sort them
alphabetically, so it is actually possible to find
something in the list.
Also print a short description of the chosen config.
Include the appropriate headers as some function prototypes were moved lately.
Also, re-order the include order of the gdk/*private.h headers alphabetically
in the files that were updated.
Creative people managed to create an X11 display and a Wayland display
at once, thereby getting EGL and GLX involved in a fight to the death
over the ownership of the glFoo() symbolspace.
A way to force such a fight with available tools here is (on Wayland)
running something like:
GTK_INSPECTOR_DISPLAY=:1 GTK_DEBUG=interactive gtk4-demo
Related: xdg-desktop-portal-gnome#5
On Windows, GLES is not that widely available unless one installs wrapper
libraries such as libANGLE, so GLES/EGL support on Windows is used more like
a fallback mode if Desktop OpenGL (WGL) support is inadequate on the system.
Hence, unless one forces WGL or EGL, we will first try to initialize WGL, and
then try to initialize GLES if enabled and if WGL initialization failed, and
then just return whatever the last result we can obtain from these
initialization attempts, since unlike X11 EGL contexts, we do not have
separate modes for WGL except for legacy and non-legacy contexts.
We were setting the WGL pixel format in GdkWin32Display too early, so the code
does not bail out correctly when we retry establishing the WGL context.
Fix this by pushing back setting the WGL pixel format only after it passes the
shader availability check.
Should fix issue #4257.
1. Change INSUFFICIENT_MEMORY to TOO_LARGE
GTK crashes on insufficient memory, we don't emit GErrors.
2. Split UNSUPPORTED into UNSUPPORTED_CONTENT and UNSUPPORTED_FORMAT
So we know if you need to find an RPM with a loader or curse and
the weird file.
3. Translate error messages, they are meant for end users.
When loading, convert all >8-bit data to
GDK_MEMORY_R16G16B16A16_PREMULTIPLIED.
When saving, save all 8-bit formats as 8-bit RGBA,
and save all >8-bt formats as 16-bit RGBA.
Use our own loader to (de)serialiaze textures
to and from png and tiff.
We still fall back to gdk-pixbuf for handling all
the other image formats, and for pixbufs.
This is a companion to gdk_texture_save_to_png, using
the tiff format, which will let us avoid lossy conversion
of HDR data, since we can store floating point data.
Add support for the tiff format, which is flexible
enough to handle all our memory texture formats
without loss.
As a consequence, we are now linking against libtiff.
Using libpng instead of the lowest-common-denominator
gdk-pixbuf loader. This will allow us to load >8bit data,
and apply gamma and color correction in the future.
For now, this still just provides RGBA8 data.
As a consequence, we are now linking against libpng.
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.
It seems these are sent with `xwindow` set to the root window, so this
was failing to find a surface and get the screen from that.
I'm not sure if there's a reason not to get the screen this way
elsewhere in the function, but it seems this should be correct.
This fixes the behavior of `gdk_x11_display_get_monitors()`, which
wasn't correctly changing when monitors were added or removed. For
instance, this python code was always showing the same number of
monitors when one was turned off and on, but updates correctly with this
change applied:
```python
import gi
gi.require_version("GLib", "2.0")
gi.require_version("Gdk", "4.0")
gi.require_version("Gtk", "4.0")
from gi.repository import GLib, Gdk, Gtk
def f():
print(len(Gdk.Display.get_default().get_monitors()))
return True
GLib.timeout_add_seconds(1, f)
GLib.MainLoop().run()
```
_gdk_macos_event_source_new() calls g_source_set_static_name(), which
for GLib versions before 2.69.1 is a macro defined in gdk-private.h.
Fixes#4195
modified: gdk/macos/gdkmacoseventsource.c
Goals:
1. Provide as much information as possible in the error message, so
users can try to fix their system themselves.
2. Try to formulate the error message in a way that explains that this
is not something GTK can fix, but a lower layer problem.
Related: #4193
When we initialize OpenGL, check whether we have OpenGL 2.0 or later; if not,
check whether we have the 'GL_ARB_shader_objects' extension, since we must be
able to support shaders if using OpenGL for GTK.
If we don't support shaders, as some Windows graphics drivers do not support
OpenGL adequately, notably older Intel drivers, reject and destroy the GL
context that we created, and so fallback to the Cairo GSK renderer, so that
things continue to run, albeit with an expected warning message that the GL
context cannot be realized.
Also, when we could not make the created dummy WGL context current during
initialization, make sure that we destroy the dummy WGL context as well.
Fixes issue #4165.
With gtkmm, when using `Application()`, the display is initialized
before we know the application name and therefore, the program class
associated to the display is NULL.
Instead of providing a default value, we set it equal to program name
when NULL. Moreover, we give up on capitalizing the class name to keep
the code super simple. Also, not using a capitalized name is
consistent with `gdk_x11_display_open()`. If someone has a good reason
to use a capitalized name, here is how to do it.
```c
class_hint = XAllocClassHint ();
class_hint->res_name = (char *) g_get_prgname ();
if (display_x11->program_class)
{
class_hint->res_class = (char *) g_strdup (display_x11->program_class);
}
else if (class_hint->res_name && class_hint->res_name[0])
{
class_hint->res_class = (char *) g_strdup (class_hint->res_name);
class_hint->res_class[0] = g_ascii_toupper (class_hint->res_class[0]);
}
XSetClassHint (xdisplay, impl->xid, class_hint);
g_free (class_hint->res_class);
XFree (class_hint);
```
Fix eff53c023a ("x11: set a default value for program_class")
It is basically not used by default and is pretty much broken at this point, so
it's about time to drop it.
Let's focus on fixing the OLE2 DnD protocol.
Now, we just print a whitespace-separated list of GTypes and mime types.
This makes this neat for 2 things:
1. Parsing it (see next commit)
2. Using it in GtkBuilder (see commits after that)
In particular, the common case of supporting a single GType (or mime
type) looks like just printing the GType (or mime type), which in
GtkBuilder looks like
<property name="formats">GdkTexture</property>
Usually the "dnd-finished" signal will be used to unref the GdkDrag. In
those cases, we would lose the object, so that when we do the final
drag_drop_done() afterwards, we wouldn't have a remaining reference.
With the reference guard, this now works.
Since UCKeyTranslate() converts these keys to Space key unexpectedly,
applications can't distinguish these keys by keysyms.
To solve it, this fix translates these keys by the same way with
function keys & keypad keys.
This patch is equivalent to the patch proposed in:
https://bugzilla.gnome.org/show_bug.cgi?id=702841Closes#4117
It is good practice for (floating) window managers to respect explicit
position hints from clients (as long as the window wouldn't end up
off-screen etc.).
Before commit 13d3afa56e, GTK had a flag for setting the PPosition hint,
but now does so unconditionally. However the real intention is to *not*
request a fixed position, so don't do that.
The dummy Win32 window that we use to capture display change events and
to create dummy WGL contexts was created with CS_OWNDC, so we really do
not need to (and should not) call ReleaseDC() on the HDC that we
obtained from it, so drop these calls.
Since the shaders need to be updated for using with GLES (libANGLE at
least), default to WGL for now. Unfortunately it is not that common for
Windows to have GLES support, in which the easiest way to obtain such
support is via Google's libANGLE.
It turns out that the problem of the WGL window not drawing was due to
the fact that I messed up where I placed SwapBuffers() during the
conversion... doh:|
At the same time, stop storing the HDC in the GdkWin32GLContextWGL, but
instead always create it along the surface we created, so that it is ready
for use for operating with WGL when we are not dealing with "surfaceless"
contexts. If we are dealing with "surfaceless" contexts, just use the
HDC of the dummy window that we created when we created the
Gdk(Win32)Display.
WGL contexts should now be in working order at this point.
This commit attempts to split GdkWin32GLContext into two parts, one for
WGL and the other for EGL (ANGLE), and attempts to simplify things a
bit, by:
* We are already creating a Win32 window to capture display changes,
so we can just use that to act as our dummy window that we use to
find out the pixel format that the system supports for WGL. We also
use it to obtain the dummy legacy WGL context that we will always
require to create our more advanced Core WGL contexts.
* Like what is done in X11, store up the WGL pixel format or the
EGLConfig in our GdkWin32Display.
* Ensure we do not create the dummy WGL context unnecessarily.
In this way, we can successfully create the WGL/EGL contexts, however
there are some issues at this point:
* For WGL, the code successfully initializes and realizes the WGL
Contexts, but for some reason things became invisible. When running
gtk4-demo, this can be verified by seeing the mouse cursor changing
when moved to spots where one can resize the window, although they
were invisible.
* For EGL, the code initializes EGL but could not realize the EGL
context as shaders failed to compile. It seems like the shader issue
is definitely outside the scope of this MR.
nvidia sets the default draw buffer to GL_NONE if EGL contexts are
initially bound to EGL_NO_SURFACE which is exactly what we are doing. So
bind them to GL_BACK when drawing, as they should be.
See https://phabricator.services.mozilla.com/D118743 for a discussion
about EGL_NO_CONTEXT and draw buffers.
This way, one can force using WGL on Windows even if EGL support was
enabled. Also update the help text for gl-egl as it will apply for
Windows, albeit a bit later.
This has the benefit that we can refactor it and make sure we deal with
GdkDisplay::init_gl() not being called at all because
GDK_DEBUG=gl-disable had been specified.
It's not used there, but both backends have independent
immplementationgs for it.
I want to get rid of GdkGLContextX11 and moving code from it is the
first step.
Now that we have the display's context to hook into, we can use it to
construct other GL contexts and don't need a GdkSurface vfunc anymore.
This has the added benefit that backends can have different GdkGLContext
classes on the display and get new GLContexts generated from them, so
we get multiple GL backend support per GDK backend for free.
I originally wanted to make this a vfunc on GdkGLContextClass, but
it turns out all the abckends would just call g_object_new() anyway.