Commit Graph

218 Commits

Author SHA1 Message Date
Simon Ser 7a9f8d8d6b Use struct initializers instead of memset()
This is a bit more type-safe.
2023-07-07 17:31:11 +02:00
Alexander Orzechowski 57a0313779 wlr_scene: Don't recompute node location during rendering
We already compute it during the render list creation, we should cache
it and re-use the value.
2023-07-01 09:48:25 +00:00
Alexander Orzechowski 48f2a7a3a1 wlr_scene: Simplify direct scanout handling
By adding a sent_feedback bool into the list entry that we can mutate
we no longer need to maintain this `sent_direct_scanout_feedback` variable.

sent_feedback will also be useful for output layers.
2023-07-01 09:48:25 +00:00
Alexander Orzechowski 9613b3bc8a wlr_scene: Wrap render_list nodes in struct
We will be able to add more state here
2023-07-01 09:48:25 +00:00
Alexander Orzechowski ea3c6fde3a wlr_scene: Add opaque region blend mode optimization
If we are only rendering within a region of the surface that is
advertised as opaque, we can choose no blending
2023-06-27 14:02:25 +00:00
Simon Ser be05097968 output: add wlr_output_state_init()
This changes the semantics of wlr_output_state. Instead of having
fields with uninitialized memory when missing from the committed
bitflag, all fields are always initialized (and maybe NULL/empty),
just like we do in wlr_surface_state. This reduces the chances of
footguns when reading a field, and removes the need to check for
the committed bitfield everywhere.

A new wlr_output_state_init() function takes care of initializing
the Pixman region.
2023-06-23 18:07:26 +00:00
Alexander Orzechowski b5eaa47049 scene: Use wlr_output_state_copy for direct scanout path 2023-06-22 11:56:30 +02:00
Alexander Orzechowski 2ac31fc630 wlr_scene: Introduce wlr_scene_buffer_set_filter_mode 2023-06-20 09:04:35 +00:00
Alexander Orzechowski 58a2f8bd5c wlr_scene: Clear damage ring on transform change 2023-06-15 14:57:51 +00:00
Alexander Orzechowski 61667404ce wlr_scene: Clear damage ring on scale change
If we were trying to change the scale in wlr_scene_output_build_state,
we would be using incorrect damage
2023-06-15 14:57:51 +00:00
Alexander Orzechowski 96b95bf775 wlr_scene: Reset damage ring bounds every frame
This fixes damage issues when a output state attempts to change
the transformed size in some way
2023-06-15 14:57:51 +00:00
Alexander Orzechowski 4391845910 wlr_damage_ring_set_bounds: Ignore duplicate size requests 2023-06-15 14:57:51 +00:00
Alexander Orzechowski 3896b6b107 wlr_scene: Fix transforms with non 1 scale
wlr_region_transform / wlr_box_transform want unscaled coordinates here
2023-06-15 14:57:51 +00:00
Alexander Orzechowski 0925a500d1 wlr_scene: Don't use direct scanout if trying to commit a new render_format
Found by inspection.
2023-06-12 20:30:09 -04:00
Alexander Orzechowski 05dd08afe5 scene: introduce wlr_scene_output_build_state() 2023-06-12 14:13:09 +02:00
Alexander Orzechowski 7e67b8152b scene: Don't rely on output current state during rendering
In the next commit, state such as scale, transform, width/height that
we gather from the output might be outdated and incorrect.
2023-06-12 14:13:02 +02:00
Rose Hudson 9e8947e4d5 add render timer API
Based on five calls:
wlr_render_timer_create - creates a timer which can be reused across
  frames on the same renderer
wlr_renderer_begin_buffer_pass - now takes a timer so that backends can
  record when the rendering starts and finishes
wlr_render_timer_get_time - should be called as late as possible so that
  queries can make their way back from the GPU
wlr_render_timer_destroy - self-explanatory

The timer is exposed as an opaque `struct wlr_render_timer` so that
backends can store whatever they want in there.
2023-06-05 19:50:07 +00:00
Kirill Primak af4181f388 drag: use unified map logic 2023-06-02 17:26:18 +00:00
Kirill Primak c63f3659c5 layer-shell: use unified map logic 2023-06-02 17:26:18 +00:00
Kirill Primak b0437fc416 xdg-shell: use unified map logic 2023-06-02 17:26:18 +00:00
Kirill Primak c590bb600f subcompositor: use unified map logic 2023-06-02 17:26:18 +00:00
Alexander Orzechowski 95062904c7 wlr_scene: Introduce wlr_scene_buffer_set_opacity 2023-05-30 15:43:29 +00:00
Alexander Orzechowski 2346b90a9f wlr_scene: Make scene_rect_from_node public
This is in an effort to be more consistent with both already public
getters: wlr_scene_buffer_from_node and wlr_scene_tree_from_node
2023-05-30 15:40:41 +00:00
Alexander Orzechowski 88f80c4a7c wlr_scene: Make scene_tree_from_node public
This is to allow for compositors that want to be more implicit about
how their scene is organized. Such a compositor may want to walk up
at a certain scene node to find something such as a surface to focus on.
2023-05-30 15:40:41 +00:00
Alexander Orzechowski d495fb8c04 wlr_{box, fbox}_equal: Consider empty boxes NULL 2023-05-23 17:57:16 +00:00
Simon Ser d7fcc1e96f scene: port to wlr_render_pass 2023-04-25 17:26:35 +02:00
Alexander Orzechowski eac2eaa6a9 wlr_scene: Fix potential use-after-free in wlr_scene_buffer_set_buffer
Fixes: #3636
2023-04-16 14:01:54 +02:00
Alexander Orzechowski 39be67df46 wlr_scene: Send presentation event before direct scanout output commit
We were doing it too late before and surfaces were never getting
the presentation event.
2023-04-14 22:29:24 +02:00
Simon Ser ec5135cb09 scene: check wlr_output_is_direct_scanout_allowed() 2023-04-06 21:43:43 +02:00
Alexander Orzechowski 9ac94516b8 wlr_scene: Skip direct scanout if there is no damage 2023-03-09 05:38:53 +01:00
Alexander Orzechowski 3ef9f91283 wlr_scene: Add dmabuf_feedback helper 2023-02-20 17:21:17 -05:00
Alexander Orzechowski 4ddc20e14c wlr_scene: Extract considering logic for direct scanout 2023-02-20 16:53:59 -05:00
Alexander Orzechowski 323f0b94db wlr_scene: Cleanup header includes
We don't need to pull wlr_compositor.
2023-02-20 16:53:59 -05:00
Kenny Levinsen 1225f81a6a scene: Add fractional scale handling 2023-02-08 16:31:39 +01:00
Alexander Orzechowski 7b32c25a4f wlr_scene: Rename wlr_scene_surface_from_buffer
This renames it to wlr_scene_surface_try_from_buffer to be more clear
that this function can return NULL. This is inline with the rest of
wlroots[1].

[1] https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3991
2023-02-04 02:57:42 -05:00
Alexander Orzechowski 5007e713b4 wlr_scene: Send intersecting list of scene outputs for outputs_update signal 2023-01-21 16:23:30 -05:00
Simon Ser fecbaa2bd6 scene: stop listening for output enable/mode events
These will go away.
2022-12-01 20:05:04 +00:00
Johan Malm 338e0a3976 scene/layer_shell_v1.c: remove redundant comment 2022-11-29 18:01:57 +00:00
Johan Malm 8e80432a72 scene/layer_shell_v1.c: set exclusive zone correctly
...when only one edge is anchored.

The layer-shell protocol specifies that a positive exclusive-zone value is
'meaningful' if the surface is anchored to either:

1. one edge
2. one edge and both perpendicular edges.

For example, if you wish to position a layer-shell client along the top
edge and make it exclusive, you should be able to either set anchor=TOP or
anchor=TOP|LEFT|RIGHT. It appears that many panels/bars use the latter
approach (anchor to an edge and also both perpendicular edges) which is
probably why this has not been reported previously.

This patch adds support for the first case and thereby makes exclusive
zone behaviour consistent with the protocol and also with sway's extant
layer-shell implementation.
2022-11-29 18:01:57 +00:00
Alexander Orzechowski 32d00984e1 wlr_scene: Expand damage cull region with fractional scales 2022-11-29 07:43:39 +00:00
Alexander Orzechowski fe21fc6920 wlr_scene: Don't cull the entire output when entering direct scanout
We don't need to.
2022-11-29 07:43:39 +00:00
Kirill Primak 5477ad7d90 scene: fix output damage expansion condition
Now, it is checked whether an output pixel corresponds to an integer
number of buffer pixels; if it doesn't, the region is altered to take
this into account.
2022-11-28 23:54:29 +00:00
Simon Ser 35a0d9c85d scene: set output damage during direct scan-out
This allows the backend to have access to the frame damage, as
reported by the scanned-out client. Some KMS drivers can make use
of it (e.g. for PSR, or optimized USB transfers in the GUD driver),
and the Wayland/X11 backends forward it to the parent compositor.
2022-11-26 10:06:56 +01:00
Simon Ser ce089498cc scene: use wlr_output_state for direct scanout
Avoids polluting wlr_output.pending with temporary state. Removes
the need to call wlr_output_rollback() in error codepaths.
2022-11-26 09:52:49 +01:00
Kirill Primak 060df4c6c0 scene: introduce wlr_scene_buffer.events.outputs_update
This event is useful for e.g. sending the preferred buffer scale to the
client.
2022-11-24 22:28:13 +00:00
Simon Ser 48541d2f2e scene: check wlr_renderer_begin return value 2022-11-15 15:50:19 +00:00
Simon Ser 258bf9be1e compositor: drop wlr_surface.{sx,sy}
The concept of a persistent accumulated surface offset is wrong
from a protocol point-of-view. wl_surface.offset is tied to a
commit, its interpretation depends on the surface role.

For example, with the following sequence:

    wl_surface@1.offset(1, 1)
    wl_surface@1.commit()
    wl_pointer@2.set_cursor(wl_surface@1, 42, 42)

The final cursor hotspot is (42, 42): the commit which happened
before the set_cursor request has no impact on the hotspot
computation.

The wlr_output_cursor logic already uses wlr_surface.current.{dx,dy}.
wlr_scene's drag icon doesn't, update it accordingly.
2022-11-15 13:41:09 +00:00
Alexander Orzechowski c8a5dfcc87 wlr_scene: Add drag icon helper 2022-11-14 15:44:43 +00:00
Simon Ser 2b22a10478 scene: constify region APIs 2022-11-11 23:11:17 +00:00
Alexander Orzechowski c58ad0f171 wlr_scene: Remove duplicate buffer check when submitting a new buffer
wlr_buffer allows mutation during its lifetime. This happens for
wlr_client_buffer which fixes damage tracking issues.
2022-11-11 15:37:22 +00:00
Alexander Orzechowski ea40ba4f6a wlr_scene: Fix texture reuse
Add private interface to ignore a buffer that's locking a client_buffer
for damage tracking. This should eventually be replaced by wlr_raster.
2022-11-11 00:08:04 +00:00
Simon Ser 440d7fa072 scene: destroy addons before cleaning up internal state
This allows addons to access wlr_scene_node/wlr_scene_surface
fields to clean up themselves.
2022-11-08 16:47:59 +00:00
Simon Ser 24c149fefb scene: fix whitespace 2022-11-08 16:47:59 +00:00
Kirill Primak 123a08b448 scene: fix output damage expansion
This fixes e.g. `weston-simple-damage --use-viewport` which technically
renders at the buffer scale of 0.5.
2022-11-08 06:37:42 +00:00
Kirill Primak 92e3c5b798 scene: fix buffer source box transforming 2022-11-05 14:44:57 +03:00
Alexander Orzechowski c2d2773df5 wlr_scene: Handle fractional scaling better
Try to alleviate scaling inaccuracies by implementing a fudge factor.
2022-10-22 19:13:21 +00:00
Alexander Orzechowski c07424411a wlr_scene: Destroy the texture when setting a new buffer.
Fixes: https://github.com/labwc/labwc/issues/587
Fixes: f0e31e806f (wlr_scene: Fix not updating the scene node when setting a new buffer)
2022-10-14 20:11:28 +00:00
Alexander Orzechowski 5ba6cf517b wlr_scene: use wl_container_of() instead of casts 2022-10-13 16:36:05 +00:00
Alexander Orzechowski 99f55303aa wlr_scene: Apply source box translation 2022-10-10 08:09:55 +00:00
Alexander Orzechowski ceff381747 wlr_scene: Ignore disabled outputs 2022-10-10 08:09:55 +00:00
Alexander Orzechowski f0e31e806f wlr_scene: Fix not updating the scene node when setting a new buffer
If a new buffer is set for a buffer node, we must update the entire
node unconditionally if the buffer size changes, or the buffer is given
a buffer where it was previously NULL.

While we're here, let's avoid calling scene_node_update on just damage
updates. If the caller hasn't given us a damage region we just assume
the whole buffer.
2022-10-10 08:09:55 +00:00
Alexander Orzechowski dd9cfd3e2f wlr_scene: Be resilient against overflow conditions
If the area calculations for output overlap overflow a signed int, we
may not consider it to be a primary output. Turn this into an unsigned
type so this happens less frequently.
Additionally, it is possible the overflow would produce 0, we can handle
this by simply changing the comparison to more than or equal.

While we're here, let's assert that we always assign a primary output
if there are any intersecting outputs.
2022-10-10 08:09:55 +00:00
Alexander Orzechowski 2e06ff5688 wlr_scene: Clarify surface commit frame events 2022-09-05 08:24:50 +00:00
Alexander Orzechowski 35d94d779c wlr_scene: Consider screen position when culling background 2022-09-03 18:42:17 -04:00
Alexander Orzechowski 78cf39b6bd wlr_scene: Don't leak a region32 when texture failed to upload 2022-08-29 16:19:30 +00:00
Alexander Orzechowski fe9e193ab5 wlr_scene: More sanity checking
The render list should neither contain scene trees or null buffers.
2022-08-29 16:19:30 +00:00
Alexander Orzechowski fa7d2cb8d6 wlr_scene: Only consider visible parts of the node when culling background
Originally, I thought that we could safely subtract opaque regions
from the background even if the black rect optimization was kicking in.
This is wrong because a scene node that isn't fully occluded will still
appear in the render list even if its partially under a black rect. We
need to make sure that while culling the background, we only consider
opaque regions that are also visible. This will fix the black rect
optimization with the background.
2022-08-26 19:07:52 -04:00
yiqiang 6a11256cd0 scene/wlr_scene:fix judgment of invisible node 2022-08-26 22:19:22 +00:00
Alexander Orzechowski d3cb6b73a2 wlr_scene: Initialize region32 before trying to use it 2022-08-22 14:46:41 -04:00
Alexander Orzechowski 8bd7170fd9 Use env helpers 2022-08-22 10:18:52 -04:00
Alexander Orzechowski e7477c7114 wlr_scene: Improve awkward code style 2022-08-22 10:18:00 -04:00
Alexander Orzechowski 9bba4284e4 wlr_scene: Cull background
We don't need to worry about the black rect optimization here (that
always assumes that there will be a black background) because the
background is culled based on the render list. That means if a black rect
is removed, the visibility will reach all the way to the bottom forcing
the renderer to clear the area not breaking the assumption.
2022-08-22 10:17:59 -04:00
Alexander Orzechowski 6d1b8b376d wlr_scene: Only enable black rect optimization if culling is enabled
If culling is not enabled, there is no longer any guarantee that the
elements behind the rect won't be rendered. We must render the black rect
in all circumstances to cover up anything rendered.

This fixes the WLR_SCENE_DISABLE_VISIBILTY option.
2022-08-19 16:18:46 -04:00
Alexander Orzechowski 4d4f823263 wlr_scene: Simplify calculate_visibilty option 2022-08-19 16:18:11 -04:00
Kenny Levinsen 7c575922c0 wlr_scene: Convert render_list to wl_array
This simplifies some of the growth logic, but uses array_realloc to shrink the
array if needed.
2022-08-19 19:38:33 +02:00
Alexander Orzechowski ef4baea0e2 Use wl_signal_emit_mutable 2022-08-18 07:16:16 -04:00
yiqiang 3621c14b82 wlr_scene: fix color value when filtering black boxes
Signed-off-by: yiqiang <yiqiang@kylinos.cn>
2022-08-16 10:52:03 +08:00
Alexander Orzechowski bea4bd43e3 wlr_scene: Use wlr_box_equal 2022-08-15 07:37:09 -04:00
Alexander Orzechowski bcf7a79357 wlr_scene: Use wlr_fbox_equals 2022-08-15 06:14:59 -04:00
Alexander Orzechowski 919e67da7d wlr_scene: Account for occlusion by other scene nodes when calculating visibility 2022-08-14 02:38:51 -04:00
Alexander Orzechowski ce57485e6a wlr_scene: Calculate output intersections based on node visibility
This has a few benefits one of them crucial for proper operation:
 - The primary output will be based on the largest area that is actually
 visible to the user. Presentation and frame done events are based on
 this state. This is important to do since we cull frame done events.
 If we happen to be in a situation where a surface sits mostly on output
 A and some on output B but is completely obstructed by for instance a
 fullscreen surface on output A we will erroneously send frame_done
 events based on output A. If we base things as they are in reality
 (visibility) the primary output will instead be output B and things will
 work properly.
 - The primary output will be NULL if the surface is completely hidden.
 Due to quirks with wayland, on a surface commit, frame done events are
 required to be sent. Therefore, a new frame will be submitted for rendering
 on the primary output. We can improve adaptive sync on completely hidden
 but enabled surfaces if we null out the primary output in this state.
 - The client will be more likely to choose better metadata to use
 for rendering to an output's optimal rendering characteristics.
2022-08-14 02:38:51 -04:00
Alexander Orzechowski 342830e99c wlr_scene/surface: Hook through opaque metadata 2022-08-14 02:38:50 -04:00
Alexander Orzechowski 18417026be wlr_scene: Introduce buffer opaque region metadata 2022-08-14 02:38:50 -04:00
Alexander Orzechowski 0a9a941ba3 wlr_scene: Rewrite direct scan out logic to rely on visibility
Also make the regular rendering logic use the introduced
render list.
2022-08-14 02:38:50 -04:00
Alexander Orzechowski 14f4cfffba wlr_scene: Don't render non visible parts of textures/rects
We can also get rid of the intersection checks in the rendering functions
because we are guaranteed to already be in the node do to the prior
intersection checking of the node visibility.
2022-08-14 02:38:50 -04:00
Alexander Orzechowski d16d341381 wlr_scene: Only send frame done events for visible buffers 2022-08-14 02:38:50 -04:00
Alexander Orzechowski 6d62300324 wlr_scene_set_buffer_with_damage: Only damage the visible parts of the node 2022-08-14 02:38:50 -04:00
Alexander Orzechowski c6246272fd wlr_scene: Rework damage handling
Simplify damage handling by using our cached visibility state.
Damaging can happen in one step because since we can use the old visibility
state which represent what portions of the screen the scene node was. This
way we can damage everything in one step after the fact.
2022-08-14 02:38:50 -04:00
Alexander Orzechowski 028606512d wlr_scene: Add per scene node visibility 2022-08-14 01:39:20 -04:00
Alexander Orzechowski f411ca040e wlr_scene: Damage scene on node destroy by disabling node
This removes one trivial call of scene_node_damage_whole. It's easier
to disable the node later than it is to do the damage dance later.
2022-08-14 01:39:20 -04:00
Alexander Orzechowski 7f17774d18 wlr_scene: Introduce scene_nodes_in_box
Will query the scene for all nodes that appear in the given wlr_box.
The nodes will be sent to the iterator from closest to farthest from the
eye.

Refactor wlr_scene_node_at to use this new function.
2022-08-14 01:39:20 -04:00
Alexander Orzechowski f72aeacd6e wlr_scene: Add option to disable direct scanout
Closes: #3405
Supersedes: !3562

Co-authored-by: Xiao YaoBing <xiaoyaobing@qq.com>
2022-08-08 00:40:21 -04:00
Kenny Levinsen 3baf2a6bcf scene/layer_shell: Ignore unmapped exclusion zone
Only the exclusion zone for mapped layer shell surfaces should be respected. In
particular, a layer shell surface that was mapped with an exclusion zone but is
now unmapped should not adjust the usable area.

Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3471
2022-08-06 00:23:44 +02:00
Alexander Orzechowski 5dc1d4671d wlr_scene: Maintain damage highlight regions per output
The logic doesn't support handling multiple outputs so let's not break
the assumption and handle damages per output much like how damage_ring
is done.
2022-07-03 12:21:52 -04:00
Alexander Orzechowski fdfdd01a79 wlr_scene: Use direct assignment for damage indicator timestamps 2022-07-03 12:21:39 -04:00
Kirill Primak 694b8c6683 scene: add missing output damage listener
This is necessary to handle damage coming from the backend and software
cursors.
2022-06-29 21:19:38 +03:00
Kirill Primak 97f0347780 scene: switch to wlr_damage_ring 2022-06-29 18:54:27 +03:00
Johan Malm d57d2e0e36 scene/layer_shell_v1.c: fix bug in width/height calculations
...in wlr_scene_layer_surface_v1_configure()

Reproduce bug with waybar by setting `"margin": 5,`
in ~/.config/waybar/config. It will result in the right edge of the panel
extending outside the edge of the output.

The bug can also be reproduced with gtk-layer-demo by anchoring
left/right/top/bottom and setting respective margins

Relates-to: https://github.com/labwc/labwc/issues/382
2022-06-08 20:13:55 +00:00
Consolatis 0173275f7e scene/output_layout: Fix crash in scene_output_layout_output_destroy
Closes: #3448
2022-06-07 20:58:41 +02:00
Alexander Orzechowski cc5a02e75d wlr_scene_buffer: Update primary_output on output destroy 2022-06-02 10:33:04 -04:00