Commit Graph

98 Commits

Author SHA1 Message Date
Benjamin Otte
2ee16e5dd9 gl: Set correct context when disposing GLDriver 2024-08-10 01:40:45 +02:00
Benjamin Otte
32625381fa gsk: Deprecate GskGLShader and the rendernode
The new renderers don't support them due to the required complexity of
integrating them with Vulkan and the assumptions those nodes make about
the renderer (the GL renderer exports its internal APIs into the
GLShader).

There haven't been any complaints that I'm aware of since 4.14 was
released where the default renderer does not support the nodes, so usage
in public seems to be close to nonexistant.

The 2 uses I know of were workarounds about missing features in GTK that
have stopped since GTK now supports them:

1. GStreamer used in to do premultiplication when the old GL renderer
   did not do so in hardware but on the CPU.
2. Adwaita used it for masking before the mask node wa added in 4.10.
2024-07-04 21:28:06 +02:00
Matthias Clasen
d1d4d80a1d Simply some internal api
The only caller of gdk_memory_texture_from_texture doesn't use
the second argument.
2024-06-19 02:06:14 -04:00
Benjamin Otte
141769fb46 gl: Turn has_foo flags into GdkGLFeatures
The goal is to have it mirror GdkVulkanFeatures, and in particular
having an environment variable to turn individual flags off.
2024-03-16 13:44:02 +01:00
Matthias Clasen
f779832861 Tweak profiling strings
Capitalize our mark names, and use GTK as category.

The justification is: it looks better in sysprof.
2024-01-21 14:02:08 -05:00
Matthias Clasen
59578c6d18 Fix typos throughout
These were pointed out by codespell.
2024-01-07 20:44:05 -05:00
Matthias Clasen
ab1fba6fdc gl: When loading a texture, really create a mipmap
If we need a mipmap, and we find an existing texture that can't
mipmap, we need to recreate it.
2024-01-03 12:26:13 -05:00
Benjamin Otte
96a71d515b gl: Track if mipmap generation is allowed
... and if it isn't, switch to a format that does allow mipmaps.
2024-01-03 16:56:43 +01:00
Matthias Clasen
79009d4158 gsk: Handle straight-alpha dmabufs
This omission was noticed by Benjamin Otte. Add a premultiply
uniform to the external shader, and add a separate premultiply
shader for the non-external case.
2023-12-15 07:40:27 -05:00
Matthias Clasen
00ebd51d06 gsk: Be more careful about texture slice formats
We need to make sure that all our textures have the same memory
format, or we'll run into trouble in the upload code, at least
on GLES, which isn't as forgiving about format mismatches.

Related: #6238
2023-11-28 14:16:21 -05:00
Matthias Clasen
2bfd4a88d6 Fix some more static analysis warnings 2023-11-24 16:36:46 -05:00
Matthias Clasen
b24ae31716 dmabuf: Improve consistency of debug messages
Make sure all our dmabuf debug messages are display-scoped so the
inspector doesn't trigger them, use the same formatting throughout,
and improve consistency of wording here and there.
2023-11-12 13:02:58 +01:00
Benjamin Otte
cd7e1c1387 dmabuf: Modify gdk_gl_context_import_dmabuf()
Move a bunch of code - namely the target selection - into the function.

I want to use the same code in the NGL renderer, so no need to duplicate
it.
2023-11-07 05:12:57 +01:00
Benjamin Otte
51a181af7a Merge branch 'wip/otte/for-main' into 'main'
dmabuf: Seek back to the start

See merge request GNOME/gtk!6526
2023-10-23 19:57:21 +00:00
Benjamin Otte
8fcd9bc0c4 gl: Make sure render_texture() sets the right format for high depth
Setting the format got lost when converting this coe to the texture
builder, because that codepaths avods the texture sniffing and always
uses RGBA8.
2023-10-23 21:22:17 +02:00
Matthias Clasen
4d1ef63009 gsk: Ensure dmabuf formats are initialized
We just poking at display members here, there is no guarantee that
dmabuf formats have been initialized. So do it explicitly.

This prevents a crash in the inspector when viewing a recorded frame
containing a dmabuf texture, since the inspector uses a separate
display connection.
2023-10-22 22:48:18 -04:00
Matthias Clasen
06822581f7 gsk: Use external textures
When we are running under GLES, we can use GL_TEXTURE_EXTERNAL_OES
to support YUV formats.

Since we don't want to deal with the combinatorial explosion of
compiling all our shaders with all combinations  of sampler2D vs
samplerExternalOES for all their textures, we copy the external
textures to a regular texture before using them.
2023-10-22 16:50:43 -04:00
Matthias Clasen
d02d45dd8d gsk: Allow shaders without clip variants
Add a GSK_GL_DEFINE_PROGRAM_NO_CLIP, which is like
GSK_GL_DEFINE_PROGRAM but compiles the shader just once,
with NO_CLIP defined.

This will be used in the future for shaders that do
texture conversion.
2023-10-22 16:42:17 -04:00
Matthias Clasen
52254f755f gsk: Support dmabuf textures
Defer handling of dmabuf textures to the driver,
and add the necessary code in load_texture.
2023-10-22 16:42:17 -04:00
Matthias Clasen
31abe56b7a gsk: Cosmetics 2023-10-16 23:32:37 -04:00
Mohammed Sadiq
64e27cd87d gldriver: Fix a possible use-after-free
g_hash_table_insert() frees the given key if it already exists
in the hashtable.  But since we use the same pointer in the
following line, it will result in use-after-free.

So instead, insert the key only if it doesn't exist.
2023-06-27 22:45:07 +05:30
Matthias Clasen
957fa87fce gsk: Support straight alpha textures
This is not the optimal way of doing it: we're
reuploading the texture with client-side conversion.
But it fits nicely into our current handling of mipmaps.

We can do better once we use shaders for colorspace
conversions.
2023-05-31 14:37:33 -04:00
Matthias Clasen
4a8a6e9f70 gsk: Don't build unused functions
The only caller is #if 0 ed, so don't build
these functions.
2023-05-16 20:13:57 -04:00
Matthias Clasen
aee214b09d gsk: Fix some renderer gotchas
unrealize() needs to clean up the surface that was set
in realize(), and both need to emit property change
notification.
2023-05-10 20:21:54 -04:00
Matthias Clasen
1a93efecf3 gsk: Dispose the driver when the display is closed
This was the intention, but the object data by itself
does not achieve that: We do run dispose on the display
when it is closed, but object data is only cleared in
finalize. So listen to the ::closed signal and remove
the driver ourselves.

Fix up the drivers dispose implementation enough for
that to actually work.
2023-05-10 20:21:12 -04:00
Matthias Clasen
d7c3235cd0 gsk: Add some debug helpers 2023-05-05 12:05:09 -04:00
Matthias Clasen
92a9f8cd7e gldriver: Add a sync when creating textures 2023-04-28 06:23:45 +02:00
Benjamin Otte
76e5fd0ece glrenderer: Port to GdkGLTextureBuilder 2023-04-27 06:40:47 +02:00
Matthias Clasen
22ea1af569 gsk: Avoid copying GL texture in more cases
When the GL texture already has a mipmap, we don't
have to download and reupload it to generate one.

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

This almost fixes trilinear filtering with
sliced textures.
2023-03-22 00:14:43 -04:00
Matthias Clasen
8f73a7c690 gsk: Cosmetics 2023-03-22 00:14:16 -04:00
Benjamin Otte
b5345b7f25 glrenderer: Handle filters differently
Instead of uploading a texture once per filter, ensure textures are
uploaded as little as possible and use samplers instead to switch
different filters.

Sometimes we have to reupload a texture unfortunately, when it is an
external one and we want to create mipmaps.
2023-03-18 21:33:17 -04:00
Matthias Clasen
8aa095c4d7 gsk: Avoid reuploading textures too much
When filtering changes for an already-cached
texture, we need to clear the render data
before setting the new one, otherwise it
does not take and we end up reuploading
the texture every frame.
2023-03-17 22:31:10 -04:00
Matthias Clasen
f3b0aa27ea gsk: Be more careful when slicing
We can only reuse existing slices if they
have the right filtering.
2023-03-17 00:50:01 -04:00
Benjamin Otte
9a4decc30f gldriver: Quick workaround for filter mismatch
We should really use texture views or samplers to handle this case for
shared textures, but this at least makes NEAREST not break.
2023-03-17 00:43:21 +01:00
Matthias Clasen
9f88dba162 gsk: Stop using g_slice 2023-03-14 14:56:42 -04:00
Benjamin Otte
c9f54ca371 texture: Export gdk_texture_get_format()
The API docs outline why quite well.

This should make it possible to do saving of textures to image files
without any private API with the same featureset that GTK uses.

Also remove the gsktextureprivate.h include where
gdk_texture_get_format() was the only reason for it.
2023-02-15 00:39:18 +01:00
Matthias Clasen
82c02574f1 gl: Make texture slicing more flexible
Allow to specify the filtering to use for the slices,
and allow forcing the number of slices. This will be
used in the next commit.
2023-02-11 15:09:38 -05:00
Christian Hergert
fb12ad807a gsk/gl: fix warning when join_sources() is unused 2023-01-12 13:22:25 -08:00
Matthias Clasen
b12d31d189 Fix spelling errors
These were pointed out by codespell.
2022-11-17 22:49:45 -05: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
Matthias Clasen
84b3b1fab5 gsk/gl: Typo fix 2022-04-08 11:20:12 -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
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