Commit Graph

2686 Commits

Author SHA1 Message Date
Matthias Clasen
8009ed3a3c gpu: Add more details to debug spew
Print the number of items in the cache hash tables.
2024-01-27 19:50:45 -05:00
Matthias Clasen
1d95a171f6 gpu: Don't forget to unage cached textures
Whenever we successfully looking up a cached item, we need to
call use() on it to mark it as fresh.
2024-01-27 19:50:41 -05:00
Matthias Clasen
e0136b283a Cosmetics 2024-01-27 19:49:58 -05:00
Matthias Clasen
42867c7a3c Cosmetics 2024-01-27 19:49:57 -05:00
Matthias Clasen
c1270cf52b gpu: Fix a crash in vulkan
The node processing wasn't skipping 0-size nodes when using the
uber shader, leading to assertions down the road. Since the ngl
renderer doesn't use uber shaders, this only affects vulkan.

Test included.

Fixes: #6370
2024-01-27 10:30:38 -05:00
Benjamin Otte
e67bb62b1f Merge branch 'wip/otte/6363' into 'main'
gpu: Add support for MacOS default framebuffer

See merge request GNOME/gtk!6815
2024-01-27 15:15:38 +00:00
Matthias Clasen
746cfe48b0 nodeparser: Fix a font handling mishap
When we don't have an embedded font file via a url, then we want
to parse fonts "as normal", i.e. allow fallback for aliases like
"Monospace 10". This was broken when the url support was added.
Make it work again.

Update affected tests. In particular, the output of the text-fail
test goes back to be the same it was before the url changes.
2024-01-26 23:54:58 -05:00
Benjamin Otte
3a93d52718 gpu: Add support for MacOS default framebuffer
This adds the same code as the GL renderer used to allow backends to
redirect rendering to a different framebuffer.

Related: #6363
2024-01-26 16:55:49 +01:00
Benjamin Otte
d74855fe9f gpu: Don't use layout binding in old GL versions
GL needs version 4.2 before it supports explicit bindings. We use GLES
usually, and Mesa supports GL 4.6, so we didn't hit this case before.

However, MacOS does use GL and Mac OS is stuck on GL 4.1.

Fixes #6363
2024-01-26 14:17:16 +01:00
Matthias Clasen
98e3fca284 gsk: Change the default renderer
The intent of this change to get wider testing and verify that the
new renderers are production-ready. If significant problems show
up, we will revert this change for 4.14.

The new preference order is ngl > gl > vulkan > cairo.

The gl renderer is still there because we need it to support gles2
systems, and vulkan still has some rough edges in application support
(no gl area support, webkit only works with gl).

If you need to override the default renderer choice, you can
still use the GSK_RENDERER environment variable.
2024-01-25 14:41:04 -05:00
Benjamin Otte
502fb250ab gpu: Fix zero-width border corner rendering
When a border side has a width of 0 but we're having rounded corners, we
draw content in the edges of that side, and naturally pick its color.
That is wrong though, when the width is zero, we're supposed to keep
using the color of the other side in that corner.

So do that.

Fixes the border-corner-zero-width-rendering.ui reftest.
2024-01-25 19:39:34 +01:00
Benjamin Otte
7d7d3ff35c gpu: Fix variable
I had a test that allocated over 4GB of ops and...
2024-01-25 19:08:32 +01:00
Matthias Clasen
7624e6621a gpu: Add profiler marks around cache gc 2024-01-25 09:41:49 -05:00
Matthias Clasen
cdddb6cb96 gpu: Print more detailed cache statistics
Print out stale glyphs and dead pixel ratios.
2024-01-25 09:41:49 -05:00
Matthias Clasen
f6c01a7674 gpu: Fix ordering problem in clear_cache()
We must free the glyphs before their atlases, since we now maintain
the dead pixel count of the atlas when glyphs are freed.
2024-01-25 09:41:49 -05:00
Matthias Clasen
ffa5bf1b7d gpu: Fix atlas freeing
We need to unset current_atlas if we free that one.
2024-01-25 09:41:49 -05:00
Matthias Clasen
4c6e623ec5 gpu: Keep track of atlas use
Count how many dead pixels we have, and free the atlas if more than
half of its pixels are dead.

As part of this, change when glyphs are freed. We now keep them
in the hash table until their atlas is freed and we only do dead
pixel accounting when should_collect is called. This keeps the
glyphs available for use from the cache as long as are in the atlas.

If a stale glyph is sused, we 'revive' it by removing its pixels
from the dead.

This matches more closely what the gl renderer does.
2024-01-25 09:41:48 -05:00
Matthias Clasen
621ef0703a gpu: Make atlas freeing more robust
Currently, we don't free an atlas before all its glyphs are gone,
but we might revisit that in the future, so be prepared for it.
2024-01-25 09:40:58 -05:00
Matthias Clasen
f514caadb0 gpu: Evict stale glyphs from the cache
Same story as for textures: if it hasn't been used for 4 seconds,
it is stale and can go.
2024-01-25 09:40:58 -05:00
Matthias Clasen
4d92093c67 gpu: Fix texture eviction
If we gc a cached texture for which the GdkTexture is still alive,
the cached texture object will remain accessible via the render
data, so need to make sure not to leave a dangling pointer behind
here.
2024-01-25 09:40:58 -05:00
Matthias Clasen
bd9ea05ebb gpu: Evict stale textures from the cache
This is straightforward. If a texture hasn't been used for 4 seconds,
we consider it stale, and drop it the next time gc comes around.

The choice of 4 seconds is arbitrary.

Fixes: #6346
2024-01-25 09:40:58 -05:00
Matthias Clasen
e8599bd36e gpu: Start doing cache gc
Call the gc function periodically from a timeout to collect
stale cached items.
2024-01-25 09:40:58 -05:00
Matthias Clasen
1accd0c1ba gpu: Print some cache stats
This reuses the GLYPHCACHE debug flag that is used for the same
purpose in the gl renderer.
2024-01-25 09:40:58 -05:00
Matthias Clasen
14488041bc gpu: Add a static assertion
Stating the obvious, maybe.
2024-01-25 09:40:58 -05:00
Benjamin Otte
c31b6ff1d5 gpu: Implement subpixel positioning
This makes glyph rendering match the Cairo and GL renderers.
2024-01-23 06:17:14 +01:00
Benjamin Otte
cf4b9dcb4d gpu: Align glyphs to the pixel grid
Add GSK_GPU_SKIP=glyph-align to turn off the glyph aligning.

FIXME: Should this be handled by the renderer at all or should we rely
on higher rendering layers to align glyphs properly?

This is kind of a tricky question just like with texture-scale nodes and
NEAREST filtering, because rendernodes can be embedded in other nodes
that disturb the pixel grid.
2024-01-23 06:17:14 +01:00
Benjamin Otte
b7f7487b53 cairo: Fix wrong offset when tiling repeat nodes 2024-01-23 06:17:14 +01:00
Benjamin Otte
dfc34b7295 gpu: Offset tiles properly
When drawing repeat nodes as tiles, this could result in wrong
renderings when the tiles were clipped wrong.
2024-01-23 06:17:14 +01:00
Benjamin Otte
00be97e741 gsk: Respect offscreen_for_opacity of first child
The container node constructor forgot to initialize that value from the
first child.

Testcase included.

Fixes #6350
2024-01-22 18:22:50 +01:00
Matthias Clasen
9b9e8b385e Merge branch 'matthiasc/for-main' into 'main'
Tweak profiling strings

See merge request GNOME/gtk!6796
2024-01-22 13:46:52 +00:00
Benjamin Otte
183d712252 gpu: Handle a full cache
Previously, we only checked if the cache had exhausted the maximum
number of slices.
But we also need to check that the height of the slices doesn't exceed
the height of the texture.
2024-01-22 07:47:10 +01:00
Benjamin Otte
3eb5447376 rendernodeparser: Improve error handling for font parsing
After the node-editor crashed on me once too often, I decided to take a
good hard look at the parsing code and add a bunch of weird corner
cases into the testsuite.

That meant redoing the parser so that the error paths cause neither
crashes nor duplicated or wrong error messages.
2024-01-22 07:47:10 +01:00
Matthias Clasen
f779832861 Tweak profiling strings
Capitalize our mark names, and use GTK as category.

The justification is: it looks better in sysprof.
2024-01-21 14:02:08 -05:00
Matthias Clasen
c43294c837 gl: Fix text carets going missing on NVidia
Use the same logic for uploading the 'corner pixel' that we use
for uploading glyphs, since that works.

Fixes: #6348
2024-01-21 08:22:47 -05:00
Matthias Clasen
b2f783b70b gl: Avoid a use-after-free
This only happens with big, non-atlased glyphs, so it is rare, but
it gets triggered by the Masking demo in gtk4-demo.

Fixes: #6347
2024-01-20 13:33:54 -05:00
Matthias Clasen
a91a0720f5 gl: Consistently use float apis 2024-01-20 11:52:42 -05:00
Matthias Clasen
f01208ad94 gpu: Consistently use ceilf
There was a mix of ceil() and ceilf() calls here, but the arguments
are always floats, so use ceilf() throughout.
2024-01-20 11:33:59 -05:00
Matthias Clasen
56b955f819 roundedrect: Use fabsf
The arguments are floats.
2024-01-20 11:33:59 -05:00
Matthias Clasen
0d7761269c gpu: Use gsk_rect_scale 2024-01-20 11:33:59 -05:00
Matthias Clasen
9ebaafa2af gsk: Inline some more rect functions
When we use graphene_rect_scale, the rect is always normalized,
so we can avoid some overhead here.
2024-01-20 11:33:59 -05:00
Matthias Clasen
b4b7e9b040 gpu: Fix up gc
Make the gc loop free the the right item.
2024-01-20 08:04:43 -05:00
Matthias Clasen
c3fcf0f7b0 gpu: Plug a memory leak
This looks like just a leftover line.
2024-01-20 08:02:20 -05:00
Matthias Clasen
60fc48e71f gpu: Cosmetics
s/timestsamp/timestamp/
2024-01-20 08:01:59 -05:00
Matthias Clasen
7b66bc45aa Cosmetics
Add some vim modelines.
2024-01-19 09:26:32 -05:00
Benjamin Otte
4e2c7d5eb0 gl: Require GL/GLES flag when looking up memory formats
This code just adds the argument to the function and fixes all callers.

It's separate because it's just a bunch of boilerplate.
2024-01-16 20:35:20 +01:00
Matthias Clasen
385b9a7241 gsk: Serialize custom fonts with url
If we see custom fonts when serializeing text nodes, write data
url that contains the font file, the first time we see it.

This does not add blobs standard fonts, like Cantarell or Monospace.

Update all affected nodeparser tests.
2024-01-16 07:04:45 -05:00
Matthias Clasen
8158945de9 gsk: Allow custom fonts in node files
This will let us store complete test fonts inside node files,
as data: urls. You can also use a file: url to refer to a local
file.

The syntax is as follows:

text {
  font: "FONT DESCRIPTION" url("data:font/ttf;base64,FONT DATA");
}

with the url being optional.
2024-01-15 18:58:17 -05:00
Matthias Clasen
1c85141612 gsk: Keep a fontmap reference in text nodes
A PangoFont keeps a weak reference to its fontmap. In addition,
keep a strong reference in GskTextNode, so we can be sure that
custom font maps won't go away before the node is finalized.
2024-01-15 18:25:15 -05:00
Matthias Clasen
93715b963e gsk: Fix big glyphs getting clipped
We were inadvertedly shifting the rendering by one pixel.
2024-01-12 15:55:27 -05:00
Benjamin Otte
a51c6aed47 gpu: Introduce "contained" clip
This clip is different from "none" in that the bounds rect cannot be
ignored and that potential drawing outside the clip must be avoided.

In particular it means that clip nodes cannot be discarded if they
encompass the full clip region.

Fixes #6322
2024-01-12 20:06:04 +01:00