Commit Graph

352 Commits

Author SHA1 Message Date
Simon Ser c73a8cde83 render/gbm_allocator: fix gbm_device use-after-free
We need to destroy any gbm_bo we've created before gbm_device_destroy.

Closes: https://github.com/swaywm/wlroots/issues/2601
2021-01-15 19:27:49 +01:00
Simon Ser f0303978e3
render/gbm_allocator: log GBM backend name 2021-01-15 11:18: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 02a086599c
render/gles2: save/restore EGL context in destroy_buffer
It can be surprising that destroying a buffer changes the EGL context,
especially since this can be triggered from anywhere wlr_buffer_unlock
is called.

Prevent this from happening by saving and restoring the EGL context.
2021-01-14 12:00:06 +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 1d461687d2 render/egl: replace init/finish with create/destroy
This ensures wlr_gles2_renderer can properly take ownership of the
wlr_egl.

Closes: https://github.com/swaywm/wlroots/issues/2612
2021-01-12 11:31:04 +01:00
Simon Ser 50b120927d render/egl: remove wlr_egl_swap_buffers 2021-01-12 11:31:04 +01:00
Simon Ser 76ed2255ef render/egl: remove support for EGL_NATIVE_VISUAL_ID
Nobody uses it anymore.
2021-01-12 11:31:04 +01:00
Simon Ser 2585f322cb
render/gles2: fix EGL use-after-free
The wlr_egl was cleaned up too early.

While at it, also fix a memory leak.

Fixes: b899a412e3 ("backend: remove wlr_egl from all backends")
2021-01-12 10:45:14 +01:00
Simon Zeni b899a412e3 backend: remove wlr_egl from all backends 2021-01-07 17:11:22 +01:00
Simon Ser 07d75c99db render: remove EGL config and visual from wlr_renderer_autocreate
This isn't used anymore by any backend.

Some examples still provide an EGL config to wlr_egl_init, so we can't
drop it yet there.
2021-01-06 12:05:51 +01:00
Simon Ser c4635c68d2 render/drm_format_set: add special case for LINEAR-only formats
Our wlr_format_set structs don't hold GBM usage flags. Instead, users
who want to get a LINEAR buffer can use the DRM_FORMAT_MOD_LINEAR
modifier even if the kernel driver doesn't support modifiers.

Add a special case to wlr_drm_format_intersect to properly handle this
situation.
2020-12-30 11:17:43 +01:00
Simon Ser b9460ab724
Stop using wlr_texture_get_size
Just use wlr_texture.{width,height} directly.
2020-12-25 12:21:29 +01:00
Simon Ser d37214cb16 render/drm_format_set: add wlr_drm_format_{create,add} 2020-12-18 09:41:12 +01:00
Simon Ser bdf26f87d5
render/allocator: ignore NULL in wlr_allocator_destroy 2020-12-17 20:34:19 +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
Ilia Bozhinov 12ede67c62 egl: fix memory leak
I have noticed this with LeakSanitizer, I hope these are all occurrences.
2020-12-10 23:29:59 +01:00
Simon Ser f91e89fd9f render/gles2: query alpha size from render buffer
If we're using a render buffer, query the alpha size from it.

Closes: https://github.com/swaywm/wlroots/issues/2527
2020-12-09 21:45:28 +01:00
Simon Ser be8403e73d render/gles2: don't eglGetConfigAttrib on EGL_NO_CONFIG_KHR
If we don't have an EGL config, don't try to query anything from it.
2020-12-09 21:45:28 +01:00
Simon Ser 8a6930c138
render/drm_format_set: assert len <= cap when duplicating 2020-12-08 23:35:05 +01:00
Simon Ser 29da97c185
render/drm_format_set: allocate using cap when duplicating
In wlr_drm_format_dup, allocate the new wlr_drm_format using cap instead
of len. This makes it so the cap field is up-to-date and the chunk of
memory isn't too small if we append new modifiers (we don't allow this
yet but might in the future).
2020-12-08 16:02:44 +01:00
Simon Ser 037710b1d4 render/egl: support config-less wlr_egl
When using wlr_swapchain, there's no need to select an EGLConfig. Add
support for creating config-less EGL contexts.
2020-12-07 11:40:45 +01:00
Simon Ser 82443ea46b render/drm_format_set: introduce wlr_drm_format_intersect
Intersects modifiers from two wlr_drm_format structs. If either format
doesn't support modifiers, the resulting format won't support modifiers.
2020-12-03 10:52:25 +01:00
Simon Ser 83a5d03bf3 render/egl: remove wlr_egl.external_only_dmabuf_formats
Replace it with wlr_egl.dmabuf_render_formats.
2020-11-30 11:08:44 +01:00
Simon Ser 1f15dd093d render: assert {X,A}RGB8888 are supported
The Wayland protocol requires those to be supported.
2020-11-30 11:08:44 +01:00
Simon Ser c94ab99ae2 render: rename wlr_renderer_get_formats
Rename wlr_renderer_get_formats to wlr_renderer_get_shm_texture_formats.
This makes it clear those formats are only suitable for shm import.
2020-11-30 11:08:44 +01:00
Simon Ser 49115e9d5d render: rename wlr_renderer_get_dmabuf_formats
Rename wlr_renderer_get_dmabuf_formats to
wlr_renderer_get_dmabuf_texture_formats. This makes it clear the formats
are only suitable for creating wlr_textures.
2020-11-30 11:08:44 +01:00
Simon Ser 5d008d9030 render: introduce wlr_renderer_get_dmabuf_render_formats
It describes which DMA-BUF formats can be used to render.
2020-11-30 11:08:44 +01:00
Simon Ser 61612ecb36 render: remove wlr_renderer_format_supported
Instead, callers can just use wlr_renderer_get_formats and iterate over
the list.

This function was unused in wlroots.
2020-11-30 11:08:44 +01:00
Simon Ser 44cea53e72 render/egl: don't rely on being able to open primary node
On some setups (e.g. remote access via SSH) the current user won't have
the permission to open the primary node at all. It's still possible to
use drmGetDevices to match the primary node name returned by EGL.

Closes: https://github.com/swaywm/wlroots/issues/2488
2020-11-28 19:21:36 +01:00
Ronan Pigott dc7c6c4860 render/egl: recognize EGL_BAD_DEVICE_EXT error 2020-11-19 00:42:37 +01:00
Simon Ser eb8360bda3 render: introduce wlr_renderer_get_drm_fd 2020-11-15 22:54:07 +01:00
Simon Ser c8d95acc37 render/egl: introduce wlr_egl_dup_drm_fd 2020-11-15 22:54:07 +01:00
Simon Ser c11c6c4568 render/swapchain: add support for buffer age 2020-11-15 22:48:42 +01:00
Simon Ser 1245730ea2 render/gles2: fix y-inverted output when rendering to buffer 2020-11-15 22:48:42 +01:00
Simon Ser 6136fe87d1 render/gles2: implement wlr_renderer_bind_buffer 2020-11-15 22:48:42 +01:00
Simon Ser c88c54fb38 render: introduce wlr_renderer_bind_buffer 2020-11-15 22:48:42 +01:00
Simon Ser b0a663d39d render: introduce wlr_swapchain
The swapchain maximum capacity is set to 4, so that we have enough room
for:

- A buffer currently displayed on screen
- A buffer queued for display (e.g. to KMS)
- A pending buffer that'll be queued next commit
- An additional pending buffer in case we want to invalidate the
  currently pending one
2020-11-15 22:48:42 +01:00
Simon Ser 7c6212a0f7 render/drm_format_set: introduce wlr_drm_format_dup 2020-11-15 22:48:42 +01:00
Simon Ser 5913040110 render: introduce wlr_gbm_allocator 2020-11-15 22:48:42 +01:00
Simon Ser f47445f142 render: introduce wlr_allocator 2020-11-15 22:48:42 +01:00
Isaac Freund 0724b3c453 Use uint32_t in wlr_renderer_begin signature
This matches the signature of wlr_renderer_impl.begin
2020-11-11 11:01:46 +01:00
Guido Cella 6949d0fd38 render: Don't crash on 0 dimensions
Don't force compositors to check when an empty shape is being renderered.
References #2282. This was motivated by dwl crashing when setting window
borders to 0 (djpohly/dwl#51).
2020-08-27 17:39:31 +02: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
Andri Yngvason 6ef5d18757 render: egl: Use current display to restore NULL context
eglGetCurrentDisplay() returns EGL_NO_DISPLAY when there is no context current
and eglMakeCurrent() needs a display argument.

Fixes #2327
2020-07-14 19:55:20 +02:00
Andri Yngvason e05a85327f render: gles2: Fix y-inversion in gles2_blit_dmabuf() 2020-07-01 11:43:02 +02:00
Simon Zeni 4a4da256dd render/gles2: use glGetAttribLocation instead of hardcoded indices 2020-06-24 20:01:19 +02:00
Simon Ser 58df3eda9f render/egl: print error name
Allows for easier debugging.
2020-06-18 07:56:05 -06:00
Simon Ser 315bf08733 render: add wlr_render_subtexture_with_matrix
This renders only a subset of the texture, instead of the full texture.
2020-06-17 09:10:54 -06:00
Simon Ser 5118189a2b render/gles2: use .x/.y instead of .s/.t
texcoord is a vector of coordinates, with the first member being the X
axis value and the second member being the Y axis value. It makes more
sense to use the accessors with the same names.
2020-06-17 09:10:54 -06:00
Rouven Czerwinski d3d1bac1c2 render: assert sane values for box functions
Width and height should always be > 0 for render functions which take a
wlr_box.

References https://github.com/swaywm/wlroots/issues/2281
2020-06-16 15:16:02 +02:00
Simon Ser 7f9bbaaa17 render/egl: explicit client extension handling
Prior to this commit, wlr_egl_init seemed to assume the extension string
queried via EGL_NO_DISPLAY was a subset of the extension string queried
via an initialized display. This isn't correct.

EGL_EXT_client_extensions [1] defines two types of extensions: client
extensions and display extensions. The set of supported client and
display extensions are disjoint (ie. an extension is either a client or
a display extension, not both). Client extensions are queried via
EGL_NO_DISPLAY, display extensions are queried via an initialized
display.

Rename the variables to make this clear. Remove the misleading comment.
Log both client and display extensions.

[1]: https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_client_extensions.txt
2020-06-10 14:55:29 +02:00
Andri Yngvason 78d6eed6b3 render: Fix blit_dmabuf() breakage due to API change 2020-06-08 21:37:32 +02:00
Andri Yngvason b64a8a7f98 render: Add wlr_renderer_blit_dmabuf() 2020-06-08 20:49:41 +02:00
Andri Yngvason 11b598fe33 render: egl: Add utility functions for saving/restoring context 2020-06-08 20:49:41 +02: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 e91417ea8d render: stop making EGL context current in wlr_egl_init
This leaves an EGL context current behind. wlr_gles2_renderer_create was
assuming the EGL context was already current because of this (because it
called a GL function right off the bat).
2020-06-02 14:23:24 -06:00
Simon Ser af2f69e6c1 render/egl: unset current context after swapping buffers
After swapping buffers, it doesn't make sense to perform more rendering
operations. Unset the context to reflect this.

This commit makes it so the context is always only current between
wlr_egl_make_current and wlr_egl_swap_buffers.

This is an alternative to [1].

[1]: https://github.com/swaywm/wlroots/pull/2212
2020-05-20 17:39:34 +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 05803511db render/texture: make write_pixels optional 2020-04-28 21:45:14 +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 5dc3a9c754 render/gles2: add wlr_gles2_renderer_check_ext 2020-04-22 22:40:54 +02:00
Simon Ser 01d4506253 render/drm_format_set: disallow DRM_FORMAT_INVALID
It doesn't make sense to add DRM_FORMAT_INVALID to a format set. Adding
an assertion allows us to safely query the format set with
DRM_FORMAT_INVALID. See [1].

[1]: https://github.com/swaywm/wlroots/pull/2021#discussion_r385839668
2020-04-22 22:14:44 +02:00
Simon Ser d10f8a98ec render: only expose linux-dmabuf if EGL extension is supported
Only expose linux-dmabuf extension if EGL_EXT_image_dmabuf_import_ext is
supported.

Closes: https://github.com/swaywm/wlroots/issues/2076
2020-04-09 00:16:03 +00:00
Simon Ser 4a1015faff render/gles2: only call wlr_egl_bind_display if supported
This allows us to hard-fail if the extension is advertised but we fail
to enable it.
2020-04-09 00:16:03 +00:00
Simon Ser 6787ff521b render/egl: make config attribs const
wlr_egl_init is not allowed to mutate these attribs.
2020-04-09 00:15:25 +00:00
Isaac Freund c682d97841 Return failure of wlr_renderer_init_wl_display()
This makes it easier for the user of this library to properly handle
failure of this function.

The signature of wlr_renderer_impl.init_wl_display was also modified to
allow for proper error propagation.
2020-03-23 15:19:16 +01:00
Simon Ser a71649dde9 render/gles2: remove duplicated format list 2020-03-09 15:26:28 +01: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 2b04857343 render/egl: remove SURFACELESS_MESA special case
Users can just pass EGL_DEFAULT_DISPLAY themselves.
2020-01-12 10:10:09 -07:00
Simon Ser 346b43e937 render: guard rendering operations between begin() and end()
Add a wlr_renderer.rendering bool, set it to true between
wlr_renderer_begin() and wlr_renderer_end(). Assert we're rendering when
calling functions that render.
2019-12-31 08:07:44 -07:00
Scott Anderson cff1c2f740 meson: Various improvements
Bumps minimum version to 0.51.0

- Remove all intermediate static libraries.
  They serve no purpose and are just add a bunch of boilerplate for
  managing dependencies and options. It's now managed as a list of
  files which are compiled into libwlroots directly.

- Use install_subdir instead of installing headers individually.
  I've changed my mind since I did that. Listing them out is annoying as
  hell, and it's easy to forget to do it.

- Add not_found_message for all of our optional dependencies that have a
  meson option. It gives some hints about what option to pass and what
  the optional dependency is for.

- Move all backend subdirectories into their own meson.build. This
keeps some of the backend-specific build logic (especially rdp and
session) more neatly separated off.

- Don't overlink example clients with code they're not using.
  This was done by merging the protocol dictionaries and setting some
  variables containing the code and client header file.
  Example clients now explicitly mention what extension protocols they
  want to link to.

- Split compositor example logic from client example logic.

- Minor formatting changes
2019-12-23 07:48:29 -05:00
Simon Ser 01818ad2c8 render: fix EGL extensions not loaded
Some extensions are only advertised by the EGL implementation with a
non-zero EGLDisplay. That's the case when the extension can only be
enabled when the hardware/driver supports it for instance.

Instead of checking for all extensions without a display, check only for
EGL_EXT_platform_base and EGL_KHR_debug which are used before
eglGetDisplay. Check for all other extensions when we have a display.

Closes: https://github.com/swaywm/wlroots/issues/1955
2019-12-21 08:54:24 -05: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
Ronan Pigott 5df606d8ab render/gles2: do not set GL_TEXTURE_MAG_FILTER 2019-11-26 09:42:10 -05:00
Simon Ser bcd5f7d259 render: remove return in wlr_texture_get_size
Otherwise this error happens:

    ../subprojects/wlroots/render/wlr_texture.c: In function ‘wlr_texture_get_size’:
    ../subprojects/wlroots/render/wlr_texture.c:47:9: error: ISO C forbids ‘return’ with expression, in function returning void [-Werror=pedantic]
       47 |  return texture->impl->get_size(texture, width, height);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../subprojects/wlroots/render/wlr_texture.c:45:6: note: declared here
       45 | void wlr_texture_get_size(struct wlr_texture *texture, int *width,
          |      ^~~~~~~~~~~~~~~~~~~~
2019-11-25 08:54:04 -05: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
Drew DeVault 4c9423278a Introduce wlr_renderer_get_egl 2019-11-11 19:10:10 +01: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 51416738ea render/egl: prevent use-after-free when destroying current surface 2019-10-23 09:36:50 +00: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
Simon Ser 11bf87d678 render/egl: support formats with zero modifiers 2019-10-11 08:09:08 -04:00
Scott Anderson 06644575da render/egl: Change KHR_debug log to include error code 2019-09-15 10:06:34 +03:00
Filip Sandborg 734c64a6cc render/gles2: fix calculation for partial gles2 pixel read (#1809) 2019-08-31 23:00:52 +03:00
Drew DeVault 540e23d102 Revert "render/drm: keep old drm_format if realloc fails"
This reverts commit c1be9b6945.
2019-08-12 19:53:39 +09:00
Antonin Décimo c1be9b6945 render/drm: keep old drm_format if realloc fails 2019-08-12 09:37:21 +09:00
Simon Ser 6dbdf5db34 render/dmabuf: add wlr_dmabuf_attributes_copy 2019-06-07 09:06:11 -04:00
Simon Ser e516ea4c79 backend/drm: check format when scanning out DMA-BUF 2019-06-07 09:06:11 -04:00
Simon Ser 107a1789ea render/gles2: print GL_RENDERER
This is often the name of the GPU and can help debugging graphics issues.
2019-05-07 10:51:52 -06:00
Simon Ser d6e250b389 render/egl: fix swapping with no damage
According to the spec:

> If <n_rects> is 0 then <rects> is ignored and the entire
> surface is implicitly damaged and the behaviour is equivalent
> to calling eglSwapBuffers.

When we want to swap with an empty damage region, set the damage to a single
empty rectangle.
2019-04-26 10:08:08 -06:00
Simon Ser f42816ce3f render/egl: fix zero-length VLA 2019-04-23 14:36:02 -06:00
Alyssa Ross 95b22619e0 Fix missing headers when building without X11
The deleted includes are redundant, because other headers will include
the necessary files. Additionally, they cause build failures, because
including EGL/egl.h or EGL/eglext.h directly, instead of through
wlr/render/egl.h or wlr/render/interface.h, will mean that
MESA_EGL_NO_X11_HEADERS will not have been defined, and so the EGL
headers will attempt to pull in unnecessary X11 headers that may not
exist on the system.

For the headers produced by glgen.sh, the includes couldn't simply be
deleted, because no other header would include the EGL headers. Neither
wlr/render/egl.h or wlr/render/interface.h felt appropriate to include,
so I opted instead to copy the MESA_EGL_NO_X11_HEADERS definition before
the EGL includes.
2019-04-22 00:04:08 +03:00
emersion e42178d03f
render: switch wlr_renderer to wlr_drm_format_set 2019-04-01 19:18:04 +03:00
Scott Anderson c01b81c99c
render: introduce wlr_drm_format_set
This types adds a container for formats + modifiers.

A list that is of [format [modifier]] was chosen instead of
[format modifer] because that is how GBM accepts them.

Co-Authored-By: emersion <contact@emersion.fr>
2019-04-01 19:15:56 +03:00
emersion 5445d8aad0 meson: enable more compiler warnings 2019-03-01 09:20:23 +01:00
emersion 75371d2c88
Require libdrm >= 2.4.95 2019-01-29 19:33:38 +01:00