Commit Graph

339 Commits

Author SHA1 Message Date
Simon Ser 3ce2ea9e16 Move allocator stuff into new directory
Add render/allocator/ and include/render/allocator/ to hold
everything allocator-related.
2021-08-25 09:57:20 -04:00
Rouven Czerwinski aa78c50bf1 output: check output enabled before sending frame
Similar to commit 85757665e6 ("backend/drm: Check if output is enabled
before sending frame event"), check if the output is still enabled
before sending the frame event. This fixes the bug not only for the DRM
backend, but for wayland and X11 as well.
2021-08-17 21:07:43 +02:00
Kirill Primak 11f799e88e wlr_outputs: add wlr_addon_set 2021-08-10 19:15:48 +02:00
Simon Ser df0e75ba05 output: try skipping buffer allocation if the backend allows it
When enabling an output, skip the empty buffer allocation if the
backend accepts modesets without a buffer.

This fixes mode-setting with the noop backend.
2021-08-04 10:18:59 -04:00
Simon Ser 923258b0be backend/drm: preserve mode order from kernel
The kernel orders the mode list from highest to lowest. Preserve
this ordering in the wlr_output.modes list.
2021-08-02 09:28:21 -04:00
Simon Ser 3132c0ab10 output: drop wlr_output_state.buffer_type
This is now unconditionally set to WLR_OUTPUT_STATE_BUFFER_SCANOUT.
2021-07-29 09:48:33 -04:00
Simon Ser 4ddde1a7bd output: drop wlr_output_impl.{attach,rollback}_render
No backend uses these anymore.
2021-07-29 09:48:33 -04:00
Simon Ser 6aadf811aa output: fallback to modifier-less allocation on modeset test failure
Sometimes we allocate a buffer with modifiers but then fail to
perform a modeset with it. This can happen on Intel because of
bandwidth limitations. To mitigate this issue, it's possible to
re-allocate the buffer with modifiers.

Add the logic to do so in wlr_output.
2021-07-28 22:52:35 +02:00
Simon Ser 0fb55c76d0 output: allocate and attach empty buffer on modeset
Some backends need a buffer in order to be able to perform a
modeset.
2021-07-28 22:52:35 +02:00
Simon Ser 1a5b6722a8 output: use pending resolution when allocating swapchain
This allows the swapchain to be created with the correct resolution
during a mode change.
2021-07-28 22:52:35 +02:00
Simon Ser d1c931cbe8 output: fallback to XRGB in output_pick_format
This will be necessary for the primary buffer.
2021-07-28 22:52:35 +02:00
Simon Ser bcd5d8504c output: remove wlr_output_impl.export_dmabuf
No backend is using it anymore.
2021-07-12 13:29:03 -04:00
Simon Ser 87e8c60faf output: add generic wlr_output_export_dmabuf implementation
When wlr_output manages its own swap-chain, there's no need to
hook into the backend to grab DMA-BUFs. Instead, maintain a
wlr_output.front_buffer field with the latest committed buffer.
2021-07-12 13:29:03 -04:00
Simon Ser c2bd63c186 output: detach buffer from renderer before commit
Right now we rely entirely on implicit sync for synchronizing
access to GPU buffers. Implicit sync works by setting
synchronization points on the buffer in writers, and letting
readers wait on these sync points before accessing the buffer.

With OpenGL, sync points are created using functions such as
eglSwapBuffers or glFlush. If none of these special functions
are called, no sync point will be created and readers will
potentially access a buffer that hasn't finished rendering yet.

In the context of wlroots, OpenGL is the writer and the backend
(KMS or parent Wayland/X11 session) is the reader. After we're
done rendering a frame, and before passing that frame to the
backend, we need to call glFlush.

glFlush is called when the buffer is detached from the renderer.
This is a task done by output_clear_back_buffer. So let's call
this function before invoking the impl->commit hook, instead of
calling it after.

All of this is maybe a little tricky to get right with the
current renderer_bind_buffer API. The new
wlr_renderer_begin_with_buffer API is much better, because glFlush
is called on wlr_renderer_end, so it's more intuitive.

Closes: https://github.com/swaywm/wlroots/issues/3020
2021-07-07 12:00:43 -04:00
Simon Zeni e192d87731 move wlr_box from /types to /util 2021-07-06 21:43:17 +02:00
Simon Ser 6259fd23fb output: reset back buffer on failed commit
On commit failure, we need to unbind the back buffer from the
renderer.

This fixes assertions triggered on commits following a failed commit
where the compositor called wlr_output_attach_render.
2021-06-13 13:17:30 +02:00
Simon Ser b2f6db3533 render: drop wlr_ prefix from wlr_renderer_bind_buffer
Make it clear this function is a private wlroots API and will stay
that way.
2021-06-09 10:26:09 +02:00
Simon Ser fbadadf36f output: use wlr_renderer_begin_with_buffer for cursor 2021-06-09 10:26:09 +02:00
Simon Ser 1a06ea7750 output: make attach_render and rollback_render optional
If these aren't provided by the backend, allocate a swapchain for the
output.
2021-06-07 15:42:38 +02:00
Simon Ser 233a2617cf output: split output_pick_cursor_format
Introduce output_pick_format that can be re-used for the primary
buffer too.
2021-06-07 15:42:38 +02:00
Simon Ser 2b0a1aeed5 output: take a wlr_buffer in set_cursor
Instead of passing a wlr_texture to the backend, directly pass a
wlr_buffer. Use get_cursor_size and get_cursor_formats to create
a wlr_buffer that can be used as a cursor.

We don't want to pass a wlr_texture because we want to remove as
many rendering bits from the backend as possible.
2021-06-02 11:08:52 +02:00
Simon Ser 6622cd3277 output: correctly handle outputs without a test() impl
This fixes a crash when calling wlr_output_test() on a headless
output.

Closes: https://github.com/swaywm/sway/issues/6213
2021-04-21 08:52:50 +02:00
Simon Ser 44fa2c4b49 output: fix transform matrix for 90/270 rotations
We need to adjust the second translation depending on the transform
we applied.

Fixes: 9601a2abf0 ("output: improve transform matrix calculation"
Closes: https://github.com/swaywm/wlroots/issues/2774
2021-03-11 22:52:38 +01:00
Simon Zeni 9601a2abf0 output: improve transform matrix calculation
Compute only the transform matrix in the output. The projection matrix
will be calculated inside the gles2 renderer when we start rendering.

The goal is to help the pixman rendering process.
2021-03-10 15:33:36 +01:00
Simon Ser 675bc39658 Fix wl_shm_format passed to wlr_texture_from_pixels
Fixes: 27fba3df43 ("render: use DRM formats in wlr_texture_from_pixels")
2021-02-23 17:36:32 +01:00
Simon Ser 00bf6674b3 output: use DRM format in wlr_output_preferred_read_format 2021-02-23 16:09:26 +01:00
Simon Ser b3e76d6678 output: send commit event after pending state is cleared
References: https://github.com/swaywm/wlroots/issues/2098
2021-01-16 09:06:27 +01:00
Simon Ser cc56b4f073 output: remove scale/transform events
Instead, the commit event should be used.
2021-01-15 10:18:56 +01:00
Simon Ser 768131e488 output: stop assuming a frame is pending in init
- The DRM backend initially doesn't have a frame scheduled initially.
  However the compositor is expected to set a mode to start the
  rendering loop (frame_pending is set to true in drm_crtc_pageflip).
- The headless and X11 backends have a timer to schedule frames, so they
  ignore this hint completely.
- The Wayland backend renders a fake frame to start the rendering loop.
  It's the only case where a frame is pending on init, move the
  assumption there.
2020-12-13 12:16:28 +01:00
Simon Ser e9c1f0f7d3
output: improve basic test logging 2020-12-09 22:20:24 +01:00
Kenny Levinsen ebecc5404b surface: Make send_enter store entered outputs
wlr_surface_send_enter now stores outputs that have been entered.
Combined with a new 'bind' event on wlr_output, this allows us to delay
enter events as necessary until the respective wl_output global has been
bound.

Closes: https://github.com/swaywm/wlroots/issues/2466
2020-11-23 10:58:50 +01:00
Simon Ser 8c8164c4a6 output: add when field to wlr_output_event_commit
Similar to the one already present in wlr_output_event_precommit.
2020-11-05 09:43:42 +01:00
Simon Ser c674241ec0 output: introduce wlr_output_event_commit
This event contains a `committed` bitfield, which allows callers to know
which output fields changed during the commit.

This allows users to setup a single atomic commit listener, instead of
setting up one listener for each event (mode, scale, transform, and so
on).

References: https://github.com/swaywm/wlroots/issues/2098
2020-08-27 13:54:19 -06:00
Ilia Bozhinov 0032954c75 make sure to fail setting gamma on disabled outputs 2020-08-03 12:05:35 +02:00
Simon Ser 155d57b01d output: fix dangling renderer context after wlr_output_preferred_read_format
attach_render was called without un-setting the current rendering
context afterwards.

Closes: https://github.com/swaywm/wlroots/issues/2164
2020-06-19 11:50:42 -06:00
Simon Ser 3c5dbfd97c output: make rollback_render mandatory
If the output backend provides attach_render, assert it also provides a
way to revert it via rollback_render.
2020-06-19 11:50:42 -06:00
Simon Ser bf93d2e67c output: rename impl->rollback to rollback_render
The output backend API is now mostly state-less thanks to the atomic
hooks (commit and test). There is one exception though: attach_render.
This function makes the rendering context current. However sometimes the
compositor might decide not to render after attach_render (e.g. when
there's nothing new to render to the back buffer). Thus
wlr_output_rollback has been introduced to revert the pending state.

Because the output backend API is mostly state-less, the only thing
wlr_output_impl.rollback needs to do is revert the current rendering
context. Rename the function to rollback_render to make this clear. Add
a check in the common wlr_output code to only call rollback_render when
attach_buffer has been previously called.

On the long term, we'll be able to remove attach_render and
rollback_render together.
2020-06-19 11:50:42 -06:00
Simon Ser 347bdb6d9a output: make wlr_output_set_gamma atomic
wlr_output_set_gamma is now double-buffered and applies the gamma LUT on
the next output commit.
2020-05-14 20:09:28 +02:00
Simon Ser 0281b58d2f output: fix maybe-uninitialized warning
GCC is complaining about a maybe-uninitialized variable when doing a
release build. Even if that can't actually happen because all enum
values are handled, add an abort call to silence the warning.
2020-04-10 17:05:00 +02:00
Simon Ser 50ade3671f output: check for buffer size compatibility in common code
Instead of checking for buffer size compatibility in each backend,
centralize the check in wlr_output itself.
2020-04-10 15:52:20 +02:00
Simon Ser 5f092c55d1 output: fix blurred hw cursors with fractional scaling
The scaling factor was being implicitly cast to an int.

Closes: https://github.com/swaywm/sway/issues/4927
2020-04-10 15:10:12 +02:00
Simon Ser 507d9bc19e Add wlr_output_impl.rollback
Most of the pending output state is not forwarded to the backend prior
to an output commit. For instance, wlr_output_set_mode just stashes the
mode without calling any wlr_output_impl function.
wlr_output_impl.commit is responsible for applying the pending mode.

However, there are exceptions to this rule. The first one is
wlr_output_attach_render. It won't go away before renderer v6 is
complete, because it needs to set the current EGL surface.

The second one is wlr_output_attach_buffer.
wlr_output_impl.attach_buffer is removed in [1].

When wlr_output_rollback is called, all pending state is supposed to be
cleared. This works for all the state except the two exceptions
mentionned above. To fix this, introduce wlr_output_impl.rollback.

Right now, the backend resets the current EGL surface. This prevents GL
commands from affecting the output after wlr_output_rollback.

This patch is required for FBO-based outputs to work properly. The
compositor might be using FBOs for its own purposes [2], having leftover
FBO state can have bad consequences.

[1]: https://github.com/swaywm/wlroots/pull/2097
[2]: https://github.com/swaywm/wlroots/pull/2063#issuecomment-597614312
2020-04-08 17:33:00 +02:00
Simon Ser 6977f3a843 output: check buffer in wlr_output_test
Check that buffer can be scanned out in wlr_output_test instead of
wlr_output_attach_buffer. This allows the backend to have access to the
whole pending state when performing the check.

This brings the wlr_output API more in line with the KMS API.

This removes the need for wlr_output_attach_buffer to return a value,
and for wlr_output_impl.attach_buffer.
2020-04-08 16:31:21 +02:00
Simon Ser e041158988 output: introduce wlr_output_test 2020-04-08 16:31:21 +02:00
Simon Ser 6595db6409 buffer: add a release event
Consumers call wlr_buffer_lock. Once all consumers are done with the
buffer, only the producer should have a reference to the buffer. In this
case, we can release the buffer (and let the producer re-use it).
2020-04-02 15:03:43 +02:00
Simon Ser e0bbafc253 output: replace wlr_output.damage with a damage event
This patch disambiguates the needs_frame event by uncoupling it from
damage. A new separate damage event is emitted when the backend damages
the output (this happens e.g. VT is changed or software cursors are
used). The event specifies the damaged region.

The wlr_output.damage field is removed. wlr_output is no longer
responsible for tracking its own damage, this is wlr_output_damage's
job.

This is a breaking change, but wlr_output_damage users shouldn't need an
update.

Bugs fixed:

- Screen flashes on VT switch
- Cursor damage issues on the X11 and headless backends

Closes: https://github.com/swaywm/sway/issues/5086
2020-03-12 22:47:59 +01:00
Simon Ser 07737e85cc output: add comment about needs_frame in wlr_output_schedule_frame
Add a comment to not forget why this call is necessary.

References: https://github.com/swaywm/wlroots/pull/2053
2020-03-12 15:01:09 +01:00
Simon Ser 7bce056f1d output: don't send a needs_frame event if already sent 2020-03-06 21:35:00 +01:00
Simon Ser a4c7c6db09 output: make wlr_output_schedule_frame set output->needs_frame
This way, wlr_output_schedule_frame will always be followed by a
wlr_output_commit. This forces the compositor to render an extra
frame before stopping the rendering loop.

To test, run wleird's frame-callback [1], make sure it's the only
visible client on the output and check the interval between frame
events is the output's refresh period instead of zero.

[1]: https://github.com/emersion/wleird/blob/master/frame-callback.c

Closes: https://github.com/swaywm/wlroots/issues/2051
2020-03-06 21:35:00 +01:00
Simon Ser 7017fa95b8 output: add adaptive_sync_enabled property 2020-03-06 21:32:58 +01:00