Commit Graph

11316 Commits

Author SHA1 Message Date
Matthias Clasen
c8c895d160 Merge branch 'trap-bad-rr-errors' into 'main'
x11: Trap XRandr errors when getting outputs during init and update

See merge request GNOME/gtk!6046
2023-06-02 11:31:45 +00:00
Luca Bacci
acbd7f212e Merge branch 'for-main' into 'main'
GdkWin32 Cleanup

See merge request GNOME/gtk!5714
2023-06-02 09:34:48 +00:00
Marco Trevisan (Treviño)
f2a2889153 x11: Trap XRandr errors when getting outputs during init and update
We may try to update the XRR outputs and Crtcs when they're changing in
the server, and so we may get BadRROutput that we're currently not
handling properly.

As per this, use traps and check whether we got errors, and if we did
let's ignore the current output.

It's not required to call init_randr13() again because if we got errors
it's very likely that there's a change coming that will be notified at
next iteration during which we'll repeat the init actions.
2023-06-02 00:30:14 +02:00
sumibi-yakitori
1fce2b1e06 Fix an issue where min_version was not being used as the minimum version required by GTK 2023-06-01 23:05:44 +09:00
sumibi-yakitori
7b8a5235d4 Fix a bug in error checking conditions. This avoids unintentional Legacy of the created OpenGL context 2023-06-01 16:46:24 +09:00
sumibi-yakitori
3c9b3ead6f The GL version reported by epoxy seems to depend on the current GL context, so the GL context to create should be the one determined by gdk_gl_context_get_matching_version 2023-06-01 16:43:57 +09:00
Matthias Clasen
39f4d5ccf7 gltexturebuilder: Update the docs
We do handle unpremultiplied alpha correctly (albeit
non-optimally) now.
2023-05-31 14:39:07 -04:00
Luca Bacci
24af4b48cc GdkWin32: Remove unused functions 2023-05-31 12:15:57 +02:00
Luca Bacci
1c8caf745f GdkWin32: Remove declarations of unused types from gdkprivate-win32.h 2023-05-31 12:15:57 +02:00
Luca Bacci
395d80f131 GdkWin32: Remove declarations of unexisting functions from gdkprivate-win32.h 2023-05-31 12:15:57 +02:00
Luca Bacci
74229572e7 GdkWin32: Remove defines for old MinGW headers 2023-05-31 12:15:57 +02:00
Luca Bacci
cbb3d3f177 GdkWin32: Remove _gdk_display_hdc global variable 2023-05-31 12:15:57 +02:00
Luca Bacci
8861d0eb53 GdkWin32: Turn a few functions to static
When used only in the source file they're defined in.
Also remove the corresponding declarations from
gdkrivate-win32.h.
2023-05-31 12:15:57 +02:00
Luca Bacci
a23bc894e9 GdkWin32: Remove unused debug functions
* _gdk_win32_print_paletteentries
 * _gdk_win32_print_system_palette
 * _gdk_win32_print_hpalette
 * _gdk_win32_drag_protocol_to_string
 * _gdk_win32_data_to_string
 * _gdk_win32_gdkrectangle_to_string
 * _gdk_win32_cairo_region_to_string
 * _gdk_win32_surface_description
2023-05-31 12:15:57 +02:00
Matthias Clasen
f29c7e76f5 gltexture: Use proper alignment for downloads 2023-05-30 22:35:45 -04:00
Matthias Clasen
876b439d4a Merge branch 'matthiasc/conversion-tests' into 'main'
Texture format work

See merge request GNOME/gtk!6035
2023-05-31 00:13:51 +00:00
Matthias Clasen
4f6d7c69a1 gltexturebuilder: Document format expectations
Provide some details about storage and alpha handling.
2023-05-30 19:46:13 -04:00
Matthias Clasen
1c72f46eed gltexture: Rewrite downloading code
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.
2023-05-30 15:57:18 -04:00
Matthias Clasen
0f61c52593 gdk: Simplify gdk_memory_format_gl_format
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.
2023-05-30 14:49:45 -04:00
Sophie Herold
894a4bda85 gdk: Support gray/alpha in PNG loader 2023-05-30 14:41:01 -04:00
Sophie Herold
2b88505ca4 gdk: Support gray/alpha in TIFF loader
Use PHOTOMETRIC_MINISBLACK for grayscale image
2023-05-30 14:41:01 -04:00
Sophie Herold
ef8c835762 gsk: Support swizzle for gray and alpha formats
Swizzling is needed to display one channel memory formats
as gray etc.
2023-05-30 14:41:01 -04:00
Sophie Herold
50115d70c6 gdk: Add grayscale and alpha memory formats 2023-05-30 14:41:01 -04:00
Luca Bacci
1a058a41c9 Do not keep HINSTANCE variables around
Use &__ImageBase for the GTK DLL and GetModuleHandle (NULL)
for the application module. Then remove DllMain as it's not
necessary anymore.

References:

 [1] Accessing the current module's HINSTANCE from a static library:
     https://devblogs.microsoft.com/oldnewthing/20041025-00/?p=37483
2023-05-30 19:31:54 +02:00
Marco Trevisan (Treviño)
be4f6ff3da gdkselectioninputstream-x11: Explicitly handle stream ownership in signal
The display xevent signal connection takes the ownership of the stream
until we get a valid event, so it should manage the stream lifetime.

So make this clearer, by automatically removing the stream reference
when we disconnect from the xevent signal handler.
2023-05-30 17:59:19 +02:00
Marco Trevisan (Treviño)
4fcf899852 gdkselectioninputstream-x11: Make it clearer how we manage the stream ownership
It gets unreffed during gdk_x11_selection_input_stream_complete, so use
APIs that make this clearer.
2023-05-30 17:54:29 +02:00
Marco Trevisan (Treviño)
371e860184 gtkselectioninputstream-x11: Do not add an extra reference to the returned stream
We create a new stream during gdk_x11_selection_input_stream_new_async()
then such stream is referenced when passed to the task via
g_task_return_pointer(), so there's no need to reference it again before
returning it, or we'd end up leaking.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4892
2023-05-30 17:50:56 +02:00
Marco Trevisan (Treviño)
bce1e0bfdd gtkselectioninputstream-x11: Do not add unreffed bytes to the chunks queue
This should never happen, but we may exit the loop because of count value
with an unreffed bytes pointer being added back to the chunks queue.
2023-05-30 17:43:57 +02:00
Marco Trevisan (Treviño)
468d2cb7f2 gtkselectioninputstream-x11: Do not add EOF marker twice to the chunks queue
We were adding the same EOF marker two times back to the chunks queue,
one implicitly, and the other time could happen when exiting the loop.
2023-05-30 17:42:59 +02:00
Luca Bacci
21c53a1969 Merge branch 'win32-monitors' into 'main'
GdkWin32Monitor fixes

See merge request GNOME/gtk!6015
2023-05-29 09:50:30 +00:00
FineFindus
2d8c112f08
docs: add HSL to Gdk.RGBA.parse
Update the Gdk.RGBA.parse docs to reflect the ability to parse HSL, which has been added in 4.5.0.
2023-05-25 17:16:55 +02:00
Jason Francis
cf79ad4433
win32: implement fullscreen_on_monitor
Track the HMONITOR so it can be used by the toplevel layout.
2023-05-24 18:48:37 -04:00
Benjamin Otte
d912628583 Merge branch 'wip/otte/for-main' into 'main'
2 GDK GL XWayland improvements

See merge request GNOME/gtk!6014
2023-05-24 22:22:48 +00:00
Jason Francis
f254ab700c
win32: Invalidate inactive monitors
Without this, there are still GdkMonitors present for displays that are
present but disconnected (such as when a laptop disables the internal
display to connect to an external monitor).
2023-05-24 17:34:34 -04:00
Benjamin Otte
c7b62d89e3 glx: Implement support for EXT_swap_control
XWayland (at least on gnome-shell) does not support SGI_swap_control,
which we were using to unset the swap interval.

It does support EXT_swap_control though, which is the more modern
version of the same thing, so this commit adds support for that.

And now GDK_DEBUG=no-vsync gives me >1000fps instead of just 60fps,
2023-05-24 21:44:43 +02:00
Benjamin Otte
46e3454eb7 gl: Update tracked buffers from 2 to 4
With XWayland and direct scanout it is possible that some apps get into
a situation where more than 2 buffers are in flight and in that case we
want to be able to still track the change regions for those buffers.

Usually 3 buffers are in use, so we go one higher, just to be safe.
2023-05-24 21:44:43 +02:00
Benjamin Otte
7573a9d2a7 gl: Rewrite update area tracking code
Make it more generic. That way we could dynamically change the number of
buffers we track.

We don't do that yet though.
2023-05-24 21:44:29 +02:00
Matthias Clasen
d6fc0d6c94 gdk: Fix up introspection build
Referring to files across directories is not
easy, we need to use files() in just the right
way to make this work.
2023-05-21 09:46:49 -04:00
Benjamin Otte
b530ade8c6 gdk: Clamp frame region to surface size
The region may be larger than the surface's size, but many rendering
APIs require the size to be clamped.

Fixes #5812
2023-05-16 18:53:09 +02:00
Matthias Clasen
0b59290bad gdk: Drop some unused private api 2023-05-15 20:30:38 -04:00
Matthias Clasen
3fb06ca29d Merge branch 'matthiasc/for-main' into 'main'
tools: Cosmetics

See merge request GNOME/gtk!5972
2023-05-16 00:02:15 +00:00
Matthias Clasen
ed265f6a7e gdk: Deprecated some pixbuf apis
These are already documented as 'don't use
in new apis'. Lets make it official and
deprecate them properly.
2023-05-15 18:22:37 -04:00
Matthias Clasen
343472931d Cosmetics
Linkify a reference.
2023-05-15 15:25:11 -04:00
Matthias Clasen
89d993b6ec wayland: Try harder to be compatible
We can keep the old unexport_handle api working
in the case that there is only a single exported
handle.
2023-05-15 00:20:24 -04:00
Matthias Clasen
250a5c0dfd Deprecate gdk_wayland_toplevel_unexport_handle
It doesn't do anything anymore, and is no longer
used internally. The replacement is
gdk_wayland_toplevel_drop_exported_handled().
2023-05-15 00:20:24 -04:00
Matthias Clasen
af3ceb5755 wayland: Reimplement exporting
Change things so that every call to export_handle
creates a new handle, and unexport_handle destroys
the handle that it is given.
2023-05-14 23:49:44 -04:00
Matthias Clasen
982a696311 wayland: Give toplevels a destroy hook
We will need to do some cleanup before the
wl_surface is destroyed, so add a hook for that.
2023-05-14 23:49:44 -04:00
Matthias Clasen
e5f1e4545d gdk: Change the private export handle api
Make unexport_handle take the handle, so we
can in the future deal with multiple exports.

Update the one caller in gtkwindow.c to pass
the handle.
2023-05-14 23:49:44 -04:00
Matthias Clasen
bf87a40b20 wayland: Add new backend api
Add an alternative to unexport_handle that
does take the handle.
2023-05-14 23:49:44 -04:00
Matthias Clasen
38f610f85e Fix a typo 2023-05-14 13:26:14 -04:00
Matthias Clasen
5393173afa wayland: Remove some unused fields 2023-05-14 13:06:00 -04:00
Matthias Clasen
51ad2a55a8 gdk: Add an assertion
We simply overwrite any previous region,
so assert that the field was NULL before.
2023-05-14 07:50:11 -04:00
Matthias Clasen
2cd5b4df1b Add missing va marshallers
Whenever we pass a marshaller to g_signal_new,
call g_signal_set_va_marshaller with the corresponding
va marshaller.
2023-05-13 12:38:24 -04:00
Emmanuele Bassi
9d68bebdd1 Minimize the amount of inclusions in public headers
Public headers should mainly include gdktypes.h, which already include
the symbol visibility and versioning macros; we can also modify
gdktypes.h to include the enumerations.
2023-05-09 17:36:59 +01:00
Matthias Clasen
d7b9d35c02 Use #pragma once
We switched over to using #pragma once, so lets
use it consistently, in generated headers as well.
2023-05-09 16:43:35 +01:00
Matthias Clasen
383c404792 Drop the gdk/gdkversionmacros.h header
It was just added to avoid touching too many files.
Touching them now.
2023-05-09 16:43:35 +01:00
Matthias Clasen
197d921347 Add a missing file 2023-05-09 16:43:25 +01:00
Matthias Clasen
3d5529760a Fix install location 2023-05-09 16:43:25 +01:00
Matthias Clasen
e216f469a1 Don't excessively define GDK_EXTERN
Once is enough.
2023-05-09 16:43:25 +01:00
Matthias Clasen
5ae25519a7 Make it build
Fix the circular dependency by moving the generated
headers to gdk/version/, and build that directory
first.

Misc other fixes, such as putting the custom targets
as sources, not depedencies, and using the correct
major version in the generator script.
2023-05-09 16:43:25 +01:00
Emmanuele Bassi
4d1f7a476d Generate version and deprecation macros at build time
Let's poach the same script used by GLib to avoid having to add all the
version macros by hand every time we increment the GTK version.

This is a work in progress:

- need to rename the GLIB_STATIC_COMPILATION check
- circular dependency: libgtkcss depends on gdkversionmacros.h, but libgdk
  depends on libgtkcss
2023-05-09 16:43:25 +01:00
Benjamin Otte
a959fba18a Merge branch 'wip/otte/no-vsync' into 'main'
Add GDK_DEBUG=no-vsync

See merge request GNOME/gtk!5944
2023-05-09 15:16:43 +00:00
Benjamin Otte
961a6c12ec wayland: Don't assert when requesting another frame
When GDK_DEBUG=no-vsync is on, we might have more than one outstanding
frame. Don't assert when that hapens. Just request a frame callback for
the first and skip the others.
2023-05-09 16:29:41 +02:00
Benjamin Otte
c227493c65 frameclock: Keep more history
Not all frames get timing info with GDK_DEBUG=no-vsync, so make sure
that even when we render tons of frames, the one frame that does get
timing info is still there when the timing info arrives.

I set it to 128 from 16 now.
This is roughly good enough to go to 5000fps from on a 60Hz monitor.
2023-05-09 16:29:41 +02:00
Benjamin Otte
02e2a6f311 gdk: Add GDK_DEBUG=no-vsync
That turns off waiting and freezing in the frame clock and in
surfaces and triggers redraws asap.
2023-05-09 16:29:41 +02:00
Benjamin Otte
fa42e02a76 frameclock: Add gdk_frame_clock_idle_is_frozen()
This is in preparation for a future commit.

Also turn some macros into inline functions and pass the clock instead
of its priv pointer.
2023-05-09 16:29:37 +02:00
Chun-wei Fan
0073ee29da gdkglcontext-win32-wgl.c: Always request alpha bits
...when we are using wglChoosePixelFormatARHB().  This ensures that we
hvae a HDC with a pixel format that will really support alpha bits, as
we did for the traditional ChoosePixelFormat().

Thanks to Patrick Zacharias for testing and pointing things out.
2023-05-09 18:15:23 +08:00
Benjamin Otte
e9ed5e21ef win32: Turn off multisampling
We know we draw beautiful Windows, but drawing them once is totally
enough.
2023-05-09 18:15:23 +08:00
Benjamin Otte
c37786af36 win32: Actually increase the counter
We were sending random junk to ChoosePixelFormat().

Also assert that we don't overflow the array. That might be usefu to
know if we carelessly add attributes later.
2023-05-09 18:15:23 +08:00
Chun-wei Fan
a7b09e19f1 GDK/Win32: Use dummy WGL contexts more
... for creating the actual WGL contexts, so that we can cut down on the
number of times where we need to create the base, legacy WGL contexts in
order to create the WGL contexts with attributes.  We could just use the
dummy context that we have to make it current to create the needed
WGL contexts.
2023-05-09 18:15:23 +08:00
Chun-wei Fan
50ef36d387 gdkglcontext-win32-wgl.c: Fix using wglChoosePixelFormatARB()
If we are querying the best supported pixel format for our HDC via
wglChoosePixelFormatARB() (i.e. we have the WGL_ARB_pixel_format extension),
it may return a pixel format that is different from the pixel format that we
used for the dummy context that we have setup, in order to, well, run
wglChoosePixelFormatARB(), which sadly requires a WGL context (HGLRC) to be
current in order to use it, which means the dummy HDC already has a pixel
format that has been set (notice that each HDC is only allowed to have its
pixel format to be set *once*). This is notably the case on Intel display
drivers.

Since we are emulating surfaceless GL contexts, we are using the dummy GL
context (and thus dummy HDC that is derived from the notification HWND used in
GdkWin32Display) for doing that, we would get into trouble if th actual HDC
from the GdkWin32Surface has a different pixel format set.

So, as a result, in order to fix this situation, we do the following:

* Create yet another dummy HWND in order to grab the HDC to query for the
  capabilities the GL drivers support, and to call wglChoosePixelFormatARB() as
  appropriate (or ChoosePixelFormat()) for the final pixel format that we use.
* Ditch the dummy GL context, HDC and HWND after obtaining the pixel format.
* Then set the final pixel format that we obtained onto the HDC that is derived
  from the HWND used in GdkWin32Display for notifications, which will become our
  new dummy HDC.
* Create a new dummy HGLRC for use with the new dummy HDC to emulate surfaceless
  GL support.
2023-05-09 18:15:23 +08:00
Chun-wei Fan
d02ae09124 gdkglcontext-win32-wgl.c: Fix WGL context realization on 32-bit
We are currently using g_clear_pointer() on the intermediate WGL contexts
(HGLRC)'s that we need to create in the way, which means that we need to ensure
that the correct calling convention for wglDeleteContext() is being applied.

To be absolutely safe about it, use the gdk_win32_private_wglDeleteContext()
calls, which will in turn call wglDeleteContext() directly from opengl32.dll
(using the OpenGL headers from the Windows SDK) instead of going via libepoxy,
which will assure us that the correct calling convention is applied.

Fixes issue #5808.
2023-05-09 11:47:28 +08:00
Benjamin Otte
2a950dec71 Merge branch 'wip/otte/update-texture' into 'main'
Add texture update regions

See merge request GNOME/gtk!5880
2023-05-06 00:59:25 +00:00
Benjamin Otte
6506a3bc9c texturebuilder: Add ::udpate-region and ::update-texture 2023-05-02 00:30:58 +02:00
Benjamin Otte
1883035d34 texture: Add gdk_texture_diff()
... and use it in rendernodes.

Setting up textures for diffing is done via gdk_texture_set_diff() which
should only be used during texture construction.

Note that the pointers to next/previous are allowed to dangle if one of
the textures is finalized, but that's fine because we always check both
textures' links to each other before we consider the pointer valid.
2023-05-01 22:24:14 +02:00
Matthias Clasen
d92c6406d1 Merge branch 'displaymanager-warning-fix' into 'main'
Avoid a bad warning

See merge request GNOME/gtk!5901
2023-05-01 16:56:40 +00:00
Matthias Clasen
d666f4ab7f Avoid a bad warning
This isn't what we intended, and it breaks CI for
various projects.
2023-05-01 10:40:26 -04:00
Jordan Petridis
0197149ba3 vulkan: Correct error enum version guards
Vulkan 218 introduced these errors by they were marked as
the beta till version 238.

00671c64ba (diff-e222ae95c2b0d5082b94d6086fb1c24da18ee31384c1a39840df3b9152023ee6)

Followup to f9b2d3104a
2023-05-01 09:41:35 +03:00
Benjamin Otte
6cc1548c5f Merge branch 'wip/carlosg/x11-artifacts' into 'main'
gdk/x11: Invalidate whole surface after size change

See merge request GNOME/gtk!5857
2023-04-29 18:11:21 +00:00
Carlos Garnacho
24302315fb gdk/x11: Invalidate whole surface after size change
The Expose events following a ConfigureNotify may arrive at
a time that we did not resize the surface yet, making these
expose events a no-op. Even though gsk/gtk take care of the
window content itself, this might lead to unrendered portions
of the window shadow.

This may be seen with GSK_RENDERER=cairo and GDK_BACKEND=x11,
attempting to tile a window (e.g. gtk4-demo) left or right.
The window will show black rectangles or other artifacts in
the window shadow areas that correspond to the newly painted
portions (as the window needs to expand vertically).

In order to fix this with a similar behavior to Wayland,
consider ourselves the whole surface invalidated after resize,
in order to ensure everything is painted from scratch.
2023-04-29 11:51:32 +02:00
Benjamin Otte
11aaa29a69 wayland: Use wl_surface_damage_buffer() in Cairo
... when it is available.

Also introduce the new function gdk_rectangle_transform_affine(), which
looks like overkill for this purpose, but I'm about to use it elsewhere.
2023-04-29 05:07:03 +02:00
Benjamin Otte
b4c859c011 wayland: Set EGL swap interval to 0.
There's no need for EGL to do any timing, we do it in GTK already.

This fixes hangs in Mesa when we hide a surface after a SwapBuffers()
but before the frame callback arrives.
If we then reshow the surface and immediately render to it, Mesa would
still have a frame callback from before the hiding and forever poll()
waiting for the compositor to send the callback.

Fixes #5761
2023-04-28 22:40:39 +02:00
Benjamin Otte
45216e1c88 wayland: Disconnect the frame callback when hiding
Do not leave spurious frame callbacks around wen hiding surfaces.
Instead, store the callback and remove it.
2023-04-28 22:21:42 +02:00
Matthias Clasen
6efaa79e3c gltexture: Synchronize when downloading
If the GL texture has a sync object, wait
on it before downloading the data.
2023-04-27 06:57:02 +02:00
Matthias Clasen
92eb845482 gltexture: Optionally take a sync object
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.
2023-04-27 06:55:37 +02:00
Matthias Clasen
5071e6154c glcontext: Add a way to check for GLsync 2023-04-27 06:54:49 +02:00
Benjamin Otte
18a4b2475e gltexture: Deprecate gdk_gl_texture_new()
Use GdkGLTextureBuilder instead.
2023-04-27 06:40:47 +02:00
Benjamin Otte
aae7b2c8a8 texturebuilder: Pass the destroy notify to the build() function
This is more compatible with bindings that want to create per-object
callbacks and not have their callbacks reused over different build()
calls.
2023-04-27 06:40:47 +02:00
Benjamin Otte
e37fbaf13a texturebuilder: Add ::format and ::has-mipmap
We were trying to deduce that previously. Now we have explicit API
2023-04-27 06:40:47 +02:00
Benjamin Otte
e4f4cfaf14 gdk: Add GdkGLTextureBuilder
Building GL textures is complicated, so create an object to make them.

So far, this object just contains the functionality of
gdk_gl_texture_new(), but that will change in the future.
2023-04-27 06:40:47 +02:00
Benjamin Otte
9254ab8503 wgl: Improve error messages when GL init fails
In particular, we want to get the GL version, when the Windows box/VM
has an unsuitable GL implementation.

This is somewhat helpful in analyzing failures to bring up GL on
machines where users claim GL does work.
2023-04-27 02:19:25 +02:00
Benjamin Otte
d6afcee1e4 wgl: Create context during WGL initialization
This way, we can realize it and either print success information about
it or return NULL if that fails.

This makes it more likely that we fail early, which means we can then
initialize EGL.
2023-04-27 02:16:46 +02:00
Benjamin Otte
c71ca481c1 win32: Get rid of display->gl_version
We can just query the display's GL context.

And it's not used otherwise anymore.
2023-04-27 02:13:33 +02:00
Benjamin Otte
8ef38c46b5 win32: Refactor context creation
This refactor achieves the following:

 * check GL version against proper matching context version
   In particular, for legacy contexts, we now actually check
 * make sure the actual version is set, even for legacy contexts
 * make sure set_is_legacy() is set properly
2023-04-27 02:13:33 +02:00
Benjamin Otte
4333d754b8 gdk: Add workaround for Visual Studio
apparently casting something to itself makes it not constant.
2023-04-27 02:13:33 +02:00
Benjamin Otte
9f82d537b0 mac: Properly set GLContext.is_legacy() 2023-04-27 02:13:32 +02:00
Benjamin Otte
7c7a3d67ca glcontext: assert all contexts set the version on realize()
Now that all contexts do that, insist that they keep doing it.

And because they keep doing it, we can support querying the GL version
from gdk_gl_context_get_version() without requiring the context to be
made current.
2023-04-27 02:13:32 +02:00
Benjamin Otte
d33b82249b mac: Try all different OpenGL profiles
.. and pick the best one that is supported.

Also make sure that the resulting context has at least the desired
version, otherwise bail.
2023-04-27 02:13:32 +02:00
Benjamin Otte
5f833f1d31 glcontext: Compute matching version the simple way
Do it all in one function instead of requiring two different ones.
2023-04-27 02:13:32 +02:00
Benjamin Otte
b8958419e6 win32: Make sure highest possible GL version is created
Mirror EGL here.
2023-04-27 02:13:32 +02:00
Benjamin Otte
919c90182f win32: Pass the version properly through the creation stack
We were using major/minor instead of GdkGLVersion.

And we were resetting back to 0 and ignoring the required min version
which we should not do.
2023-04-27 02:13:32 +02:00
Benjamin Otte
ab2a548479 glx: Make sure highest possible GL version is created
Mirror EGL here.
2023-04-27 02:13:32 +02:00
Benjamin Otte
34662fc4b0 egl: Make sure highest possible GL version is created
The EGL spec states:

    The context returned must be the specified version, or a later
    version which is backwards compatible with that version.
    Even if a later version is returned, the specified version
    must correspond to a defined version of the client API.

GTK has so far been relying on EGL implementations returning a
later version, because that is what Mesa does.
But ANGLE does not do that and only provides the minimum version, which
means Windows EGL has been forced to use a lower EGL version for no
reason.

So fix this and try versions in order from highest to lowest.
2023-04-27 02:13:32 +02:00
Benjamin Otte
5b376cedcf gdk: Move GdkGLAPI enum into gdkenums.h 2023-04-27 02:13:32 +02:00
Benjamin Otte
3aefed39b1 glcontext: Use GdkGLVersion elsewhere
... and add a convenience API to generate GL versions from strings to
make the gdk_gl_context_check() API nicer.
2023-04-27 02:13:32 +02:00
Benjamin Otte
f86429177a gdk: Introduce GdkGLVersion
... and use it.

Makes the code simpler.
2023-04-27 02:13:32 +02:00
Benjamin Otte
dacfed3e11 win32: Remove an outdated check
We require GL 3.0, so checking for less than 2.0 makes no sense anymore.
2023-04-27 02:13:32 +02:00
Benjamin Otte
9d0448756f display: Remove ::create_surface() vfunc
Instead, have a toplevel_type and popup_type in GdkDisplay and
call g_object_new() with those types.
2023-04-26 21:03:34 +02:00
Benjamin Otte
03d7ce3287 wayland: Set default title in toplevel_init() 2023-04-26 21:03:34 +02:00
Benjamin Otte
f2083d36a1 macos: Add surface from ::constructed() 2023-04-26 21:03:34 +02:00
Benjamin Otte
cb642bec25 gdk: Remove GDK_SURFACE_DRAG enum member
I want to remove the whole enum, but this value was used all over the
place. So removing it first ensures I didn't forget anything.
2023-04-26 21:03:34 +02:00
Benjamin Otte
8c530264f7 wayland: Create drag surface directly
... instead of going through create_surface().
2023-04-26 21:03:34 +02:00
Benjamin Otte
d99042dd91 wayland: Remove struct member
It's unused.
2023-04-26 21:03:34 +02:00
Benjamin Otte
486196c979 x11: Add private gdk_x11_drag_surface_new()
... and use it.
2023-04-26 21:03:34 +02:00
Benjamin Otte
83faacabe3 x11: Set frame clock in ::constructed 2023-04-26 21:03:34 +02:00
Benjamin Otte
31aae62f9a x11: Move window construction to ::constructed() 2023-04-26 21:03:34 +02:00
Benjamin Otte
726be8e2b2 broadway: Create gdk_broadway_drag_surface_new()
... and use it.
2023-04-26 21:03:34 +02:00
Benjamin Otte
ab0fa08d8e win32: Create gdk_win32_draw_surface_new()
... and use it.
2023-04-26 21:03:34 +02:00
Benjamin Otte
42cea18f3e macos: Set frame clock in ::constructed 2023-04-26 21:03:34 +02:00
Benjamin Otte
44e54e1b4c broadway: Set frame clock in ::constructed
... instead of passing it to g_object_new().
2023-04-26 21:03:34 +02:00
Benjamin Otte
a79ae95e7e broadway: Move surface init code into ::constructed() 2023-04-26 21:03:34 +02:00
Benjamin Otte
77fe9116af win32: Set frame clock in constructed()
... instead of passing it as construct argument.
2023-04-26 21:03:34 +02:00
Benjamin Otte
808cde74be wayland: Construct the frame clock in the surface
... instead of passing it to g_object_new().
2023-04-26 21:03:34 +02:00
Benjamin Otte
13120ccf9d surface: Make gdk_surface_set_frame_clock() available
... to backends.

That way, frame clocks can be constructed by the backends' surface
implementations and dont need to be passed in as construct arguments.

Also add an assertion that they are indeed constructed.
2023-04-26 21:03:34 +02:00
Benjamin Otte
a306401023 macos: Move native window creation to ::constructed()
That way, it doesn't need a specific init function.

Also chain up last, so that the generic initialization code in
GdkSurface::constructed can access a fully initialized macos surface.
2023-04-26 21:03:34 +02:00
Benjamin Otte
7e18a1cea7 macos: Don't pass sizes to macos_surface_new()
They're 0, 0, 100, 100 always, so just use those values everywhere.
2023-04-26 21:03:34 +02:00
Benjamin Otte
9a6e6be785 macos: Create drag surface directly
Do not go via macos_surface_new().
2023-04-26 21:03:34 +02:00
Benjamin Otte
093a4e83d5 macos: Move construction stuff into ::constructed 2023-04-26 21:03:34 +02:00
Benjamin Otte
428798b53f macos: toplevels have no parent 2023-04-26 21:03:34 +02:00
Benjamin Otte
4fa81cf70f win32: Move surface init code into ::constructed() 2023-04-26 21:03:34 +02:00
Benjamin Otte
9ac31fe0a0 win32: Abort on error
Returning NULL from a function that must not return NULL is not a good
idea.
2023-04-26 21:03:34 +02:00
Benjamin Otte
69fabb3ce9 win32: Remove outdated debug messages
They are not needed anymore as they print stuff that's no decided in
that function anymore.
2023-04-26 21:03:34 +02:00
Benjamin Otte
f59c230a96 win32: Move toplevel signal into the toplevel class 2023-04-26 21:03:34 +02:00
Benjamin Otte
80d99b893e broadway: Pass parent as a construct argument 2023-04-26 21:03:34 +02:00
Benjamin Otte
cbe89b955a x11: Get rid of sizes when constructing surfaces
Just call XCreateWindow with 0, 0, 1, 1 size.
2023-04-26 21:03:34 +02:00
Benjamin Otte
2d827978a6 x11: Remove unused variable 2023-04-26 21:03:34 +02:00
Benjamin Otte
b2e304189e wayland: Move surface initialization into constructed()
That way, it doesn't ned a specific init function.

Also chain up last, so that the generic initialization code can access a
fully initialized wayland surface.
2023-04-26 21:03:34 +02:00
Benjamin Otte
35c2d85468 wayland: Move toplevel-specific code into the toplevel
The display->toplevels tracking belongs to GdkWAylandToplevel.
2023-04-26 21:03:34 +02:00
Benjamin Otte
7ef5f6ef1a display: Remove x/y/w/h from create_surface() 2023-04-26 21:03:34 +02:00
Marc-André Lureau
ff9cd989c6 gdk/win32: fix defined but not used warnings
[30/1038] Compiling C object gdk/win32/libgdk-win32.a.p/gdkmain-win32.c.obj
../gdk/win32/gdkmain-win32.c:146:1: warning: 'gdk_win32_finalize_ole' defined but not used [-Wunused-function]
  146 | gdk_win32_finalize_ole (void)
      | ^~~~~~~~~~~~~~~~~~~~~~
../gdk/win32/gdkmain-win32.c:113:1: warning: 'gdk_win32_finalize_com' defined but not used [-Wunused-function]
  113 | gdk_win32_finalize_com (void)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-25 16:37:58 +04:00
Marc-André Lureau
5b69df96fe gdk/win32: fix hr set but not used
A number of warnings are produced:

[23/1038] Compiling C object gdk/win32/libgdk-win32.a.p/gdkinput-dmanipulation.c.obj
../gdk/win32/gdkinput-dmanipulation.c: In function 'reset_viewport':
../gdk/win32/gdkinput-dmanipulation.c:354:11: warning: variable 'hr' set but not used [-Wunused-but-set-variable]
  354 |   HRESULT hr;
      |           ^~

Try to do something sensible instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-25 16:37:58 +04:00
Marc-André Lureau
d8ead56b9c gdk/win32: fix g_string_free warning
../gdk/win32/gdkclipdrop-win32.c: In function 'transmute_cf_shell_id_list_to_text_uri_list':
C:/msys64/ucrt64/include/glib-2.0/glib/gstring.h:72:5: warning: ignoring return value of 'g_string_free_and_steal' declared with attribute 'warn_unused_result' [-Wunused-result]

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-25 16:14:57 +04:00
Marc-André Lureau
0e2d7111eb gdk/win32: fix GDK_NOTE redefined warning
In file included from ../gdk/win32/gdkdrag-win32.c:201:
../gdk/win32/gdkprivate-win32.h:45: warning: "GDK_NOTE" redefined
   45 | #define GDK_NOTE(type,action)                             \
      |
../gdk/win32/gdkdrag-win32.c:40: note: this is the location of the previous definition
   40 | #define GDK_NOTE(a,b)

Fixes: bc159207bd ("gdk: Drop old debug macros")

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-25 16:11:11 +04:00
Takao Fujiwara
26e3824d1d gdkdisplaymanager: Add missing nullable to display name 2023-04-25 12:08:08 +09:00
Benjamin Otte
104b5ef157 surface: reformat function
Make the function follow usual coding conventions.

And while doing that, remove duplicate functionality.
2023-04-22 16:35:16 +02:00
Benjamin Otte
893862a51a surface: Refactor code
Move the early exit conditions to the top and turn them into early exits
instead of nesting if statements.
2023-04-22 16:33:35 +02:00
Benjamin Otte
823eb4c6d9 surface: Fold function into its only caller
No other changes
2023-04-22 16:29:58 +02:00
Benjamin Otte
be0ed15b40 surface: Stop maintaining an unused linked list
wat?
2023-04-22 16:27:27 +02:00
Benjamin Otte
040af44b00 surface: Remove in_update tracking
It's 2023, we use frame clocks now and don't have nested surface drawing
anymore.
2023-04-22 16:24:16 +02:00
Benjamin Otte
4154f87418 surface: Stop tracking the active update area
It's unused.
2023-04-22 16:10:24 +02:00
Marc-André Lureau
250414d6b3 gdk/win32: drop some unused variables
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-17 04:50:17 +00:00
Marc-André Lureau
d69cdf6c05 gdk: drop libangle GLES minimum version
GLES 2.0 version is fine now with current gtk according to B. Otte.
Let's use the same minimum requirement for all implementations.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-17 04:50:17 +00:00
Marc-André Lureau
9532657fa2 gdk: use GLES when on win32/ANGLE
When using GDK_DEBUG=gl-egl, we end up using GL, but that is not well supported:

Creating EGL context version 3.0 (debug:no, forward:no, legacy:yes, es:no)
Created EGL context[0000000000000004]
OpenGL version: 0.0 (legacy)
* GLSL version: (NULL)
* Max texture size: -1059701680
* Extensions checked:
 - GL_KHR_debug: no
 - GL_EXT_unpack_subimage: yes
 - OES_vertex_half_float: no

** (gtk4-demo.exe:14324): WARNING **: 19:16:41.468: Compile failure in
vertex shader:
ERROR: 0:7: 'gl_Position' : undeclared identifier
---8<---

Use GLES when EGL implementation is ANGLE.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-17 04:50:17 +00:00
Marc-André Lureau
3cb2115212 gdk: drop unused vertex_array_object
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-17 04:50:17 +00:00
Benjamin Otte
8965d6c7f8 gl: Only allow RGB(A)8 on GLES2
GLES2 has no idea what 16bit textures even are, let alone floating point.
2023-04-17 05:57:44 +02:00
Benjamin Otte
62951c7277 wayland: Don't leak all surfaces
X11 does add an extra reference to surfaces that gets released when the
DestroyNotify event arrives.
Wayland doesn't ave such an event, so that reference never gets
released.

This fixes a copy/paste error introduced in commit 590f3dfa1f.
2023-04-16 19:28:21 +02:00
Benjamin Otte
8e00f6e5e5 wayland: Don't insta-crash when a surface gets disposed
We want to remove the event queue from the list of event queues, not the
surface.
Otherwise the freed queue stays in the list and the next time an event
comes in, we access invalid memory.

Fixes thinko introduced in commit 7fafa5133b.

Luckily, we leak all surfaces, so this problem never occured.
2023-04-16 19:28:21 +02:00
Matthias Clasen
189aced844 wayland: Improve logging for primary selection 2023-04-15 15:02:52 +02:00
Georges Basile Stavracas Neto
9c013d40c1 gdk/vulkancontext: Use more appropriate present mode
Check if the driver supports MAILBOX and prefer using it; in its
absense, checkif the driver supports IMMEDIATE and prefer using
it; finally, if neither of them are supported, use the guaranteed
to be supported FIFO mode.
2023-04-13 13:54:45 -03:00
Benjamin Otte
cfaf1b3e71 x11: Remove commented outdated code
... and it's copy/paste into the win32 backend
2023-04-13 17:15:35 +02:00
Benjamin Otte
9763d83a9d gdk: Remove unused vfunc 2023-04-13 17:15:35 +02:00
Benjamin Otte
75bea01a86 wayland: Keep EGL window around when hidden
See previous commit:

We want to keep resources around as long as the surface exists.
2023-04-13 05:19:18 +02:00
Benjamin Otte
5d3cec5441 wayland: Don't destroy the wl_surface on hide()
We want to keep the wl_surface around, because surfaces create their
resources on construct and keep them until destroyed. See the HWND ond
Windows and the XWindow on X11.

This is relevant for graphics resources, where we want to have access
to the VkSurface and eglSurface while the GdkSurface is hidden.
We also want these surfaces to be permanent and not change during the
lifetime of the GdkSurface.

What we can - and must - destroy however are the xdg surfaces, because
those handle visibility on screen.
And we also need to ensure no buffer is attached, so that during the
next creation of the xdg surface we don't get a protocol error.
2023-04-13 04:23:35 +02:00
Benjamin Otte
891242920e wayland: Split out a function
We have a create_wl_surface(), create a matching destroy_wl_surface().
2023-04-13 02:56:12 +02:00
Benjamin Otte
b375f17f09 wayland: Remove useless function
gdk_wayland_surface_maybe_resize() just calls
gdk_wayland_surface_update_size(), so make all callers call that one
instead.

The check that it does is done by the other function again.
2023-04-13 02:48:47 +02:00
Benjamin Otte
ec69990126 wayland: Remove an old workaround
This workaround - were it ever to trigger - is broken today. It destroys
the wl_surface and all associated structs but does not recreate the
xdg_popup or xdg_toplevel struct, so it would cause a hidden window.

The workaround looked a lot different when it was introduced in commit
83b54bab57, too - both in what it did and
in what the vfuncs did that it called.
2023-04-13 02:44:05 +02:00
Georges Basile Stavracas Neto
5c27a0dd2b vulkan: Support fractional scaling
Basically what GL does, but without any debug or feature flag
to gatekeep it, since the Vulkan backend itself is experimental
already.

Ceil surface sizes, and floor coordinates, to the fractional scale
value.
2023-04-03 11:10:27 -03:00
Matthias Clasen
5e95c22844 wayland: Be more careful about scale-factor
Only emit notify::scale-factor if it actually
changes. This potentially avoids a lot of work
in GTK (reloading icons, etc).
2023-04-02 13:23:19 -04:00
Matthias Clasen
70269a5aee docs: Add some details 2023-04-02 13:18:51 -04:00
Matthias Clasen
4746ffc4eb Make fractional scaling for GL opt-in
Fractional scaling with the GL renderer is
experimental for now, so we disable it unless
GDK_DEBUG=gl-fractional is set.

This will give us time to work out the kinks.
2023-04-02 11:05:57 -04:00
Matthias Clasen
fa58dd9256 Use fractional scale for the GL renderer
This commit combines changes in the Wayland backend,
the GL context frontend, and the GL renderer to switch
them all to use the fractional scale.

In the Wayland backend, we now use the fractional scale
to size the EGL window.

In the GL frontend code, we use the fractional scale to
scale the damage region and surface in begin/end_frame.

And in the GL renderer, we replace gdk_surface_get_scale_factor()
with gdk_surface_get_scale().
2023-04-02 09:22:56 -04:00
Matthias Clasen
76ac91512b Deprecate gdk_surface_create_similar_surface
This function is part of the cairo drawing API and
we are moving away from that. Update all callers.
2023-04-01 23:09:19 -04:00
Matthias Clasen
075bea788b Add gdk_surface_get_scale
Add a scale property to GdkSurface and use the
fractional scale for it on Wayland.
2023-04-01 19:09:16 -04:00
Benjamin Otte
6d4d9af14e wayland: Use fractional scaling with the Cairo renderer
Cairo can do that, so just enable it:

 * Create surfaces with the correct fractionally scaled size.
 * Set the Cairo surface's device scale to that number.
2023-04-01 20:05:06 +02:00
Benjamin Otte
84b235aac1 wayland: Allow creating fractional Cairo surfaces
We don't do that yet, because the buffer scale code can't deal with it,
but we can do it now.
2023-04-01 20:05:05 +02:00
Benjamin Otte
1a71e82fc5 wayland: Use wp_viewport to set buffer scale
Instead of setting the buffer scale via the buffer-scale command, set it
via the viewport.

This technically allows setting fractional scales, but we're not doing
that.
2023-04-01 20:05:01 +02:00
Benjamin Otte
8dd5d649b8 wayland: Use GdkFractionalScale for surface scale
We still always round it to integers when we read it, but we store it as a fraction.

So we could now use it for fractional scaling.
2023-04-01 18:23:38 +02:00
Benjamin Otte
40ac6f22a3 wayland: Introduce GdkFractionalScale type
We want to use it later for various things, this just adds the
infrastructure we will need.
2023-04-01 18:23:38 +02:00
Matthias Clasen
ffdbb9077c wayland: Some debug spew tweaks 2023-04-01 09:31:12 -04:00
Benjamin Otte
54e8bd898a wayland: Add support for the fractional scale protocol
April fools!

No, really.
The fractional scale protocol is just a way to track the surface scale,
but not a way to draw fractional content.
This commit uses it for that, so tht we don't rely on tracking outputs.

This also allows magnifiers etc to send us a larger (integer) scale if
they would like that, that is not represented by the outputs.
2023-04-01 12:57:03 +02:00
Benjamin Otte
b4492a97bf wayland: Use wl_seat_get_version() 2023-04-01 02:22:21 +02:00
Benjamin Otte
6f93f52b56 wayland: Use zwp_pointer_gestures_v1_get_version() 2023-04-01 02:22:21 +02:00
Benjamin Otte
68b8c5cd99 wayland: Use gtk_shell1_get_version()
... or correct gtk_surface1_get_version() alternative.
2023-04-01 02:22:21 +02:00
Benjamin Otte
9d99259cbd wayland: Use wl_data_device_manager_get_version() 2023-04-01 02:22:21 +02:00
Benjamin Otte
55b5c847f7 wayland: Use zxdg_output_manager_v1_get_version() 2023-04-01 02:22:21 +02:00
Benjamin Otte
3d3d22e844 wayland: Remove unused variable
Also, Wayland has get_version() functions, so if we ever need it, we can
use that.
2023-04-01 02:22:21 +02:00
Benjamin Otte
ae2c28af89 wayland: Check correct interface
buffer scale is a surface property, so check the version of the surface
interface, not the compositor one.
2023-04-01 02:22:21 +02:00
Benjamin Otte
c7499a33fd wayland: Use wl_compositor_get_version()
Wayland has functions to check versions, so use those.
2023-04-01 02:22:21 +02:00
Benjamin Otte
c97b489316 wayland: Use proper macro
Wayland has macros to check required versions. Use those instead of
custom ones.
2023-04-01 02:22:21 +02:00
Matthias Clasen
a1c5a806b3 Convert headers to #pragma once
The conversion was done by guard2one.
2023-03-31 15:11:10 -04:00
Georges Basile Stavracas Neto
6e80c8b07e gdk/vulkancontext: Accept Khronos validation layers
The Lunarg validation layers seem to have been deprecated in favour
of the Khronos ones. There's no reason not to have both, to accept
loading both - simultaneously, even.
2023-03-30 17:13:35 -03:00
Georges Basile Stavracas Neto
c0449e3245 gdk/vulkancontext: Pass all painted rects
Instead of passing a single, potentially massive rectangle that is
just the extents of the damage rect, collect and pass all damage
rects individually.
2023-03-30 17:13:35 -03:00
Georges Basile Stavracas Neto
8217b6e484 gdk/wayland/surface: Track and apply buffer scale
Add a new flag to track whether buffer scale is dirty or not,
and centralize calling wl_surface_set_buffer_scale() in a single
place: gdk_wayland_surface_sync_buffer_scale().

gdk_wayland_surface_sync_buffer_scale() is only called by
gdk_wayland_surface_sync(), which itself is called by the GL,
Vulkan, and Cairo contexts, right before submitting a frame.
This ensure that each frame has an up-to-date buffer scale.

This mimics how opaque and input regions are tracked.
2023-03-30 16:32:50 -03:00
Matthias Clasen
65dc4cac86 wayland: Fix corner cases in positioning
We were not handling some cases correctly.
This was making the dropdown in the gtk-demo
image-scaling demo appear in the top left
corner.
2023-03-28 20:37:54 -04:00
Matthias Clasen
ea572227f0 Merge branch 'wayland-popup-anchor' into 'main'
wayland: Comply with protocol requirements

See merge request GNOME/gtk!5723
2023-03-28 15:36:34 +00:00
Matthias Clasen
a8d8724a02 gdk: Avoid a pointless indirection
Don't use g_fprintf if GLib is using system printf
anyway.
2023-03-27 21:56:41 -04:00
Matthias Clasen
321877e94b gdk: Improve logging for backends
Log more when trying backends.
2023-03-27 21:42:10 -04:00
Matthias Clasen
68d629f84d Merge branch 'bilelmoussaoui/gi-docs' into 'main'
docs: Fix various broken links

See merge request GNOME/gtk!5734
2023-03-27 19:53:33 +00:00
Bilal Elmoussaoui
d1c43b94ef docs: Fix various broken links 2023-03-27 21:29:08 +02:00
Jonas Ådahl
c88f2caa04 wayland/popup: Handle late received reposition feedback
If we map, reposition, unmap, remap, the reposition feedback from the
last time a popup was mapped might be received while we're dealing with
the new version of the popup. At this point, the old reposition token
has no meating, so lets drop it. Also reset the reposition tokens when
creating new protocol objects, so that the reposition token are as if
we're in the initial state.

This fixes an issue where we'd get stuck if repeatedly smashing a button
that'd create popups that'd immediately get dismissed by the compositor.
2023-03-27 21:27:44 +02:00