Commit Graph

2780 Commits

Author SHA1 Message Date
Matthias Clasen
4f1cc8ec6d gsk: Make uber shader handle fonts the same
The code converting text nodes for the uber shader was missing
some of the recent font handling improvements. Make things match.

Related: #6514
2024-03-08 20:44:42 -05:00
Matthias Clasen
5242205a65 gsk: Ignore transforms for font handling
We were turning off hinting and subpixel positioning if the
transform isn't 2D affine. The idea behind this was that transforms
likely indicate animations, and for animations, this may reduce
jitter. But the heuristic of transform==animation is not very
reliable, and we pay for this with a jump from hinted to unhinted
at the beginning and end of it. Also, the heuristic does not even
work for the most relevant 'animation' we have today: scrolling.

So, lets drop this for now. We can revisit it later.
2024-03-08 20:44:42 -05:00
Matthias Clasen
77a2cd4d8d gsk: Fix mis-scaled text rendering
This was happening when rotated text was partially redrawn.

A test that failed before this change is included.

Fixes: #6504
2024-03-06 17:52:35 -05:00
Matthias Clasen
0986981d1a gpu: Empty clip is still empty after transform
When transforming an empty clip, it stays empty.

Previously, we were setting it to CONTAINED, but that's wrong, because
the bounds are not contained in the clip, the clip is contained in the bounds.

This reverts part of commit a51c6aed47.

Related: !6692
2024-03-06 17:52:22 -05:00
Matthias Clasen
b23600ae4b gsk: Preserve dpi when modifying fonts
When scaling a font or changing font options, we need to be
careful to preserve the dpi as well, otherwise the rendering
might leak out of the node bounds, leading to spectacular
glitches.

Fixes: #6508
2024-03-05 16:22:26 -05:00
Christian Hergert
d181d53762 gsk/gpu: add profiler node for shader loading
This is helpful when tracking down why a frameclock cycle took so long. In
quick recordings it seems to often correlate with a shader compile.
2024-03-04 11:54:13 -08:00
Matthias Clasen
0b4c695d65 Merge branch 'hinting-proper-positioning' into 'main'
gsk: Handle hinted fonts better

Closes #6502

See merge request GNOME/gtk!6966
2024-03-03 23:27:00 +00:00
Matthias Clasen
4f2d63b8ac gsk: Handle hinted fonts better
Enforce the following rules:
- No hinting or subpixel positioning in transformed context
- glyph-align determines if we use integral or fractional
  device pixel positions
- For hinting, always use an integral y position (the hinter
  assumes integral positions, and only operates vertically).
2024-03-03 13:08:29 -05:00
Matthias Clasen
81c97f0910 gsk: Add a private helper
Add a function to get the hint style of a font.
2024-03-03 13:08:29 -05:00
Matthias Clasen
d1b52cc292 gsk: Preserve the antialiasing setting of the font
When we get an unhinted font for text node extents, don't change
the antialiasing setting. It doesn't affect the extents we get
here, but if we later need an unhinted font for rendering, the
one we create this way will be the right one, so it will already
exist.
2024-03-03 13:08:29 -05:00
Matthias Clasen
ddedb39329 gsk: Tweak gsk_get_hinted_font slightly
Make it possible to preserve some of the fonts original options.
2024-03-03 13:08:29 -05:00
Matthias Clasen
b95eceea60 Don't fall back to cairo for software rendering
The experience with gl+llvmpipe is not great, in particular on
fractional scales. But it is less broken than cairo in that
situation.
2024-03-03 12:28:20 -05:00
Matthias Clasen
8a48becb7e Cosmetics 2024-03-03 08:56:32 -05:00
Matthias Clasen
b018da2acd gsk: Accept font options in node files
The goal is to fix all the context that influences the rendering
of text nodes in the node file. This will help with better font
testing.

The newly accepted properties are

hint-style: none/slight/full
antialias: none/gray

We are omitting font options and values that aren't supported
in GSK or have no influence on the rendering.

Note that these settings will get incorporated in the PangoFont
that gets set on the resulting text node.

Parser tests included.
2024-03-02 18:39:14 -05:00
Matthias Clasen
ab5f3f59ce gsk: Use unhinted extents for text nodes
We need precise bounds. And while hinting might shift the rendering
around from these bounds by a fraction of a pixel, we account for
this in the places where it matters: when determining diff regions,
when sizing offscreens, and when determining the size of atlas
regions for glyphs.
2024-03-02 18:39:14 -05:00
Matthias Clasen
0127217e10 gsk: Add a way to get a (un)hinted font
Add a function to change the cairo font options of a font to
to the given values while keeping everything else the same.

We use pango api for this if available.

Note that this is not a fully general api, but tailored to the
needs of GSK. We don't allow setting hint-metrics (because it
only influences layout, not rendering) or subpixel-mode (since
we don't have component alpha available).
2024-03-02 18:39:14 -05:00
Matthias Clasen
16a476fe22 gsk: Stop passing scale to glyph upload op
It is always 1.0 now, so there is no point. Instead of the scale,
print the font when doing verbose logging.
2024-03-02 18:39:14 -05:00
Matthias Clasen
c8ca6930c5 gsk: Use a scaled font for glyph rendering
This changes the approach we take to rendering glyphs in the
presence of a scale transform: Instead of scaling the extents
and rendering to an image surface with device scale, simply
create a scaled font and use it for extents and rendering.

This avoids clipping problems with scaling of extents in
the presence of hinting.
2024-03-02 18:39:14 -05:00
Matthias Clasen
c4f33f36de gsk: Add a way to get a scaled font
Add a function to change the size of a font while keeping everything
else the same. We use pango api for this if available.
2024-03-02 18:39:14 -05:00
Matthias Clasen
c7806eb908 gsk: Fix handling of hex boxes
The pango code that is drawing hex boxes, invisible glyphs, etc,
is depending on the width being set in the PangoGlyphInfo. Once
we set that, everything falls into place.

Testcase included.
2024-03-01 16:51:58 -05:00
Matthias Clasen
f5159e1ecb gsk: Make glyph parsing more flexible
It is a bit annoying that one has to specify the glyph width
when specifying glyphs numerically for a text node, since this
information really is part of the font.

Make the parser more flexible, and allow to specify just the glyph
ids, without an explicit width. In this case, the width will be
determined from the font.

With this, glyphs can now be specified in any of the follwing
ways:

glyphs: "ABC";              (ASCII)
glyphs: 23, 45, 1001;       (Glyph IDs)
glyphs: 23 10, 100 11.1;    (Glyph IDs and advance widths)
glyphs: 23 10 1 2 color;    (with offsets and flags)

Tests have been updated to cover these variants.
2024-03-01 11:22:28 -05:00
Matthias Clasen
b7422c0f62 nodeparser: Change default font
Use Cantarell 15px instead of Cantarell 11, ot make roundtrip
tests easier to read.
2024-02-27 23:45:46 -05:00
Matthias Clasen
c2311c7154 gsk: Serialize fonts with absolute size
This is more often what we want. Our testcases tend to have
pixel sizes, and we want to preserve then when resaving the
test files.
2024-02-27 14:10:10 -05:00
Matthias Clasen
9b5aee0d1b Cosmetics 2024-02-25 18:20:22 -05:00
Matthias Clasen
02a7a30978 Merge branch 'disable-depth-test' into 'main'
GL, NGL: Disable depth test

Closes #6401

See merge request GNOME/gtk!6917
2024-02-19 19:14:36 +00:00
Luca Bacci
79568d2944 gpu: Disable GL_DEPTH_TEST
The call to enable depth testing was copied from the GL
renderer, but it's not needed.

Fixes #6401
2024-02-19 18:16:35 +01:00
Luca Bacci
ae45be7875 GL renderer: Disable GL_DEPTH_TEST
It was introduced in bbfe4324 to support GtkGLArea. It's not
needed anymore

See #6401
2024-02-19 18:16:35 +01:00
Matthias Clasen
ad719a9c47 Merge branch 'ink-rect-fixaroo' into 'main'
gsk: Stop padding text node bounds

See merge request GNOME/gtk!6912
2024-02-16 20:30:45 +00:00
Matthias Clasen
24de5ffd4e gsk: Stop padding text node bounds
This should not be necessary, provided that the ink extents that
pango provides are accurate.

Update affected tests.
2024-02-16 14:45:20 -05:00
Benjamin Otte
4933bc505f gpu: External textures are never mipmap'able
We were just assuming they were if the format matches.

Fixes crashes in Webkit where the external texture is actually a dmabuf
imported as an EGL image.
2024-02-16 20:16:38 +01:00
Benjamin Otte
afc7b46264 gpu: Add an epsilon before ceil()ing for offscreen size
Avoids getting the scale wrong when due to a rounding error our
pixel-aligned rectangle is 5.000000003px big and we ceil() to 6px
and produce blurry output.

Fixes #6439
2024-02-14 20:11:59 +01:00
Benjamin Otte
86db9e2ce0 gsk: Use gsk_rect_scale() in more places 2024-02-14 20:11:30 +01:00
Benjamin Otte
cb6c720d37 gpu: Render enough of a scaled texture offscreen
We were not thinking about pixel alignment and the potential later
linear blend for the final composite.

Fixes #6428
2024-02-14 20:11:29 +01:00
Matthias Clasen
fb4023af22 Fix rounded rect intersection code
The code was written under the assumption that the corners of
the rounded rect are disjoint. If they aren't, there are a few
more cases to consider.

Fixes: #6440
2024-02-14 10:37:56 -05:00
Matthias Clasen
72614fdb67 gsk: Normalize node bounds upon creation
We lost this when a bunch of rect code was inlined in
commit 36314f28e2, and as it turns out, that broke some
applications. So, bring it back.

Fixes: #6435
2024-02-13 20:06:16 -05:00
Matthias Clasen
230ee92857 Add gsk_rect_normalize
This is an inline version of graphene_rect_normalize_in_place.
2024-02-13 20:06:16 -05:00
Matthias Clasen
b2d22d8125 Merge branch 'wip/abono/fallthrough' into 'main'
gsk: Remove unnecessary G_GNUC_FALLTHROUGH

See merge request GNOME/gtk!6898
2024-02-13 22:17:50 +00:00
Benjamin Otte
ee34781a13 gpu: Pixel-align the blur rectangle
Fixes blurriness in shadows.

Not sure to do a proper test for this feature. Usually proper pixel
alignment is tested by drawing a crips line and checking that it is
indeed crisp. But we are testing the blur operation here...

Fixes #6380
2024-02-13 21:56:01 +01:00
Benjamin Otte
9fc80a0bd5 gpu: Update blur code to newer internal API
The recommended way to draw offscreens has been init_draw() for a bit,
but apparently this code wasn't updated.
2024-02-13 21:56:01 +01:00
Benjamin Otte
a1dda0ec3c gpu: Adjust shadows clip by shadow offset
When computing the clip of the shadow rect, don't forget that it will
ultimately be offset by the shadow offset.

Fixes #6425
2024-02-13 21:56:01 +01:00
Benjamin Otte
dbbc16947f gpu: Handle one layer of NULL return
This isn't really a useful thing in itself, because none of the callers
handle the NULL return.
But the resulting crash is easier to debug when it's a NULL image than
when add_node() is called on an uninitializes NodeProcessor.
2024-02-13 21:56:01 +01:00
Benjamin Otte
dc47abc60e gpu: Don't oversize node image
There's no need - even if given clip bounds - to render the parts
outside the node.

So clip to the node bounds.
2024-02-13 21:56:01 +01:00
Alessandro Bono
ca9ba3cc80 gsk: Remove unnecessary G_GNUC_FALLTHROUGH
In GSK the following pattern is used four times:
```
  switch (self->filter)
    {
      default:
        g_assert_not_reached ();
        G_GNUC_FALLTHROUGH;
      case GSK_GPU_BLIT_LINEAR:
        filter = GL_LINEAR;
        break;

      case GSK_GPU_BLIT_NEAREST:
        filter = GL_NEAREST;
        break;
    }
```
The G_GNUC_FALLTHROUGH macro is not required. When G_DISABLE_ASSERT
is defined the body of the `default` case is empty, thus there is
no need. When G_DISABLE_ASSERT is not defined the body of the `default`
case contains g_assert_not_reached() thus it won't fallthrough.

This resolves the following:
```
[221/1379] Compiling C object gsk/libgsk.a.p/gpu_gskgpublitop.c.o
[...]
error: fallthrough annotation in unreachable code [-Werror,-Wimplicit-fallthrough]
1 error generated.
```
2024-02-13 18:29:03 +01:00
Matthias Clasen
ea7a61a763 gpu: Print globals when being verbose
This can be helpful to see that there is an enormous scale blowing
things up. We omit the matrix, since it is 16 floats that are hard
to interpret at a glance.
2024-02-13 06:59:58 -05:00
Matthias Clasen
2104d7b062 fixup! gsk: Don't use gpu renderers with llvmpipe 2024-02-12 14:41:14 -05:00
Matthias Clasen
6c4739a2f1 gsk: Don't use gpu renderers with llvmpipe
Unless the renderer has been explicitly selected via the
GSK_RENDERER environment variable, don't use it with llvmpipe.

It is important that we allow explicit setting to override
this, so we can continue to use ngl in ci, where we don't
have hw and want to test with llvmpipe.

This should address many of the "performance is terrible in
GNOME OS" complaints that are coming from people running in
VMs, etc.
2024-02-12 14:19:57 -05:00
Matthias Clasen
925d2ba9ae Merge branch 'wip/otte/for-main' into 'main'
gpu: Avoid offscreens for disjoint containers

See merge request GNOME/gtk!6889
2024-02-12 12:58:14 +00:00
Benjamin Otte
2fe1f47e6d gpu: Avoid offscreens for disjoint containers
When opacity is set but the container is disjoint - ie no children
overlap - don't redirect into an offscreen, because it's not necessary.
2024-02-12 08:34:18 +01:00
Matthias Clasen
1db696be79 offload: Find and use source rectangle
Look for nodes like subsurface { clip { texture {} } }, and use
the clip to provide a source rectangle for subsetting the texture.

Update affected tests, and add a new one.
2024-02-11 21:44:47 -05:00
Matthias Clasen
9a30ea1f69 subsurface: Have a source rectangle
This will let us use a subset of the full texture, which can
be necessary in the case that converters put padding around
content in dmabufs. The naming follows the Wayland viewporter
spec.

For now, make all callers pass the full texture rect.
2024-02-11 21:44:27 -05:00