2022-02-21 03:18:38 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
2023-01-30 05:30:24 +01:00
|
|
|
#include <wlr/types/wlr_output.h>
|
2022-02-21 03:18:38 +01:00
|
|
|
#include <wlr/types/wlr_scene.h>
|
2023-01-30 05:30:24 +01:00
|
|
|
#include <wlr/util/log.h>
|
2023-01-31 03:35:13 +01:00
|
|
|
#include "common/scene-helpers.h"
|
2024-05-15 23:07:23 +01:00
|
|
|
#include "magnifier.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
|
2022-05-26 00:39:04 +02:00
|
|
|
struct wlr_surface *
|
|
|
|
|
lab_wlr_surface_from_node(struct wlr_scene_node *node)
|
|
|
|
|
{
|
|
|
|
|
struct wlr_scene_buffer *buffer;
|
|
|
|
|
struct wlr_scene_surface *scene_surface;
|
|
|
|
|
|
|
|
|
|
if (node && node->type == WLR_SCENE_NODE_BUFFER) {
|
|
|
|
|
buffer = wlr_scene_buffer_from_node(node);
|
2023-02-07 14:28:40 -05:00
|
|
|
scene_surface = wlr_scene_surface_try_from_buffer(buffer);
|
2022-05-26 00:39:04 +02:00
|
|
|
if (scene_surface) {
|
|
|
|
|
return scene_surface->surface;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2022-04-26 23:56:27 +02:00
|
|
|
|
|
|
|
|
struct wlr_scene_node *
|
|
|
|
|
lab_wlr_scene_get_prev_node(struct wlr_scene_node *node)
|
|
|
|
|
{
|
|
|
|
|
assert(node);
|
|
|
|
|
struct wlr_scene_node *prev;
|
|
|
|
|
prev = wl_container_of(node->link.prev, node, link);
|
|
|
|
|
if (&prev->link == &node->parent->children) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return prev;
|
|
|
|
|
}
|
2023-01-30 05:30:24 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is a copy of wlr_scene_output_commit()
|
|
|
|
|
* as it doesn't use the pending state at all.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
lab_wlr_scene_output_commit(struct wlr_scene_output *scene_output)
|
|
|
|
|
{
|
|
|
|
|
assert(scene_output);
|
|
|
|
|
struct wlr_output *wlr_output = scene_output->output;
|
|
|
|
|
struct wlr_output_state *state = &wlr_output->pending;
|
2024-05-15 23:07:23 +01:00
|
|
|
struct output *output = wlr_output->data;
|
|
|
|
|
bool wants_magnification = output_wants_magnification(output);
|
|
|
|
|
static bool last_mag = false;
|
2023-01-30 05:30:24 +01:00
|
|
|
|
|
|
|
|
if (!wlr_output->needs_frame && !pixman_region32_not_empty(
|
2024-05-15 23:07:23 +01:00
|
|
|
&scene_output->damage_ring.current) && !wants_magnification
|
|
|
|
|
&& last_mag != is_magnify_on()) {
|
2023-01-30 05:30:24 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2024-05-15 23:07:23 +01:00
|
|
|
|
|
|
|
|
last_mag = is_magnify_on();
|
|
|
|
|
|
2023-01-30 05:30:24 +01:00
|
|
|
if (!wlr_scene_output_build_state(scene_output, state, NULL)) {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to build output state for %s",
|
|
|
|
|
wlr_output->name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-05-15 23:07:23 +01:00
|
|
|
|
|
|
|
|
struct wlr_box additional_damage = {0};
|
|
|
|
|
if (state->buffer && is_magnify_on()) {
|
|
|
|
|
magnify(output, state->buffer, &additional_damage);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-30 05:30:24 +01:00
|
|
|
if (!wlr_output_commit(wlr_output)) {
|
2024-04-08 16:29:20 +02:00
|
|
|
wlr_log(WLR_INFO, "Failed to commit output %s",
|
2023-01-30 05:30:24 +01:00
|
|
|
wlr_output->name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* FIXME: Remove the following line as soon as
|
|
|
|
|
* https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4253
|
|
|
|
|
* is merged. At that point wlr_scene handles damage tracking internally
|
|
|
|
|
* again.
|
|
|
|
|
*/
|
|
|
|
|
wlr_damage_ring_rotate(&scene_output->damage_ring);
|
2024-05-15 23:07:23 +01:00
|
|
|
|
|
|
|
|
if (!wlr_box_empty(&additional_damage)) {
|
|
|
|
|
wlr_damage_ring_add_box(&scene_output->damage_ring, &additional_damage);
|
|
|
|
|
}
|
2023-01-30 05:30:24 +01:00
|
|
|
return true;
|
|
|
|
|
}
|