Commit Graph

124 Commits

Author SHA1 Message Date
Simon Ser d5556ec78f render/egl: add save_context parameter to wlr_egl_make_current()
Saving the old context and immediately making our own context
current is a common pattern. Let's make it easier to do.

No functional change, just refactoring.
2024-02-23 18:52:48 +01:00
Simon Ser 842093bb84 Define _POSIX_C_SOURCE globally
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead,
require POSIX.1-2008 globally. A lot of core source files depend
on that already.

Some care must be taken on a few select files where we need a bit
more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and
some files need BSD extensions (_DEFAULT_SOURCE). In both cases,
these feature test macros imply _POSIX_C_SOURCE. Make sure to not
define both these macros and _POSIX_C_SOURCE explicitly to avoid
POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001
but _XOPEN_SOURCE says POSIX.1-2008).

Additionally, there is one special case in render/vulkan/vulkan.c.
That file needs major()/minor(), and these are system-specific.
On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need
to make sure it's not defined for this file. On Linux, we can
explicitly include <sys/sysmacros.h> and ensure that apart from
symbols defined there the file only uses POSIX toys.
2024-02-15 15:41:12 +01:00
Paul Cercueil 220df2aa0f
Add more POSIX compliance macros to fix uClibc support
- Add POSIX 1993.09 compliance macro in source files that use
  "struct timespec";
- Add POSIX 2001.12 compliance macro in source files that use
  "struct sigaction" and the SA_SIGINFO macro, or the fchmod()
  function;
- Add POSIX 2008.09 compliance macro in source files that use the
  getline() function.

These compliance macros are enough for wlroots to compile with the
git-master version of uClibc-ng.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
2024-02-12 17:41:45 +01:00
Leo Li 60af3b6b78 render/gles2: Fixup dropping has_alpha from pixel_format
Fixes: 71fb55f3 ("render/pixel-format: Move has_alpha into it's own array")
2024-01-31 20:27:22 +01:00
Leo Li 71fb55f3bf render/pixel-format: Move has_alpha into it's own array
Some opaque pixel formats (nv12, p010) require per-plane bytes_per_block
info. However, it doesn't make sense to store them in
wlr_pixel_format_info, as they will never be useful (currently, this
info is used for shm, which doesn't have a concept of multi-planar
buffers.)

Let's define a separate array and function for determining whether a
pixel format has alpha.
2024-01-31 13:47:17 -05:00
Alexander Orzechowski c5a3c5ca4c render: Implement texture_preferred_read_format 2023-11-30 20:01:12 -05:00
Alexander Orzechowski e7055b4840 render/gles2: Implement texture_read_pixels
Also get rid of gles2_texture.owns_texture. We only use the tex/fbo
2023-11-30 19:56:41 -05:00
Simon Ser 876d789ad5 render/gles2: reword wlr_gles2_texture comments
These comments were a bit misleading:

- "GL_TEXTURE_2D == mutable": not really, imported non-external-only
  DMA-BUFs would also use this target, but are not mutable.
- "Only affects target == GL_TEXTURE_2D": same here.
- "If imported from a wlr_buffer": not really, would be NULL if
  imported from a shm wlr_buffer.

Adjust these comments to better reflect reality and adjust the check
in gles2_texture_update_from_buffer().
2023-11-30 16:38:25 +01:00
Alexander Orzechowski 84bef5c0c2 render/gles2: Inline texture invalidation
Let's us share more code with the other code path
2023-11-30 10:13:18 -05:00
Alexander Orzechowski 9bf51e744e render/gles2: Don't attach texture as buffer addon
Since wlr_gles2_buffer is now managing importing for us, there is
no reason for us to continue doing this.
2023-11-30 10:13:18 -05:00
Alexander Orzechowski 829e34b305 render/gles2: Don't track image in texture
We can get it from the buffer
2023-11-30 10:13:18 -05:00
Alexander Orzechowski cb5f67431b render/gles2: Don't double import dmabuf
We can double import a dmabuf if we use it as a texture target and
a render target. Instead, let's unify render targets and texture dmabuf
imports to use wlr_gles2_buffer which manages the EGLImageKHR
2023-11-30 10:13:18 -05:00
Alexander Orzechowski 9118226634 render/gles2: Don't track has_alpha in pixel_format
Why track the alpha here when we can already get that information
elsewhere?
2023-11-29 13:25:06 +01:00
Simon Ser 56ec13596a Cleanup wlr_matrix.h includes
Many files used to require wlr_matrix but no longer do.
2023-11-25 08:37:43 +01:00
Alexander Orzechowski 1b0694b794 treewide: Migrate from sizeof(struct) to sizeof(*pointer) where practical 2023-10-03 01:51:07 -04:00
Simon Ser fe06e5f49a Use wl_container_of() instead of casts
This slightly improves type safety.

The culprits were found with:

    git grep -E '\([a-z0-9_ ]+ \*\)\W?[a-z]'
2023-07-11 20:16:17 +02:00
Simon Ser 7a9f8d8d6b Use struct initializers instead of memset()
This is a bit more type-safe.
2023-07-07 17:31:11 +02:00
Simon Ser 96f3f3c92e render/pixel-format: add support for block-based formats
Some formats like sub-sampled YCbCr use a block of bytes to
store the color values for more than one pixel. Update our format
table to be able to handle such formats.
2023-05-21 20:28:45 +00:00
Alexander Orzechowski db0e962368 wlr_texture: Expose owning renderer 2022-12-01 04:41:43 -05:00
Simon Ser 6e88eeadeb render/pixel_format: import pixel_format_info_check_stride()
We'll use this function from wlr_shm too.

Add some assertions, use int32_t (since the wire protocol uses that,
and we don't want to use 16-bit integers on exotic systems) and
switch the stride check to be overflow-safe.
2022-11-15 16:30:00 +00:00
Simon Ser 6baf045590 render/texture: constify wlr_texture_update_from_buffer() 2022-11-11 23:11:17 +00:00
Alexander Orzechowski ef4baea0e2 Use wl_signal_emit_mutable 2022-08-18 07:16:16 -04:00
Simon Ser 98cf38601f render: replace wlr_texture_write_pixels with update_from_buffer
This lets the renderer handle the wlr_buffer directly, just like it
does in texture_from_buffer. This also allows the renderer to batch
the rectangle updates, and update more than the damage region if
desirable (e.g. too many rects), so can be more efficient.
2022-08-12 08:41:32 +00:00
Simon Ser 29291cb47c render/texture: drop wlr_texture_is_opaque
Whether a texture is opaque or not doesn't depend on the renderer
at all, it just depends on the source buffer. Instead of forcing
all renderers to implement wlr_texture_impl.is_opaque, let's move
this in common code and use the wlr_buffer format to know whether
a texture will be opaque.
2022-06-16 14:43:24 +02:00
Manuel Stoeckl 7ad67e0f1d render/gles: add support for some 16-bpc unsigned shm formats
These formats require EXT_texture_norm16, which in turn needs OpenGL
ES 3.1. The EXT_texture_norm16 extension does not support passing
gl_internalformat = GL_RGBA to glTexImage2D, as can be done for
formats available in OpenGL ES 2.0, so this commit adds a field to
wlr_gles2_pixel_format to provide a more specific internalformat
parameter to glTexImage2D.
2022-05-07 16:25:38 +00:00
Simon Ser a04cfca4da Remove support for DMA-BUF flags
They are never used in practice, which makes all of our flag
handling effectively dead code. Also, APIs such as KMS don't
provide a good way to deal with the flags. Let's just fail the
DMA-BUF import when clients provide flags.
2021-11-17 16:12:59 +00:00
Simon Zeni 9579d62a16 types/buffer: make {begin,end}_data_ptr_access part of the public API 2021-09-15 11:50:44 +02:00
Simon Ser 4e7a8707cc buffer: add data_ptr access flags
This allows callers to specify the operations they'll perform on
the returned data pointer. The motivations for this are:

- The upcoming Linux MAP_NOSIGBUS flag may only be usable on
  read-only mappings.
- gbm_bo_map with GBM_BO_TRANSFER_READ hurts performance.
2021-09-10 13:16:10 -04:00
Simon Ser ad7651a370 render/gles2: make wlr_gles2_texture a wlr_buffer addon 2021-08-12 10:22:19 +02:00
Simon Ser 9dba176e8d render/gles2: set has_alpha for DMA-BUFs
Use our internal pixel format table to figure out whether an
imported DMA-BUF has alpha.
2021-07-12 09:16:09 -04:00
Simon Ser 4e07d4cbf9 render/gles2: use wlr_drm for wl_drm implementation
This allows use to remove all of our special wl_drm support code.
2021-07-05 11:13:41 -04:00
Simon Ser 29be2d47e4 render: drop wlr_renderer_impl.texture_from_dmabuf 2021-07-01 14:57:52 -04:00
Simon Ser 18adb43a44 render: drop wlr_renderer_impl.texture_from_pixels 2021-07-01 14:57:52 -04:00
Simon Ser a2419eb4ea render/egl: make most functions private
The wlr_egl functions are mostly used internally by the GLES2
renderer. Let's reduce our API surface a bit by hiding them. If
there are good use-cases for one of these, we can always make them
public again.

The functions mutating the current EGL context are not made private
because e.g. Wayfire uses them.
2021-06-24 13:53:05 -04:00
Simon Ser 6e43d642b2 render/gles2: add support for DATA_PTR buffers in texture_from_buffer 2021-06-07 09:22:56 -04:00
Simon Ser abf527b075 render/gles2: fix texture cleanup on destroy
When importing a DMA-BUF wlr_buffer as a wlr_texture, the GLES2
renderer caches the result, in case the buffer is used for texturing
again in the future. When the wlr_texture is destroyed by the caller,
the wlr_buffer is unref'ed, but the wlr_gles2_texture is kept around.
This is fine because wlr_gles2_texture listens for wlr_buffer's destroy
event to avoid any use-after-free.

However, with this logic wlr_texture_destroy doesn't "really" destroy
the wlr_gles2_texture. It just decrements the wlr_buffer ref'count.
Each wlr_texture_destroy call must have a matching prior
wlr_texture_create_from_buffer call or the ref'counting will go south.

Wehn destroying the renderer, we don't want to decrement any wlr_buffer
ref'count. Instead, we want to go through any cached wlr_gles2_texture
and destroy our GL state. So instead of calling wlr_texture_destroy, we
need to call our internal gles2_texture_destroy function.

Closes: https://github.com/swaywm/wlroots/issues/2941
2021-05-30 10:11:09 -04:00
Simon Ser f6ba26ff58 render/gles2: implement texture_from_buffer
Make it so wlr_gles2_texture is ref'counted (via wlr_buffer). This
is similar to wlr_gles2_buffer or wlr_drm_fb work.

When creating a wlr_texture from a wlr_buffer, first check if we
already have a texture for the buffer. If so, increase the
wlr_buffer ref'count and make sure any changes made by an external
process are made visible (by invalidating the texture).

When destroying a wlr_texture created from a wlr_buffer, decrease
the ref'count, but keep the wlr_texture around in case the caller
uses it again. When the wlr_buffer is destroyed, cleanup the
wlr_texture.
2021-05-17 16:22:43 +02:00
Simon Ser 9221ed7b4c render/gles2: add gles2_texture_create
This centralizes the wlr_texture initialization.

In future commits, more fields will need to get initialized.
2021-05-17 16:22:43 +02:00
Simon Ser 6f69e2f12e render/gles2: remove unnecessary EGL import ext checks
We require the ext in the renderer init function.
2021-05-17 10:09:22 -04:00
Simon Ser c314920a3d render: remove NULL checks in wlr_texture_impl.destroy
The NULL check already exists in wlr_texture_destroy, no need to
duplicate it in each impl
2021-04-22 15:44:49 +02:00
Simon Ser 661ba49564 render/gles2: destroy textures on renderer teardown 2021-04-22 15:44:49 +02:00
Simon Ser 004cf887b7 render/gles2: prevent imported DMA-BUF textures from being mutated
The compositor shouldn't write to client buffers if the client
attaches a DMA-BUF to a wl_surface, then attaches a shm buffer.
Make gles2_texture_write_pixels return an error to prevent this
from happening.
2021-04-15 10:49:42 +02:00
Simon Ser 9ecfa4343a render: remove wlr_texture_to_dmabuf
This is unused in wlroots, and the use-cases for compositors are
pretty niche since they can access the original DMA-BUF via the
wlr_buffer.
2021-04-08 09:09:50 +02:00
Simon Zeni 78d21fa131 render/gles2: remove depth and bpp gles2_pixel_format, use drm pixel format 2021-03-25 10:55:54 +01:00
Simon Ser 27fba3df43 render: use DRM formats in wlr_texture_from_pixels 2021-02-23 16:09:26 +01:00
Simon Ser 549435aee5 render/gles2: replace wlr_gles2_texture.wl_format with drm_format 2021-02-23 16:09:26 +01:00
Simon Ser fab396f149 render/gles2: convert format table to DRM formats 2021-02-23 16:09:26 +01:00
Simon Ser 6ca59519c9 render/gles2: check buffer stride when uploading texture
If the stride is too small, the driver could end up segfaulting
(e.g. radeonsi segfaults in __memmove_sse2_unaligned_erms).
2021-02-19 23:35:38 +01:00
Simon Ser 9396d8433a
render/gles2: remove YUV blocklist
Mesa provides YUV shaders, and can import multi-planar YUV DMA-BUFs
as a single EGLImage. Remove the arbitrary limitation.

If the driver doesn't support importing YUV as a single EGLImage,
the import will fail and the result will be the same anyways.
2021-02-05 15:56:29 +01:00
Quantum 975d14b799 render/wlr_texture: clamp texture coordinates to edge by default
Clamping texture coordinates prevents OpenGL from blending the left and
right edge (or top and bottom edge) when scaling textures with GL_LINEAR
filtering. This prevents visual artifacts like swaywm/sway#5809.

Per discussion on IRC, this behaviour is made default. Compositors that want
the wrapping behaviour (e.g. for tiled patterns) can override this by doing:

    struct wlr_gles2_texture_attribs attribs;
    wlr_gles2_texture_get_attribs(texture, &attribs);

    glBindTexture(attribs.target, attribs.tex);
    glTexParameteri(attribs.target, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(attribs.target, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glBindTexture(attribs.target, 0);
2021-02-01 21:19:17 +01:00