2019-08-21 22:07:37 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "private.h"
|
|
|
|
|
2019-09-12 10:39:06 +02:00
|
|
|
struct liftoff_layer *liftoff_layer_create(struct liftoff_output *output)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
2019-09-12 10:39:06 +02:00
|
|
|
struct liftoff_layer *layer;
|
2019-08-21 22:07:37 +02:00
|
|
|
|
|
|
|
layer = calloc(1, sizeof(*layer));
|
|
|
|
if (layer == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
|
2019-08-21 22:07:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
layer->output = output;
|
2019-09-12 10:39:06 +02:00
|
|
|
liftoff_list_insert(output->layers.prev, &layer->link);
|
2019-11-24 13:25:59 +01:00
|
|
|
output->layers_changed = true;
|
2019-08-21 22:07:37 +02:00
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2019-09-12 10:39:06 +02:00
|
|
|
void liftoff_layer_destroy(struct liftoff_layer *layer)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
2019-12-31 20:46:08 +01:00
|
|
|
if (layer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-24 13:25:59 +01:00
|
|
|
layer->output->layers_changed = true;
|
2019-12-06 15:06:14 +01:00
|
|
|
if (layer->plane != NULL) {
|
|
|
|
layer->plane->layer = NULL;
|
|
|
|
}
|
2019-09-30 20:22:01 +02:00
|
|
|
if (layer->output->composition_layer == layer) {
|
|
|
|
layer->output->composition_layer = NULL;
|
|
|
|
}
|
2019-08-21 22:07:37 +02:00
|
|
|
free(layer->props);
|
2019-09-12 10:39:06 +02:00
|
|
|
liftoff_list_remove(&layer->link);
|
2019-08-21 22:07:37 +02:00
|
|
|
free(layer);
|
|
|
|
}
|
|
|
|
|
2019-09-12 10:39:06 +02:00
|
|
|
struct liftoff_layer_property *layer_get_property(struct liftoff_layer *layer,
|
|
|
|
const char *name)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < layer->props_len; i++) {
|
|
|
|
if (strcmp(layer->props[i].name, name) == 0) {
|
|
|
|
return &layer->props[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-12 10:39:06 +02:00
|
|
|
void liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
|
|
|
|
uint64_t value)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
2019-09-12 10:39:06 +02:00
|
|
|
struct liftoff_layer_property *props;
|
|
|
|
struct liftoff_layer_property *prop;
|
2019-08-21 22:07:37 +02:00
|
|
|
|
|
|
|
/* TODO: better error handling */
|
|
|
|
if (strcmp(name, "CRTC_ID") == 0) {
|
2019-10-07 08:47:53 +02:00
|
|
|
liftoff_log(LIFTOFF_ERROR,
|
|
|
|
"refusing to set a layer's CRTC_ID");
|
2019-08-21 22:07:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = layer_get_property(layer, name);
|
|
|
|
if (prop == NULL) {
|
|
|
|
props = realloc(layer->props, (layer->props_len + 1)
|
2019-09-12 10:39:06 +02:00
|
|
|
* sizeof(struct liftoff_layer_property));
|
2019-08-21 22:07:37 +02:00
|
|
|
if (props == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "realloc");
|
2019-08-21 22:07:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
layer->props = props;
|
|
|
|
layer->props_len++;
|
|
|
|
|
|
|
|
prop = &layer->props[layer->props_len - 1];
|
|
|
|
memset(prop, 0, sizeof(*prop));
|
|
|
|
strncpy(prop->name, name, sizeof(prop->name) - 1);
|
2019-10-13 17:28:45 +02:00
|
|
|
|
2020-12-05 12:28:50 +01:00
|
|
|
layer->changed = true;
|
2019-08-21 22:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
prop->value = value;
|
2019-12-13 11:36:09 +01:00
|
|
|
|
2020-12-05 12:28:50 +01:00
|
|
|
if (strcmp(name, "FB_ID") == 0 && layer->force_composition) {
|
2019-12-13 11:36:09 +01:00
|
|
|
layer->force_composition = false;
|
2020-12-05 12:28:50 +01:00
|
|
|
layer->changed = true;
|
2019-12-13 11:36:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void liftoff_layer_set_fb_composited(struct liftoff_layer *layer)
|
|
|
|
{
|
|
|
|
if (layer->force_composition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
liftoff_layer_set_property(layer, "FB_ID", 0);
|
|
|
|
|
|
|
|
layer->force_composition = true;
|
2020-12-05 12:28:50 +01:00
|
|
|
layer->changed = true;
|
2019-08-21 22:07:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 10:39:06 +02:00
|
|
|
uint32_t liftoff_layer_get_plane_id(struct liftoff_layer *layer)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
|
|
|
if (layer->plane == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return layer->plane->id;
|
|
|
|
}
|
2019-09-15 16:00:48 +02:00
|
|
|
|
|
|
|
void layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect)
|
|
|
|
{
|
|
|
|
struct liftoff_layer_property *x_prop, *y_prop, *w_prop, *h_prop;
|
|
|
|
|
|
|
|
x_prop = layer_get_property(layer, "CRTC_X");
|
|
|
|
y_prop = layer_get_property(layer, "CRTC_Y");
|
|
|
|
w_prop = layer_get_property(layer, "CRTC_W");
|
|
|
|
h_prop = layer_get_property(layer, "CRTC_H");
|
|
|
|
|
|
|
|
rect->x = x_prop != NULL ? x_prop->value : 0;
|
|
|
|
rect->y = y_prop != NULL ? y_prop->value : 0;
|
|
|
|
rect->width = w_prop != NULL ? w_prop->value : 0;
|
|
|
|
rect->height = h_prop != NULL ? h_prop->value : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool layer_intersects(struct liftoff_layer *a, struct liftoff_layer *b)
|
|
|
|
{
|
|
|
|
struct liftoff_rect ra, rb;
|
|
|
|
|
|
|
|
layer_get_rect(a, &ra);
|
|
|
|
layer_get_rect(b, &rb);
|
|
|
|
|
|
|
|
return ra.x < rb.x + rb.width && ra.y < rb.y + rb.height &&
|
|
|
|
ra.x + ra.width > rb.x && ra.y + ra.height > rb.y;
|
|
|
|
}
|
2019-10-13 17:28:45 +02:00
|
|
|
|
|
|
|
void layer_mark_clean(struct liftoff_layer *layer)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
2020-12-05 12:28:50 +01:00
|
|
|
layer->changed = false;
|
|
|
|
|
2019-10-13 17:28:45 +02:00
|
|
|
for (i = 0; i < layer->props_len; i++) {
|
2020-12-05 12:28:50 +01:00
|
|
|
layer->props[i].prev_value = layer->props[i].value;
|
2019-10-13 17:28:45 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-15 21:43:44 +01:00
|
|
|
|
2020-02-26 11:23:26 +01:00
|
|
|
static void log_priority(struct liftoff_layer *layer)
|
|
|
|
{
|
|
|
|
if (layer->current_priority == layer->pending_priority) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
liftoff_log(LIFTOFF_DEBUG, "Layer %p priority change: %d -> %d",
|
|
|
|
(void *)layer, layer->current_priority,
|
|
|
|
layer->pending_priority);
|
|
|
|
}
|
|
|
|
|
2019-11-15 21:43:44 +01:00
|
|
|
void layer_update_priority(struct liftoff_layer *layer, bool make_current) {
|
|
|
|
struct liftoff_layer_property *prop;
|
|
|
|
|
2020-12-05 12:28:50 +01:00
|
|
|
/* TODO: also bump priority when updating other properties */
|
2019-11-15 21:43:44 +01:00
|
|
|
prop = layer_get_property(layer, "FB_ID");
|
2020-12-05 12:28:50 +01:00
|
|
|
if (prop != NULL && prop->prev_value != prop->value) {
|
2019-11-15 21:43:44 +01:00
|
|
|
layer->pending_priority++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (make_current) {
|
2020-02-26 11:23:26 +01:00
|
|
|
log_priority(layer);
|
2019-11-15 21:43:44 +01:00
|
|
|
layer->current_priority = layer->pending_priority;
|
|
|
|
layer->pending_priority = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-12-19 17:49:18 +01:00
|
|
|
|
|
|
|
bool layer_has_fb(struct liftoff_layer *layer) {
|
|
|
|
struct liftoff_layer_property *fb_id_prop;
|
|
|
|
|
|
|
|
fb_id_prop = layer_get_property(layer, "FB_ID");
|
|
|
|
return fb_id_prop != NULL && fb_id_prop->value != 0;
|
|
|
|
}
|
2021-02-24 11:40:01 +01:00
|
|
|
|
|
|
|
bool layer_is_visible(struct liftoff_layer *layer)
|
|
|
|
{
|
|
|
|
struct liftoff_layer_property *alpha_prop;
|
|
|
|
|
|
|
|
alpha_prop = layer_get_property(layer, "alpha");
|
|
|
|
if (alpha_prop != NULL && alpha_prop->value == 0) {
|
|
|
|
return false; /* fully transparent */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layer->force_composition) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return layer_has_fb(layer);
|
|
|
|
}
|
|
|
|
}
|