Commit Graph

11216 Commits

Author SHA1 Message Date
Benjamin Otte
b1b8a98568 gdk: Add function to query alpha format for depth
It's meant to be used in renderers.
2023-07-22 01:33:44 +02:00
Benjamin Otte
4a8122f685 gdk: Make A8 and A16 formats premultiplied
The relevant question here is about details, because we have to choose
if we declare alpha-only formats as having their (nonexistant) color
channels premultiplied or not, so that the code paths using them can do
the right thing.

Because we are premultiplied by default, it makes sense to treat alpha
like that, because then the alpha-only code doesn't need to do
workarounds for straight alpha.

Where this is relevant of course is when expanding the alpha channel
into color channels, where we want to end up with white.
So make sure we do color = alpha there instead of color = 1 like we did
before.
2023-07-22 01:33:44 +02:00
Benjamin Otte
7a58439977 memoryformat: Copy idea from tiff code
The static assertion makes sure that newer formats get added.
2023-07-22 01:33:44 +02:00
Benjamin Otte
27fbdcbecb gdk: Add A16_FLOAT and A32_FLOAT formats
We need them for mask-only textures.

For tiffs, we convert the formats to RGBA (the idea that tiff can save
everything needs to be buried I guess) as tiffs can't do alpha-only.
2023-07-22 01:33:44 +02:00
Benjamin Otte
6e75e26a0c vulkan: Add new error code 2023-07-22 01:33:44 +02:00
Matthias Clasen
fd4da47125 gdk: Drop unnecessary conditionals
We require GLib 2.76 now.
2023-07-20 15:18:13 -04:00
Benjamin Otte
2cbe89de7d memoryformat: fast-path copies of the same format
Basically, memcpy() asap if possible.

This happens a lot in Vulkan, where we gdk_memory_conert() image
data from memory textures straight into the VulkanBuffer.

And usually we support the format.
2023-07-19 21:30:35 +02:00
Benjamin Otte
0f289fddf7 vulkan: Fix leaks with pipeline cache
In particular, we were leaking the actual cache and then created a new
one.
2023-07-19 21:30:35 +02:00
Benjamin Otte
83960622e3 vulkan: Store shaders in the display
Have a resource path => vkShaderModule hash table instead of doing fancy
custom objects.

A benefit is that shader modules are now shared between all renderers
and pipelines.
2023-07-16 12:12:36 +02:00
José Roberto de Souza
526c0404c2 vulkan: Wait for device to be idle before create/recreating swapchain
Wait for device to be idle because this function is also called in
window resizes.
And if we destroy old swapchain it also destroy the old VkImages,
those images could be in use by a vulkan render.

This fixes a issue reported in Mesa repository when running
GTK with Xe KMD.

Fixes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9044
Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
2023-07-13 05:40:55 -07:00
Carlos Garnacho
e28ff79bec gdk/wayland: Switch behavior of BTN_STYLUS/STYLUS2 as middle/right click
This mapping of stylus evdev input event codes into GDK button numbers
makes gdk/wayland inconsistent with gdk/x11, so depending on the backend
the same button middle-click pastes or right-click pops up menus.

Make the wayland backend consistent with X11, so that a GNOME wayland
session gets these buttons consistently mapped across all kinds of
clients.

Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5935
2023-07-05 16:54:54 +02:00
Daniel Boles
dccf6b55bd GdkTexture: Don't mention private new_from_surface
The stuff about Cairo Surfaces is in gdktextureprivate.h, & so end users
will not be able to use them; we shouldn't confuse by implying they can.
2023-07-05 12:07:33 +01:00
Benjamin Otte
ce5d74d7df glcontext: Fix typo in Apple extension name 2023-07-03 22:02:44 +02:00
Chun-wei Fan
42a704fefb Merge branch 'gdk-win32-input-fixes' into 'main'
GdkWin32 input fixes

Closes #5877

See merge request GNOME/gtk!6131
2023-06-30 04:33:08 +00:00
Benjamin Otte
684a015c98 vulkan: Add a pipeline cache
Make the display handle the cache, because we only need one.

We store the cache in
  $CACHE_DIR/gtk-4.0/vulkan-pipeline-cache/$UUID.$VERSION
so we regenerate caches for each different device (different UUID) and
each different driver version.

We also keep track of the etag of the cache file, so if 2 different
applications update the cache, we can detect that.
Vulkan allows merging caches, so the 2nd app reloads the new cache file
and merges it into its cache before saving.
2023-06-26 20:28:11 +02:00
Luca Bacci
3912d6aba9 GdkWin32: Fix keyboard state for WinPointer input
The dwKeyStates field of the POINTER_INFO structure
is always set to 0, no matter what. Use GetKeyState
instead.

Forward-port of !4327 to GTK4
2023-06-21 16:18:01 +02:00
Luca Bacci
871685e271 GdkWin32: Use double coordinates for mouse events
Mouse coordinates reported by the system are still integers,
but go sub-pixel when dividing by the window scale factor.
2023-06-21 16:07:55 +02:00
Luca Bacci
5e9daa9728 GdkWin32: Unscaled coordinates in current_root_x, current_root_y
Also modify gdk_win32_surface_do_move_resize_drag() to take
unscaled root coordinates.

Fixes #5877
2023-06-21 16:01:42 +02:00
Luca Bacci
412bc1713a GdkWin32: Keep track of the last cursor position in move / resize contexts
...and avoid doing any work if the position hasn't changed.
2023-06-21 15:31:48 +02:00
Benjamin Otte
299c6a3d6f vulkan: Take offscreen fromat from context
We want to create offscreens in compatible formats, and in particular we
want to ideally use the same format as rendering would use.
2023-06-20 20:15:12 +02:00
Benjamin Otte
015cebc046 vulkan: Set descriptorBindingStorageBufferUpdateAfterBind
It's necessary now that we use storage buffers for gradients:

[ VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingStorageBufferUpdateAfterBind-03008 ] Object 0: handle = 0x1e72d70, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x943cc552 | vkCreateDescriptorSetLayout(): pBindings[0] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT for VK_DESCRIPTOR_TYPE_STORAGE_BUFFER since descriptorBindingStorageBufferUpdateAfterBind is not enabled. The Vulkan spec states: If VkPhysicalDeviceDescriptorIndexingFeatures::descriptorBindingStorageBufferUpdateAfterBind is not enabled, all bindings with descriptor type VK_DESCRIPTOR_TYPE_STORAGE_BUFFER must not use VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingStorageBufferUpdateAfterBind-03008)
2023-06-20 20:15:12 +02:00
Benjamin Otte
4045a0edd1 vulkan: Check for descriptor indexing extension
By checking if the extension is supported and avoiding devices when it
isn't, we avoid critical warnings later.
2023-06-19 15:08:00 +02:00
Benjamin Otte
636591c080 vulkan: Refactor function
Instead of checking for one specific extension, instead pass the
extension to check for by name.

This way we can reuse it for different extensions.
2023-06-19 15:08:00 +02:00
Benjamin Otte
aa6c670f15 vulkan: Add support for high bit depth 2023-06-19 15:08:00 +02:00
Benjamin Otte
63edecd857 vulkan: Make gsk_renderer_realize() work with NULL surface
Pretty much copy what GL does and just use the default display to create
GPU-related resources without the need for a display.

This also adds gdk_display_create_vulkan_context() but I've
kept it private because the Vulkan API is generally considered in flux,
in particular with our pending attempts to redo how renderers work.
2023-06-19 14:13:03 +02:00
Benjamin Otte
090cd2238a gdk: Replace prefers_high_depth with depth
Now that we track depth, we can also pass it into the GDK frame code.

For now it's just passed along, code acts the same as with
prefers_high_depth.
2023-06-18 14:28:39 +02:00
Benjamin Otte
8b8dfcdfb4 rendernode: Change to gsk_render_node_get_preferred_depth()
Instead of just tracking preferred_high_depth(), track the actual depth
we'd like to have.
2023-06-18 14:26:18 +02:00
Benjamin Otte
9015ed1c43 memoryformat: Add gdk_memory_format_get_depth()
Replace gdk_memory_format_prefers_high_depth with the more generic
gdk_memory_format_get_depth() that returns the depth of the individual
channels.

Also make the GL renderer use that to pick the generic F16 format
instead of immediately going for F32 when uploading textures.
2023-06-18 14:26:18 +02:00
Carlos Garnacho
c523c68cef gdk: Include pads in GDK_SEAT_CAPABILITY_ALL
The GDK_SEAT_CAPABILITY_TABLET_PAD stood awkwardly out of the
ALL value. Even though it's not a keyboard, its focus has more
resemblance to it, so it should be part of this group together
with keyboards.
2023-06-14 01:42:53 +02:00
Carlos Garnacho
9f4320a4ac gdk/wayland: Create pad devices on enter
We were creating the pad device on wp_tablet_pad.done, but
at that time we do not know what tablet it is associated with,
thus we cannot get appropriate vid/pid/name properties for it.

To get that, we need to wait for the pad to enter a surface,
at that time we do know what tablet it is associated with, so
we can get better information about the device.

There are pads that may plausibly "change" tablet between
one .enter event and the next (e.g. Wacom Express Key Remote),
but this situation is highly unlikely. The pad devices created
are thus persistent until that situation happens.
2023-06-14 01:42:53 +02:00
Luca Bacci
cf980cdefb Merge branch 'focus-modal-windows' into 'main'
win32: Focus modal windows when clicking on unfocused parent

See merge request GNOME/gtk!6051
2023-06-12 13:55:45 +00:00
Luca Bacci
51265e2367 Merge branch 'center-dialogs' into 'main'
win32: Center newly created transient windows

Closes #5407

See merge request GNOME/gtk!6050
2023-06-12 13:53:00 +00:00
Matthias Clasen
53af7208e6 gdk: Fix an oversight in GdkContentFormats
When clearing a builder, reset the counts to 0.

Otherwise valgrind spots uninitialized memory
use in our testsuite.
2023-06-09 08:17:34 -04:00
dgsasha
84840f1f2e win32: Center newly created transient windows
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5407
2023-06-08 16:42:27 -04:00
Marco Trevisan
d2638f0955 Merge branch 'wip/otte/fix-glx' into 'main'
glx: Ignore all errors

See merge request GNOME/gtk!6065
2023-06-06 10:56:55 +00:00
Benjamin Otte
e580dcf18d glx: Fake an X request to make GLX hack work
Sometimes, GLX can decide to use the previous request serial when faking
XErrors via __glXSendError() (look through the Mesa sources to enjoy).
This can cause the error trap we just installed to not feel responsible
for the error. And that makes GDK decide to immediately abort the
application.
That is not what we or GLX want.

So we use a no-op X Request to bump the request number so that when GLX
does its shenanigans, it uses a serial that our error trap will catch.

Fixes a crash in mutter's CI which apparently manages to drive GLX
without an X server.
2023-06-06 05:20:34 +02:00
Benjamin Otte
14e44f36bf glx: Move error trap even further out
This way we only create one error trap for all attempts to create a
context instead of up to 3.
2023-06-06 05:20:34 +02:00
Benjamin Otte
1e60ad1430 glx: Ignore all errors
In error cases, glXCreateContextAttribsARB() will always return NULL so
it is enough to run the loop until the first non-NULL context is
returned.

And at that point, we can just look at the return value and ignore all
errors.
2023-06-06 05:20:34 +02:00
Matthias Clasen
51f4ad55cf wayland: Free seat globals in dispose
This matches what we do for the display globals.
2023-06-05 20:50:09 -04:00
Matthias Clasen
94d65f6ef1 gdk: Dispose seats when a display is closed
We dispose the display itself. It does not make
sense to hold onto seat resources beyond that point.
2023-06-05 20:50:09 -04:00
Matthias Clasen
c3f446a95a wayland: Don't leak all globals 2023-06-05 20:50:09 -04:00
Matthias Clasen
ad8e5c3a39 wayland: Drop an unused field
Nobody is using the wl_input_device field.
2023-06-05 20:50:09 -04:00
Matthias Clasen
a9f9fb2022 gl: Free all tracked buffers
This was overlooked when the number of tracked
buffers was bumped from 2 to 4 in 46e3454eb7.
2023-06-04 22:17:56 -04:00
Benjamin Otte
fd5d15004e Merge branch 'wip/otte/vulkan' into 'main'
Vulkan hacking going overboard

See merge request GNOME/gtk!5992
2023-06-04 18:21:21 +00:00
Benjamin Otte
0f1b039306 vulkan: Implement bindless texture rendering
Instead of having a descriptor set per operation, we just have one
descriptor set and bind all our images into it.

Then the shaders get to use an index into the large texture array
instead.

Getting this to work - because it's a Vulkan extension that needs to be
manually enabled, even though it's officially part of Vulkan 1.2 - is
insane.
2023-06-04 19:42:01 +02:00
Matthias Clasen
85bafbdff0 wayland: Don't leak cursor structs
Found by gcc's -fanalyzer.
2023-06-04 07:58:24 -04:00
Matthias Clasen
c380d17621 Revert "gdk/x11: Also grab keyboard during XDnD grabs"
This reverts commit ae94417f80.
2023-06-03 12:25:25 -04:00
Matthias Clasen
686d18dfc2 x11: Stop using passive grabs
The keynav that this implements is half-broken under
xwayland anyway, and it confused and complicates things
on the compositor side.
2023-06-03 12:25:25 -04:00
Benjamin Otte
0a1702ae99 Merge branch 'wip/otte/fix-glx' into 'main'
glx: Trap errors inside loop

Closes #5857

See merge request GNOME/gtk!6056
2023-06-03 16:19:09 +00:00
Benjamin Otte
0016fea36b glx: Trap errors inside loop
Instead of trapping errors for the whole loop trying to create GL
contexts, trap them once per GL context.

Apparently GLX does throw an error when a too high version is requested
and doesn't just return NULL and then that error lingers when we try
lower versions.

Fixes #5857
2023-06-03 18:03:56 +02:00