Commit Graph

10424 Commits

Author SHA1 Message Date
David Edmundson
66de8f33fb wayland: drop unused member variables 2021-10-15 11:53:18 +01:00
Christian Hergert
e3ef21f770 macos: fix scale on macOS 12 beta
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.
2021-10-14 14:46:30 -07:00
Benjamin Otte
ddc4a40c33 gl: Refactor texture uploading
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.
2021-10-13 14:33:44 +02:00
Benjamin Otte
52e88ed4c8 gltexture: Determine format in current thread
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.
2021-10-13 14:33:44 +02:00
Benjamin Otte
5199bebdb5 gl: Move texture uploading to the renderer
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.
2021-10-13 14:33:44 +02:00
Benjamin Otte
31e9072906 gl: Fix downloading textures *again*
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.
2021-10-13 14:33:44 +02:00
Benjamin Otte
c2368cc605 png: Refactor png saving
Do all the memory format shenanigans in GTK now and support all the PNG
formats.
2021-10-13 14:33:44 +02:00
Benjamin Otte
1e7fb52b21 Add memory formats used by libpng
Add unpremultiplied high-depth formats. They are used in the real world,
so let's support them.
2021-10-13 14:33:44 +02:00
Benjamin Otte
7b41738979 png: Do loader conversions in GDK
Not inside libpng.

We really want to do them in GL, but we don't have a premultiply step
yet.
2021-10-12 02:06:44 +02:00
Benjamin Otte
b65b64628d texture: Refactor downloading
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.
2021-10-12 02:06:43 +02:00
Emmanuele Bassi
086a3044e3 Add getter to GdkFileList
Language bindings don't really have any mean of accessing the list of
files for GdkFileList.
2021-10-11 21:40:29 +01:00
Bastien Nocera
fc32c19ca7 broadway: Quiet initialisation failures
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"
2021-10-11 20:36:53 +02:00
Benjamin Otte
d89e82d4a0 Merge branch 'wip/otte/for-master' into 'master'
x11: Don't try to move destroyed windows

See merge request GNOME/gtk!4054
2021-10-11 18:36:20 +00:00
Benjamin Otte
f40ce51a13 x11: Don't try to move destroyed windows
Fixes BadWindow crashes when the resize happen right when tooltips or
other such transient popups were in the process of being destroyed.
2021-10-11 19:28:59 +02:00
Bastien Nocera
e6ae3b8a2b broadway: Quiet initialisation failures
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"
2021-10-11 14:01:20 +02:00
David Edmundson
dc503897b1 wayland: Mark opaque_region as dirty on hide
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.
2021-10-11 12:34:53 +01:00
Matthias Clasen
49a64da7ec Merge branch 'ngl-is-the-new-gl' into 'master'
Rename ngl to gl

Closes #4318

See merge request GNOME/gtk!4037
2021-10-11 06:43:41 +00:00
Benjamin Otte
d4959a95c2 gl: Make sure to set a proper alignment
No matter which branch we take, the alignment setting is always the
same.
2021-10-09 05:25:41 +02:00
Benjamin Otte
780ae5232d gl: Check the stride is a multiple of the bpp 2021-10-09 05:25:41 +02:00
Benjamin Otte
caddea4624 gl: Set stride properly in fallback 2021-10-09 04:44:30 +02:00
Benjamin Otte
27b5dc1452 gl: Fix broken internal format 2021-10-09 04:44:30 +02:00
Benjamin Otte
e974a0412f glcontext: Add gdk_gl_context_get_api()
This is mostly for inspector.

Not sure if we also want to deprecate gdk_gl_context_get_use_es() in
favor of this function.
2021-10-08 03:31:07 +02:00
Benjamin Otte
f584d4f500 gl: Check allowed APIs in realize()
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
2021-10-08 03:31:07 +02:00
Benjamin Otte
8c1f7f7531 glcontext: Deprecate gdk_gl_context_set_use_es()
Make it call gdk_gl_context_set_allowed_apis().

Also port callers to use this function.
2021-10-08 03:31:07 +02:00
Benjamin Otte
c6dd3c11fa glcontext: Add GdkGLContext::allowed-apis
This allows specifying the GL APIs in a more comprehensive way than
gdk_gl_context_set_use_es().
2021-10-08 03:31:07 +02:00
Matthias Clasen
144f727d5a Rename ngl to gl
We have only one gl renderer now, and it is
a bit odd for it not be called gl.
2021-10-07 13:05:53 -04:00
Chun-wei Fan
70a622ce54 gdkdisplay.c: Include stdlib.h
It is needed for qsort().
2021-10-07 18:00:51 +08:00
Benjamin Otte
8950c0dc96 texture: Make format a property of GdkTexture
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.
2021-10-07 02:41:30 +02:00
Benjamin Otte
3f4fb93379 cairo: Use GdkTexture for converting from pixbuf 2021-10-06 22:50:07 +02:00
Benjamin Otte
dc6e831524 gdk: hdr => 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.
2021-10-06 22:50:07 +02:00
Benjamin Otte
afa004fb8b memoryformat: Add gdk_memory_format_prefers_high_depth()
This is unused so far, but is part of preparations for high depth
support in renderers.
2021-10-06 22:50:07 +02:00
Benjamin Otte
149395c306 gl: Move memory <=> GL format mapping
Put it into gdkmemoryformat.c, where all the mapping goes.
2021-10-06 22:50:07 +02:00
Benjamin Otte
48781cf7f7 memorytexture: Split out GdkMemoryFormat handling
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.
2021-10-06 22:50:07 +02:00
Matthias Clasen
f819e88e9c gdk: Fix an oversight
The intention here was obviously to return
the hdr config.
2021-10-05 23:47:51 -04:00
Benjamin Otte
cdc85232b2 egl: Implement HDR support
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.
2021-10-06 03:44:59 +02:00
Benjamin Otte
5eb42dd9f3 gdk: Add GDK_DEBUG=hdr
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.
2021-10-06 03:44:59 +02:00
Benjamin Otte
7ede468849 gdk: Add a request_hdr argument to begin_frame()
It's not used by anyone, it's just there.

gdk_draw_context_begin_frame_full() has been added so renderers can
make use of it.
2021-10-06 03:44:58 +02:00
Benjamin Otte
bc7c0d05f8 egl: Support EGL_KHR_no_config_context
If the extension is supported, we create configless contexts.

This will come in handy real soon now, we use different configs for HDR
and SDR.
2021-10-06 03:44:37 +02:00
Benjamin Otte
3ca84c4357 glcontext: Handle failure of eglBindAPI()
We don't want to be sure if we have GL or GLES.
2021-10-06 03:44:36 +02:00
Benjamin Otte
2ff1ea555f egl: Unify contexts
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.
2021-10-06 03:44:36 +02:00
Benjamin Otte
03cc603093 glcontext: Remove unused functionality
The recent changes made and unused function removals make these features
unused.
2021-10-06 03:44:36 +02:00
Benjamin Otte
64f10eff20 gdk: Remove unused gdk_gl_texture_quads() function
That function carried a lot of baggage.
2021-10-06 03:44:36 +02:00
Benjamin Otte
111c2769a5 cairo-gl: Don't leak framebuffers
The framebufffer was cached, but never deleted. And because this
function is deprecated and nobody should ever use it: Don't bother with
caching now.
2021-10-06 03:44:36 +02:00
Benjamin Otte
482845b027 wayland: Remove initial GL API bind
This is leftover from before the addition of GLES support.

GTK works fine without OpenGL and just OpenGLES.
2021-10-06 03:44:36 +02:00
Benjamin Otte
f8b9b309b0 egl: Move extension checks to GdkDisplay
We check the same extensions anyway, so no need to duplicate the code.
2021-10-06 03:44:36 +02:00
Benjamin Otte
d128ffcc14 egl: Move EGLSurface handling to GdkSurface
Calling gdk_surface_set_egl_native_window() enables this.
2021-10-06 03:44:35 +02:00
Benjamin Otte
aba37c40d3 display: Get carried away by extension checker
I wanted to make it easy to check for multiple extensions and then got
carried away by trying to generate beautiful error messages.
2021-10-06 03:43:47 +02:00
Benjamin Otte
c8204a902c surface: Add a private struct
Adding a random member to it resulted in a lot of header surgery as a
side effect.
2021-10-06 03:43:47 +02:00
Benjamin Otte
032eb15079 glcontext: The content cannot be the current context
The current context owns a reference to the context, so it cannot be
disposed.
2021-10-06 03:43:47 +02:00
Benjamin Otte
70607f56d9 x11: Port to shared EGL code 2021-10-06 03:43:47 +02:00
Benjamin Otte
bfb158d773 egl: Move initialization code and port Wayland
Moves the EGL initialization code to gdk/ so it can be shared between
backends.

Also port the Wayland backend to this code, so I know that it works.
2021-10-06 03:43:47 +02:00
Benjamin Otte
ae8de7168a build: Add a HAVE_EGL define to config.h 2021-10-06 03:43:47 +02:00
Benjamin Otte
04da2ff7c8 surface: Use g_clear_thing() 2021-10-05 04:48:15 +02:00
Benjamin Otte
38461ee204 gdk: Make GDK_DEBUG GL backend selection global
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.
2021-10-05 04:48:15 +02:00
Benjamin Otte
6ec6bcafbf win32: Remove unused variables 2021-10-05 04:48:15 +02:00
Benjamin Otte
d939f379f4 win32: Comment out unused function 2021-10-04 04:26:49 +02:00
Matthias Clasen
b8622adac5 contentdeserializer: Plug a small memleak
Found by asan in ci. We intern the mimetypes
when they are registered, so there is no need
to leak this string.
2021-10-03 14:52:09 -04:00
Timm Bäder
1efccfcced gdk loaders: Add noreturn attribtues where appropriate 2021-10-02 09:08:14 +02:00
Matthias Clasen
08fd62e328 x11: Better debug for egl
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.
2021-10-01 22:23:08 -04:00
Matthias Clasen
a9f401a9a0 wayland: better debug for egl
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.
2021-10-01 20:55:05 -04:00
Matthias Clasen
2a3a1aaf1e Merge branch 'fix-wgl-cairo-fallback' into 'master'
Apply MR !3964 to master (fix WGL->Cairo fallback-related items)

Closes #4257

See merge request GNOME/gtk!3987
2021-10-01 00:29:40 +00:00
Chun-wei Fan
9bff56db9f GDK-Win32: Fix build
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.
2021-09-30 16:21:38 +08:00
Christian Hergert
e77eaa0ace macos: handle NULL surface when creating GL context
Fixes #4279
2021-09-28 17:36:23 -07:00
Benjamin Otte
30a741e6af Merge branch 'wip/lantw/GDK-Win32-Use-lowercase-windows.h' into 'master'
GDK/Win32: Use lowercase windows.h

See merge request GNOME/gtk!4000
2021-09-27 23:23:36 +00:00
Povilas Kanapickas
68bd94fa25 gdk/x11: Implement XI2.4 touchpad gesture support 2021-09-27 23:19:33 +03:00
Povilas Kanapickas
d981694c64 gdk/x11: Report XI2 version on the server 2021-09-27 23:17:04 +03:00
Ting-Wei Lan
5175b1676b GDK/Win32: Use lowercase windows.h
Fix build on case-sensitive file systems, so it can be cross-compiled
from Linux with MinGW.
2021-09-26 21:52:12 +08:00
Ting-Wei Lan
f96c4eb5bb broadway: Use the correct way to call find_library
While broadway currently doesn't build on Windows, it is still better to
avoid using the old and unsupported way to call find_library.
2021-09-26 18:51:13 +08:00
Benjamin Otte
a29474567a gdk: Remove gdkinternals.h 2021-09-24 22:50:29 +02:00
Benjamin Otte
279f9aa6d3 wayland: Don't include gdkinternals.h 2021-09-24 22:50:29 +02:00
Benjamin Otte
d4f9d38368 win32: Fix gcc warnings 2021-09-24 22:50:29 +02:00
Benjamin Otte
47e0539968 x11: Don't include gdkinternals.h 2021-09-24 22:50:29 +02:00
Benjamin Otte
4e836493cc macos: Don't include gdkinternals.h 2021-09-24 22:50:29 +02:00
Benjamin Otte
226ecaf9a2 win32: Don't include gdkinternals.h 2021-09-24 22:50:29 +02:00
Benjamin Otte
bcd9a0141a broadway: Don't include gdkinternals.h 2021-09-24 22:11:57 +02:00
Benjamin Otte
811b5d995b gdk: Don't include gdkinternals.h in gdk-private.h 2021-09-24 22:11:57 +02:00
Benjamin Otte
c7992884ae gdk: Remove gdk.h include form gdkframeclockidle.c 2021-09-24 22:11:57 +02:00
Benjamin Otte
39f2bb28de gdk: Remove gdk.h include from header 2021-09-24 22:11:57 +02:00
Benjamin Otte
78d7cb712e gdk: Remove gdk.h include from gdk-private.h 2021-09-24 22:11:57 +02:00
Benjamin Otte
d61c71c378 macos: Actually set the vfuncs 2021-09-24 22:11:57 +02:00
Benjamin Otte
23acc993cc gdk: Make sure only one GL backend is used
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
2021-09-24 01:59:37 +02:00
Matthias Clasen
0b9f6985b1 texture: Document constructors as threadsafe
We aren't providing async loading apis here,
but we want to allow applications to create
textures in a thread, to avoid blocking the
main thread.
2021-09-21 23:10:53 -04:00
Chun-wei Fan
ece02317b9 gdkdisplay-win32.c: Don't retry WGL initialization
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.
2021-09-22 11:09:02 +08:00
Chun-wei Fan
218a3e3d01 gdkglcontext-win32-wgl.c: Fix Cairo fallback check
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.
2021-09-22 11:08:53 +08:00
Benjamin Otte
d19f4ad53a Merge branch 'wip/otte/for-master' into 'master'
cssprovider: Be clearer about warnings vs errors

See merge request GNOME/gtk!3980
2021-09-20 05:38:27 +00:00
Benjamin Otte
d17552670c wayland: Add format hex value to debug print
It's how it's listed in the spec, this makes it easier to search.
2021-09-20 07:04:20 +02:00
Matthias Clasen
56e6a51ac0 Merge branch 'delayed-loading' into 'master'
gtk-demo: Cosmetics

See merge request GNOME/gtk!3975
2021-09-18 23:02:00 +00:00
Matthias Clasen
c9135546b6 loaders: Add profiler marks
These are potentially expensive calls, we
should make sure they show up in profiles.
2021-09-18 17:35:00 -04:00
Timm Bäder
c24b7877a0 gdktiff: Use guint32 instead of int32
The latter seems to be deprecated.
2021-09-18 09:00:16 +02:00
Benjamin Otte
1b85b5597b texture: Implement GIcon and GLoadableIcon
This is mainly for feature parity with GdkPixbuf. And it doesn't hurt
anyone (I hope).
2021-09-17 04:31:46 +02:00
Benjamin Otte
fae32846c7 texture: Refactor gdk_texture_new_from_bytes()
1. Split into a real loader and a fake one

2. Only try the fake one if the real one doesn't support the file.
2021-09-17 04:31:46 +02:00
Benjamin Otte
b271a94f92 texture: Rework error enum
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.
2021-09-17 03:25:35 +02:00
Matthias Clasen
b226478e8b Support 16bit formats in the png loader
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.
2021-09-17 02:02:51 +02:00
Matthias Clasen
14280b5f5b contentdeserializer: Use our on jpeg loader 2021-09-17 02:02:51 +02:00
Matthias Clasen
e720f9d35d Add code to save jpegs 2021-09-17 02:02:51 +02:00
Benjamin Otte
679c93e843 texture: Add private can_load() function
... and use it to load textures in gtk_picture_set_from_file().
2021-09-17 00:25:22 +02:00
Benjamin Otte
2d3de8608c texture: Split out type detection
This way, the code using it becomes clearer and we can use it in
multiple places without accidentally doing it wrong (hint: see next
commit).
2021-09-17 00:25:22 +02:00
Benjamin Otte
100b0bf7d9 texture: Remove declaration for nonexisting function 2021-09-17 00:25:22 +02:00
Matthias Clasen
f2ca9ebbd7 texture: Avoid pixbufs when loading resources
We can just use our own loaders here now.
2021-09-17 00:25:22 +02:00
Benjamin Otte
b1bb7c3258 texture: Add gdk_texture_save_to_tiff_bytes() 2021-09-17 00:25:22 +02:00
Matthias Clasen
d27bc74481 Use our own loaders for content (de)serialization
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.
2021-09-17 00:25:22 +02:00
Matthias Clasen
daf29e174f Load jpegs without gdk-pixbuf
Use our own loader for jpeg files.
2021-09-17 00:25:22 +02:00
Matthias Clasen
729ba8111a Add code to load jpegs
This lets us avoid gdk-pixbuf for loading
textures from the common image formats.

As a consequence, we are now linking against libjpeg.
2021-09-17 00:25:22 +02:00
Matthias Clasen
d30a029689 Add gdk_texture_save_to_tiff
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.
2021-09-17 00:25:22 +02:00
Matthias Clasen
f925e12e1d Load tiffs without gdk-pixbuf
This will let us load floating point data, in
the future.
2021-09-17 00:25:22 +02:00
Matthias Clasen
a03594df52 Add code to load and save tiff files
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.
2021-09-17 00:25:22 +02:00
Matthias Clasen
d7c8f92733 Add gdk_texture_save_to_png_bytes
Just expose what we already have available
internally, so e.g. tests can use it without
static linking.
2021-09-17 00:25:22 +02:00
Matthias Clasen
7949aaabb7 Save pngs without cairo
Use our own loader for pngs, which will allow
us to save e.g. 16-bit data in the future.
2021-09-17 00:25:22 +02:00
Matthias Clasen
a71877bf99 Load pngs without gdk-pixbuf
Use our own loader for pngs, which will allow
us to get e.g. 16-bit data in the future.
2021-09-17 00:25:22 +02:00
Matthias Clasen
f51f7f85eb Add code to load and save pngs
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.
2021-09-17 00:25:22 +02:00
Matthias Clasen
66031fd00b texture: Add error enum 2021-09-17 00:25:22 +02:00
Benjamin Otte
75dfb4d63b API: Add gdk_texture_new_from_filename()
There are quite a few places where we can make use of it, in particular
in the testsuite and icontheme.
2021-09-16 23:59:37 +02:00
Benjamin Otte
551f76ea69 gltexture: Fallback in download_float()
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.
2021-09-16 23:59:37 +02:00
Benjamin Otte
a4f3fbbda1 gltexture: Fix download() for GLES
GLES can't do glGetTexImage(), so implement a version that does
glReadPixels() on GLES.
2021-09-16 23:59:37 +02:00
Matthias Clasen
9f8d6ff29c texture: Mention download_float in the docs 2021-09-15 22:00:16 -04:00
Matthias Clasen
1230bce133 Add gdk_texture_new_from_bytes
Add this new api, and make gdk_texture_new_from_file
a wrapper around it.
2021-09-15 22:00:09 -04:00
Matthias Clasen
75b45aeabf Fix memorytexture float conversion
This was silently dropping the alpha in one case.
2021-09-15 21:14:59 -04:00
Matthias Clasen
38fce67a9b Annotate gdk_rgba_to_string as malloc 2021-09-14 16:38:08 -04:00
Matthias Clasen
04ef7055cd Annotate gdk_drag_action_is_unique as const 2021-09-14 16:38:08 -04:00
Matthias Clasen
ebca260f2d Annotate gdk_unichar_direction as const 2021-09-14 16:38:08 -04:00
Benjamin Otte
6785461c26 gltexture: Make sure downloading textures works in a different thread
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.
2021-09-13 01:40:03 +02:00
Benjamin Otte
719eafa60c gl: Implement uploading and downloading HDR formats
Also refactor the GL uploading so it does the fallback in a
GLES-compatible way, which means we only need one fallback.
2021-09-12 05:54:37 +02:00
Benjamin Otte
1759d27da9 memorytexture: Add support for HDR formats
Also sanitize the input bytes so the strides match alignment
requirements of the data types.
2021-09-12 05:54:37 +02:00
Benjamin Otte
53275481a5 texture: Add gdk_texture_download_float() 2021-09-12 05:54:37 +02:00
Benjamin Otte
cbe6d0da76 gdk: Deprecate gdk_cairo_draw_from_gl()
It's broken with various pixel formats and OpenGL ES, it's hard to
understand what everything does, and gdk_texture_download() can be used
instead.
2021-09-12 05:54:37 +02:00
Benjamin Otte
c349ed9562 gltexture: Implement download() via glGetTexImage()
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.
2021-09-12 05:22:21 +02:00
Benjamin Otte
74ce69a8a1 gltexture: Make release() use download_texture()
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.
2021-09-12 05:22:21 +02:00
Benjamin Otte
4f17f3ac24 texture: Add gdk_texture_download_texture()
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.
2021-09-12 05:22:21 +02:00
Benjamin Otte
9c8e464b04 texture: Add GdkMemoryConversion private enum
Now gdk_memory_convert() converts to one of these conversions instead of
re(ab)using parts of the GdkMemoryFormat enum.
2021-09-12 05:22:21 +02:00
Benjamin Otte
51d0d13a9e gltexture: release() to a texture, not a cairo_surface
This makes forwarding vfuncs a lot easier, because we can just call them
on the texture.
2021-09-12 05:22:21 +02:00
Benjamin Otte
0ee3b1c861 texture: Remove unused argument from vfunc 2021-09-12 05:22:21 +02:00
Benjamin Otte
9e11ea699c Merge branch 'hsl' into 'master'
gdk_rgba_parse: Support HSL colors

See merge request GNOME/gtk!3899
2021-09-11 12:57:25 +00:00
Matthias Clasen
c1c1d4431d Refactor gdk_gl_context_upload_texture slightly
Introduce a gl_internalformat variable. This will
let us handle more formats in a uniform way in
future commits.
2021-09-10 22:17:31 -04:00
James Westman
0782c8a051
gdk_rgba_parse: Support HSL colors 2021-09-10 16:56:42 -05:00
Luca Bacci
93878da2ca
Fix DND coordinates on Windows 2021-09-10 14:01:15 +02:00
Luca Bacci
3f798dbbcd
Make the DND indicator not interfere with the drag and drop operation 2021-09-10 14:01:14 +02:00
Matthias Clasen
a4f067481c gdk: Make GDK_DEBUG=default-settings unconditional
Our tests use this settings, so we should respect it
in non-debug builds as well.
2021-08-30 11:01:55 -04:00
Benjamin Otte
119458f13e contentdeserializer: Fix some API awkwardness
Allow uninitialized GValues to be passed. Makes life easier for the
inspector code I'm writing.
2021-08-30 06:02:16 +02:00
Benjamin Otte
3b15f32335 Merge branch 'wip/otte/symbolic-paintable' into 'master'
Add GtkSymbolicPaintable

See merge request GNOME/gtk!3895
2021-08-30 03:54:35 +00:00
Benjamin Otte
2f9a67b8a1 docs: Fix vfunc references
vfunc references should just use the object name, not the
class/interface/iface name.
2021-08-29 04:29:02 +02:00
Ian Douglas Scott
9e5a501c73 x11: Fix handling of RRScreenChangeNotify/RRNotify events
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()
```
2021-08-27 18:07:39 -07:00
Matthias Clasen
e281bbbb55 Merge branch 'treeexpander-indent-property' into 'master'
GtkTreeExpander: indent-without-expander property

Closes #4175

See merge request GNOME/gtk!3858
2021-08-25 11:48:59 +00:00
Matthias Clasen
892bacee52 Merge branch '4195-include-gdkprivate-h' into 'master'
gdkmacoseventsource: Include "gdk-private.h"

Closes #4195

See merge request GNOME/gtk!3882
2021-08-25 11:48:11 +00:00
Peter Bloomfield
9eb8aa9a32 gdkmacoseventsource: Include "gdk-private.h"
_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
2021-08-24 16:55:52 -04:00
Benjamin Otte
95931a7e6c wayland: Better error on eglGetDisplay() failure
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
2021-08-24 19:55:22 +00:00
Jan Lukas Gernert
88e796bb45 Add 4.6 version macros 2021-08-23 07:54:27 +02:00
Benjamin Otte
d2ea7af335 docs: Expand gdk_clipboard_set() docs 2021-08-22 18:49:12 +00:00
Matthias Clasen
d8ab5c3c45 gdk: Add a missing annotation
Mark an array as zero-terminated.

Fixes: #4097
2021-08-20 08:57:27 -04:00
Luca Bacci
c02bae9e08
Move the _gdk_win32_pointer_input_api global variable into GdkWin32Display 2021-08-19 16:29:45 +02:00
Luca Bacci
3977518f00
Fix typo 2021-08-19 15:57:44 +02:00
Luca Bacci
8adee3dace
Disable visual feedback for pen ad touch 2021-08-19 15:57:43 +02:00
Luca Bacci
09ad930da4
Filter out spurious mouse messages while handling pen or touch input 2021-08-19 15:57:43 +02:00
Luca Bacci
52f7bb6950
Add _gdk_win32_get_cursor_pos utility 2021-08-19 15:57:42 +02:00
Luca Bacci
68db945e47
Handle WinPointer input 2021-08-19 15:57:41 +02:00
Luca Bacci
b54f4cf5d4
Initialize WinPointer and enumerate devices 2021-08-19 15:57:41 +02:00
Luca Bacci
9a8a9451b1
Add new GdkDeviceWinpointer type 2021-08-19 15:57:40 +02:00
Luca Bacci
fffa903ce9
Add winpointer.h header file for type declarations 2021-08-19 15:57:39 +02:00
Luca Bacci
ab08885a32
Add entry for WinPointer in GdkWin32TabletInputAPI enum 2021-08-19 15:57:38 +02:00
Luca Bacci
ad3995b1b9
Make room for other API's than Wintab 2021-08-19 15:57:38 +02:00
Luca Bacci
75cc0710ac
Remove _gdk_input_ignore_wintab variable
Also remove unused variable _gdk_max_colors
2021-08-19 15:57:37 +02:00
Luca Bacci
7cec7054e2
Rename some Wintab-related functions 2021-08-19 15:57:36 +02:00
Luca Bacci
fe280e578f
Set active physical device when using the mouse 2021-08-19 15:57:36 +02:00
Luca Bacci
a32973f56b
Move use of _gdk_win32_get_next_tick from synthesize_crossing_events to its callers 2021-08-19 15:57:35 +02:00
Luca Bacci
7762311911
Add a physical_device argument to send_crossing_event et al 2021-08-19 15:57:34 +02:00
Luca Bacci
edd73ffbed
Raise _WIN32_WINNT macro to target Windows 7 API 2021-08-19 15:57:33 +02:00
Benjamin Otte
6f165efcdb contentprovider: Switch wrong order in type check
We can provide textures as a paintable - we can't provide paintables as
textures.
2021-08-19 03:16:48 +02:00
Matthias Clasen
bb65564c7d Merge branch 'seat-v7' into 'master'
gdk/wayland: add support for wl_seat version 7

See merge request GNOME/gtk!3842
2021-08-18 21:10:30 +00:00
Matthias Clasen
03031b3dc1 Merge branch 'fix/wm_class2' into 'master'
x11: ensure WM class is not null even if display is initialized early

See merge request GNOME/gtk!3808
2021-08-18 18:24:37 +00:00
Benjamin Otte
b7636ebbc0 Merge branch 'win32-drop-local-dnd' into 'master'
gdk/win32: Drop local DnD protocol

See merge request GNOME/gtk!3830
2021-08-18 14:27:14 +00:00
Chun-wei Fan
5d0f188615 GDK-Win32: Reject WGL context if shaders aren't supported
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.
2021-08-17 16:25:09 +08:00
Benjamin Otte
27cad85247 gdk: Include Vulkan error code in vulkan_strerror() 2021-08-12 14:19:30 +02:00
Simon Ser
ad0c1d4dbe gdk/wayland: add support for wl_seat version 7
Version 7 requires wl_keyboard keymaps to be mapped with
MAP_PRIVATE, so that the compositor can share the same keymap
file between multiple clients.
2021-08-11 16:37:03 +02:00
Simon Ser
00abaed89a gdk/wayland: add support for wl_seat version 6
Version 6 adds two new wl_touch events, which can be ignored.
2021-08-11 16:36:57 +02:00
Vincent Bernat
2ebde276d1 x11: ensure WM class is not null even if display is initialized early
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")
2021-08-10 09:14:36 +02:00
Chun-wei Fan
8acce5f294 gdk/win32: Drop local DnD protocol
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.
2021-08-06 17:16:27 +08:00
Matthias Clasen
2a528df977 Merge branch 'titlebar-gesture' into 'master'
Delegate titlebar action to the compositor if possible

See merge request GNOME/gtk!3797
2021-08-02 01:14:08 +00:00
Vincent Bernat
eff53c023a x11: set a default value for program_class
This was also the behaviour with GTK 3. We use the capitalized program
name.

Fixes #4138

Signed-off-by: Vincent Bernat <vincent@bernat.ch>
2021-07-30 23:22:32 +02:00
Florian Müllner
0c7b1431d7 gdk/toplevel: Add gdk_toplevel_titlebar_gesture()
Where supported, this allows delegating the titlebar action to the
compositor instead of trying to replicate its behavior client-side.

https://gitlab.gnome.org/GNOME/mutter/-/issues/602
2021-07-29 21:39:32 +02:00
Matthias Clasen
cc6ecc8b62 Merge branch 'source-static-name' into 'master'
Avoid copying static debug strings

See merge request GNOME/gtk!3789
2021-07-29 11:59:02 +00:00
Matthias Clasen
19b534f7de Avoid copying static debug strings
The g_source_set_name calls were showing up as a
major source of strdups in our profiles. Avoid that
by using new GLib api when available.
2021-07-28 22:42:46 -04:00
Marc-André Lureau
1b080826db gdk: add missing Since annotation
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-07-27 21:01:31 +04:00
Matthias Clasen
910f23ea19 Merge branch 'wip/otte/widgetfactory-dnd' into 'master'
Improve DND

See merge request GNOME/gtk!3785
2021-07-27 04:12:58 +00:00
Benjamin Otte
131be5f2e8 contentformats: Add gdk_content_formats_parse() 2021-07-27 04:13:42 +02:00
Benjamin Otte
6a5d555f58 contentformats: Change the format of gdk_content_formats_to_string()
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>
2021-07-26 02:28:49 +02:00
Benjamin Otte
f5dc71021f dnd: Guard drags with a reference when finishing
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.
2021-07-26 02:18:54 +02:00
gsittyz
bd7b8e87c1 Correct translation of Mac JIS Eisu & Kana keys
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=702841

Closes #4117
2021-07-24 20:59:18 +09:00
Emmanuele Bassi
527b2c5ab1 Merge branch 'no-pposition' into 'master'
gdk/x11: Do not set PPosition hint

See merge request GNOME/gtk!3781
2021-07-24 11:45:00 +00:00
Florian Müllner
4d0c2997cf gdk/x11: Do not set PPosition hint
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.
2021-07-24 06:32:16 +02:00
Matthias Clasen
fce23c981b Add more sysprof marks
Add a few more marks during gtk_init to figure out where
our startup time goes, and avoid the sysprof initialization
from distorting the first mark.
2021-07-22 14:47:02 -04:00
Benjamin Otte
620ccdabb5 glx: Get rid fo DrawableInfo
Store the frame counter in the surface, where it belongs.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
4b12dc6547 gdkdisplay-win32.c: Don't call ReleaseDC() unnecessarily
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.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
bd69d7e23f GDK-Win32: init_gl(): Default to WGL for now
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.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
8648486400 GDK-Win32: Fixup, and cleanup WGL HDC handling
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.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
6c00117119 Split out WGL/EGL stuff and simplify things
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.
2021-07-22 16:28:16 +02:00
Benjamin Otte
9c4c4eaaa1 gl: Fix issue with EGL + nvidia
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.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
969b3257a7 GDK: Add debug option for WGL usage
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.
2021-07-22 16:28:16 +02:00
Chun-wei Fan
65c6af31e1 GDK-Win32: Move some functions out of gdkglcontext-win32.c
We want these to be out of the way as we split between WGL and EGL/ANGLE
GL contexts, so that they don't get in the way.
2021-07-22 16:28:16 +02:00
Benjamin Otte
6b8bc83420 display: Move GL selection code into gdkdisplay-x11.c
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.
2021-07-22 16:28:16 +02:00
Benjamin Otte
30aaab5c6c x11: Move code from GdkGLContextX11
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.
2021-07-22 16:28:16 +02:00
Benjamin Otte
e06e0e8555 gdk: Move GL context construction to GdkGLContext
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.
2021-07-22 16:27:32 +02:00