Commit Graph

12020 Commits

Author SHA1 Message Date
Matthias Clasen
1d7aa9e40b Merge branch 'matthiasc/for-main' into 'main'
Small cleanups

See merge request GNOME/gtk!7592
2024-08-11 11:01:58 +00:00
Benjamin Otte
8de4b04819 Merge branch 'wip/otte/for-main' into 'main'
color: NEVER EVER use memcpy() in critical path

See merge request GNOME/gtk!7593
2024-08-11 05:39:26 +00:00
Benjamin Otte
175dba86fd color: NEVER EVER use memcpy() in critical path
Unless there is a very good reason to use memcpy(), don't use it.

Not using it makes the compiler not screw up and waste tons of CPU that
it could have not wasted.

Gets my framerate back from 1250 => 1750 and makes sysprof no longer
report ~40% of render time spent in gsk_gpu_colorize_op().
2024-08-11 06:51:58 +02:00
Matthias Clasen
202a51d9e3 Cosmetics 2024-08-10 22:41:31 -04:00
Matthias Clasen
d718fda057 memory texture: Fix a memory leak
The callers assumed that gdk_memory_sanitize is transfer full in
both directions, but it wasn't. Make it so.
2024-08-10 22:24:29 -04:00
Benjamin Otte
f8a30ddfc1 gdk: Deprecate gdk_surface_set_opaque_region() 2024-08-10 01:40:46 +02:00
Benjamin Otte
999d9bc73b gdk: Introduce gdk_surface_is_opaque()
... and use it in the mac backend instead of a hand-rolled version.
2024-08-10 01:40:46 +02:00
Benjamin Otte
16c7003acb gdk: Pass the opaque rect to begin_frame() actually
We know it at begin_frame() time, so if we pass it there instead of
end_frame(), we can use it then to make decisions about opacity.

For example, we could notice that the whole surface is opaque and choose
an RGBx format.
We don't do that yet, but now we could.
2024-08-10 01:40:46 +02:00
Benjamin Otte
f64045c229 gdk: Pass the opaque rect on to the opaque region
The opaque rect from the rendernodes are now used to set the opaque
region in the backend.

This means applications can now set a transparent window background and
make indivual parts of their window opaque.
But because this is a best effort method, it is not guaranteed to
succeed in finding all opaque regions, in particular if the rendernodes
used to build it are not straightforward to analyze.
2024-08-10 01:40:46 +02:00
Benjamin Otte
58aebc4447 surface: Put opaque_region in the priv structure
This is in preparation for future patches.
2024-08-10 01:40:46 +02:00
Benjamin Otte
3b3b6036f8 mac: Remove clear optimization
1. We want to get rid of exposing the opaque region

2. Cairo optimizes clearing the whole surface
2024-08-10 01:40:46 +02:00
Benjamin Otte
f90fb68aec gdk: Deprecate public begin/end_frame() APIs
We are using so many internal extra features that it is no longer a good
idea to use these functions.
And they aren't really used anyway.

These extra features are also constantly in flux and rely on internal
APIs, so exposing them would just cause extra pain.
2024-08-10 01:40:45 +02:00
Benjamin Otte
4fa3943e51 gdk: "inline" gdk_draw_context_get_frame_region()
By using the inlining macro trick, we can work around deprecation
warnings from removing this function as a public API, which will happen
in the next commits.
2024-08-10 01:40:45 +02:00
Benjamin Otte
0a92f741b3 vulkan: Remove 2 unneeded return_if_fail() checks
I want to deprecate that function, so getting rid of calls to it sounds
like a good idea.
2024-08-10 01:40:45 +02:00
Benjamin Otte
b08ccc0bec ngl: Stop crashing with zink and llvmpipe
We were not calling make_current() early enough anymore after the
Vulkan validation-layer fixes in !7468

Change that by calling it earlier.
2024-08-10 01:40:45 +02:00
Benjamin Otte
523cd0dff7 glcontext: Add a surface_attached flag
GLContexts marked as surface_attached are always attached to the surface
in make_current().
Other contexts continue to only get attached to their surface between
begin_frame() and end_frame().

All our renderer use surface-attached contexts now.
Public API only gives out non-surface-attached contexts.

The benefit here is that we can now choose whenever we want to
call make_current() because it will not cause a re-make_current() if we
call it outside vs inside the begin/end_frame() region.

Or in other words: I want to call make_current() before begin_frame()
without a performance penalty, and now I can.
2024-08-10 01:40:45 +02:00
Benjamin Otte
0b2275774f gdk: Add gdk_draw_context_end_frame_full()
... and pass the opaque region of the node.

We don't do anything with it yet, this is just the plumbing.

The original function still exists, it passes NULL which is the value
for no opaque region at all.
2024-08-10 01:40:45 +02:00
Benjamin Otte
b6c848d711 x11: Remove special casing from get_damage() call
This function is only ever called while inside a frame, so the check is
not necessary.
2024-08-10 01:40:45 +02:00
Benjamin Otte
f24be8476e wayland: Clean up after ourselves in the xx-color code
If an image description query is running while the surface gets
destroyed, we were not properly cleaning up, causing the callbacks to be
emitted on freed variables.
2024-08-10 01:40:45 +02:00
Benjamin Otte
cf84d999d8 dmabuf: Add DRM_FORMAT_MOD_INVALID to our formats
That's gonna be necessary for the next commits.
2024-08-08 19:03:31 +00:00
Benjamin Otte
99d291eb69 Merge branch 'wip/otte/occlusion' into 'main'
Implement advanced occlusion culling

See merge request GNOME/gtk!7570
2024-08-08 14:22:22 +00:00
Benjamin Otte
3313fd4e2b vulkan: Turn debug messages into warnings
Vulkan errors are quire critical, so we want to see them.

Our code is good enough to handle all non-critical errors.
2024-08-08 04:41:16 +02:00
Benjamin Otte
5c071cb02e dmabuf: Fix a check
We were comparing with destination stride, not with source stride, and
in rare cases when those were different, this would trigger aborts in
the testsuite.
2024-08-07 19:06:02 +02:00
Matthias Clasen
6edb526561 Merge branch 'plug-gtask-leaks' into 'main'
Plug GTask leaks

See merge request GNOME/gtk!7551
2024-08-07 16:26:52 +00:00
Matthias Clasen
fd78bd3eaf memoryformat: Add a debug helper
I need this often enough that I'll just put it here.
2024-08-07 08:22:05 -04:00
Jonas Ådahl
7fd65cc3c1 gdk/surface: Don't leak the EGLSurface
Each time we create a new window, we create a new EGLSurface. Each time
we destroy a window, we failed to destroy the EGLSurface, due to passing
a GdkDisplay instead of a EGLDisplay to eglDestroySurface().

This effectively leaked not only the EGL surface metadata, but also the
associated DMA buffers. For applications where one opens and closes many
windows over the lifetime of the application, and where the application
runs for a long time; for example a terminal emulator server, this
causes a significant memory leak, as the memory will only ever be freed
once once the application process itself exits, if ever.

Fix this passing an actual EGLDisplay instead of an GdkDisplay, to
eglDestroySurface().
2024-08-06 23:42:11 +02:00
Benjamin Otte
a4854dfa9e memoryformat: Use "(p)" as premultiplied indicator in names
This matches what the gpu renderer does when printing
colorstates.

It also avoids it printing "S*RGBA8" for the format and instead prints
"SRGBA8(p)" now.
2024-08-06 22:15:17 +02:00
Matthias Clasen
03ef6a7719 colorstate: Drop xyz for now
Converting to and from xyz turns out to be more difficult than
expected, depending on what whitepoint you choose, And different
specs choose different whitepoints, so we can't directly map
css xyz to cicp xyz anyway.
2024-08-06 15:38:31 -04:00
Matthias Clasen
dbd16cd9da Rename GDK_COLOR_INIT_SRGB
Rename the macro to GDK_COLOR_SRGB, and make it usable as
a compound literal as well.

Update all users.
2024-08-06 00:06:41 -04:00
Matthias Clasen
3a337824e6 Merge branch 'css-color-hookup-1' into 'main'
Add GdkColor, make non-srgb css colors work for color nodes

See merge request GNOME/gtk!7546
2024-08-05 16:11:39 +00:00
Matthias Clasen
c9c0d444a2 cairo: Add gdk_cairo_set_source_color
This lets us set a GdkColor as a cairo source.
2024-08-05 11:11:14 -04:00
Matthias Clasen
13a8704f51 Add GdkColor
For now, this is all private api.

Parts of it will be opened up in 4.18.
2024-08-05 11:11:14 -04:00
Sergey Bugaev
85830c059e Plug GTask leaks
The error-prone pattern seems to be:

  GTask *task = g_task_new (...);

  if (condition)
    {
      g_task_return_... (task, ...);
      /* need g_object_unref (task) here! */
      return;
    }

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2024-08-05 14:38:23 +03:00
Matthias Clasen
ffc89e40a0 colorstate: Add a color conversion function
Add a function for converting a single color from one
color state to another. This is a generalization of the
already existing function to convert a GdkRGBA to another
color state.
2024-08-04 14:21:15 -04:00
Arjan Molenaar
84847e46fa macos: fix window transparency
Revert window decoration changes from
a6ce506714.
2024-08-02 17:30:48 +02:00
Matthias Clasen
3af0cfb53b Drop debug code
The dmabuf download code for P010 had a hack left in it that
was preventing it from working.
2024-07-31 21:08:14 -04:00
Matthias Clasen
3d802177be wayland: No viewporter for cursors
The outlook for mutter supporting this in GNOME 47 are cloudy,
so lets flip the switch back. You can still set
USE_POINTER_VIEWPORT in the environment to try this code.
2024-07-31 07:44:48 -04:00
Matthias Clasen
249cf0833c dmabuf: Fix the disjointness check
We were checking the wrong fds here.

This came up while toying with udmabuf and creating multi-plane
NV12 buffers.
2024-07-30 23:44:07 -04:00
Arjan Molenaar
f0925e4ef2 docs: Update function docs for gdk_event_triggers_context_menu
Include macOS, make code snipper easier identifyable.
2024-07-29 20:07:13 +02:00
Arjan Molenaar
df87b1820b macos: Add Ctrl+left-click mapping for context menus
Update GdkEvent.triggers_context_menu to trigger a context menu
on macOS.
2024-07-29 19:59:29 +02:00
Benjamin Otte
87e8265a2d Merge branch 'wip/otte/colomplications' into 'main'
wayland: Do not use compositor-provided image descriptions

See merge request GNOME/gtk!7522
2024-07-29 17:56:41 +00:00
Matthias Clasen
9fd6d431e3 Merge branch 'fix-ephy-crash' into 'main'
subsurface: Avoid a crash

Closes #6891

See merge request GNOME/gtk!7521
2024-07-29 17:39:05 +00:00
Benjamin Otte
d71a7c901d wayland: Do not use compositor-provided image descriptions
When the compositor sends us an image description, we currently happily
reuse it.

However, those image descriptions may contain optional properties that
we do not handle - example: reference white level. So if we were to
reuse that image description, we would set a wrong reference white
level.

To avoid issues like that, never use compositor-provided image
descriptions.

However, query those image descriptions and map them to the closest
GdkColorState, so that we can quickly look up *our* version of that
image description and use that one.
2024-07-29 18:45:41 +02:00
Matthias Clasen
65f727731c subsurface: Avoid a crash
When finalizing a subsurface, we need to make sure it is removed
from the sibling lists in its parent, or bad things will happen.

This should crashes seen in Epiphany nightly.

Fixes: #6891
2024-07-29 11:54:10 -04:00
Matthias Clasen
b8f12c5d28 cicp: Improve the docs
Fix some formatting issues, and document GdkCicpRange.
2024-07-29 11:17:13 -04:00
Matthias Clasen
3d75292c4d Fix indirect color state conversions
convert_func2 is a 'from' conversion function, ie it expects to
be passed the target color state. This was wrong both in
gdk_memory_convert and gdk_memory_convert_color_state.
2024-07-28 23:40:59 -04:00
Matthias Clasen
1040d7c7e4 Merge branch 'matthiasc/for-main' into 'main'
cicp: Fill in some more transfer functions

See merge request GNOME/gtk!7515
2024-07-28 20:51:40 +00:00
Matthias Clasen
1b53359cd3 Merge branch 'wip/smcv/ubsan' into 'main'
Avoid undefined behaviour in a few simple cases

See merge request GNOME/gtk!7508
2024-07-28 20:00:06 +00:00
Benjamin Otte
b8890ca27d Merge branch 'wip/smcv/warnings' into 'main'
Fix compiler warnings on 32-bit

See merge request GNOME/gtk!7507
2024-07-28 18:40:46 +00:00
Matthias Clasen
50ea9450ea cicp: Fill in some more transfer functions
Handle gamma 2.2 and gamma 2.8.
2024-07-28 11:56:43 -04:00
Matthias Clasen
d2028c7323 Cosmetics 2024-07-28 11:33:39 -04:00
Benjamin Otte
76c1ea0449 Merge branch 'wip/smcv/gsize-is-guintptr' into 'main'
gdk: Codify the requirement that gsize is pointer-sized

See merge request GNOME/gtk!7514
2024-07-28 14:12:59 +00:00
Simon McVittie
a97f378d64 gdk: Codify the requirement that gsize is pointer-sized
This is widely assumed, but is not guaranteed by Standard C, and is
known to be false on CHERI architectures (which have 64-bit sizes and
128-bit tagged pointers). Add a static assertion to ensure that GTK
will not build on platforms where this assumption does not hold.

As discussed on GNOME/gtk!7510, if GTK switches from gsize to uintptr_t
as its representation of the underlying bits in a pointer, GTK maintainers
would prefer that to be done project-wide so that it's done consistently,
after which this static assertion could be removed.

At the time of writing, GLib makes the same assumption (GNOME/glib#2842),
but GLib contributors are gradually removing it (mostly by replacing gsize
with uintptr_t where a pointer-sized quantity is needed). Finishing
that work in GLib would be a prerequisite for being able to make GTK
work on the affected platforms.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-28 14:31:31 +01:00
Matthias Clasen
1373a7a6f0 Change the matrix implementation
Go from float[3][3] to float[9]. That is easier to manage in
static initialization.
2024-07-27 19:20:14 -04:00
Matthias Clasen
a5aac30843 jpeg: Load grayscale as-is
We can handle grayscale textures just fine nowadays, so no need to
convert them to RGB.
2024-07-27 19:20:14 -04:00
Matthias Clasen
3149493679 jpeg: Set downloader color state explictly
This avoids surprises.
2024-07-27 19:02:59 -04:00
Simon McVittie
6649af5ec6 Avoid calling memcpy with n == 0
Some callers of these functions ask to copy 0 items from a NULL source,
which would be valid if they were copied in a loop (because NULL would
never be dereferenced), but is declared to be undefined behaviour for
Standard C memcpy. Guard the call to memcpy so that we only call it
if we have more than 0 items, and therefore should have a non-NULL
source pointer.

Detected by running a subset of the test suite with
-Dsanitize=address,undefined on x86_64.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-27 20:16:21 +01:00
Simon McVittie
15a09c79f9 Fix debug format strings for non-LP64 platforms
Unfortunately the format string for a size_t, `%zu`, is not portable
to all Windows compilers, and the appropriate format string for the
fundamental type that implements size_t varies between platforms
(typically `%u` on 32-bit platforms, `%lu` on 64-bit Linux or
`%llu` on 64-bit Windows).

In gtk-demo, cast the number of search results to long, to avoid
breaking up a translatable string.

Elsewhere, use GLib's abstraction for this.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-27 18:14:31 +01:00
Simon McVittie
e2a7dc5427 vulkan: Fix compiler warnings on 32-bit
Vulkan handles are pointers on 64-bit, but 64-bit integers on 32-bit.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-27 15:14:57 +01:00
Benjamin Otte
ec489e673c wayland: Add preferred formats to the hash tables
So we don't look them up all the time.
2024-07-27 07:26:51 +02:00
Benjamin Otte
a904da12b7 wayland: Don't query preferred colorstate if we don't care
If there's no change callback connected, exit early, because all this
lot of work would be for invoking that callback.
2024-07-27 07:26:51 +02:00
Benjamin Otte
91865d172b wayland: Track color information identities
So we don't need to query them all the time.

Or so I thought, because I get different ones for the same colorstate.
Thx Mutter.
2024-07-27 07:26:51 +02:00
Benjamin Otte
adedb89779 wayland: Actually sync the colorstate with the compositor 2024-07-27 07:26:51 +02:00
Benjamin Otte
514dbcacd4 wayland: Actually query the preferred colorstate
We weren't doing that, so everything looked like it wanted SRGB.
2024-07-27 07:26:51 +02:00
Benjamin Otte
25c812fa87 wayland: Redo the image description code
Main changes:

1. Avoid invalid writes by not passing pointers to a GArray that
   realloc()s its data
2. Use a hash table to store image defs, instead of an array. This
   requires a custom hash/equal function
3. Make image desc computation sync, so that setting a cs always
   succeeds or always fails and doesn't depend on timing.
4. Add a few debug messages in failure paths. For lack of a category,
   they ended up in MISC.
2024-07-27 07:26:51 +02:00
Matthias Clasen
ea9f8b2f77 downloader: Add some docs
Mention the default format and color state.
2024-07-26 17:38:27 -04:00
Matthias Clasen
45c5b250b9 texture: Don't mess up color states
gdk_texture_download_surface was converting twice from the texture
color state to the target color state, with predictably bad results.
2024-07-26 17:27:20 -04:00
Matthias Clasen
f4b35093bd jpeg: Port to GdkMemoryTextureBuilder
This is in preparation for some color state handling.
2024-07-26 16:43:54 -04:00
Benjamin Otte
50403fbca8 wayland: Actually compare the right values
Wayland primaries/transfer functions aren't cicp values, so we can't
compare them.
2024-07-25 22:06:56 +02:00
Benjamin Otte
7de91d1777 wayland: We use v4 of the protocol 2024-07-25 22:06:56 +02:00
Benjamin Otte
0001562850 dmabuf: Fix Vulkan formats for P010 and friends
The P01x and P21x formats were swapped.
2024-07-25 18:53:55 +02:00
Matthias Clasen
c9443dd04d Fix the hlg transfer function
Fix a bug in the formula, and enable hlg as a transfer function.

The tests are passing now.
2024-07-24 18:59:18 -06:00
Matthias Clasen
5f2e70df8e Drop hlg for now
For some reason, roundtrip tests  with the hlg tf are failing,
so we don't support it.
2024-07-24 17:53:12 -06:00
Matthias Clasen
a46bcc2755 Move transfer functions and matrices to a header
This way, we can write tests against them without static linking.
2024-07-24 16:45:21 -06:00
Matthias Clasen
229edc5225 wayland: Normalize cicp values
We don't want to create multiple image descriptions for functionally
equivalent tuples.
2024-07-24 16:45:21 -06:00
Matthias Clasen
fb10b61528 gdk: Add public api for cicp
Add a GdkCicpParams object that acts a bit like a builder for
cicp color states.
2024-07-24 16:45:21 -06:00
Matthias Clasen
64f4967867 png: Make loader use cicp api
This should make non-default color states work with our png
loading and saving machinery.
2024-07-24 08:16:08 -06:00
Matthias Clasen
c37fa3a895 wayland: Use cicp color states
This is entirely untested, and the Wayland protocol makes it very
annoying.
2024-07-24 08:16:08 -06:00
Matthias Clasen
d907c0a42e colorstate: Add cicp support
This adds machinery to create colorstate objects from cicp
tuples, as well as a function to return a cicp tuple for a
colorstate.

Still missing: a conversion shader for non-default colorstates.
2024-07-24 08:16:08 -06:00
Matthias Clasen
4255230e36 colorstate: Cosmetics
Document a private api.
2024-07-24 07:46:05 -06:00
Matthias Clasen
d8a0915ada colorstate: Slight reorg
Move the conversion functions out of the default section, since
we will reuse the conversion functions for cicp. No functional
changes.
2024-07-24 07:46:05 -06:00
Matthias Clasen
32b348776e memoryformat: Allow indirect conversions
If we don't have a direct conversion function between two
colorstates, go indirectly via rec2100-linear.
2024-07-24 07:46:05 -06:00
Matthias Clasen
bbe552d6a8 Add gdk_color_state_get_convert_from
Our conversion machinery supports converting from any color
state to any default color state or back. Direct conversion
between two non-default color states isn't guaranteed. For
converting *to* a cicp color state, we need this function.
2024-07-24 07:46:05 -06:00
Luca Bacci
ccc6f7c24e GdkWin32: Drop unused variable
We still check whether depth buffer bits must be > 0,
we just don't use that variable anymore.
2024-07-24 15:36:25 +02:00
Luca Bacci
41b21b6634 WGL: Search pixel format with defined swap method (opengl32)
We want to get PFD_SWAP flags as that's required to enable incremental
rendering. However, as documented on MSDN, ChoosePixelFormat ignores
PFD_SWAP flags.

We may get PFD_SWAP flags or not depending on the way the OpenGL driver
orders its pixel formats. While PFD_SWAP flags are very important for
GUI toolkits, they are best avoided by games, as most games render the
scene in its entirety on each frame. Drivers optimized for games tend
to order pixel formats with no PFD_SWAP flags first.

Se we implement our own method to select the best pixel format. We check
for usable pixel formats and assign penalties for each one, until we find
a format with 0 penalty or the sequence ends. Then the best pixel format
is selected.
2024-07-24 15:36:25 +02:00
Luca Bacci
b46a900d71 WGL: Search pixel format with defined swap method (arb)
Getting a defined swap method is necessary to enable incremental
rendering. We cannot just add a swap method attribute since
exchange is generally preferred, but is not always available.
Here we try to infer what the driver prefers, then ask for
exchange or copy, in sequence.
2024-07-24 15:35:40 +02:00
Matthias Clasen
ebc4bb2363 wayland: Switch to v4 of the color management protocol 2024-07-23 23:37:00 -06:00
Matthias Clasen
23e4c788fa Merge branch 'dmabuf-formats-autoptr' into 'main'
gdkdmabufformats: Add autoptr definition

See merge request GNOME/gtk!7484
2024-07-23 19:48:01 +00:00
Marco Trevisan (Treviño)
e46e61643c gdkdmabufformats: Add autoptr definition 2024-07-23 19:55:47 +02:00
Jordan Petridis
cc5526e019
gdkvulkancontext: set the VkSemaphore to VK_NULL_HANDLE
Vulkan objects are integers on 32bit and it's failing when it's set to
just NULL.

```
../gdk/gdkvulkancontext.c:677:24: error: assignment to ‘VkSemaphore’ {aka ‘long long unsigned int’} from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
  677 |   priv->draw_semaphore = NULL;
```
2024-07-23 18:01:56 +02:00
Benjamin Otte
14a7b4b4b4 vulkan: Remove unused features
Now that we don't use the fancy features anymore, we don't need to
enable them.
And that also means we don't need an env var to disable it for testing.
2024-07-22 19:40:24 +02:00
Benjamin Otte
2e1686091f dmabuf: Make NULL the default colorstate in the builder
YUV dmabufs are not sRGB.

So instead of making the dmabuf builder have sRGB as the default
colorstate, add a NULL default option that makes the builder choose
the colorstate based on fourcc when build() is called.

If that happens, we pick sRGB usually, but for YUV we pick narrow range
BT601, like we did in versions before colorstates.
2024-07-22 14:54:05 +02:00
Benjamin Otte
496211727d vulkan: dmabufs require ycbcr
So make sure that GDK_VULKAN_DISABLE=ycbcr also disables dmabufs.
2024-07-22 01:28:39 +02:00
Carlos Garnacho
31a79fbd9f Merge branch 'main' into 'main'
Ignore grabbing tablet devices without pads or tools

See merge request GNOME/gtk!7470
2024-07-18 12:10:36 +00:00
Jie Liu
d8919311b1 Ignore grabbing tablet devices without pads or tools
Signed-off-by: Jie Liu <liujie01@kylinos.cn>
2024-07-18 18:19:26 +08:00
Benjamin Otte
619926ec83 dmabuf: fix mmap() calls
* We cannot map with offset, because offsets need to be page-size
  aligned. And our code doesn't expect an offset anyway.
* The error return value from mmap() is MAP_FAILED aka -1, not NULL aka
  0.
2024-07-18 04:33:14 +02:00
Benjamin Otte
1afb832ff0 dmabuf: Do a naive implementation of P010, P012 and P016
These are the common HDR formats, so we better have the baseline of
those.
2024-07-18 04:33:14 +02:00
Benjamin Otte
4966f8cdf8 vulkan: Add an acquire semaphore to frames
Vulkan requires us waiting on the image acquired from
vkAcquireNextImageKHR() before we start rendering to it, as that
function is allowed to return images that are still in use by the
compositor.
Because of that requirement, vkAcquireNextImageKHR() requires a
semaphore or fence to be passed that it can signal once it's done.

We now use a side channel to begin_frame() - calling
set_draw_semaphore() - to pass that semaphore so that the
vkAcquireNextImageKHR() call inside begin_frame() can use it, and then
we can wait on it later when we submit.

And yes, this is insanely convoluted, the Vulkan developers should
totally have thought about GTK's internal designs before coming up
with that idea.
2024-07-17 22:59:23 +02:00
Benjamin Otte
31e0ec71f2 png: Add color state support
When loading or saving png files, encode the CICP flags of the color
state into the PNG.

When loading, decode the CICP flags if available and detect the
colorstate they use.
If we do not support the cicp tags, we do not load the image.

So far, we ignore the ICC profiles.

Includes regeneration of nodeparse test *reference* output to include
the new tags we write to PNGs.
The original tests do not include those tags, so we implicitly test that
we read untagged files correctly.
2024-07-16 22:04:10 +02:00
Benjamin Otte
6c33afc13c png: Move texture data download further down
We only download the data when we actually need it for writing into the
PNG stream.

This allows modifying the download parameters (in particular color state
in the next commit) while writing out their settings, so the code for
selecting the right colorstate liives in only one place.

We have to be careful though, because the download now happens after the
setjmp(), so we need to make sure the error path handles both cases
without leaking: Where the download has happened and where it hasn't.
2024-07-16 22:03:48 +02:00
Benjamin Otte
03daf42fb5 png: Port to MemoryTextureBuilder 2024-07-16 22:03:46 +02:00
Matthias Clasen
b33b68ef75 dmabuf texture: color state support 2024-07-16 21:23:44 +02:00
Matthias Clasen
0ee8ca43d1 gl texture: color state support 2024-07-16 21:23:44 +02:00
Benjamin Otte
5e1c3c5d69 gdk: Add GdkMemoryTexture::color-state
This allows setting the color state of textures.
2024-07-16 21:23:44 +02:00
Benjamin Otte
3c8a93b972 gdk: Add GdkMemoryTextureBuilder
Same thing as dmabuf and GL texture builders. Preparation for adding
color state support to texture constructors.

As a bonus, we can now do update regions with memory textures.
2024-07-16 21:23:44 +02:00
Benjamin Otte
11543a229a texturedownloader: Add color state
... and plumb the color state through the downloading machinery, where
no matter what path it takes it ends up in
gdk_memory_convert_color_state() or gdk_memory_convert().

The 2nd of those has been expanded to optionally do colorstate
conversion when the 2 colorstates are different.
2024-07-16 21:23:44 +02:00
Robert Mader
b241fcd418 wayland/subsurface: Handle NULL-buffers in dmabuf_buffer_release
This happens when buffer creation fails in `get_dmabuf_wl_buffer()` and
we manually call `listener->release (data, NULL)`.

Fixes: 2478dd8322 ("subsurface: Split a function")
2024-07-16 01:43:15 +02:00
Benjamin Otte
86e735cd5c Merge branch 'wip/otte/for-main' into 'main'
vulkan: Remove draw semaphore

Closes #6861

See merge request GNOME/gtk!7460
2024-07-14 21:11:06 +00:00
Benjamin Otte
d32fd76b31 docs: Fix typo 2024-07-14 21:54:40 +02:00
Benjamin Otte
b08a17064e vulkan: Remove draw semaphore
That's unused (or wrongly used) leftover code from 2017.

The validation layers also don't like it.
2024-07-14 21:54:40 +02:00
Benjamin Otte
3f39cb38c4 Merge branch 'wayland-color-states' into 'main'
Wayland color management

See merge request GNOME/gtk!7444
2024-07-14 19:46:56 +00:00
Matthias Clasen
533aaba5eb wayland: Support xx-color-management-v2
This is a still experimental protocol (thus the xx prefix).

We are using it go obtain information about the compositors
preferred color state, and pass that on to our rendering machinery.

The currently supported color states are srgb, srgb-linear, rec2100-pq
and rec2100-linear. We don't have any support for ICC profiles.

Unlike other protocols, keep the support code for this protocol
fairly isolated behind wrapper objects, since the protocol is
still subject to change.
2024-07-14 14:58:00 -04:00
Matthias Clasen
72c782af17 Merge branch 'matthiasc/for-main' into 'main'
colorstate: Add autoptr definitions

See merge request GNOME/gtk!7457
2024-07-14 18:12:34 +00:00
Matthias Clasen
ee7ba54a7f colorstate: Add autoptr definitions
A little convenience never hurts.
2024-07-14 12:52:56 -04:00
Matthias Clasen
53d99f5521 Use the surface colorstate in begin_frame
begin_frame is the place where we make decisions about the format,
depth and colorstate for our rendering. Make these calls take the
surface color state into account.

In particular, if the surface colorstate is suitable for GL_SRGB,
and we don't need high depth, set things up for that.
2024-07-14 12:51:05 -04:00
Matthias Clasen
52d2975af3 surface: Add a color state
This will be set by the backend, and it will be used to set up
the draw context properly. For now, this is always SRGB.
2024-07-14 12:46:20 -04:00
Matthias Clasen
7aeab7a63f Add a debug flag for hdr rendering
Set GDK_DEBUG=hdr to force the use of rec2100 as compositing
colorstate.
2024-07-13 15:11:07 -04:00
Matthias Clasen
a2389b3169 Cosmetics
Shift debug flags around so we can put hdr next to linear.
2024-07-13 15:11:07 -04:00
Matthias Clasen
54e5cc296f colorstate: Add rec2100-pq and rec2100-linear
These are wide-gamut, HDR colorstates that we will need for HDR support.
2024-07-13 15:11:07 -04:00
Matthias Clasen
2d69f35e0e colorstate: More details in the docs
Add links to srgb definitions and references.
2024-07-13 15:09:12 -04:00
Benjamin Otte
a61d7f3864 vulkan: Remove GDK_DEBUG=vulkan-validate
The modern incantation to get validation layers enabled is via

VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation

Vulkan has a bunch of environment variables to toggle stuff, let's use
those instead of doing our own.
2024-07-13 08:52:28 -04:00
Matthias Clasen
d0e2d9e2f4 colorstate: Small reorg
Introduce a helper macro.
2024-07-12 18:15:28 -04:00
Matthias Clasen
abb7e85260 colorstate: Consistent naming
Make the conversion functions use srgb_linear in their names, since
the name of the color state is srgb-linear.
2024-07-12 18:14:44 -04:00
Benjamin Otte
25f04f3c37 Merge branch 'wip/otte/for-main' into 'main'
dmabuf: Add DRM_FORMAT_INVALID to our formats

See merge request GNOME/gtk!7446
2024-07-12 15:29:40 +00:00
Matthias Clasen
cb91f96fd3 wayland: Fix handling of the font-rendering setting
The settings portal is reporting enums as string values, so
we need to translate this setting back to what we need.

Fixes

(gtk4-demo:18902): GLib-CRITICAL **: 19:06:14.783: g_variant_get_int32: assertion 'g_variant_is_of_type (value, G_VARIANT_TYPE_INT32)' failed

that could be seen in recent nightly flatpaks.
2024-07-11 19:06:50 -04:00
Matthias Clasen
5cea9f9e17 Small doc fixes
Pointed out be Emmanuele Bassi.
2024-07-11 16:56:10 -04:00
Benjamin Otte
a9cce55693 dmabuf: Add DRM_FORMAT_INVALID to our formats
That's gonna be necessary for the next commit.
2024-07-11 18:39:14 +02:00
Benjamin Otte
cf12503fec gpu: Don't replace cache items
Instead, keep them. This is not useful yet, but will become so in the
next commits.
2024-07-11 14:57:20 +02:00
Benjamin Otte
fa33af248e cairo: Improve gdk_texture_download_to_surface()
Previously, we were always downloading into CAIRO_FORMAT_ARGB32.
Now we check the texture depth and pick a suitable format.

This improves rendering for high depth content, but it's slower.

That's why we're not yet making sure the depth is suitable for the
colorspace conversion. That would force all SRGB textures into float
surfaces as we don't consider conversions suitable for U8 in our generic
code.
2024-07-11 14:57:20 +02:00
Benjamin Otte
e6cfbc00fc gdk: Support more formats in gdk_texture_new_for_surface() 2024-07-11 14:57:20 +02:00
Benjamin Otte
527f305690 vulkan: Compare different depths by their Vulkan format
GdkMemoryFormats can be identical for different Vulkan formats, in
particular in the srgb vs non-srgb case.
2024-07-11 14:57:20 +02:00
Benjamin Otte
b05c9c26bd vulkan: Add support for SRGB formats 2024-07-11 14:57:20 +02:00
Matthias Clasen
a78796f22c gpu: Add a color convert shader
This shader converts between two color states, by using the
same functions that we use on the cpu. The conversion to perform
is passed as part of the variation.

As premultiplication is part of color states on the shader, we also
encode the premultiplication in the shader.
And because opacity is a useful optimization, we also allow setting
opacity.

For now, the only possible color states are srgb and srgb-linear.
2024-07-11 14:57:20 +02:00
Benjamin Otte
6287eaa745 cairo: Add colorstate to GskRenderNode::draw and use it
This adds the following:
- ccs argument to GskRenderNode::draw
  This is the compositing color state to use when drawing.

- make implementations use the CCS argument
  FIXME: Some implementations are missing

- gsk_render_node_draw_with_color_state()
  Draws a node with any color state, by switching to its compositing
  color state, drawing in that color state and then converting to the
  desired color state.
  This does draw the result OVER the previous contents in the passed in
  color state, so this function should be called with the target being
  empty.

- gsk_render_node_draw_ccs()
  This needs to be passed a css and then draws with that ccs.
  The main use for this is chaining up in rendernode draw()
  implementations.

- split out shared Cairo functions into gdkcairoprivate.h
  gskrendernode.c and gskrendernodeimpl.c need the same functions.
  Plus, there's various code in GDK that wants to use it, so put it in
  gdk/ not in gsk/

gsk_render_node_draw() now calls gsk_render_node_draw_with_color_state()
with GDK_COLOR_STATE_SRGB.
2024-07-11 14:57:20 +02:00
Benjamin Otte
2ae13229ea colorstate: Add utility function to convert GdkRGBA
This should end up in GdkColor, but that doesn't exist yet.

It's also why the bad name doesn't concern me much.
2024-07-11 14:57:20 +02:00
Matthias Clasen
2879d35f3d gdk: Add a fast-path
Special case u8 RGBA8p, which is the common case.
2024-07-11 14:57:20 +02:00
Benjamin Otte
ab7d969700 gdk: Add color state arg to gdk_texture_download_surface()
All callers set it to SRGB at the moment.
2024-07-11 14:57:20 +02:00
Matthias Clasen
e1031ac5ad gdk: Add gdk_memory_format_convert_color_state
This allows in-place color state conversions.
2024-07-11 14:57:20 +02:00
Benjamin Otte
1b1e7f4296 drawcontext: Make begin_frame() set colorstate + depth
Make begin_frame() set a rendering colorstate and depth, and provide it
to the renderers via gdk_draw_context_get_depth() and
gdk_draw_context_get_color_state().

This allows the draw contexts to define their own values, so that ie the
Cairo and GL renderer can choose different settings for rendering (in
particular, GL can choose GL_SRGB and do the srgb conversion; while
Cairo relies on the renderer).
2024-07-11 14:57:20 +02:00
Benjamin Otte
1bbf5f7a17 gdk: Add GDK_MEMORY_NONE depth
That's basically the "undefined" value. We need that when drawing
nothing, which so far only happens with empty container nodes.

But empty container nodes can be children of other nodes, and that makes
things propagate. So instead of catching them, force the whole rest of
the code to deal with an undefined depth.

We also can't just set a random depth, because that will cause merging
to fail.
2024-07-11 14:57:20 +02:00
Benjamin Otte
9abc83fdad gdk: Make gdk_memory_depth_merge() use a table
This makes it clearer how depths are merged.

Also use the actual desired merge modes, the previous code had some
weird behaviors.
2024-07-11 14:57:20 +02:00
Matthias Clasen
8d5325b816 glx: Create srgb drawables if possible
Make our visual selection code prefer fbconfigs that are
'srgb framebuffer capable', and mark the surface as 'is srgb'
in this case.

This arranges things so that GSK knows not to use an offscreen
for converting contents back to srgb in the end.
2024-07-11 14:57:20 +02:00
Matthias Clasen
ad6fd451fb gdk: Create our egl surface with srgb colorspace
For GDK_MEMORY_U8_SRGB depth, try to create an SRGB surface.

This requires the EXT_KHR_gl_colorspace extension, which
isn't super-common in the wild (37%), so we fall back to regular U8 if
that fails.

But if we have the extension, create our egl surface with the
srgb colorspace, and report that fact in gdk_surface_gl_is_srgb().
2024-07-11 14:57:20 +02:00
Matthias Clasen
dfd181d7d5 gdk: Add gdk_surface_get_gl_is_srgb()
This is a way to query whether the framebuffer we use is using GL_SRGB
or equivalent. Currently, it just returns FALSE.
2024-07-11 14:57:20 +02:00
Benjamin Otte
b707568fc1 egl: Pass depth through the fbconfig selection code
We still only differentiate between high bit depth or not, but we now
choose at the end instead of the start, which makes it easier to adapt
to a different method of choosing.
2024-07-11 14:57:20 +02:00
Benjamin Otte
16c29a7db5 texture: Add gdk_texture_get_depth()
... and use it.
2024-07-11 14:57:20 +02:00
Benjamin Otte
127b92e3db color_state: Make U8_SRGB the depth for COLOR_STATE_SRGB
This will only be used with linear compositing, so we force U8 when
we're not compositing linear.
2024-07-11 14:57:19 +02:00
Benjamin Otte
a7ceb8ce66 gdk: Add GDK_MEMORY_U8_SRGB depth
This is an experiment for now, but it seems that encoding srgb inside
the depth makes sense, as we not just use depth to decide on the
GL fbconfigs/Vulkan formats to pick, depth also encodes how the [0...1]
color values are quantized when stored.

Let's see where this goes.
2024-07-11 14:57:19 +02:00
Matthias Clasen
5297c5f2ee gdk: Give textures a color state
Adds gdk_texture_get_color_state() and GdkTexture::color-state property.

All texture implementations initialize the property to SRGB for now.
2024-07-11 14:57:19 +02:00
Benjamin Otte
bdb6b10be8 colorstate: Add gdk_color_state_get_rendering_color_state()
Returns the linear color state that renderers should render in when
this is the target color state.

We disable this function unless linear compositing is enabled and just
return @self by default.
2024-07-11 14:57:19 +02:00