Commit Graph

1533 Commits

Author SHA1 Message Date
Christian Hergert
56daad9c35 ngl: ensure vertices buffer allocates enough vertices
It's not guaranteed that a single power of two growth will be enough.

Fixes #3770
2021-03-18 10:43:24 -07:00
Andrey Kozlovskiy
6b48fb767d Fix a typo in gsk_border_node_diff
Typo was introduced in !3278 and results in an incorrect handling of different uniformity.
2021-03-17 15:38:01 +00:00
Kjell Ahlstedt
50beae7541 meson: Find libcairo-script-interpreter when cairo is a subproject
If cairo is a subproject, it's not necessarily installed when gtk
is built. In the build tree, libcairo-script-interpreter is not stored
in the same directory as other cairo libraries.
2021-03-16 11:47:28 +01:00
Benjamin Otte
1fd534ef1e ngl: Remove duplicate check
We check the extents, so there's no need to check overlap before.
2021-03-15 01:30:34 +01:00
Matthias Clasen
28de2eecc9 ngl: Special-case css backgrounds
Recognize a common pattern: A rounded clip with
a color node, followed by a border node, with the
same outline. This is what CSS backgrounds frequently
produce, and we can render it more efficiently with
a combined shader.
2021-03-14 16:49:31 -04:00
Matthias Clasen
ed3f0012b1 ngl: Don't bother with uniform border nodes
Now that colors aren't uniforms anymore, we don't
win much by using the inset_shadow shader. The fragment
shaders of inset_shadow and border are identical. And
the regular border setup does nine-slicing.
2021-03-14 16:49:31 -04:00
Matthias Clasen
51074ca5df ngl: Small shader improvements
Add a variant of gskSetOutputColor that saves a
few multiplications, and use it where possible.
2021-03-14 16:49:31 -04:00
Matthias Clasen
8aac574d63 ngl: Improve the coloring shader
Since we are now passing a float anyway, we can avoid
the branch in the fragment shader.
2021-03-14 16:49:31 -04:00
Matthias Clasen
c1f98d6837 ngl: Improve the gradient shaders
Use a define for MAX_COLOR_STOPS, and give the loop
a fixed limit.
2021-03-14 16:49:31 -04:00
Matthias Clasen
3f60c39de4 ngl: Rewrite gsk_ngl_render_job_visit_text_node
Make this more compact, and thus easier to read.
2021-03-14 16:49:31 -04:00
Matthias Clasen
4aa570ba88 ngl: Drop gsk_ngl_render_job_set_color
Colors are not state that we carry across draw ops,
so setting the color on the render job doesn't make
much sense. Instead, pass the color to the various
draw calls. Add a few new ones for that purpose.

Also, shorten the names of some by going from
'load_vertices_from_offscreen' to 'draw_offscreen'.
2021-03-14 16:49:31 -04:00
Matthias Clasen
233969e9e4 ngl: Refactor gsk_ngl_render_job_visit_border_node
With color sorting out of the picture, this can
be much simpler.
2021-03-14 16:49:31 -04:00
Matthias Clasen
19e3a6af5d ngl: Consistently use gsk_scaled_premultiply
Its not going to make much of a difference, but we
can just as well be consistent.
2021-03-14 16:49:31 -04:00
Matthias Clasen
29501f5398 ngl: Fix up uniform enums
This got messed up when color was changed from
a uniform to an attribute in 06d5c8e72d.
2021-03-14 16:49:31 -04:00
Emmanuel Gil Peyrot
064947356a ngl: Fix the coloring shader on GLES 2.0
Integer varyings didn’t exist in GLSL ES 1.00, neither did the flat
attribute.
2021-03-13 22:00:54 +00:00
Matthias Clasen
42dfc21b2d ngl: Fix up some debug printouts 2021-03-12 18:26:15 -05:00
Matthias Clasen
daed57c30e Merge branch 'wip/chergert/fewer-uniforms' into 'master'
ngl: apply fewer uniforms

See merge request GNOME/gtk!3289
2021-03-12 22:55:00 +00:00
Matthias Clasen
ebe30d851b ngl: Identify shaders
Add a comment with a name to each shader. That makes
identifying the shaders in apitrace much easier.
2021-03-12 15:35:40 -05:00
Christian Hergert
f97ce21e59 ngl: reintroduce comparison checks
This reduces how many changes we make when recording uniform state, which
increases the chances that the data offset will be the same when applying
uniforms.
2021-03-12 11:47:15 -08:00
Christian Hergert
0b7d8e19c3 ngl: add front cache to reduce uniform changes
Since we make full snapshots when recording uniform state of batches, we
need to perform some deduplication to avoid so many repeated uniform calls.

This uses a closed hashtable to determine if we are likely changing the
value to something new.

This does not currently compare values, it instead only compares that we
are going to point at a new offset into the uniform buffer. We could go
further if we compare upon updating values (we did that early on in the
prototype) so that offsets are less likely to be changed.
2021-03-12 11:22:59 -08:00
Matthias Clasen
6a30c6b01c ngl: Make the coloring shader more versatile
When the color passed is transparent black, use
the color from the texture as source, instead of
as mask. This lets use use the coloring program
both for regular and color glyphs, avoiding
program changes in text with Emoji.
2021-03-12 13:19:37 -05:00
Matthias Clasen
06d5c8e72d ngl: Set color as vertex attribute
Instead of using uniforms for color used in multiple
programs, pass it as vertex attributes. This will let
us batch more draw calls, since we don't have to change
uniforms so often. In particular, for syntax-highlighted
text.
2021-03-12 13:18:47 -05:00
Matthias Clasen
3252f1e301 gsk: Give ngl its own shader sources
We may want to change the interface between the
shaders and the renderer for ngl, and therefore,
sharing the shaders between gl and ngl will not
be practical, going forward.
2021-03-12 13:18:47 -05:00
Matthias Clasen
7450427757 gsktransform: Convert docs 2021-03-11 16:37:32 +00:00
Matthias Clasen
b836707979 gskroundedrect: Convert docs 2021-03-11 16:37:32 +00:00
Matthias Clasen
70f805cdfe rendernode: Add property annotations
Connect properties, getters, and setters with annotations
2021-03-11 16:37:32 +00:00
Matthias Clasen
458bc5500c gskrenderer: Add property annotations
Connect properties, getters, and setters with annotations
2021-03-11 16:37:32 +00:00
Matthias Clasen
22b375534e glshader: Add property annotations
Connect properties, getters, and setters with annotations
2021-03-11 16:37:32 +00:00
Matthias Clasen
ca3120919f docs: Improve gsk docs
Convert link formats, add summaries, and make
a few missing things show up in the docs.
2021-03-11 16:37:31 +00:00
Benjamin Otte
c696385130 Merge branch 'wip/otte/for-master' into 'master'
Wip/otte/for master

See merge request GNOME/gtk!3279
2021-03-09 19:11:09 +00:00
Matthias Clasen
124f60593b nodeparser: Print debug message before child
This puts the message up top, where it can be seen,
and not at the other end of an endless tree of children.

Update tests to match.
2021-03-09 12:15:25 -05:00
Matthias Clasen
09af40faeb ngl: Render simple borders simply
Use 4 color commands for uniform, rectilinear
borders. Most of our borders are rounded with
Adwaita, but there are still some of these.
2021-03-09 12:15:25 -05:00
Matthias Clasen
bf59ddd01d gsk: Add gsk_border_node_get_uniform_color
Maintain this bit of information separately,
it will be useful in the next commit.
2021-03-09 12:15:25 -05:00
Benjamin Otte
fea67dea6a vulkan: Improve rounded rect clipping
Handle the case where the inner rounded rect is fully contained
within the outer rounded rect.
2021-03-09 17:43:28 +01:00
Benjamin Otte
9f18c138d1 vulkan: Fix invalid read
Look at the right rect to compute circularness
2021-03-09 17:43:28 +01:00
Matthias Clasen
07ca46e92c Merge branch 'ngl-clip-classification' into 'master'
Ngl clip classification

See merge request GNOME/gtk!3274
2021-03-08 20:20:50 +00:00
Matthias Clasen
57e354c297 glsl: Make rounded rect clipping cheaper
Add early acceptance checks for non-corner cases.
2021-03-08 14:41:48 -05:00
Matthias Clasen
5f664dbbbb Revert "ngl: Remove a few redundant checks"
This reverts commit 4375f8e382.

These were not redundant after all, as pointed out by Timm.
2021-03-08 08:10:35 -05:00
Matthias Clasen
46d1fc1c24 gsk: Use clip defines in shaders
Use the NO_CLIP and RECT_CLIP defines to make
simpler shaders for these cases.

Note: This does not work yet.
2021-03-07 20:30:45 -05:00
Matthias Clasen
2c05b758c7 ngl: Add infrastructure for clip-variants of shaders
Make ngl compile each shader three times.
Once with #define NO_CLIP 1
once with #define RECT_CLIP 1
and once as before.
2021-03-07 20:30:45 -05:00
Matthias Clasen
5788338a14 ngl: Classify clips
Maintain the 'fully contained' information in the clip
stack. This will let us pick simpler shaders in the future.
2021-03-07 20:30:45 -05:00
Matthias Clasen
c60a316e22 Move gtk_rounded_rect_scale_affine to the right place
This function should live with the rest of the
GskRoundedRect code in gskroundedrect.c.
2021-03-07 15:17:32 -05:00
Matthias Clasen
87b800c11d Merge branch 'bilelmoussaoui/gi-annotations' into 'master'
g-i: add missing since annotations for 4.2

See merge request GNOME/gtk!3268
2021-03-07 19:46:59 +00:00
Bilal Elmoussaoui
6e903e13a5 g-i: add missing since annotations for 4.2 2021-03-07 19:50:32 +01:00
Matthias Clasen
d0dce4cfa1 ngl: Treat radial gradients like others
Handle colorstop overflow for radial gradients
the same way we do for linear and conic gradients.
2021-03-07 10:18:47 -05:00
Matthias Clasen
4375f8e382 ngl: Remove a few redundant checks
We bail early on invisible nodes. No need to
repeat that check in individual visit functions.
2021-03-07 10:18:47 -05:00
Matthias Clasen
6ab779cd06 roundedrect: Remove unclear language from the docs
The various intersection function for rounded rects are
precise. No need to add wordy disclaimers about the handling
of the corners.
2021-03-07 09:04:43 -05:00
Benjamin Otte
91932ada63 vulkan: Handle simple transforms in the clipping code
Requires pushing the GskTransform into the clipping code so that we
can actually look at its category.
2021-03-05 19:36:36 -05:00
Matthias Clasen
dbb264dfc9 vulkan: Add visible fallback rendering
Hook up the "Show fallback rendering" switch for Vulkan.

This brings home the sobering truth that the Vulkan renderer
is doing *all* fallback, since we switched from offset nodes
to transform nodes.
2021-03-05 18:42:04 -05:00
Christian Hergert
b368d3abde ngl: remove unnecessary suffix array
We didn't end up using this in the final version, so we can just delete
it and avoid MSVC issues.
2021-03-03 13:03:24 -08:00
Matthias Clasen
96ac85038b rendernode: Fix glyph serialization
We serializing to a string of ASCII, we need to
escape some chars, such as '\' and '"'.

Fixes: #3710
2021-03-02 11:32:29 -05:00
Christian Hergert
d6694a4408 ngl: fix typo from NGL rename 2021-03-01 10:28:26 -08:00
Matthias Clasen
e9ed874231 gsk: Replace a last instance of "next"
The output of GSK_RENDERER=help was still talking about
the "next" renderer, while actually looking for "ngl".
2021-02-23 18:36:41 -05:00
Christian Hergert
2a38cecd33 gsk: add OpenGL based GskNglRenderer
The primary goal here was to cleanup the current GL renderer to make
maintenance easier going forward. Furthermore, it tracks state to allow
us to implement more advanced renderer features going forward.

Reordering

This renderer will reorder batches by render target to reduce the number
of times render targets are changed.

In the future, we could also reorder by program within the render target
if we can determine that vertices do not overlap.

Uniform Snapshots

To allow for reordering of batches all uniforms need to be tracked for
the programs. This allows us to create the full uniform state when the
batch has been moved into a new position.

Some care was taken as it can be performance sensitive.

Attachment Snapshots

Similar to uniform snapshots, we need to know all of the texture
attachments so that we can rebind them when necessary.

Render Jobs

To help isolate the process of creating GL commands from the renderer
abstraction a render job abstraction was added. This could be extended
in the future if we decided to do tiling.

Command Queue

Render jobs create batches using the command queue. The command queue
will snapshot uniform and attachment state so that it can reorder
batches right before executing them.

Currently, the only reordering done is to ensure that we only visit
each render target once. We could extend this by tracking vertices,
attachments, and others.

This code currently uses an inline array helper to reduce overhead
from GArray which was showing up on profiles. It could be changed to
use GdkArray without too much work, but had roughly double the
instructions. Cycle counts have not yet been determined.

GLSL Programs

This was simplified to use XMACROS so that we can just extend one file
(gskglprograms.defs) instead of multiple places. The programs are added
as fields in the driver for easy access.

Driver

The driver manages textures, render targets, access to atlases,
programs, and more. There is one driver per display, by using the
shared GL context.

Some work could be done here to batch uploads so that we make fewer
calls to upload when sending icon theme data to the GPU. We'd need
to keep a copy of the atlas data for such purposes.
2021-02-23 14:41:52 -08:00
Matthias Clasen
5a8e2a8c2d gsk: Add a missing GDK_AVAILABLE_IN_ALL
gsk_text_node_has_color_glyphs was not properlty exported,
by accident.

Fixes: #3675
2021-02-17 15:20:24 -05:00
Emmanuele Bassi
a9c616284a gsk: Move from g_memdup() to g_memdup2()
The g_memdup() function is replaced by a safer version in newer versions
of GLib.
2021-02-11 14:22:22 +00:00
Christian Hergert
6fab195643 gsk: move transform structure to private.h
This allows using the category without having to call a function from the
hot paths of the renderer.
2021-02-10 16:14:59 -08:00
Matthias Clasen
dff2aa20ff gl: Fixed clipped offscreen rendering
When we are rendering a texture node to an offscreen,
and we have a clip, we must force the offscreen rendering.
Otherwise, the code will notice: Hey, it already is a texture
node, so no need to render it to a texture again. But when
clipping is involved, that is exactly what we want to do.

Testcase included.

Fixes: #3651
2021-02-09 22:43:15 -05:00
Christian Hergert
86c5f2df6e gsk: make gsk_render_node_get_node_type() use const
There isn't any state to modify in the type so we can use const here.
Doing so allows some of the renderer code to use const across a
number of functions so that repeated calls are elided if inlined.
2021-02-08 11:29:43 -08:00
Christian Hergert
09b447a9e1 gsk: make render node getters pure
These do not do modify anything so they can be marked as pure to
potentially ellide calls. Since they do dereference, I do not believe
we can make them const although that is unclear since we could technically
just return a pointer + offset. Therefore it *might* be possible to also
make these G_GNUC_CONST.
2021-02-08 11:29:39 -08:00
Christian Hergert
161ddcfa92 gsk: make render node getters const
This also removes the return if fail macros from these as a good portion
of them didn't have them anyway. I think it's fair to say that access to
these incorrectly is a programmer error.

It significantly reduces the amount of code generated into generally a
movss,ret.
2021-02-08 11:29:36 -08:00
Matthias Clasen
3c15fa96bc vulkan: Fix image uploading by regions
This code did not make sense; it was incrementing
the wrong variable.

Pointed out in https://www.viva64.com/en/b/0793/
2021-02-04 00:12:44 -05:00
Timm Bäder
79f273348d gl renderer: Fix viewport computation when rendering offscreen
Fixes #3615
2021-01-29 10:37:48 +01:00
Timm Bäder
8ebcef97ff shader builder: Improve error output 2021-01-29 09:45:25 +01:00
Matthias Clasen
20fb155e8c gsk: Fix render node serialization
When looking for ascii glyphs, we must match
the pango shape flags that GTK is using.
2021-01-28 18:19:42 -05:00
Matthias Clasen
0d0bdaa02e gsk: Fix a thinko
With subpixel positioning, we need to offset the
cached glyphs by their phase.
2021-01-28 18:16:16 -05:00
Fabio Lagalla
d83502d054 gskglshaderbuilder: bind correct uv location 2021-01-28 17:08:46 +01:00
Fabio Lagalla
a1dd6521e8 gskglrenderer: Remove switch fallthrough comments 2021-01-27 12:52:11 +01:00
Fabio Lagalla
0088f840fe gskrendernode: Cache angle in conic gradients 2021-01-27 12:44:10 +01:00
Fabio Lagalla
1b698c896e gskglrenderer: Use gboolean instead of bool 2021-01-27 12:44:10 +01:00
Fabio Lagalla
04000f28e7 gskglrenderer: First class support of repeating-radial-gradient 2021-01-27 12:44:10 +01:00
Fabio Lagalla
976a05f6eb gskglrenderer: First class support of repeating-linear-gradient 2021-01-27 12:44:10 +01:00
Fabio Lagalla
b15902bf44 gskglrenderer: Optimize conic-gradient shader 2021-01-27 12:44:10 +01:00
Fabio Lagalla
5ac7529771 gskglrenderer: Optimize radial-gradient shader 2021-01-27 12:44:10 +01:00
Fabio Lagalla
bbf68c0d9d gskglrenderer: Optimize linear-gradient shader 2021-01-27 12:44:10 +01:00
Timm Bäder
d9f6b268d3 gl renderer: Use rect_contains_rect() copy
And this way the contains_rect() inside
rounded_inner_rect_contains_rect() goes from 3.3% to 0.79% in the
fishbowl when rendering the levelbars.
2021-01-17 04:39:26 +01:00
Timm Bäder
4d7a01562e gl renderer: Don't reset offset when drawing offscreen 2021-01-17 04:39:26 +01:00
Timm Bäder
650eed7f72 gl renderer: Properly y-flip non-offscreen children of rounded clips 2021-01-17 04:39:26 +01:00
Fabio Lagalla
8c61038b9f gl renderer: print fragment shader info
It was logged twice the vertex shader info, instead
2021-01-11 17:06:03 +01:00
xndcn
34ffdc6e3f gl: Fix implicit leaking of shader object
According to OpenGL spec, a shader object will only be flagged
for deletion unless it has been detached; when a program object
is deleted, those shader objects attached to it will be detached
but not deleted unless they have already been flagged for deletion.

So we shall detach a shader object before it is deleted, and delete
it before the program object is deleted best.
2020-12-29 23:50:45 +08:00
Timm Bäder
108933b655 Merge branch 'wip/chergert/volatile-fixes' into 'master'
types: fix various use of volatile in type registration

See merge request GNOME/gtk!2865
2020-12-29 07:49:12 +00:00
Emmanuel Gil Peyrot
28c4adac24 Fix gtk4-demo’s gears demo on OpenGL ES
Here is a command to reproduce this testcase:
GDK_DEBUG=gl-gles gtk4-demo --run gears

Without this patch, Mesa throws this compile error:
0:130(13): error: no matching function for call to `mod(error, float)'; candidates are:

This is caused by `u_rotation - 90` being of type error since
`u_rotation` is a float and it’s illegal to subtract it with an integer.
2020-12-25 01:21:08 +01:00
Matthias Clasen
7e579bb59a Merge branch 'wip/otte/for-master' into 'master'
Wip/otte/for master

See merge request GNOME/gtk!2997
2020-12-24 07:13:22 +00:00
Benjamin Otte
dee863dbb2 rendernode: Bail if matrix is invalid
Invalid matrices are okay in GSK (and GL), but not in Cairo.

Testcase included.
2020-12-24 06:38:45 +01:00
Matthias Clasen
e854b90293 Merge branch 'wip/baedert/for-master' into 'master'
Wip/baedert/for master

See merge request GNOME/gtk!2990
2020-12-22 04:53:31 +00:00
Matthias Clasen
9cec9e4ce2 gsk: Export the glyph serialization privately
We want to use the same serialization in the inspector,
so export this function.
2020-12-21 13:11:08 -05:00
Matthias Clasen
26119af7a6 gsk: Improve glyph serialization
The special case for ASCII glyphs is unfortunately not
working very well, because of an oversight in pango:
When I added subpixel positioning, I made pango_shape()
default to not rounding, and make PangoLayout call
pango_shape_with_flags() and pass the rounding information
down. The upshot is that we need to use the _with_flags
variant here and tell it to round position, so it matches
what the text node contains.
2020-12-21 13:08:34 -05:00
Matthias Clasen
aa95ae774f gsk: Fix serialization of glyphs
We were forgetting to put a space between two numbers
in some cases, confusing the parser.

Test included.

Fixes: #3496
2020-12-21 10:49:56 -05:00
Timm Bäder
526c76181e gl renderer: Check for pointer equality in rounded_rect_equal 2020-12-21 15:22:08 +01:00
Timm Bäder
9fefa7b44c rendernode: Different uniformity in border nodes
Means they are different and a diff is impossible.
2020-12-21 10:26:03 +01:00
Timm Bäder
a2a70c3b65 rendernode: Sort diff() requirements by complexity 2020-12-21 10:26:03 +01:00
Timm Bäder
fdda4e4e99 GskTransform: Add nullable annotations to _equals()
Both can be NULL here.
2020-12-21 10:26:03 +01:00
Timm Bäder
e1cf0cff26 gl renderer: Proper state tracking for color matrix ops 2020-12-21 10:26:03 +01:00
Timm Bäder
634fa772c9 gl renderer: Add missing debug output for repeat ops 2020-12-21 10:26:03 +01:00
Timm Bäder
4b3bbe0ecd gl renderer: Create shader-global uniform ops on draw()
This way we can render the first frame of tests/testoutsetshadowdrawing
in 153 ops instead of 183.

And the first frame of gtk4-demo in 260 instead of 300.
2020-12-21 10:26:03 +01:00
Timm Bäder
cde43541d0 gl renderer: Unify new clip/viewport rects in blur_texture() 2020-12-21 10:26:03 +01:00
Timm Bäder
186287ecfb GskTransform: Fix identity transform class name 2020-12-21 10:26:02 +01:00
Timm Bäder
bd5d1615ac GskTransform: Avoid a ref+unref pair
If gsk_transform_is_identity() returned FALSE for the next transform,
the previous code did a ref + unref pair, even though it was unneeded.
2020-12-21 10:26:02 +01:00
Timm Bäder
a8213d7f45 gl renderer: Avoid setting modelview to identical values
The previous comment here was incorrect. We can save the op itself, we
just can't save us the entry in the modelview stack.
2020-12-21 10:26:02 +01:00
Matthias Clasen
d5143a1bf0 Revert "gl renderer: Render too big textures to the clipped area"
This reverts commit 7f6608cbed.
2020-12-19 11:43:56 -05:00