Commit Graph

639 Commits

Author SHA1 Message Date
Matthias Clasen
4aabc45685 Drop gdkintl.h
This header was merely including gi18n-lib.h.
Just do that directly.
2022-09-23 23:33:42 -04:00
Matthias Clasen
9818ec4ad9 gsk: Use the new debug macros 2022-09-23 18:11:48 -04:00
Matthias Clasen
511a4ec475 gsk: Make glyph upload more similar to icons
When uploading glyphs to the atlas, clear
the padding bytes so that no dirt remains there.
2022-09-10 15:25:59 -04:00
Luca Bacci
bcccb46b7c GL Renderer: Ensure that GdkGLContext is current in gsk_gl_driver_shader_weak_cb
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5140
2022-08-27 13:58:17 +02:00
Christian Hergert
654d74bfb8 gsk/gl: use critical instead of assert in dispose
Instead of asserting only in debug builds (which are generally not
shipped in distributions) we should deliver a critical log-level message
so that these can be found sooner when not developing with jhbuild,
Flatpak, etc.

Also assert that we've setup the state correctly when realizing the
GskGLRenderer object.

Fixes #4625
2022-05-16 10:50:48 -07:00
Sophie Herold
a546ae32d7 Remove all nicks and blurbs from param specs
Those property features don't seem to be in use anywhere.
They are redundant since the docs cover the same information
and more. They also created unnecessary translation work.

Closes #4904
2022-05-11 18:16:29 +02:00
Matthias Clasen
0da75b0bbf gsk: Check for half float support
The GL renderer currently relies on half float support
in vertex buffers, so check that we have it.

Related: #4894
2022-05-06 11:05:57 -04:00
Matthias Clasen
84b3b1fab5 gsk/gl: Typo fix 2022-04-08 11:20:12 -04:00
Matthias Clasen
8c548d5579 Merge branch 'nonoverlapping-containers' into 'main'
gsk/gl: Avoid offscreening in more cases

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

The concrete change here is that we now avoid
offscreens for container nodes with multiple children,
as long as they don't overlap. In particular, this
avoid offscreens for ellipsized dim labels.
2022-04-05 14:57:38 -04:00
Matthias Clasen
21cba193ad Merge branch 'blurry-offscreen' into 'main'
gsk/gl: Always align offscreen rendering with the pixel grid

Closes #3833

See merge request GNOME/gtk!4621
2022-04-05 12:25:59 +00:00
Matthias Clasen
48dbbbc099 gl: Don't leak big glyphs
We were never resetting the accessed bit of
glyphs that are big enough to be stored individually,
so these would just accumulate and never be dropped.
2022-04-04 23:00:45 -04:00
Sebastian Keller
85a6517d65 gsk/gl: Always align offscreen rendering with the pixel grid
This fixes two issues with the offscreen rendering code for nodes with
bounds not aligned with the pixel grid:

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

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

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

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

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3833
2022-04-04 21:40:01 +02:00
Matthias Clasen
af20f7e9b5 gl: Don't leak big glyphs
We were never resetting the accessed bit of
glyphs that are big enough to be stored individually,
so these would just accumulate and never be dropped.
2022-04-03 20:25:22 -04:00
Matthias Clasen
2af8ac655b gsk: Plug a memory leak
This was introduced in 9defc7fc64.
2022-04-03 07:34:44 -04:00
Christian Hergert
cbbca38d88 gsk/gl: use consistent library naming 2022-03-18 14:59:49 -07:00
Christian Hergert
c64836e1c9 gsk/gl: make texture libraries more autonomous
This moves a lot of the texture atlas control out of the driver and into
the various texture libraries through their base GskGLTextureLibrary class.

Additionally, this gives more control to libraries on allocating which can
be necessary for some tooling such as future Glyphy integration.

As part of this, the 1x1 pixel initialization is moved to the Glyph library
which is the only place where it is actually needed.

The compact vfunc now is responsible for compaction and it allows for us
to iterate the atlas hashtable a single time instead of twice as we were
doing previously.

The init_atlas vfunc is used to do per-library initialization such as
adding a 1x1 pixel in the Glyph cache used for coloring lines.

The allocate vfunc purely allocates but does no upload. This can be useful
for situations where a library wants to reuse the allocator from the
base class but does not want to actually insert a key/value entry. The
glyph library uses this for it's 1x1 pixel.

In the future, we will also likely want to decouple the rectangle packing
implementation from the atlas structure, or at least move it into a union
so that we do not allocate unused memory for alternate allocators.
2022-03-18 14:59:46 -07:00
Christian Hergert
6b23fe3aa7 gsk/gl: pin atlases to single texture library
This removes the sharing of atlases across various texture libraries. Doing
so is necessary so that atlases can have different semantics for how they
allocate within the texture as well as potentially allowing for different
formats of texture data.

For example, in the future we might store non-pixel data in the textures
such as Glyphy or even keep glyphs with color content separate from glyphs
which do not and can use alpha channel only.
2022-03-18 12:48:43 -07:00
Christian Hergert
9defc7fc64 gsk/gl: add more control over shader generation
This allows the gskglprograms.defs a bit more control over how a shader
will get generated and if it needs to combine sources. Currently, none of
the built-in shaders do that, but upcoming shaders which come from external
libraries will need the ability to inject additional sources in-between
layers.
2022-03-18 12:34:32 -07:00
Christian Hergert
9d56f44cdf gsk/gl: rename glyphs to glyphs_library
This naming style is less likely to collide with shader naming and makes
it clear where it is consumed what it is.
2022-03-18 12:34:32 -07:00
Christian Hergert
1b9da2bb17 gsk/gl: allow configuring atlas size 2022-03-18 12:34:27 -07:00
Christian Hergert
2efc1729e2 gsk/gl: check for format as well
This could potentially happen if a uniform had never been set.
2022-03-18 12:33:33 -07:00
Christian Hergert
a66a0dde81 gsk/gl: only clear glyph cache durign reclaimation
We don't need to clear the front cache on every frame as we can clear it
specifically when we do reclaimation to avoid unnecessary memset() calls.
2022-03-18 12:33:33 -07:00
Christian Hergert
7062411bad gsk/gl: ignore max_entry_size when zero
If the max_entry_size is zero, then assume we can add anything to the
atlas. This allows for situations where we might be uploading an arc list
to the atlas instead of pixel data for GPU font rendering.
2022-03-18 12:33:33 -07:00
Christian Hergert
9dbd137ec8 gsk/gl: make max-frame-age configurable
This is nice for some texture libraries that we might want to keep around
for longer than say 60 frames such as a glyph cache.
2022-03-18 12:33:33 -07:00
Benjamin Otte
b28c3ef3d9 renderers: Handle large viewports
When large viewports are passed to gsk_renderer_render_texture(), don't
fail (or even return NULL).

Instead, draw multiple tiles and assemble them into a memory texture.

Tests added to the testsuite for this.
2022-02-26 20:35:44 +01:00
Christian Hergert
f9268e8137 gsk/gl: support non-standard default framebuffer
There are situations where our "default framebuffer" is not actually
zero, yet we still want to apply a scissor rect.

Generally, 0 is the default framebuffer. But on platforms where we need
to bind a platform-specific feature to a GL_FRAMEBUFFER, we might have a
default that is not 0. For example, on macOS we bind an IOSurfaceRef to
a GL_TEXTURE_RECTANGLE which then is assigned as the backing store for a
framebuffer. This is different than using gsk_gl_renderer_render_texture()
in that we don't want to incur an extra copy to the destination surface
nor do we even have a way to pass a texture_id into render_texture().
2022-02-22 12:01:24 -08:00
Christian Hergert
08d0575ed0 gsk/gl: avoid clearing opaque regions
If the rendering operation is over an opaque region, we can potentially
avoid clearing a large section of the framebuffer destination. Some cases
you do want to clear, such as when clearing the whole contents as some
drivers have fast paths for that to avoid bringing data back into the
framebuffer.
2022-02-21 23:43:17 -08:00
Marek Kasik
cb1dd66220 Fix kerning of GL rendered glyphs
Multiple scaled shifts by 1024 too.

Fixes: #4602
2022-02-01 09:31:35 +01:00
Luca Bacci
2aab55983d Merge branch 'wgl-legacy' into 'main'
GSK/GL: Relax check for GL 3.x+ legacy contexts

See merge request GNOME/gtk!4187
2022-01-03 13:11:04 +00:00
Benjamin Otte
2ce2afa036 gles: Be picky abpout glGetFramebufferAttachmentParameter()
This function does not at all work like in OpenGL - if it works at all.
So make it behave accordingly.

Fixes #4571
2021-12-25 15:07:44 +01:00
Benjamin Otte
2caab68be9 gl: Change gdk_gl_context_check_version()
Instead of just passing major/minor, pass them twice, once for GL and
once for GLES. This way, we don't need to check for GL and GLES
separately.

If something is supported unconditionally, passing 0/0 works fine.

That said, I'd like to group the arguments somehow, because otherwise
it's just a confusing list of numbers - but I have no idea how to do
that.
2021-12-25 15:07:44 +01:00
Timm Bäder
ceb61e6600 gskglcommandqueue: Mark some variables G_GNUC_UNUSED
These are unused if sysprof isn't being used.
2021-12-16 11:06:50 +01:00
Timm Bäder
fd6b3ef5a0 gl: Linear gradients don't support 3d transforms
Add another helper similar to the one for transforms, but that only
works on 2d transforms.

Fixes #4501
2021-12-12 12:57:44 +01:00
Chun-wei Fan
652ab1ac72 gskglcompiler.c: Force GLSL version 300 es as needed
For libANGLE to work with our shaders, we must use "300 es" for
the #version directive in our shaders, as well as using the non-legacy/
non-GLES codepath in the shaders.  In order to check whether we are
using the GLSL 300 es shaders, we check whether we are using a GLES 3.0+
context.  As a result, make ->glsl_version a const char* and make sure
the existing shader version macros are defined apprpriately, and add a
new macro for the "300 es" shader version string.

This will allow the gtk4 programs to run under Windows using EGL via
libANGLE.  Some of the GL demos won't work for now, but at least this
makes things a lot better for using GL-accelerated graphics under Windows
for those that want to or need to use libANGLE (such as those with
graphics drivers that aren't capable of our Desktop (W)GL requirements in
GTK.
2021-12-03 10:39:59 +08:00
Chun-wei Fan
a619e8af4a gskglcompiler.c: Relax check for GL 3.x+ legacy contexts
On Windows with nVidia drivers at least, when we create a legacy context
via wglCreateContext(), we may still get a (W)GL 4.x context.  Allow
such contexts to also use GLSL version 130 instead of 110, so that
things do continue to work.
2021-12-01 17:29:02 +08:00
Benjamin Otte
ade7509b97 GL renderer: Remove noperspective usage
It causes issues with compilation of GLES shaders and isn't in any
way correct.
2021-11-30 14:12:10 +01:00
Matthias Clasen
5b1cd335bb Go back to using pango for glyph rendering
Using just cairo makes us lose hexboxes. So, until
we implement that ourselves, go back to using pango.
2021-11-20 11:13:52 -05:00
Benjamin Otte
95574f98c4 gl: Use GL_BACK_LEFT
The spec doesn't allow GL_BACK, but many drivers do. Use the
spec-accepted equivalent instead.

Fixed #4402
2021-11-03 22:53:59 +01:00
Benjamin Otte
2b2fd23815 Merge branch 'wip/otte/center-center-center' into 'master'
Add a bunch of reftests and fix their failures

Closes #4285

See merge request GNOME/gtk!4085
2021-10-22 16:35:41 +00:00
Benjamin Otte
b912e84df7 gl: Call make_current() before doing any GL work
But don't call it too early, we only want to call it once we have
prepared the target.

This way, we guarantee that a GL context is always available and that it
is bound to the correct target.
2021-10-22 17:51:40 +02:00
Benjamin Otte
cb03fe8f31 gsk: Allow gsk_renderer_realize (renderer, NULL, NULL)
That way, we can use renderers without surfaces.
2021-10-20 21:49:32 +02:00
Benjamin Otte
9a2e9c5be4 gl: Use gdk_memory_texture_new_from_texture()
Way less code to prepare the texture in a proper format.
2021-10-13 14:33:44 +02:00
Benjamin Otte
ddc4a40c33 gl: Refactor texture uploading
Don't pass texture + rect, but instead have
  gdk_memory_texture_new_subtexture()
and use it to generate subtextures and pass them.

This has the advantage of downloading the a too large texture only once
instead of N times.
2021-10-13 14:33:44 +02:00
Benjamin Otte
5199bebdb5 gl: Move texture uploading to the renderer
It does not belong in GdkGLContext, it's a renderer thing.
It's also the only user of that API.

Introduce gdk_gl_context_check_version() private API to make version
checks simpler.
2021-10-13 14:33:44 +02:00
Benjamin Otte
31e9072906 gl: Fix downloading textures *again*
It turns out glReadPixels() cannot convert pixels and you are only
allowed to pass a single value into the function arguments. You need to
know which ones or things will explode.

GL is great.
2021-10-13 14:33:44 +02:00
Benjamin Otte
b65b64628d texture: Refactor downloading
Pass a format do GdkTextureClass::download(). That way we can download
data in any format.

Also replace gdk_texture_download_texture() with
gdk_memory_texture_from_texture() which again takes a format.

The old functionality is still there for code that wants it: Just pass
gdk_texture_get_format (texture) as the format argument.
2021-10-12 02:06:43 +02:00
Matthias Clasen
49a64da7ec Merge branch 'ngl-is-the-new-gl' into 'master'
Rename ngl to gl

Closes #4318

See merge request GNOME/gtk!4037
2021-10-11 06:43:41 +00:00
Matthias Clasen
b7eb1d3310 gsk: provide an ngl renderer
Provide a minimal renderer implementation that fails
in realize. This avoids reusing the same type, which
might give bindings trouble.
2021-10-07 16:46:29 -04:00
Matthias Clasen
7a1644bc97 Maintain abi
Keep gsk_ngl_renderer_new and gsk_ngl_renderer_get_type,
since they were part of the abi in 4.2, and in an
installed header.

Fixes: #4318
2021-10-07 13:05:53 -04:00