mirror of
https://gitlab.freedesktop.org/emersion/libliftoff.git
synced 2025-01-30 20:34:19 +01:00
Extract plane_data init logic to function
This allows to unclutter output_choose_layers a little.
This commit is contained in:
parent
364be1c5a6
commit
aa2478cda8
1 changed files with 38 additions and 22 deletions
60
display.c
60
display.c
|
@ -364,6 +364,42 @@ struct plane_data {
|
||||||
int last_plane_zpos, last_layer_zpos;
|
int last_plane_zpos, last_layer_zpos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void plane_data_init_next(struct plane_data *data,
|
||||||
|
struct plane_data *prev,
|
||||||
|
struct liftoff_layer *layer)
|
||||||
|
{
|
||||||
|
struct liftoff_plane *plane;
|
||||||
|
struct liftoff_layer_property *zpos_prop;
|
||||||
|
|
||||||
|
plane = liftoff_container_of(prev->plane_link, plane, link);
|
||||||
|
|
||||||
|
data->plane_link = prev->plane_link->next;
|
||||||
|
data->plane_idx = prev->plane_idx + 1;
|
||||||
|
data->alloc = prev->alloc;
|
||||||
|
data->alloc[prev->plane_idx] = layer;
|
||||||
|
|
||||||
|
if (layer != NULL) {
|
||||||
|
data->score = prev->score + 1;
|
||||||
|
} else {
|
||||||
|
data->score = prev->score;
|
||||||
|
}
|
||||||
|
if (layer != NULL && plane->type != DRM_PLANE_TYPE_PRIMARY) {
|
||||||
|
data->last_plane_zpos = plane->zpos;
|
||||||
|
} else {
|
||||||
|
data->last_plane_zpos = prev->last_plane_zpos;
|
||||||
|
}
|
||||||
|
|
||||||
|
zpos_prop = NULL;
|
||||||
|
if (layer != NULL) {
|
||||||
|
zpos_prop = layer_get_property(layer, "zpos");
|
||||||
|
}
|
||||||
|
if (zpos_prop != NULL && plane->type != DRM_PLANE_TYPE_PRIMARY) {
|
||||||
|
data->last_layer_zpos = zpos_prop->value;
|
||||||
|
} else {
|
||||||
|
data->last_layer_zpos = prev->last_layer_zpos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool is_layer_allocated(struct plane_data *data,
|
static bool is_layer_allocated(struct plane_data *data,
|
||||||
struct liftoff_layer *layer)
|
struct liftoff_layer *layer)
|
||||||
{
|
{
|
||||||
|
@ -428,11 +464,6 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
}
|
}
|
||||||
plane = liftoff_container_of(data->plane_link, plane, link);
|
plane = liftoff_container_of(data->plane_link, plane, link);
|
||||||
|
|
||||||
/* These don't change depending on the layer we choose */
|
|
||||||
next_data.plane_link = data->plane_link->next;
|
|
||||||
next_data.plane_idx = data->plane_idx + 1;
|
|
||||||
next_data.alloc = data->alloc;
|
|
||||||
|
|
||||||
remaining_planes = alloc->planes_len - data->plane_idx;
|
remaining_planes = alloc->planes_len - data->plane_idx;
|
||||||
if (alloc->best_score >= data->score + (int)remaining_planes) {
|
if (alloc->best_score >= data->score + (int)remaining_planes) {
|
||||||
/* Even if we find a layer for all remaining planes, we won't
|
/* Even if we find a layer for all remaining planes, we won't
|
||||||
|
@ -499,7 +530,6 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
/* Try to use this layer for the current plane */
|
/* Try to use this layer for the current plane */
|
||||||
fprintf(stderr, "Layer %p -> plane %"PRIu32": "
|
fprintf(stderr, "Layer %p -> plane %"PRIu32": "
|
||||||
"applying properties...\n", (void *)layer, plane->id);
|
"applying properties...\n", (void *)layer, plane->id);
|
||||||
data->alloc[data->plane_idx] = layer;
|
|
||||||
if (!plane_apply(plane, layer, alloc->req, &compatible)) {
|
if (!plane_apply(plane, layer, alloc->req, &compatible)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -516,18 +546,7 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
fprintf(stderr, "Layer %p -> plane %"PRIu32": success\n",
|
fprintf(stderr, "Layer %p -> plane %"PRIu32": success\n",
|
||||||
(void *)layer, plane->id);
|
(void *)layer, plane->id);
|
||||||
/* Continue with the next plane */
|
/* Continue with the next plane */
|
||||||
next_data.score = data->score + 1;
|
plane_data_init_next(&next_data, data, layer);
|
||||||
if (plane->type != DRM_PLANE_TYPE_PRIMARY) {
|
|
||||||
next_data.last_plane_zpos = plane->zpos;
|
|
||||||
} else {
|
|
||||||
next_data.last_plane_zpos = data->last_plane_zpos;
|
|
||||||
}
|
|
||||||
if (zpos_prop != NULL &&
|
|
||||||
plane->type != DRM_PLANE_TYPE_PRIMARY) {
|
|
||||||
next_data.last_layer_zpos = zpos_prop->value;
|
|
||||||
} else {
|
|
||||||
next_data.last_layer_zpos = data->last_layer_zpos;
|
|
||||||
}
|
|
||||||
if (!output_choose_layers(output, alloc, &next_data)) {
|
if (!output_choose_layers(output, alloc, &next_data)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -541,10 +560,7 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
|
|
||||||
skip:
|
skip:
|
||||||
/* Try not to use the current plane */
|
/* Try not to use the current plane */
|
||||||
data->alloc[data->plane_idx] = NULL;
|
plane_data_init_next(&next_data, data, NULL);
|
||||||
next_data.score = data->score;
|
|
||||||
next_data.last_layer_zpos = data->last_layer_zpos;
|
|
||||||
next_data.last_plane_zpos = data->last_plane_zpos;
|
|
||||||
if (!output_choose_layers(output, alloc, &next_data)) {
|
if (!output_choose_layers(output, alloc, &next_data)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue