Commit Graph

58 Commits

Author SHA1 Message Date
Matthias Clasen
2ec1bd7248 Merge branch 'gl-renderer-more-defensive' into 'main'
gsk: Stop setting uniforms when we are out of batches

See merge request GNOME/gtk!5981
2023-05-17 00:29:40 +00:00
Matthias Clasen
71a231b71d gsk: Stop setting uniforms when we are out of batches
When the command queue is out of batches, there is
no point in doing further work like allocating uniforms.

This helps us avoid assertions in the uniform code
that we would hit when we run out of uniform space
too.
2023-05-16 20:03:19 -04:00
Benjamin Otte
112fe06323 glrenderer: Remove unused function
Thanks, macos CI.

(We should have a Fedora clang build.)
2023-05-17 01:52:42 +02:00
Matthias Clasen
97bc4f77c6 gsk: Fix a refcounting mishap
This may fix #5823
2023-05-09 06:56:09 -04:00
Matthias Clasen
81fd9741ff gsk: Better handling of offscreens
Take the scale into account for sizing the
offscreens for masks, blends and cross-fades.
2023-05-05 11:37:23 -04:00
Matthias Clasen
ce6569d1a6 gsk: Avoid some offscreens
We don't have to be too conservative when checking
if a rect is contained in a rounded rect, we have
a precise api for this.
2023-05-04 22:30:12 -04:00
Matthias Clasen
319762b908 gsk: Extract scales properly from 2D transforms
We have the code to do it properly.
2023-05-01 13:45:20 -04:00
Matthias Clasen
e453a989df Improve rounded rect intersection
Move the rounded rect/rect intersection code to
gskroundedrect.c, make it more precise, and add
tests for it.

Update the callers in the GL renderer.
2023-05-01 13:45:20 -04:00
Matthias Clasen
f56328a6cc gsk: Fix mask transform handling
We must reset the modelview transform when
offscreen, or else we end up applying
it twice.
2023-05-01 13:45:20 -04:00
Matthias Clasen
552df197c4 gsk: Fix blend transform handling
We must reset the modelview transform when
rendering offscreen, or else we end up applying
it twice.
2023-05-01 13:45:20 -04:00
Matthias Clasen
4214067d52 gsk: Fix cross-fade transform handling
We must reset the modelview transform when
rendering offscreen, or else we end up applying
it twice.
2023-05-01 13:44:55 -04:00
Matthias Clasen
d9a2b74b4a gsk: More fixes
Work towards handling negative scales and
denormalized rects everywhere.
2023-05-01 13:43:33 -04:00
Matthias Clasen
4e501d2d44 gsk: Transform rounded rects better 2023-05-01 13:43:33 -04:00
Matthias Clasen
2f96a08b3f gsk: Plug a few memory leaks 2023-04-30 18:21:23 -04:00
Matthias Clasen
8292b846d5 gsk: Synchronize when using textures
Pass the GLsync object from texture into our
command queue, and when executing the queue,
wait on the sync object the first time we
use its associated texture.
2023-04-27 06:57:02 +02:00
Benjamin Otte
3aefed39b1 glcontext: Use GdkGLVersion elsewhere
... and add a convenience API to generate GL versions from strings to
make the gdk_gl_context_check() API nicer.
2023-04-27 02:13:32 +02:00
Matthias Clasen
83091c4f15 gsk: Use explicit switches
This makes it harder to forget to add new
node types here.
2023-04-19 09:19:12 +02:00
Matthias Clasen
503a5de7d1 gsk: Mask nodes support 2d transforms
When adding mask nodes, I overlooked that
we have two separate functions for determining
what transforms a node supports without offlines.

Since we claim that mask nodes support general
transform, they must certainly support 2d transforms
as well.
2023-04-19 08:13:55 +02:00
Matthias Clasen
519cde95f0 gsk: Cosmetics
Rename scale_factor to scale in various places,
now that it is no longer an int but a float.
2023-04-02 09:06:56 -04:00
Matthias Clasen
01108d4148 gsk: Pass scale as float to the command queue 2023-04-02 09:06:56 -04:00
Georges Basile Stavracas Neto
f3b8bd8a98 gsk/gl/renderjob: Decompose matrix for 3D transforms
While this can be more expensive, it's also correct.
2023-04-01 14:47:29 -03:00
Matthias Clasen
22ea1af569 gsk: Avoid copying GL texture in more cases
When the GL texture already has a mipmap, we don't
have to download and reupload it to generate one.

We differentiate the handling for texture scale nodes,
where we do want to force the mipmap creation even if
it requires us to reupload the GL texture, and plain
texture nodes, where we just take advantage of a
preexisting mipmap to allow trilinear filtering for
downscaling, or create one if we have to upload the
texture anyway.
2023-03-23 23:17:54 -04:00
Matthias Clasen
5de8e9ec6e gsk: Drop some unused arguments
All callers of the slice apis pass 0 for
min_rows and min_cols. So just drop these.
2023-03-22 00:14:43 -04:00
Matthias Clasen
d1fc44d3a6 gsk: Use overlapping slices
Store texture coordinates for each slice
instead of assuming 0,0,1,1, and generate
overlapping slices to allow for proper mipmaps.

This almost fixes trilinear filtering with
sliced textures.
2023-03-22 00:14:43 -04:00
Matthias Clasen
8f73a7c690 gsk: Cosmetics 2023-03-22 00:14:16 -04:00
Matthias Clasen
a19cf02b16 gsk: Use mipmaps when it is beneficial
If a texture node ends up getting scaled
down a lot, it helps to use trilinear filtering.
2023-03-19 21:45:30 -04:00
Benjamin Otte
b5345b7f25 glrenderer: Handle filters differently
Instead of uploading a texture once per filter, ensure textures are
uploaded as little as possible and use samplers instead to switch
different filters.

Sometimes we have to reupload a texture unfortunately, when it is an
external one and we want to create mipmaps.
2023-03-18 21:33:17 -04:00
Matthias Clasen
d31ba5f551 gsk: Drop texture subsetting
We don't do this for unfiltered textures either,
and with working slicing, it isn't needed.
2023-03-18 00:10:38 -04:00
Matthias Clasen
3877a2e533 gsk: Drop texture subsetting
We don't do this for unfiltered textures either,
and with working slicing, it isn't needed.
2023-03-17 11:25:38 -04:00
Matthias Clasen
b14a134a46 gsk: Add slicing to texture scale nodes
This makes it possible to use large textures
with filtering.

Fixes: #5664
2023-03-17 00:51:05 -04:00
Matthias Clasen
d1256648f4 gsk: Use linear filtering for sliced textures
We use linear for unsliced textures, so we need
to do the same for sliced ones.
2023-03-15 17:50:01 -04:00
Matthias Clasen
9f88dba162 gsk: Stop using g_slice 2023-03-14 14:56:42 -04:00
Matthias Clasen
c035384fc8 gsk: Mark mask nodes as 'supports transforms'
Just like blur nodes, the renderer can handle
these without creating an extra offscreen.
2023-03-14 01:14:57 -04:00
Matthias Clasen
dcc6cb8f1c gsk: Fix rotated texture scale nodes
This was causing us to render rotated texture scale
nodes to an unclipped offscreen, bringing 'giant
intermediate texture' problems back.
2023-03-14 05:36:08 +01:00
Matthias Clasen
0f02040292 gsk: Cache scaled texture
Keep the texture we create for texture scale nodes.

Fixes: #5642
2023-03-10 21:09:27 +01:00
Matthias Clasen
3a0152b65f gl: Respect clip wehn drawing scale nodes
Use the same approach and only create an offscreen
that is big enough for the clipped part of the scaled
texture.

If the clipped part is still too large for a single
texture, we give up and just render the texture without
filters (using the regular texture rendering code path
which supports slicing).

The following commit will add the texture-scale-magnify-10000x
test which fails without this fix.
2023-03-03 11:32:08 -06:00
Matthias Clasen
0eb791eaaa Make mask nodes more versatile
Add a GskMaskMode enumeration and implement it
in the GL and cairo renderers.
2023-02-14 19:07:01 -05:00
Kjell Ahlstedt
869ab1cd1b gskglrenderjob: Fix compilation with clang 2023-02-14 10:29:25 +01:00
Matthias Clasen
a9f50f1f7a gl: Support mask nodes
Add a shader for masking.
2023-02-12 08:35:25 -05:00
Matthias Clasen
0d58e5365d gsk: Introduce mask nodes
Add GskMaskNode, and support it in the render node
parser, in the inspector and in GtkSnapshot.

The rendering is just fallback for now.

Based on old work by Timm Bäder.
2023-02-12 08:35:25 -05:00
Matthias Clasen
d916659781 gl: Handle GskTextureScaleNodes 2023-02-11 15:09:38 -05:00
Matthias Clasen
82c02574f1 gl: Make texture slicing more flexible
Allow to specify the filtering to use for the slices,
and allow forcing the number of slices. This will be
used in the next commit.
2023-02-11 15:09:38 -05:00
Matthias Clasen
26e6d2106b gl: Pass filters down from visit_texture_node
For now, we always pass GL_LINEAR.
2023-02-11 15:09:38 -05:00
Matthias Clasen
b937c19dd4 gsk: Introduce GskTextureScaleNode 2023-02-11 15:09:38 -05:00
Matthias Clasen
b441c684ab gsk: Avoid a crash with negative scales
Don't crash when both scale_x and scale_y are -1.

A test is included.
2022-11-20 12:13:02 -05:00
Matthias Clasen
b12d31d189 Fix spelling errors
These were pointed out by codespell.
2022-11-17 22:49:45 -05:00
Matthias Clasen
8c548d5579 Merge branch 'nonoverlapping-containers' into 'main'
gsk/gl: Avoid offscreening in more cases

See merge request GNOME/gtk!4619
2022-04-07 14:32:53 +00:00
Matthias Clasen
d72ed045df gsk/gl: Use pre-collected opacity information
We now collect this information during node
construction, so use it here.

The concrete change here is that we now avoid
offscreens for container nodes with multiple children,
as long as they don't overlap. In particular, this
avoid offscreens for ellipsized dim labels.
2022-04-05 14:57:38 -04:00
Sebastian Keller
85a6517d65 gsk/gl: Always align offscreen rendering with the pixel grid
This fixes two issues with the offscreen rendering code for nodes with
bounds not aligned with the pixel grid:

1.) When drawing to an offscreen buffer the size of the offscreen buffer
was rounded up, but then later when used as texture the vertices
correspond to the original bounds with the unrounded size. This could
then result in the offscreen texture being drawn onscreen at a slightly
smaller size, which then lead to it being visually shifted and blurry.

This is fixed by adjusting the u/v coordinates to ignore the padding
region in the offscreen texture that got added by the size increase from
rounding.

2.) The viewport used when rendering to the offscreen buffer was not
aligned with the pixel grid for nodes at coordinates not aligned with
the pixel grid. Then because the content of the offscreen buffer is not
aligned with the pixel grid and later when used as textures sampling
from it will result in interpolated values for an onscreen pixel. This
could also result in shifting and blurriness, especially for nested
offscreen rendering at different offsets.

This is fixed by adding similar padding at the beginning of the
texture and also adjusting the u/v coordinates to ignore this region.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3833
2022-04-04 21:40:01 +02:00
Christian Hergert
cbbca38d88 gsk/gl: use consistent library naming 2022-03-18 14:59:49 -07:00