#include <wlr/types/wlr_scene.h>
#include <wlr/util/log.h>
#include "buffer.h"
+#include "common/macros.h"
#include "common/mem.h"
#include "common/scaled-scene-buffer.h"
#include "node.h"
-/**
- * TODO
- *
- * This implementation does not react to output scale changes itself but only
- * to movement of scene nodes to different outputs. To also handle output scale
- * changes we'd need to keep a list of struct wlr_outputs * in sync and listen
- * to their commit signals.
- *
- * The detection of the max output scale is also not 100% robust for all use
- * cases as on output_enter we only compare the new output scale with the
- * primary_output scale. In specific conditions the primary output may be the
- * same as the new output even though a smaller part of the buffer node is
- * still visible on an output with a bigger scale. This could be solved the
- * same way as the previous point in keeping a list of outputs in sync.
- *
- * Most of this would be easier when wlroots would instead provide a
- * max_scale_changed event because it already touches all the relevant parts
- * when calculating the primary_output and inform wlr_scene_buffers about
- * output changes.
- *
- * See wlroots/types/scene/wlr_scene.c scene_buffer_update_outputs()
- */
-
/* Internal API */
static void
_cache_entry_destroy(struct scaled_scene_buffer_cache_entry *cache_entry, bool drop_buffer)
struct scaled_scene_buffer *self = wl_container_of(listener, self, destroy);
wl_list_remove(&self->destroy.link);
- wl_list_remove(&self->output_enter.link);
- wl_list_remove(&self->output_leave.link);
+ wl_list_remove(&self->outputs_update.link);
wl_list_for_each_safe(cache_entry, cache_entry_tmp, &self->cache, link) {
_cache_entry_destroy(cache_entry, self->drop_buffer);
}
static void
-_handle_output_enter(struct wl_listener *listener, void *data)
+_handle_outputs_update(struct wl_listener *listener, void *data)
{
struct scaled_scene_buffer *self =
- wl_container_of(listener, self, output_enter);
- /* primary_output is the output most of the node area is in */
- struct wlr_scene_output *primary = self->scene_buffer->primary_output;
- /* scene_output is the output we just entered */
- struct wlr_scene_output *scene_output = data;
- double max_scale = scene_output->output->scale;
+ wl_container_of(listener, self, outputs_update);
- if (primary && primary->output->scale > max_scale) {
- max_scale = primary->output->scale;
+ double max_scale = 0;
+ struct wlr_scene_outputs_update_event *event = data;
+ for (size_t i = 0; i < event->size; i++) {
+ max_scale = MAX(max_scale, event->active[i]->output->scale);
}
-
- if (self->active_scale != max_scale) {
+ if (max_scale && self->active_scale != max_scale) {
_update_buffer(self, max_scale);
}
}
-static void
-_handle_output_leave(struct wl_listener *listener, void *data)
-{
- struct scaled_scene_buffer *self =
- wl_container_of(listener, self, output_leave);
- /* primary_output is the output most of the node area is in */
- struct wlr_scene_output *primary = self->scene_buffer->primary_output;
-
- if (primary && primary->output->scale != self->active_scale) {
- _update_buffer(self, primary->output->scale);
- }
-}
-
/* Public API */
struct scaled_scene_buffer *
scaled_scene_buffer_create(struct wlr_scene_tree *parent,
wl_list_init(&self->link);
}
- /* Listen to output enter/leave so we get notified about scale changes */
- self->output_enter.notify = _handle_output_enter;
- wl_signal_add(&self->scene_buffer->events.output_enter, &self->output_enter);
- self->output_leave.notify = _handle_output_leave;
- wl_signal_add(&self->scene_buffer->events.output_leave, &self->output_leave);
+ /* Listen to outputs_update so we get notified about scale changes */
+ self->outputs_update.notify = _handle_outputs_update;
+ wl_signal_add(&self->scene_buffer->events.outputs_update, &self->outputs_update);
/* Let it destroy automatically when the scene node destroys */
self->destroy.notify = _handle_node_destroy;