Commit Graph

2944 Commits

Author SHA1 Message Date
Benjamin Otte
d6322c6389 gsk: Switch box shadow nodes to use offsets
Instead of
  float dx;
  float dy;
have a
  graphene_point_t offset;
in the object and in all APIs relating to them.
2024-08-10 01:40:45 +02:00
Matthias Clasen
4ea1319c6b Replay inset and outset shadow nodes properly 2024-08-08 16:01:06 -04:00
Matthias Clasen
ea28dc8cff nodeparser: Support color states for box shadows
Just switch from parse_color to parse_color2, and apply the
corresponding changes to serialization too.

Test included.
2024-08-08 15:49:55 -04: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
Matthias Clasen
56c02dd7d1 Merge branch 'css-color-hookup-2' into 'main'
Make non-srgb css colors work for borders

See merge request GNOME/gtk!7550
2024-08-07 23:14:35 +00:00
Benjamin Otte
88c9a30f77 testsuite: Half the runtime of offscreens test
It times out too much in CI.
2024-08-07 23:26:03 +02:00
Jeremy Bícha
8ee465c630 testsuite: add more files to test_data 2024-08-06 20:28:58 -04:00
Matthias Clasen
2960bb7cb2 Add a compare test for colorstates in borders 2024-08-06 07:35:00 -04:00
Matthias Clasen
a3691d311b nodeparser: Support color states in border nodes
Test included.
2024-08-06 07:35:00 -04:00
Matthias Clasen
89d449352f testsuite: Replay border nodes properly
Use the new apis for this.
2024-08-06 07:35:00 -04:00
Matthias Clasen
582dba54b1 Try to fix win32 build of compare-render 2024-08-06 07:10:04 -04:00
Matthias Clasen
0775432ed9 Add a compare test for premultiplied colors
This test checks a that a specific combination of mask with alpha
inside opacity works as expected. We were treating the mask color
as premultiplied here, although it isn't.
2024-08-06 00:59:23 -04:00
Matthias Clasen
71d6392572 nodeparser: Rewrite the color parsing
Use gtk_css_parser_consume_function, for better error handling.
We are now getting the expected error for

  color(srgb 1 2 3 4 5 6)

Test included.
2024-08-06 00:23:07 -04:00
Matthias Clasen
c1a99bf901 tests: Link compare-render statically
This is a temporary change, only needed until we make the new
snapshot and rendernode apis public.
2024-08-05 16:09:42 -04:00
Matthias Clasen
b8989b7ff6 Add a compare test for color states
This checks that the red values in all 4 default color states
come out identical to a plain old red png.
2024-08-05 11:11:15 -04:00
Matthias Clasen
d6a6cfe6c5 gtk: Fix gtk_snapshot_collect_repeat
This creates a new color node that is meant to be identical to
an existing one, so we need to use gsk_color_node_new2 to preserve
the color state information.

Test included.
2024-08-05 11:11:15 -04:00
Matthias Clasen
16431da3f2 nodeparser: Add support for cicp color states
Allow defining cicp color states with an @-rule:

    @cicp "jpeg" {
      primaries: 1;
      transfer: 13;
      matrix: 6;
      range: full;
    }

And allow using them in color() like this:

    color("jpeg" 50% 0.5 1 / 75%)

Note that custom color states use a string, unlike default color
states which use an ident.

Test included.
2024-08-05 11:11:15 -04:00
Matthias Clasen
842949fcf3 nodeparser: Support color states
And allow using color states for colors with a syntax similar
to modern css color syntax.

color(srgb 50% 0.5 1 / 75%)

Both floating point numbers and percentages can be used.

Currently, this is only supported for color nodes.

Test included.
2024-08-05 11:11:15 -04:00
Matthias Clasen
d5ae94ca5d testsuite: Update replay nodes
We can't currently recreate color nodes with public api, so cheat
and reuse the node we got.
2024-08-05 11:11:15 -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
Jeremy Bícha
20b00d3947 ci: avoid another date-dependent failure
Set the day before setting the month to avoid
failure when running the test on the 31st day of a month
2024-07-30 15:50:12 -04:00
Benjamin Otte
9f71528a05 gpu: Fix shadows even more
Math is hard.

But this time, it comes with a test!
2024-07-30 18:01:45 +02:00
Benjamin Otte
4a94c91772 gpu: Don't blur tiny blur radii
We get those wrong, and there's not really a visual effect.

And since we do a check anyway, just disallow them and treat them as
unblurred.
2024-07-30 01:50:56 +02:00
Benjamin Otte
cc3ed89e34 gpu: Draw proper shadows again
The fix in commit 5e7f227d broke shadows while trying to make them
faster.
So use a better way to make them faster.

With the normalized blur radius, we can now conclude that all the values
too far from p.y will cause the gauss() call to return close to 0, so we
can skip any y value that is too far from p.y.

And that allows us to put an upper limit on the loop iterations.

Tests included

Fixes #6888
2024-07-30 01:50:56 +02: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
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
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
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
8406c34166 Cosmetics 2024-07-27 22:11:39 -04: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
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
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
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
Juan Pablo Ugarte
c80c4ee75c Tests: add GtkPicture builder test
Add test for GtkPicture::file GFile property.
2024-07-26 18:30:58 -04:00
Matthias Clasen
b3451dda04 css: Fix relative font sizes
This regression was introduced in aeac2b54.

We need percentage values to stay non-computed, since we otherwise
fail to compute relative font sizes properly. But we want percentages
not to stick around in relative colors, so tweak things to be more
aggressive with simplication when creating relative color values.

Update affected tests.

Fixes: #6868
2024-07-26 08:45:58 -04:00
Matthias Clasen
8d87ed1a6a Add tests
Add some more texture conversion roundtrips. They are currently
ifdefed out, since they need cicp api.

Also add another test binary for internal tests.
2024-07-24 16:45:21 -06:00
Benjamin Otte
9e27acb0a6 gpu: Allocate Vulkan descriptor pools dynamically
Instead of allocating one large descriptor pool and hoping we never run
out of descriptors, allocate small ones dynamically, so we know we never
run out.

Test incldued, though the test doesn't fail in CI, because llvmpipe
doesn't care about pool size limits. It does fail on my AMD though.

A fun side note about that test is that the GL renderer handles it best
in normal operationbecause it caches offscreens per node and we draw the
same node repeatedly.
But, the replay test expands them to duplicated unique nodes, and then
the GL renderer runs out of command queue length, so I had to disable
the test on it.
2024-07-22 19:40:24 +02:00
Benjamin Otte
9be7104b71 testsuite: Add a save=>load cycle test for PNGs with colorstates 2024-07-16 22:04:11 +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
Matthias Clasen
b33b68ef75 dmabuf texture: color state support 2024-07-16 21:23:44 +02:00
Benjamin Otte
77da45a173 testsuite: Update colorstate test 2024-07-16 21:23:44 +02:00
Benjamin Otte
05953a20cc testsuite: Allow colorstate properties to have SRGB as default value
This needs custom code because boxed paramspecs always default to NULL.
But we want to always default to SRGB.
2024-07-16 21:23:44 +02:00
Matthias Clasen
b0effee9b3 colorstate: Add tests for conversions
Test roundtrip tests between color states.

For now, this just tests srgb<>srgb-linear.
2024-07-12 18:14:54 -04:00
Matthias Clasen
4253bb9922 memoryformat: Add test for depth merging
We want to ensure a few invariants:
- merge (a, a) == a
- merge (a, b) == merge (b, a)

Add tests to verify that this is now the case.
2024-07-11 14:57:20 +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
Matthias Clasen
aa746bc0c8 gdk: Add GdkColorState
This is mostly an empty shell for now. We only have static instances
for srgb and srgb-linear, which we will use as markers during our
node processing.

In the future, this object may grow more instances, as well as the
ability to create them from and save them to icc profiles or cicp
data. And a color conversion API.
2024-07-11 14:57:19 +02:00