Commit Graph

99 Commits

Author SHA1 Message Date
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
Simon Ser 642b349e94 render/gles2: restore EGL context after texture operations
It can be surprising and unexpected that texture operations (such as
texture upload and import) change the current EGL context, especially
when it's done under-the-hood by wlroots in response to wl_surface
requests.

To prevent surprises, save and restore the previous EGL context.
2021-01-15 10:19:31 +01:00
Simon Ser 3f7e0cf5f0 render/egl: remove surface and buffer age args from make_current
These aren't used anymore.
2021-01-12 11:31:04 +01:00
Simon Ser 3fd8098881
render/gles2: require GL_EXT_unpack_subimage
We implicitly depended on this extension.
2020-12-15 14:55:18 +01:00
Simon Ser 1dbcfdaf81 render/gles2: remove gles2_procs
Move the global into wlr_gles2_renderer. This removes global state and
allows us to have multiple renderers with different GL loaders.
2020-07-28 06:59:07 -06:00
Simon Ser 62da61716f render/gles2: make push/pop debug functions take a wlr_renderer 2020-07-28 06:59:07 -06:00
Simon Ser e8872d9ed7 render/gles2: keep ref to wlr_gles2_renderer in wlr_gles2_texture 2020-07-28 06:59:07 -06:00
Simon Ser 26af316b3b render/gles2: make wlr_gles2_texture_from_* private
These functions are unused by compositors (see e.g. [1]) and prevent
wlr_gles2_texture from accessing wlr_gles2_renderer state. This is an
issue for proper teardown [2] and for accessing GLES2 extensions.

[1]: https://github.com/swaywm/wlroots/pull/1962#issuecomment-569511830
[2]: https://github.com/swaywm/wlroots/pull/1962
2020-07-28 06:59:07 -06:00
Simon Ser a3ba82885c render: choose DMA-BUF texture target via eglQueryDmaBufModifiersEXT
EGL_EXT_image_dma_buf_import_modifiers tells us whether we should use
GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES. Using the right texture target
can fix some failures and/or improve performance on some drivers.

This does the same as a Weston commit [1].

[1]: https://gitlab.freedesktop.org/wayland/weston/commit/40c519a3e613

Closes: https://github.com/swaywm/wlroots/issues/2173
2020-06-06 08:59:38 +02:00
Simon Ser 1edc42157b render/egl: introduce wlr_egl_unset_current
This function can be called after wlr_egl_make_current to cleanup the
EGL context. This avoids having lingering EGL contexts that make things
work by chance.

Closes: https://github.com/swaywm/wlroots/issues/2197
2020-05-19 14:56:20 +02:00
Simon Ser 06f4c3945d render/texture: add width and height fields
Instead of requiring compositors to call wlr_texture_get_size each time
they want to access the texture's size, expose this information as
wlr_texture fields.
2020-04-28 21:45:14 +02:00
Simon Ser 6d3f3b9300 render/gles2: unbind textures after use
Keeping textures bound results in hard-to-debug situations where some GL
operations incorrectly affect the texture.
2020-01-13 07:52:30 -07:00
Simon Ser 515679e4fe Refactor EGL/GL API loading
Remove glapi.sh code generation, replace it with hand-written loading
code that checks extension strings before calling eglGetProcAddress.

The GLES2 renderer still uses global state because of:

- {PUSH,POP}_GLES2_DEBUG macros
- wlr_gles2_texture_from_* taking a wlr_egl instead of the renderer
2019-12-20 01:03:34 +00:00
Simon Ser 16e5e9541b Add -Wmissing-prototypes
This requires functions without a prototype definition to be static.
This allows to detect dead code, export less symbols and put shared
functions in headers.
2019-11-20 02:05:03 +00:00
Simon Ser 447835afc1 render/gles2: provide public API to access GL texture
Prior to this commit, compositors needed to render the texture to an
intermediate off-screen buffer using wlr_renderer APIs if they wanted to
use a custom rendering path (e.g. render to a 3D scene).

A new wlr_gles2_texture_get_attribs exposes the GL texture target and ID
so that compositors can render wlr_textures with their own shaders. An
example of a compositor doing so is available at [1].

[1]: 3db905b784/src/render.c (L227)
2019-11-07 14:24:03 -05:00
Scott Anderson 85a2ee6d30 render/gles: Simplify textures a bit
We don't need our own enum for types. Instead we just use
GL_TEXTURE_{2D,EXTERNAL_OES}, which already describes usage.

Also fixes a situation where we were using GL_TEXTURE_2D in a situation
we should not have. wl_drm buffers are always GL_TEXTURE_EXTERNAL_OES,
no matter if they're RGB or any other format.
2019-11-06 09:46:01 +01:00
Simon Ser 6bb7639a0f render/gles2: don't unset the current EGL surface when destroying texture
When a texture is destroyed between wlr_egl_make_current and
wlr_egl_swap_buffers, it resets the current EGL surface to NULL. This
makes wlr_egl_swap_buffers fail.

If the EGL context is already current, there's no need to reset it.
2019-10-16 09:40:26 -04:00
emersion 75371d2c88
Require libdrm >= 2.4.95 2019-01-29 19:33:38 +01:00
nyorain cb03a41a3b Use enum wl_shm_format for gles2 texture formats
Also rephrase the write_pixels comment.
2018-10-16 09:35:28 +02:00
nyorain cd28637187 Remove fmt parameter from wlr_texture_write_pixels
It's not allowed to change the format of a texture so remove
the confusing parameter.
2018-10-15 23:56:56 +02:00
Mariusz Bialonczyk ad406db21c gles2: change context when it is not current
Texture functions, that create and manipulate textures should switch
the current context if necessary.

thanks to: @emersion

Fixes #934
2018-08-03 07:43:22 +02:00
emersion c4915d1492 render: add wlr_texture_is_opaque 2018-07-12 23:35:33 +01:00
emersion 7cbef15206
util: add wlr_ prefix to log symbols 2018-07-09 22:49:54 +01:00
emersion 57548b557a
Merge branch 'master' into screencontent 2018-06-17 14:49:18 +01:00
Vincent Vanlaer f1a62a3200 Rename egl.exts to match the extension names 2018-06-09 19:11:51 +02:00
emersion 457bfcab19
render/egl: only request high priority context on DRM 2018-06-08 00:17:45 +01:00