output: avoid use of wlr_scene_output.WLR_PRIVATE.index

We were only using it to allow quick bitset comparisons of sets of
outputs (such as view->outputs). We can maintain our own bit IDs for
this purpose and avoid using the private wlroots field.

Note: from my reading of wlr_scene_output_create(), it appears to
always take the lowest unused index, resulting in aggressive re-use of
index values when outputs are disconnected and reconnected. I've tried
to make re-use as infrequent as possible. This could theoretically
reduce the chance of a mix-up in view_update_outputs(), although I'm
not aware of any practical scenario where it matters.

v2: prevent adding more than 64 outputs
This commit is contained in:
John Lindgren 2025-11-25 17:36:02 -05:00 committed by Consolatis
parent 6521067171
commit e96f4a032b
5 changed files with 59 additions and 4 deletions

View file

@ -257,6 +257,7 @@ struct server {
struct wl_list outputs;
struct wl_listener new_output;
struct wlr_output_layout *output_layout;
uint64_t next_output_id_bit;
struct wl_listener output_layout_change;
struct wlr_output_manager_v1 *output_manager;

View file

@ -33,6 +33,18 @@ struct output {
struct wl_listener frame;
struct wl_listener request_state;
/*
* Unique power-of-two ID used in bitsets such as view->outputs.
* (This assumes there are never more than 64 outputs connected
* at once; wlr_scene_output has a similar limitation.)
*
* There's currently no attempt to maintain the same ID if the
* same physical output is disconnected and reconnected.
* However, IDs do get reused eventually if enough outputs are
* disconnected and connected again.
*/
uint64_t id_bit;
bool gamma_lut_changed;
};

View file

@ -158,7 +158,7 @@ struct view {
* This is used to notify the foreign toplevel
* implementation and to update the SSD invisible
* resize area.
* It is a bitset of output->scene_output->index.
* It is a bitset of output->id_bit.
*/
uint64_t outputs;