Commit Graph

1628 Commits

Author SHA1 Message Date
Benjamin Otte
dd666e4fe4 ngl: Store the shared driver in the display
... instead of some random GL context.
2021-07-22 16:23:56 +02:00
Benjamin Otte
430b6f8fb1 gdk: Add GdkDisplay::init_gl vfunc
The vfunc is called to initialize GL and it returns a "base" context
that GDK then uses as the context all others are shared with. So the GL
context share tree now looks like:

+ context from init_gl
  - context1
  - context2
  ...

So this is a flat tree now, the complexity is gone.

The only caveat is that backends now need to create a GL context when
initializing GL so some refactoring was needed.

Two new functions have been added:

* gdk_display_prepare_gl()
  This is public API and can be used to ensure that GL has been
  initialized or if not, retrieve an error to display (or debug-print).
* gdk_display_get_gl_context()
  This is a private function to retrieve the base context from
  init_gl(). It replaces gdk_surface_get_shared_data_context().
2021-07-22 16:23:56 +02:00
Matthias Clasen
1c90bb522e ngl: Handle negative scales
Scale factors can be negative, but we were not
looking out for that, triggering an assertion when
trying to create a render target with negative
width of height. Avoid that.

Fixes: #4096
2021-07-15 16:40:13 -04:00
Matthias Clasen
c799452973 ngl: Do nothing for transparent text nodes
Like the previous commit - a transparent text node
will not produce any visible pixels, so bail out early.
2021-07-15 13:18:23 -04:00
Matthias Clasen
fd48afb77d ngl: Do nothing for transparent color nodes
No need to send commands to the GPU to render transparency.
2021-07-15 13:18:23 -04:00
Benjamin Otte
ca3d942b9b rendernodeparser: Remove leftover debug prints 2021-07-14 20:19:40 +02:00
Benjamin Otte
5470a1344d rendernodeparser: Don't use %g when writing file
%g is locale dependent and can add "," where "." should be. Use
string_append_double() instead.
2021-07-14 20:18:44 +02:00
Matthias Clasen
fc9c34897a ngl: Make the C half-float implementation accessible
Make this accessible for tests.
2021-07-13 09:03:49 -04:00
Matthias Clasen
f45c0b9609 gsk: Another vbo_size overflow fix
We can overflow vbo_size not just by batching
too much, but also by producing humongous text
nodes. Split them up.
2021-06-29 15:22:40 -04:00
Matthias Clasen
9ea162034a gsk: Use the right limit for batch size
We use 16 bits, so G_MAXINT16 is one bit short.
Just make it explicit as 0xffff.
2021-06-29 15:21:45 -04:00
Matthias Clasen
bd5e5beee0 gsk: Don't overflow vbo_count
We use 16 bits to store vbo_count, so we can't create
batches that have more than 65535 vertices. Pay attention
to that limit when merging batches.
2021-06-28 15:00:41 -04:00
Matthias Clasen
7a493f151d Revert "gsk: Respect max element vertices limitation"
This reverts commit f58fc6b22e.
2021-06-28 14:50:58 -04:00
Matthias Clasen
f58fc6b22e gsk: Respect max element vertices limitation
We are pretty good at batching commands now, and we can easily
produce batches that exceed the maximum number of elements per
draw call that the hw can handle. Query that number, and respect
it when merging batches.

This fixes the rendering of the overview map in GtkSourceView.
2021-06-18 06:50:59 -07:00
Matthias Clasen
938bfff3dd Add type annotations for filename arguments
Add missing "(type filename)" annotations for string
arguments that are filenames.

Fixes: #633
2021-06-12 11:12:06 -04:00
Matthias Clasen
e437c55142 Add a doc comment for gsk_rounded_rect_is_circular 2021-06-04 09:49:05 -04:00
Matthias Clasen
da9cd4659e Merge branch 'bilelmoussaoui/markdown-links' into 'master'
docs: use markdown syntax for hyperlinks

See merge request GNOME/gtk!3589
2021-06-04 02:45:25 +00:00
Matthias Clasen
578db92973 Cosmetics: Eradicate gint
Remove a handful of errant uses of gint.
2021-06-03 17:41:28 -04:00
Bilal Elmoussaoui
02672a521a docs: use markdown syntax for hyperlinks 2021-05-25 13:14:01 +00:00
Matthias Clasen
2d266d107b gsk: Clean up docs syntax
Replace leftover gtk-doc syntax (#Type) with backquotes.
2021-05-22 17:25:26 -04:00
Matthias Clasen
4a0d3d7acc docs: Reduce redundancy
Remove a boatload of "or %NULL" from nullable parameters
and return values. gi-docgen generates suitable text from
the annotation that we don't need to duplicate.

This adds a few missing nullable annotations too.
2021-05-20 20:45:06 -04:00
Matthias Clasen
7fe0610b68 introspection: Stop using allow-none
allow-none has been deprecated for a long time
already. Instead use optional and nullable everywhere.
2021-05-20 19:17:49 -04:00
Matthias Clasen
8ba16eb4f1 Documentation fixes
Mostly fixing up indentation of continuation lines,
and other small cleanups.
2021-05-20 19:17:49 -04:00
Matthias Clasen
66b4f0cac4 ngl: Reuse texture coordinates
When uploading glyphs, reuse the position that
we get from gsk_ngl_texture_library_pack, instead
of recomputing it.
2021-05-15 22:23:14 -04:00
Matthias Clasen
81e0206465 ngl: Be consistent about padding
Make gsk_ngl_texture_library_pack always return
the position including the padding. And compute
texture coordinates accurately in all cases (we
were fudging the padding for standalone textures.
2021-05-15 22:21:26 -04:00
Matthias Clasen
cb1babeeba ngl: Add padding between cached glyphs
Without this, adjacent items in the cache sometimes
bleed into the texture for a glyph.
2021-05-15 22:15:05 -04:00
Matthias Clasen
8e7bc8d742 Improve transformed offscreen rendering
Preserve the scale for 2D transforms to
avoid a pixellated appearance.
2021-05-13 19:37:16 -04:00
Matthias Clasen
930ff499ee Confine -mf16c to a single source file
We can't use this flag for any code that may get run
outside the __builtin_cpu_supports() check, and meson
doesn't allow per-file cflags. So we have to split this
code off into its own static library.
2021-05-05 18:58:23 -04:00
Alexander Mikhaylenko
ae7f380396 gsk: Fix shader gresource paths
They were never updated after having been moved.
2021-04-19 20:01:33 +05:00
Chun-wei Fan
8df32e93be GSK: Fix builds against latest stable GLib with MSVC
GLib-2.68.x now considers warning C4098 ('void' function returning a value) as
an error, so avoid doing that.
2021-04-16 11:39:17 +08:00
Matthias Clasen
4465ee5414 Merge branch 'ngl-crash' into 'master'
ngl: Fix a rare assertion violation

Closes #3853

See merge request GNOME/gtk!3434
2021-04-13 22:02:44 +00:00
Matthias Clasen
c66b030427 ngl: Fix a rare assertion violation
When we clean up the uniform allocations after a frame,
it can happen that our space requirements actually increase,
due to padding that depends on the order of allocations.

Instead of asserting that it doesn't happen, just make
it work by growing our allocation.

Fixes: #3853
2021-04-12 22:53:48 -04:00
Emmanuele Bassi
31e08d4629 gsk/ngl: Build with G_DISABLE_ASSERT enabled 2021-04-12 21:23:18 -04:00
Matthias Clasen
9d3aa2cfce gsk: Avoid compiler warnings without assertions
Disabling assertions was provoking some unused variable
warnings from the compiler. Avoid these.
2021-04-12 21:22:46 -04:00
Chun-wei Fan
d5ced21264 gsk/ngl/fp16.c: Implement runtime F16C detection on MSVC
We need to use __cpuid() to check for the presence of F16C instructions on
Visual Studio builds, and call the half_to_float4() or float_to_half4()
implementation accordingly, as the __builtin_cpu...() functions are strictly
for GCC or CLang only.

Also, since __m128i_u is not a standard intrisics type across the board, just
use __m128i on Visual Studio as it is safe to do so there for use for
_mm_loadl_epi64().

Like running on Darwin, we cannot use the alias __attribute__ as __attribute__
is also for GCC and CLang only.
2021-04-12 18:13:42 +08:00
Matthias Clasen
46ed7540b2 Merge branch 'ngl-shadow-fixes' into 'master'
ngl: Fix outset blurred shadows

See merge request GNOME/gtk!3427
2021-04-12 05:07:29 +00:00
Matthias Clasen
21a1a40555 Merge branch 'shadow-reduction' into 'master'
gsk: Don't overshadow

See merge request GNOME/gtk!3419
2021-04-12 02:39:55 +00:00
Matthias Clasen
849692b24b ngl: Fix unevenly scaled shadows
Ensure that we don't cut them off at the edges.
2021-04-11 22:35:02 -04:00
Matthias Clasen
f3bf4e4876 ngl: Don't slice unsliceable shadows
When the corners are too big to make slicing work,
don't do it, since it leads to broken results.
2021-04-11 22:10:33 -04:00
Matthias Clasen
46270d3dcd ngl: Fix a case of flipped shadow
In the non-sliced case, we were rendering the shadow
upside down.
2021-04-11 22:10:33 -04:00
Matthias Clasen
da6096faaf ngl: Add code to dump shadows
This can be helpful in understanding shadow bugs.
2021-04-11 21:13:47 -04:00
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