Commit Graph

1738 Commits

Author SHA1 Message Date
Matthias Clasen
1d9c581f10 ngl: Allow passing bounds to update_clip
update_clip only uses the bounds of the node that
we are currently passing. This opens the door to
updating the clip while handling a single node.
2021-04-11 12:54:17 -04:00
Matthias Clasen
6bfb57db16 ngl: Small optimization for shadows
When 9-slicing shadows, omit the center tile when it is
entirely contained in the outline (that is not always
the case, depending on corners and offsets).
2021-04-11 12:54:07 -04:00
Matthias Clasen
f8f2f2944f roundedrect: Speed up contains_rect and friends
gsk_rounded_rect_contains_rect was calling
gsk_rounded_rect_contains_point, which potentially
checks all four corners, for a total of up to 16
corner/point checks. But there is no need to do
more than 4 such checks to answer the question.
2021-04-11 12:52:30 -04:00
Matthias Clasen
aaf17fd3d0 ngl: Small optimization
We really want equality here.
2021-04-11 12:50:50 -04:00
Matthias Clasen
e6599c6c4f gsk: Don't overshadow
Reduce the cairo shadows to the same size as their GL brethren.
2021-04-09 21:47:55 -04:00
Matthias Clasen
bfe4aea981 ngl: Add a program change counter
Count how often we change programs during a frame.
2021-04-09 00:52:18 -04:00
Matthias Clasen
0caa28c1de ngl: Optimize underlines in text
Opportunistically use the coloring program for
drawing underlines instead of the color program.
This avoids program changes in the middle of
text.

For the Emoji text scrolling benchmark, this reduces
the program changes per frame from > 1000 to around 100.
2021-04-08 23:37:51 -04:00
Matthias Clasen
d8ba4b4114 ngl: Reserve a pixel in texture atlases
This will be used for coloring from the texture.
2021-04-08 23:34:37 -04:00
Matthias Clasen
e7963945bb ngl: Fix an oversight
All the rest of debug spew goes to stderr here.
2021-04-08 23:34:37 -04:00
Matthias Clasen
2d7169fd5f Work around compiler shortcomings on macOS
alias attributes don't work on Darwin, so
do without.
2021-04-07 22:38:47 -04:00
Matthias Clasen
885a6b8ebc gsk: Add runtime checks for F16C
Use an IFUNC resolver to determine whether we can use
intrinsics for FP16 conversion. This requires the functions
to be no longer inline.

Sadly, it turns out that __builtin_cpu_supports ("f16c")
doesn't compile on the systems where we want it to prevent
us from getting a SIGILL at runtime.
2021-04-07 22:21:23 -04:00
Matthias Clasen
9d81c129fc Add an option to disable F16C
And add a compile time check for the presence of this
CPU feature.
2021-04-07 22:21:23 -04:00
Matthias Clasen
38c6fe2ce4 Move color conversion up
Doing the color conversion early lets us reuse
the results whenever we do more than one draw
per node.
2021-04-07 21:30:43 -04:00
Matthias Clasen
7fe7b7ac7d ngl: Use a constant for (fp16)-1
No need to convert that again for every glyph.
2021-04-07 21:30:43 -04:00
Matthias Clasen
ae7f52d301 ngl: Reduce vertex storage
We only have one shader that uses the color2 attribute,
and it doesn't use the uv attribute, so save vertex
memory by putting those in the same space.

This reduce the per vertex space from 32 to 24 bytes.
2021-04-07 21:30:43 -04:00
Matthias Clasen
8b1fcb58e8 ngl: Use fp16 for colors
This reduces the size of our Vertex struct from
48 to 32 bytes. It would be nicer if we could store
the colors in fp16 format in the rendernodes, and
avoid conversion here. But this is still good.
2021-04-07 21:30:43 -04:00
Matthias Clasen
a1ece16143 ngl: Fix an oversight
We were special-casing 2D affine transforms,
but overlooked even simpler transforms.
2021-04-05 08:47:53 -04:00
Matthias Clasen
900a4e4d31 gsk: Move shader resources
Move the resources of each renderer to its subdirectory.
We've previously done that for the ngl renderer, but it
is better to be consistent and do it for all the renderers.
2021-04-03 08:24:58 -04:00
Matthias Clasen
ee63b84b6a gsk: Rename resource paths
Make the shaders of the gl renderer live under
/org/gtk/libgsk/gl. This is purely cosmetic.
2021-04-03 08:10:58 -04:00
Matthias Clasen
efb5e793a4 nodeparser: Change the serialization
Arrange things so that non-child parameters
are always printed before the children. This
greatly helps with readability, which really
suffers when there's hundreds of lines of indented
children between the node start and its parameters.

Update all affected tests.
2021-04-02 20:38:32 -04:00
Matthias Clasen
8d603dfe99 ngl: Avoid huge intermediate textures
Instead of rendering the unclipped child to a texture
(and risking blowing the texture size limit, and bad
downscaling), just render the clipped region, and live
with the fact that we can't cache the rendered texture.

This avoid bad artifacts when scrolling long textviews
in rounded clips.
2021-04-02 19:33:44 -04:00
Matthias Clasen
3ff04976e3 ngl: Plug a memory leak
This was introduced in f9457af128.
2021-04-02 18:41:53 -04:00
Matthias Clasen
54ff4fd45f ngl: Fix downscaled textures
It is not pretty, but at least it works now.
2021-04-02 18:33:01 -04:00
Matthias Clasen
f9457af128 ngl: Fix offscreen rendering with transforms
There was confusion here about the handling of the
modelview transform. The modelview transform we are
getting is already set up for rendering the node
we are given, so keep it - except for possible adding
an extra scale on top when the texture would otherwise
be too big.
2021-03-31 14:36:24 -04:00
Matthias Clasen
94f0a4ef2c ngl: Be explicit about offscreen clipping
Explicitly set all the input arguments.
This makes it clearer what is going on.
2021-03-31 14:34:16 -04:00
Matthias Clasen
53e75936cb ngl: Add sonme comments
The GskNglRenderOffscreen struct is a mix of in and
out arguments. Better annotate that a little bit.
2021-03-31 14:32:47 -04:00
Matthias Clasen
ba4e66d189 ngl: Avoid a goto
Reshuffle the code slightly, so we can use a continue
instead.
2021-03-30 00:34:52 -04:00
Matthias Clasen
2c33550048 gsk: Avoid empty glyphs early
Strip out PANGO_GLYPH_EMPTY when text nodes are
constructed. Then we don't have to check this special
case in the inner loop in visit_text_node.
2021-03-30 00:34:52 -04:00
Matthias Clasen
3add99a9a8 ngl: Speed up glyph loop
Move some work out of the loop in visit_text_node.
This takes advantage of the fact that the yoffset
of most glyphs is zero, so yphase generally does
not change in a line of text.
2021-03-30 00:19:28 -04:00
Matthias Clasen
d4ea2e848d ngl: We only need two bits for phases
We use 4 phases, so 2 bits are enough.
2021-03-30 00:19:28 -04:00
Matthias Clasen
5847f75c57 ngl: Cosmetics
Remove a local variable in gsk_render_job_visit_text_node.
2021-03-29 15:17:20 -04:00
Matthias Clasen
ce2c3efc91 ngl: Improve packing
Pack texture cache entries slightly better.

There was a 4 byte hole here.
2021-03-29 15:17:10 -04:00
Matthias Clasen
2599c5aed3 gsk: Typo fix 2021-03-29 15:16:44 -04:00
Matthias Clasen
bca39e2605 ngl: Typo fix 2021-03-29 15:16:25 -04:00
Matthias Clasen
2d5dd7b3d7 gsk: Make rendernode diffing smarter
Allow comparing container nodes to any other
node, by pretending the other node is a single
child container (if it isn't one already).

This fixes a glitch where we redraw the full
entry text when the blinking cursor goes to
opacity 0, since GskSnapshot then optimizes
away first the opacity node, and then the
single-child container.
2021-03-28 10:26:06 -04:00
Matthias Clasen
0904dd29c2 gsk: Use floorf for floats 2021-03-28 10:26:06 -04:00
Matthias Clasen
279b9347fd gsk: Cosmetics 2021-03-28 10:26:02 -04:00
Matthias Clasen
2a2ae16894 ngl: Cosmetics
Remove a commented out line that snuck in with
a recent commit.
2021-03-28 10:26:02 -04:00
Matthias Clasen
e7f9d56da5 ngl: Fix an uninitialized read
We were using the wrong matrix here.
valgrind pointed this point.
2021-03-27 16:23:40 -04:00
Xavier Claessens
086e1ed39f ngl: Fix crash with intel driver on Windows when compiling shaders
Fixes #3783.
2021-03-25 08:20:30 -04:00
Christian Hergert
f8a6a09896 ngl: move uniform key mapping into uniform state
Previously, we translated the uniform key (an enum) into a location within
the shader program in GskNglProgram. A number of performance improvements
were focused around having low nubers for the uniform locations. Generally
this is the case, but some drivers such as old Intel drivers on Windows
may use rather large numbers for those.

To combat this, we can push the translation of uniform keys into locations
at the GskNglUniformState level so that we work with unranslated keys
through the process until applying them.

Fixes #3780
2021-03-23 13:44:26 -07:00
Matthias Clasen
157218c507 Merge branch 'wip/baedert/for-master' into 'master'
ngl: Remove unused function

See merge request GNOME/gtk!3332
2021-03-22 11:17:58 +00:00
Matthias Clasen
7a56aa910e ngl: Fix a rounding error in subpixel positioning
1024 / 4 is 256, not 250.
2021-03-21 16:05:10 -04:00
Matthias Clasen
bd0df03248 gl: Fix a rounding error in subpixel positioning
1024 / 4 is 256, not 250.
2021-03-21 16:05:10 -04:00
Matthias Clasen
2e69273922 ngl: Remove an unused field
We are ignoring the debug nodes, so the
debug_groups string chunk is unused.
2021-03-21 16:05:10 -04:00
Matthias Clasen
1e014f4291 ngl: Always populate the glyph front cache
There is no reason not to do this also in the
case when we upload the glyph.
2021-03-21 16:05:10 -04:00
Matthias Clasen
fbe47106e7 ngl: Use floorf consistently 2021-03-21 16:05:10 -04:00
Timm Bäder
ea93c40644 ngl: Remove unused function 2021-03-21 18:00:10 +01:00
Matthias Clasen
b253aca883 ngl: Improve the glyph front cache
The effectiveness of the front cache is limited by
subpixel positioning making it very likely that we
will meet the same glyph in  different x phases inside
a single line of text.

Factoring the xphase into the front cache key makes things
better. For the string eeeeeeeeeeeeeeeeeee

before: 0% front cache hits
after: >90% front cache hits
2021-03-19 14:32:03 -04:00
Matthias Clasen
5ac7f7c2f6 ngl: Drop an unused struct member
GskNglGlyphLibrary.hash_table wasn't used.
2021-03-19 14:05:15 -04:00
Matthias Clasen
830efa6ce2 Revert "ngl: Remove duplicate check"
This reverts commit 1fd534ef1e.

This change revealed that we are not treating damage regions
correctly, and we regularly end up with
2021-03-19 13:17:02 -04:00
Matthias Clasen
8fdedbd73b Merge branch 'ngl-by-default' into 'master'
gsk: Make ngl the default OpenGL renderer

See merge request GNOME/gtk!3313
2021-03-19 02:01:34 +00:00
Christian Hergert
0f0ee97e1e ngl: clear Glyph front cache at the beginning of a frame
We don't want to be responsible for duplicating the effort of the hash
table, we just want to speed up subsequent lookups. Otherwise, we risk
not marking glyph usage when tracking usage for compaction.
2021-03-18 18:00:04 -07:00
Christian Hergert
af80f3a976 ngl: implement atlas compaction
This required finishing up the begin_frame/end_frame semantics for
GskNglTextureLibraryw which was apparently overlooked.

The driver was changed to provide more information to the library when
beginning frames. We do not need to use end_frame so that was removed.

The frame age is the same as GL (60) but I do wonder if that is based
on seconds if we should be using something longer for situations where
we have higher frame rates.

Fixes #3771
2021-03-18 17:59:56 -07:00
Matthias Clasen
19d9c78514 gsk: Make ngl the default OpenGL renderer
We will keep the original GL renderer around for
a while, to have an alternative. But we want to
get wider testing of the new renderer.
2021-03-18 15:00:39 -04:00
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
Matthias Clasen
12611fa142 Revert "gl renderer: Take a out graphene_rect in blur_node()"
This reverts commit 7eece7e769.
2020-12-19 11:43:43 -05:00
Timm Bäder
7eece7e769 gl renderer: Take a out graphene_rect in blur_node() 2020-12-16 09:13:12 +01:00
Timm Bäder
7f6608cbed gl renderer: Render too big textures to the clipped area 2020-12-16 08:26:46 +01:00
Timm Bäder
f816a8fb82 gl renderer: Unify viewport setting in add_offscreen_ops()
We use the same rect here a few times.
2020-12-16 08:26:46 +01:00
Matthias Clasen
e1df9a043f Add a doc comment for GskConicGradientNode 2020-12-15 14:18:26 -05:00
Emmanuele Bassi
99e0929d6c build: Use a consistent style for Meson files 2020-12-15 12:46:59 +00:00
Emmanuele Bassi
7975bbfcaa build: Remove linker flags from static libraries
We only need hardening linker flags on the libgtk shared library;
internal static libraries don't really need them.
2020-12-15 11:36:20 +00:00
Emmanuele Bassi
11bca98a29 build: Remove unused variable
We don't need a `gsk_source` variable after all.
2020-12-15 11:35:27 +00:00
Timm Bäder
33ed42d985 gl renderer: Remove RESET_OPACITY flag
We always need to do that (and always passed the flag to
add_offscreen_ops() anyway).
2020-12-06 20:03:35 +01:00
Timm Bäder
1ee4f6138b gl renderer: Reset opacity when rendering blend node children
We render those on a texture, so we need to reset the opacity because
that will be applied when rendering the resulting texture.
2020-12-06 20:01:36 +01:00
Timm Bäder
7b61ef9e0f gl renderer: Initialize rounded rect early 2020-12-06 19:57:48 +01:00
Timm Bäder
b46d077b3a gl renderer: Fix rendering clipped blurred inset shadow nodes 2020-12-06 19:18:10 +01:00
Timm Bäder
e32331d002 gl renderer: Ignore crossfades between equal texture nodes 2020-12-06 19:18:10 +01:00
Timm Bäder
05928608ec gl renderer: Use scale_x and scale_y everywhere
Try to handle two different values for scale in horizontal and vertical
direction better.

Fixes #3431
2020-12-06 19:18:05 +01:00
Christian Hergert
a47c0065fb macos: enable GL renderer by default
Now that the attribute locations are fixed for the GL renderer, we can
enable it by default on macOS.

Fixes #3420
2020-12-04 13:41:31 -08:00
Christian Hergert
6883c2214b gl: specify attribute locations for vUv and aPosition
These positions are not guaranteed to be in a specific order when linked
into the final GPU program. They need to be specified so that our code
in gskglrenderer.c can use known positions for them to match up with
our GskQuadVertex.

This fixes the GL renderer on macOS's OpenGL shader compiler.

Fixes #3420
2020-12-04 13:33:34 -08:00
Benjamin Otte
2c1bd399d2 glrenderer: Implement a shader for conic gradients 2020-12-03 13:07:17 +01:00
Benjamin Otte
fac5fba0dc rendernode: Fix some wrong constants for conic gradients
copy/paste from other nodes left some wrong values in there and that
screwed things up quite a bit.
2020-12-03 13:07:17 +01:00
Benjamin Otte
c907ad83b0 glrenderer: Emit more useful error messages
Catch the error when it happens, so that we can emit a specific and more
helpful error message.

Also verify that all branches in the code now do indeed set a proper
GError when they fail, so that the final catch-all is no longer needed.
Instead, assert that the error is set so that we catch future code
additions early that do not set the GError.
2020-12-03 13:07:17 +01:00
Matthias Clasen
35d2cbefe6 Merge branch 'wip/otte/conic' into 'master'
Add support for conic gradients

See merge request GNOME/gtk!2911
2020-12-03 03:54:24 +00:00
Benjamin Otte
55a242bd81 gsk: Add GskConicGradientNode 2020-12-03 00:47:54 +01:00
Benjamin Otte
71cb7c2063 rendernodeparser: Split out a function 2020-12-02 21:48:35 +01:00
Emmanuele Bassi
2fcd0e21bd Merge branch 'ebassi/for-master' into 'master'
Various documentation fixes

See merge request GNOME/gtk!2900
2020-12-02 13:40:25 +00:00
Christian Hergert
9e1dd15e31 macos: use Cairo renderer by default
Until the GL renderer is working on macOS OpenGL, we need to default
to the Cairo renderer.
2020-12-01 16:24:15 -08:00
Emmanuele Bassi
37f11ab77d docs: Annotate GskRenderer 2020-12-01 15:51:52 +00:00
Emmanuele Bassi
8b898818c2 docs: Annotate the GL shader objects 2020-12-01 15:51:52 +00:00
Emmanuele Bassi
0f62ab6c42 docs: Annotate all render node types 2020-12-01 15:51:52 +00:00
Emmanuele Bassi
c524b72d13 docs: Annotate structure types used by GskRenderNodes 2020-12-01 15:51:52 +00:00
Timm Bäder
da514187f5 gl renderer: Make minimal rounded rects more minimal 2020-11-30 09:21:34 -05:00
Matthias Clasen
ec21d354b9 gsk: doc fixups 2020-11-30 09:21:24 -05:00
Christian Hergert
0d2ea14ac1 types: fix various use of volatile in type registration
The use of volatile was incorrect in GLib and has been that way for
a long time. Recently however that has changed, and this makes GTK
follow suit to avoid using volatile in the type registration.

See also: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719

Combined with the above merge request for GLib, this fixes a large
number of compilation warnings when using Clang.
2020-11-18 20:21:33 -08:00
Christian Hergert
82b4c34eca gl: add some debugging information to DEBUG_OPS 2020-11-18 20:16:40 -08:00
Christian Hergert
eae5eaeb21 gl: use glFramebufferTexture2D to set framebuffer texture
When mapping a texture to the framebuffer, we can use the 2D
form instead of the cube mapping form.
2020-11-18 20:09:01 -08:00
Benjamin Otte
1c7daece7a Merge branch 'wip/otte/for-master' into 'master'
Wip/otte/for master

See merge request GNOME/gtk!2855
2020-11-17 19:08:01 +00:00
Benjamin Otte
f2284ff40f rendernode: Rename all gsk_render_node_peek_*() functions
Those are getters, they should be gsk_render_node_get_*() functions.
2020-11-17 19:04:39 +01:00
Emmanuele Bassi
b76e514322 Merge branch 'ebassi/for-master' into 'master'
Introspection fixes

Closes #3281

See merge request GNOME/gtk!2852
2020-11-17 16:04:03 +00:00
Emmanuele Bassi
5a938ad83d Annotate the gsk_border_node_peek_widths() return value
We return a fixed sized C array of floats.
2020-11-17 13:48:07 +00:00
Matthias Clasen
9a29487e25 gsk: Fix a doc oversight 2020-11-17 07:34:52 -05:00
Matthias Clasen
121e61cf01 gsk: Avoid using gtk css types in public api
Using GtkCssSection in public headers here may be
ok from the C perspective, since it all ends up in
the same library anyway. But it causes circular
dependency problems for our gir files that are still
split by namespace.

To avoid this problem, copy the GtkCssLocation struct
struct as GskParseLocation, and pass take two of them
instead of a GtkCssSection in the error callback.

Update all users.

Fixes: #2454
2020-11-16 23:27:44 -05:00
Matthias Clasen
2c9bf55eea Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!2846
2020-11-17 01:07:34 +00:00
Christian Hergert
12a9164414 gsk: use glFrameBufferTexture2D and release texture
glFrameBufferTexture maps to all faces of a cube and that is not needed
here. Additionally, texture_id is not deleted after we use the additional
flipped texture, but should be.
2020-11-16 09:26:07 -08:00
Matthias Clasen
57c95937b1 gsk: Fix some docs oversights
These apis have been renamed a few times, and the docs
haven't kept up.
2020-11-16 07:44:41 -05:00
Christoph Reiter
afc73c38ce Always parse GTK/GDK/GSK_DEBUG env vars and make some entries available in non-debug mode
Currently GTK can be built with G_ENABLE_DEBUG which enables various debug code and parsing
of those env vars, or without, which instead of parsing them prints a warning if they are set.
While building with G_ENABLE_DEBUG isn't strictly needed it's the only way to make GTK_DEBUG=interactive work,
which is a nice thing to have always.

This enables parsing of those env vars in any case and allows specific values being marked as also
available when not built with G_ENABLE_DEBUG (interactive for example). If not built with G_ENABLE_DEBUG
then all unavailable values will be marked as such in the help output and a note is added that
GTK needs to be built with G_ENABLE_DEBUG to use them, which should help discoverability.
2020-11-15 11:34:54 +01:00
Emmanuel Gil Peyrot
08193ecf1c gl renderer: Generate queries only on desktop GL
On desktop GL, GL 1.5 or GL_ARB_occlusion_query is required to get the
glGenQueries() etc. symbols.  This isn’t the case on GLES, where they
are provided by GL_EXT_occlusion_query_boolean, and more importantly
have never been made core.

This patch allows gtk4-demo to start when GDK_DEBUG=gl-gles is set, on
my Mali 400 MP running the Lima driver from Mesa.
2020-11-07 21:49:42 +01:00
Timm Bäder
82ca65956f gl renderer: Make debugging code shorter 2020-11-02 14:55:14 -05:00
Timm Bäder
c8c2106f3e gl renderer: Refactor vertex data loading code 2020-11-02 14:55:14 -05:00
Timm Bäder
8178dfb85a gl renderer: Use the load_vertex_data* functions more often 2020-11-02 14:55:14 -05:00
Timm Bäder
50e78198a8 gl renderer: More load_vertex_data* usage 2020-11-02 14:55:14 -05:00
Timm Bäder
ee04cbcfa8 gl renderer: Reword a comment 2020-11-02 14:55:14 -05:00
Timm Bäder
fc312f7ffe gl renderer: Remove an outdated comment 2020-11-02 14:55:14 -05:00
Timm Bäder
e6e964c3f3 gl renderer: Refactor rendering shadow nodes
Also use load_vertex_data_with_region here.
2020-11-02 14:55:14 -05:00
Timm Bäder
df5e796d99 gl renderer: Refactor blurred shadow drawing code
We already have various load_vertex_data* code, so try to reuse that
here.
2020-11-02 14:55:14 -05:00
Timm Bäder
d3239c953d gl renderer: Nine-slice unblurred outset shadows
See #3284
2020-11-02 14:55:13 -05:00
Matthias Clasen
7db58d5f8d gsk: Don't compile unused code
The NodeSample and GskGLImage code is not used,
so don't compile it.
2020-10-30 23:36:39 -04:00
Matthias Clasen
03fec389f4 docs: Add details for gsk_renderer_new_for_surface
Mention the GSK_RENDERER variable here.
2020-10-29 18:21:44 -04:00
Christian Hergert
a3fd46c516 glsl: tweak pre-processor to support Apple GLSL compiler
The Apple GLSL compiler cannot deal with empty pre-processor blocks such as

  #if GSK_GLES
  #elif GSK_LEGACY
2020-10-29 10:57:02 -07:00
Timm Bäder
9109dee072 gl renderer: Don't use blur node bounds
The blur node bounds are different/larger than the ones we use. This
made the textures get stretched to the blur node bounds.

Fixes #3282
2020-10-22 17:46:34 +02:00
Timm Bäder
b6a843a05b gl renderer: Fix two scale_x/y mixups 2020-10-22 17:46:34 +02:00
Sophie Herold
cd0bef9390 Add some missing nullable return annotations 2020-10-17 15:32:36 +02:00
Timm Bäder
07fb33c033 gl renderer: Fix private function name
It's a GskGLRenderer, not a GskGLRender
2020-10-14 15:06:12 -04:00
Timm Bäder
1fe7043be4 gl renderer: Add more scale_x/scale_y code
We really need all of this to be aware of both dimensions of course...
2020-10-14 15:06:12 -04:00
Timm Bäder
0e6014f2f6 gl renderer: Remove two unused uniforms 2020-10-14 15:06:12 -04:00
Timm Bäder
0a4d442849 gl renderer: return empty texture for too small blurred nodes 2020-10-14 15:06:12 -04:00
Timm Bäder
5f9fa13c65 gl renderer: Use op builder to render flipped texture
Otherwise, we don't know about the uniform state
2020-10-14 15:06:12 -04:00
Timm Bäder
161b171004 gl renderer: Remove unused parameter 2020-10-14 15:06:12 -04:00
Timm Bäder
eb345cd033 gl renderer: Use nearest filtering for textures in render_texture()
Makes the output in the node editor a bit more bearable.
2020-10-14 15:06:12 -04:00
Timm Bäder
f456438051 vulkan: Remove double initialization
Clang said:

../gsk/vulkan/gskvulkanrenderpass.c:250:5: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
    .render.node = node
    ^~~~~~~~~~~~~~~~~~~
../gsk/vulkan/gskvulkanrenderpass.c:249:13: note: previous initialization is here
    .type = GSK_VULKAN_OP_FALLBACK,
            ^~~~~~~~~~~~~~~~~~~~~~
2020-10-14 15:06:12 -04:00
Timm Bäder
4735c27e69 gl renderer: Avoid some code duplication 2020-10-14 15:06:12 -04:00
Timm Bäder
44f10c5861 gl renderer: Flip texture in render_texture() 2020-10-14 15:06:12 -04:00
Timm Bäder
44d1e81ae9 glsl: Add a comment 2020-10-14 15:06:12 -04:00
Timm Bäder
ddcff9eb0f gl renderer: simplify ->render() implementation a bit
We already use self->scale_factor when initialized whole_surface,
so set self->scale_factor first.
2020-10-14 15:06:12 -04:00
Timm Bäder
9fe21b7181 shaderbuilder: Print error message after source code
My terminal scrolls down, so showing the error message last makes sense.
2020-10-14 15:06:12 -04:00
Timm Bäder
7bf858b9d0 gl renderer: Add a helper to setup projection matrix 2020-10-14 15:06:12 -04:00
Timm Bäder
bc034d1190 gl renderer: Ignore rendering if accumulated opacity is too small 2020-10-14 15:06:12 -04:00
Timm Bäder
7222a0901d unblurred outset shadow shader: Use premultiply() 2020-10-14 15:06:12 -04:00
Timm Bäder
a0bb248bb3 gl renderer: Use premultiply() in inset shadow shader` 2020-10-14 15:06:12 -04:00
Timm Bäder
982ebf1b69 gradient shaders: Reduce out values as well
We only do 6 color stops here now. Also works around a driver bug.

Fixes #3196
2020-10-05 20:35:34 -04:00
Alexander Larsson
24a27ba44f gl renderer: Fix up texture cache key
The commit e14d2be1 forgot to actually set the parent_rect in the texture
key in the case it is necessary.
2020-10-05 15:43:04 +02:00
Matthias Clasen
cef1cd19ff gsk: Avoid long lines in serialized nodes
When encoding big blobs of data in base64, insert newlines.
Base64 allows it, CSS allows it, so not need to make GtkTextView
struggle with multi-megabyte lines.

Update nodeparser tests to reflect this change.
2020-10-03 13:10:55 -04:00
Matthias Clasen
a9809b0f67 Allow inserting newlines in css strings
Rename _gtk_css_print_string to strip the _ and add
an insert_newlines argument to it. Update all callers,
and make the render node serializer insert newlines.
2020-10-02 23:40:16 -04:00
Matthias Clasen
9033336a23 css: Move _gtk_css_print_string around
Move this to a separate header, since it is not
parser functionality, and kill the duplicate
gtkcssparserprivate.h header.
2020-10-02 23:40:16 -04:00
Matthias Clasen
dc3b140fd7 Cosmetics 2020-10-01 13:48:24 -04:00
Matthias Clasen
b0da095944 gsk: Fix compiler warnings
We forgot to teach the broadway renderer about new enum
values, and our ci didn't catch it because werror didn't
actually work there until now.
2020-09-30 15:39:30 -04:00
Alexander Larsson
e14d2be1e8 gl renderer: Fix render node texture cache
We're caching two things, either a node itself being rendered, or a
parent storing a cached version of a child as rendered to an offscreen
the size and location of the parent.

If both the parent and child uses the cache this will cause a conflict in
the cache as it is currently use keying of a node pointer which will have
the same value for the node-as-itself and the child-node-of-the-parent.

We fix this by adding another part to the key "pointer_is_child" which means
we can have the same node pointer twice in the cache.

Additionally, in the child-is-rendered-offscreen case the offscreen
result actually depends on the position and size of the parent viewport,
so we need to store the parent bounds in that case.
2020-09-30 14:53:13 +02:00
Matthias Clasen
00c6340777 gsk: Add some more shader docs
Do a pass over the docs and address minor inconsistencies,
cosmetics and formatting differences.

Mention GSK_DEBUG=shaders.
2020-09-29 14:44:31 -04:00
Matthias Clasen
4cfa9ee19f Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master

See merge request GNOME/gtk!2639
2020-09-29 12:57:36 +00:00
Matthias Clasen
07c338b487 gsk: Document radial gradient api 2020-09-29 07:04:07 -04:00
Alexander Larsson
51ab56d33a gl: Track the current uniform state for custom programs
This allows us to avoid updating uniforms if that is not necessary. This
in turn allows us to sometimes reuse the same draw op by just extending the
vertex array size we draw rather than doing a separate glDraw call.

For example, in the fishbowl demo, all the icons added at the same
time will have the same time and size, so we emit single draw calls
with 100s of triangles instead of 100s of draw calls with 2 triangles.
2020-09-29 11:52:39 +02:00
Alexander Larsson
4d697283ae Support GLShaderNode in backends
For vulkan/broadway this just means to ignore it, but for the gl
backend we support (with up to 4 texture inputs, which is similar to
what shadertoy does, so should be widely supported).
2020-09-29 09:51:16 +02:00
Alexander Larsson
7ea755e206 Add GskGLShaderNode and GskGLShader
A GskGLShader is an abstraction of a GLSL fragment shader that
can produce pixel values given inputs:
 * N (currently max 4) textures
 * Current arguments for the shader uniform
Uniform types are: float,(u)int,bool,vec234)
There is also a builder for the uniform arguments which are
passed around as immutable GBytes in the built form.

A GskGLShaderNode is a render node that renders a GskGLShader inside a
specified rectangular bounds. It renders its child nodes as textures
and passes those as texture arguments to the shader. You also pass it
a uniform arguments object.
2020-09-29 09:51:16 +02:00
Matthias Clasen
6e9b58b6f0 gsk: Add more shader debug spew
Print out the full assembled shader sources when
GSK_DEBUG=shaders is given. This is very verbose,
but may be useful to see what we actually pass
to the compiler.
2020-09-29 09:51:16 +02:00
Alexander Larsson
bacb3affb3 gl: Add some namespacing to the preamble symbols
This adds a gsk prefix to the stuff in the preamble, as we want to
avoid it conflicting with things in the main shader. Especially once
we start allow some customization of shaders.
2020-09-29 09:51:16 +02:00
Alexander Larsson
9460d0131f gl backend: Add line numbers to source in glsl compilation errors
Almost always the source is created by combining various sources, which
means the line numbers in the error messages are hard to use. Adding
the line numbers to the source in the error message helps with this.
2020-09-29 09:51:16 +02:00
Alexander Larsson
7edcd1748c gl: Properly report error if shader linking fails
In gsk_gl_shader_builder_create_program(), if linking fails we
need to return -1 to indicate error, rather than the old deleted
program id.
2020-09-29 09:51:16 +02:00
Alexander Larsson
6887d0ce24 glrenderer: Move ProgramState into Program
There is no real reason to have this on the side indexed via the
index, as it is stored next to each other anyway. Plus, storing them
together lets use use `Program` structures not in the array.
2020-09-29 09:51:10 +02:00