2023-02-20 11:56:42 +01:00
|
|
|
#include <stdlib.h>
|
2023-03-06 16:19:40 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <wlr/util/log.h>
|
2022-06-07 18:54:42 +02:00
|
|
|
#include "types/wlr_output.h"
|
|
|
|
|
2023-02-20 11:56:42 +01:00
|
|
|
void wlr_output_state_finish(struct wlr_output_state *state) {
|
2023-06-12 16:34:32 +02:00
|
|
|
if (state->committed & WLR_OUTPUT_STATE_BUFFER) {
|
|
|
|
wlr_buffer_unlock(state->buffer);
|
|
|
|
// struct wlr_buffer is ref'counted, so the pointer may remain valid after
|
|
|
|
// wlr_buffer_unlock(). Reset the field to NULL to ensure nobody mistakenly
|
|
|
|
// reads it after output_state_finish().
|
|
|
|
state->buffer = NULL;
|
|
|
|
}
|
2023-02-20 11:56:42 +01:00
|
|
|
if (state->committed & WLR_OUTPUT_STATE_DAMAGE) {
|
|
|
|
pixman_region32_fini(&state->damage);
|
|
|
|
}
|
|
|
|
free(state->gamma_lut);
|
|
|
|
}
|
|
|
|
|
2022-06-07 18:54:42 +02:00
|
|
|
void wlr_output_state_set_enabled(struct wlr_output_state *state,
|
|
|
|
bool enabled) {
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_ENABLED;
|
|
|
|
state->enabled = enabled;
|
2022-09-28 11:09:53 +02:00
|
|
|
state->allow_artifacts = true;
|
2022-06-07 18:54:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_state_set_mode(struct wlr_output_state *state,
|
|
|
|
struct wlr_output_mode *mode) {
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_MODE;
|
|
|
|
state->mode_type = WLR_OUTPUT_STATE_MODE_FIXED;
|
|
|
|
state->mode = mode;
|
2022-09-28 11:09:53 +02:00
|
|
|
state->allow_artifacts = true;
|
2022-06-07 18:54:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_state_set_custom_mode(struct wlr_output_state *state,
|
|
|
|
int32_t width, int32_t height, int32_t refresh) {
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_MODE;
|
|
|
|
state->mode_type = WLR_OUTPUT_STATE_MODE_CUSTOM;
|
|
|
|
state->custom_mode.width = width;
|
|
|
|
state->custom_mode.height = height;
|
|
|
|
state->custom_mode.refresh = refresh;
|
2022-09-28 11:09:53 +02:00
|
|
|
state->allow_artifacts = true;
|
2022-06-07 18:54:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_state_set_scale(struct wlr_output_state *state, float scale) {
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_SCALE;
|
|
|
|
state->scale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_state_set_transform(struct wlr_output_state *state,
|
|
|
|
enum wl_output_transform transform) {
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_TRANSFORM;
|
|
|
|
state->transform = transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_state_set_adaptive_sync_enabled(struct wlr_output_state *state,
|
|
|
|
bool enabled) {
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED;
|
|
|
|
state->adaptive_sync_enabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_state_set_render_format(struct wlr_output_state *state,
|
|
|
|
uint32_t format) {
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_RENDER_FORMAT;
|
|
|
|
state->render_format = format;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_state_set_subpixel(struct wlr_output_state *state,
|
|
|
|
enum wl_output_subpixel subpixel) {
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_SUBPIXEL;
|
|
|
|
state->subpixel = subpixel;
|
|
|
|
}
|
2023-02-20 12:00:18 +01:00
|
|
|
|
|
|
|
void wlr_output_state_set_buffer(struct wlr_output_state *state,
|
|
|
|
struct wlr_buffer *buffer) {
|
2023-06-12 16:34:32 +02:00
|
|
|
if (state->committed & WLR_OUTPUT_STATE_BUFFER) {
|
|
|
|
wlr_buffer_unlock(state->buffer);
|
|
|
|
}
|
|
|
|
|
2023-02-20 12:00:18 +01:00
|
|
|
state->committed |= WLR_OUTPUT_STATE_BUFFER;
|
|
|
|
state->buffer = wlr_buffer_lock(buffer);
|
|
|
|
}
|
2023-03-06 16:19:40 +01:00
|
|
|
|
2023-06-09 11:39:48 +02:00
|
|
|
void wlr_output_state_set_damage(struct wlr_output_state *state,
|
|
|
|
const pixman_region32_t *damage) {
|
|
|
|
if (state->committed & WLR_OUTPUT_STATE_DAMAGE) {
|
|
|
|
pixman_region32_fini(&state->damage);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_DAMAGE;
|
|
|
|
|
|
|
|
pixman_region32_init(&state->damage);
|
|
|
|
pixman_region32_copy(&state->damage, damage);
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:19:40 +01:00
|
|
|
bool wlr_output_state_set_gamma_lut(struct wlr_output_state *state,
|
|
|
|
size_t ramp_size, const uint16_t *r, const uint16_t *g, const uint16_t *b) {
|
|
|
|
uint16_t *gamma_lut = NULL;
|
|
|
|
if (ramp_size > 0) {
|
|
|
|
gamma_lut = realloc(state->gamma_lut, 3 * ramp_size * sizeof(uint16_t));
|
|
|
|
if (gamma_lut == NULL) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
memcpy(gamma_lut, r, ramp_size * sizeof(uint16_t));
|
|
|
|
memcpy(gamma_lut + ramp_size, g, ramp_size * sizeof(uint16_t));
|
|
|
|
memcpy(gamma_lut + 2 * ramp_size, b, ramp_size * sizeof(uint16_t));
|
|
|
|
} else {
|
|
|
|
free(state->gamma_lut);
|
|
|
|
}
|
|
|
|
|
|
|
|
state->committed |= WLR_OUTPUT_STATE_GAMMA_LUT;
|
|
|
|
state->gamma_lut_size = ramp_size;
|
|
|
|
state->gamma_lut = gamma_lut;
|
|
|
|
return true;
|
|
|
|
}
|