Commit Graph

81190 Commits

Author SHA1 Message Date
Matthias Clasen
84c28d2efb image-tool: Add an --undecorated option
This is useful if you want to debug things and don't want to end
up in the decoration rendering code paths.
2024-07-29 08:13:21 -04:00
Matthias Clasen
06372c5f2a Merge branch 'matthiasc/for-main' into 'main'
Fix indirect color state conversions

See merge request GNOME/gtk!7519
2024-07-29 11:11:28 +00: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
541ffbe4b5 Merge branch 'matthiasc/for-main' into 'main'
gst: Fix a wrong unref function

See merge request GNOME/gtk!7517
2024-07-28 23:35:16 +00:00
Matthias Clasen
17524f2794 gst: Fix a wrong unref function
Use gdk_color_state_unref on a color state.
2024-07-28 19:09:05 -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
Matthias Clasen
1987738d16 Merge branch 'wip/smcv/c11' into 'main'
README: Officially require C11, matching GLib 2.81.x

See merge request GNOME/gtk!7516
2024-07-28 19:58:51 +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
Benjamin Otte
2e7916cf4f Merge branch 'wip/smcv/align-gsk-ops' into 'main'
gskpathop: Align graphene_point_t to match gskpathop assumptions where required

Closes #6395

See merge request GNOME/gtk!7510
2024-07-28 17:54:35 +00:00
Simon McVittie
24cf5b6df8 README: Officially require C11, matching GLib 2.81.x
Previously GTK required a C99 compiler, but as discussed on
GNOME/gtk!7510 there's at least one anonymous union in public API
(in `GskPathPoint`), and that's a C11 feature.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-28 17:47:47 +01:00
Simon McVittie
214f5a6f98 gskpathop: Introduce a type to represent an aligned graphene_point_t
When we allocate a graphene_point_t on the stack, there's no guarantee
that it will be aligned at an 8-byte boundary, which is an assumption
made by gsk_pathop_encode() (which wants to use the lowest 3 bits to
encode the operation). In the places where it matters, force the
points on the stack and embedded in structs to be nicely aligned.

By using a distinct type for this (a union with a suitable size and
alignment), we ensure that the compiler will warn or error whenever we
can't prove that a particular point is, in fact, suitably aligned.
We can go from a `GskAlignedPoint *` to a `graphene_point_t *`
(which is always valid, because the `GskAlignedPoint` is aligned)
via &aligned_points[0].pt, but we cannot go back the other way
(which is not always valid, because the `graphene_point_t` is not
necessarily aligned nicely) without a cast.

In practice, it seems that a graphene_point_t on x86_64 *is* usually
placed at an 8-byte boundary, but this is not the case on 32-bit
architectures or on s390x.

In many cases we can avoid needing an explicit reference to the more
complicated type by making use of a transparent union. There's already
at least one transparent union in GSK's public API, so it's presumably
portable enough to match GTK's requirements.

Increasing the alignment of GskAlignedPoint also requires adjusting how
a GskStandardContour is allocated and initialized. This data structure
allocates extra memory to hold an array of GskAlignedPoint outside the
bounds of the struct itself, and that array now needs to be aligned
suitably. Previously the array started with at next byte after the
flexible array of gskpathop, but the alignment of a gskpathop is only
4 bytes on 32-bit architectures, so depending on the number of gskpathop
in the trailing flexible array, that pointer might be an unsuitable
location to allocate a GskAlignedPoint.

Resolves: https://gitlab.gnome.org/GNOME/gtk/-/issues/6395
Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-28 17:31:41 +01: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
ffe82b7641 Merge branch 'wip/smcv/ubsan-half-float' into 'main'
gsk, testsuite: Avoid undefined behaviour converting float <-> fp16

See merge request GNOME/gtk!7509
2024-07-28 02:59:59 +00:00
Matthias Clasen
785709d51c Merge branch 'matthiasc/for-main' into 'main'
Cosmetics

See merge request GNOME/gtk!7512
2024-07-28 02:55:57 +00:00
Matthias Clasen
8406c34166 Cosmetics 2024-07-27 22:11:39 -04:00
Matthias Clasen
2ee1f3e8cf Merge branch 'matthiasc/for-main' into 'main'
image-tool: Allow specifying cicp tuples

See merge request GNOME/gtk!7511
2024-07-27 23:45:21 +00: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
Matthias Clasen
a60cda3daa image-tool: Allow specifying cicp tuples
Accept --cicp=1/13/6/0 and similar to specify color states.
2024-07-27 18:42:39 -04:00
Simon McVittie
660c6c8d6f gsk, testsuite: Avoid undefined behaviour in half_to_float_one()
Similar to the previous commit, to avoid undefined behaviour we need
to avoid evaluating out-of-bounds shifts, even if their result is going
to ignored by being multiplied by 0 later.

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:22:09 +01:00
Simon McVittie
ad679187d3 gsk, testsuite: Avoid undefined behaviour in float_to_half_one()
If, for example, e == 0, it is undefined behaviour to compute an
expression involving an out-of-range shift by (125 - e), even if the
result is in fact irrelevant because it's going to be multiplied by 0.

This was already fixed for the memorytexture test in
commit 5d1b839 "testsuite: Fix another ubsan warning", so use the
implementation from that test everywhere. It's in the header as an
inline function to keep the linking of the relevant tests simple:
its only caller in production code is fp16.c, so there will be no
duplication outside the test suite.

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:22:09 +01:00
Simon McVittie
b769295682 gtkcssnodedeclaration: Avoid signed left shift by 31 bits
Left-shifting a signed 32-bit integer by 31 bits (such that the value
overflows into the sign bit) is undefined behaviour. Use an unsigned
integer instead.

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
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
ca7094296c gtktimsort: Avoid undefined behaviour on 32-bit
Shifting a 32-bit type by 32 bits is formally undefined behaviour,
even if it happens in code that is unreachable at runtime. Use a
compile-time check against GLib's GLIB_SIZEOF_SIZE_T, instead of hoping
a runtime check will be optimized away.

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
d301d16aee Merge branch 'wip/otte/for-main' into 'main'
wayland: Redo the image description code

See merge request GNOME/gtk!7505
2024-07-27 06:09:15 +00: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
45e76c1604 Merge branch 'wip/smcv/a11y-tests' into 'main'
tests: Fix signature of GtkTestATContext::update-selection-bound handlers

Closes #6490

See merge request GNOME/gtk!7504
2024-07-27 04:50:14 +00:00
Matthias Clasen
a9c3163a64 Merge branch 'main' into 'main'
Tests: add GtkPicture builder test

See merge request GNOME/gtk!7486
2024-07-27 03:08:15 +00:00
Simon McVittie
a8bb71383a tests: Fix signature of GtkTestATContext::update-selection-bound handlers
The signal is declared in GtkTestATContext with 0 parameters, but these
handlers were written as if the signal had one `guint` parameter.
On some architectures this accidentally works as intended, but on
others (reproduced on i386 and riscv64) the test tries to use arbitrary
stack contents as the `TestData *` and crashes when it tries to
dereference the resulting non-pointer.

Resolves: https://gitlab.gnome.org/GNOME/gtk/-/issues/6490
Signed-off-by: Simon McVittie <smcv@debian.org>
2024-07-27 00:59:03 +01:00
Matthias Clasen
3b08f8026e Merge branch 'matthiasc/for-main' into 'main'
jpeg: Port to GdkMemoryTextureBuilder

See merge request GNOME/gtk!7502
2024-07-26 23:09:27 +00:00
Matthias Clasen
2cdc2287a5 Merge branch 'amolenaar/macos-open-panel-create-folders' into 'main'
macos: Propagate the create-folders option also for Open panels

Closes #6872

See merge request GNOME/gtk!7492
2024-07-26 22:35:43 +00:00
Juan Pablo Ugarte
c80c4ee75c Tests: add GtkPicture builder test
Add test for GtkPicture::file GFile property.
2024-07-26 18:30:58 -04:00
Juan Pablo Ugarte
082691ba16 GtkBuilder: add support for paths and relative uris for GFile properties. 2024-07-26 18:30:58 -04:00
Matthias Clasen
d09a610433 Merge branch 'spinbutton-hint' into 'main'
gtkspinbutton: Set number input hint for text field

See merge request GNOME/gtk!7485
2024-07-26 22:05:34 +00: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
e2d337740f gpu: Don't mess up color states
When uploading textures, we were unintentionally converting to
srgb. Avoid that, so that yuv data survives unmolested.
2024-07-26 17:34:48 -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