AtlatestRepositorysigil-wm
1
/* SPDX-License-Identifier: BSD-3-Clause */2
/* Record every buffer commit, without retaining full frames. */3
static bool record_output_samples(struct server *server, uint64_t id,4
const int64_t *words, size_t count) {5
struct output *output = find_output(server, id);6
if (!output || output->capture[0] || count < 5 || words[0] < 1 || words[0] > 600 ||7
words[1] < 1 || words[1] > 64) return false;8
size_t points = words[1], path = 2 + points * 2;9
if (count <= path || count - path >= PATH_MAX) return false;10
for (size_t index = 2; index < path; index++)11
if (words[index] < 0 || words[index] > 16383) return false;12
for (size_t index = path; index < count; index++)13
if (words[index] < 1 || words[index] > 127) return false;14
for (size_t index = path; index < count; index++)15
output->capture[index - path] = words[index];16
output->capture[count - path] = 0;17
FILE *file = fopen(output->capture, "w");18
if (!file) { output->capture[0] = 0; return false; }19
if (fclose(file)) { output->capture[0] = 0; return false; }20
output->sample_frames = words[0];21
output->sample_index = 0;22
output->sample_count = points;23
for (size_t index = 0; index < points * 2; index++)24
output->sample_points[index] = words[index + 2];25
wlr_output_lock_attach_render(output->native, true);26
wlr_damage_ring_add_whole(&output->scene->damage_ring);27
wlr_output_schedule_frame(output->native);28
return true;29
}31
struct headless_search {32
struct wlr_backend *backend;33
unsigned count;34
};35
static void headless_backend(struct wlr_backend *backend, void *data) {36
struct headless_search *search = data;37
if (wlr_backend_is_headless(backend)) {38
search->backend = backend;39
search->count++;40
}41
}42
static bool add_headless_output(struct server *server, int64_t *words, size_t count) {43
if (count < 3 || words[0] < 1 || words[0] > 16384 || words[1] < 1 || words[1] > 16384 ||44
words[2] < 0 || words[2] > 128 || count != 3 + (size_t)words[2]) return false;45
struct headless_search search = {0};46
if (wlr_backend_is_headless(server->backend)) headless_backend(server->backend, &search);47
else wlr_multi_for_each_backend(server->backend, headless_backend, &search);48
if (search.count != 1) return false;49
for (int64_t index = 0; index < words[2]; index++) {50
if (words[index + 3] < 32 || words[index + 3] > 126) return false;51
server->pending_output_name[index] = words[index + 3];52
}53
server->pending_output_name[words[2]] = 0;54
struct wlr_output *output = wlr_headless_add_output(search.backend, words[0], words[1]);55
server->pending_output_name[0] = 0;56
if (output && !output->data) {57
wlr_output_destroy(output);58
return false;59
}60
return output != NULL;61
}