mirror of
https://gitlab.freedesktop.org/emersion/libliftoff.git
synced 2025-02-07 08:46:32 +01:00
Rename plane_alloc and plane_data
Rename plane_alloc to alloc_result and plane_data to alloc_step. This is more accurate and less confusing.
This commit is contained in:
parent
0596d6f66e
commit
74040a817b
1 changed files with 69 additions and 69 deletions
138
display.c
138
display.c
|
@ -346,7 +346,7 @@ static bool plane_apply(struct liftoff_plane *plane, struct liftoff_layer *layer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Global data for the allocation algorithm */
|
/* Global data for the allocation algorithm */
|
||||||
struct plane_alloc {
|
struct alloc_result {
|
||||||
drmModeAtomicReq *req;
|
drmModeAtomicReq *req;
|
||||||
size_t planes_len;
|
size_t planes_len;
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ struct plane_alloc {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Transient data, arguments for each step */
|
/* Transient data, arguments for each step */
|
||||||
struct plane_data {
|
struct alloc_step {
|
||||||
struct liftoff_list *plane_link; /* liftoff_plane.link */
|
struct liftoff_list *plane_link; /* liftoff_plane.link */
|
||||||
size_t plane_idx;
|
size_t plane_idx;
|
||||||
|
|
||||||
|
@ -364,8 +364,8 @@ struct plane_data {
|
||||||
int last_layer_zpos;
|
int last_layer_zpos;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void plane_data_init_next(struct plane_data *data,
|
static void plane_step_init_next(struct alloc_step *step,
|
||||||
struct plane_data *prev,
|
struct alloc_step *prev,
|
||||||
struct liftoff_layer *layer)
|
struct liftoff_layer *layer)
|
||||||
{
|
{
|
||||||
struct liftoff_plane *plane;
|
struct liftoff_plane *plane;
|
||||||
|
@ -373,15 +373,15 @@ static void plane_data_init_next(struct plane_data *data,
|
||||||
|
|
||||||
plane = liftoff_container_of(prev->plane_link, plane, link);
|
plane = liftoff_container_of(prev->plane_link, plane, link);
|
||||||
|
|
||||||
data->plane_link = prev->plane_link->next;
|
step->plane_link = prev->plane_link->next;
|
||||||
data->plane_idx = prev->plane_idx + 1;
|
step->plane_idx = prev->plane_idx + 1;
|
||||||
data->alloc = prev->alloc;
|
step->alloc = prev->alloc;
|
||||||
data->alloc[prev->plane_idx] = layer;
|
step->alloc[prev->plane_idx] = layer;
|
||||||
|
|
||||||
if (layer != NULL) {
|
if (layer != NULL) {
|
||||||
data->score = prev->score + 1;
|
step->score = prev->score + 1;
|
||||||
} else {
|
} else {
|
||||||
data->score = prev->score;
|
step->score = prev->score;
|
||||||
}
|
}
|
||||||
|
|
||||||
zpos_prop = NULL;
|
zpos_prop = NULL;
|
||||||
|
@ -389,21 +389,21 @@ static void plane_data_init_next(struct plane_data *data,
|
||||||
zpos_prop = layer_get_property(layer, "zpos");
|
zpos_prop = layer_get_property(layer, "zpos");
|
||||||
}
|
}
|
||||||
if (zpos_prop != NULL && plane->type != DRM_PLANE_TYPE_PRIMARY) {
|
if (zpos_prop != NULL && plane->type != DRM_PLANE_TYPE_PRIMARY) {
|
||||||
data->last_layer_zpos = zpos_prop->value;
|
step->last_layer_zpos = zpos_prop->value;
|
||||||
} else {
|
} else {
|
||||||
data->last_layer_zpos = prev->last_layer_zpos;
|
step->last_layer_zpos = prev->last_layer_zpos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_layer_allocated(struct plane_data *data,
|
static bool is_layer_allocated(struct alloc_step *step,
|
||||||
struct liftoff_layer *layer)
|
struct liftoff_layer *layer)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* TODO: speed this up with an array of bools indicating whether a layer
|
/* TODO: speed this up with an array of bools indicating whether a layer
|
||||||
* has been allocated */
|
* has been allocated */
|
||||||
for (i = 0; i < data->plane_idx; i++) {
|
for (i = 0; i < step->plane_idx; i++) {
|
||||||
if (data->alloc[i] == layer) {
|
if (step->alloc[i] == layer) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ static bool is_layer_allocated(struct plane_data *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool has_composited_layer_over(struct liftoff_output *output,
|
static bool has_composited_layer_over(struct liftoff_output *output,
|
||||||
struct plane_data *data,
|
struct alloc_step *step,
|
||||||
struct liftoff_layer *layer)
|
struct liftoff_layer *layer)
|
||||||
{
|
{
|
||||||
struct liftoff_layer *other_layer;
|
struct liftoff_layer *other_layer;
|
||||||
|
@ -423,7 +423,7 @@ static bool has_composited_layer_over(struct liftoff_output *output,
|
||||||
}
|
}
|
||||||
|
|
||||||
liftoff_list_for_each(other_layer, &output->layers, link) {
|
liftoff_list_for_each(other_layer, &output->layers, link) {
|
||||||
if (is_layer_allocated(data, other_layer)) {
|
if (is_layer_allocated(step, other_layer)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +442,7 @@ static bool has_composited_layer_over(struct liftoff_output *output,
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool has_allocated_layer_over(struct liftoff_output *output,
|
static bool has_allocated_layer_over(struct liftoff_output *output,
|
||||||
struct plane_data *data,
|
struct alloc_step *step,
|
||||||
struct liftoff_layer *layer)
|
struct liftoff_layer *layer)
|
||||||
{
|
{
|
||||||
ssize_t i;
|
ssize_t i;
|
||||||
|
@ -458,14 +458,14 @@ static bool has_allocated_layer_over(struct liftoff_output *output,
|
||||||
i = -1;
|
i = -1;
|
||||||
liftoff_list_for_each(other_plane, &output->display->planes, link) {
|
liftoff_list_for_each(other_plane, &output->display->planes, link) {
|
||||||
i++;
|
i++;
|
||||||
if (i >= (ssize_t)data->plane_idx) {
|
if (i >= (ssize_t)step->plane_idx) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (other_plane->type == DRM_PLANE_TYPE_PRIMARY) {
|
if (other_plane->type == DRM_PLANE_TYPE_PRIMARY) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
other_layer = data->alloc[i];
|
other_layer = step->alloc[i];
|
||||||
if (other_layer == NULL) {
|
if (other_layer == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -488,29 +488,29 @@ static bool has_allocated_layer_over(struct liftoff_output *output,
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool has_allocated_plane_under(struct liftoff_output *output,
|
static bool has_allocated_plane_under(struct liftoff_output *output,
|
||||||
struct plane_data *data,
|
struct alloc_step *step,
|
||||||
struct liftoff_layer *layer)
|
struct liftoff_layer *layer)
|
||||||
{
|
{
|
||||||
struct liftoff_plane *plane, *other_plane;
|
struct liftoff_plane *plane, *other_plane;
|
||||||
ssize_t i;
|
ssize_t i;
|
||||||
|
|
||||||
plane = liftoff_container_of(data->plane_link, plane, link);
|
plane = liftoff_container_of(step->plane_link, plane, link);
|
||||||
|
|
||||||
i = -1;
|
i = -1;
|
||||||
liftoff_list_for_each(other_plane, &output->display->planes, link) {
|
liftoff_list_for_each(other_plane, &output->display->planes, link) {
|
||||||
i++;
|
i++;
|
||||||
if (i >= (ssize_t)data->plane_idx) {
|
if (i >= (ssize_t)step->plane_idx) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (other_plane->type == DRM_PLANE_TYPE_PRIMARY) {
|
if (other_plane->type == DRM_PLANE_TYPE_PRIMARY) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (data->alloc[i] == NULL) {
|
if (step->alloc[i] == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plane->zpos >= other_plane->zpos &&
|
if (plane->zpos >= other_plane->zpos &&
|
||||||
layer_intersects(layer, data->alloc[i])) {
|
layer_intersects(layer, step->alloc[i])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -519,7 +519,7 @@ static bool has_allocated_plane_under(struct liftoff_output *output,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool output_choose_layers(struct liftoff_output *output,
|
bool output_choose_layers(struct liftoff_output *output,
|
||||||
struct plane_alloc *alloc, struct plane_data *data)
|
struct alloc_result *result, struct alloc_step *step)
|
||||||
{
|
{
|
||||||
struct liftoff_display *display;
|
struct liftoff_display *display;
|
||||||
struct liftoff_plane *plane;
|
struct liftoff_plane *plane;
|
||||||
|
@ -527,30 +527,30 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
int cursor, ret;
|
int cursor, ret;
|
||||||
size_t remaining_planes;
|
size_t remaining_planes;
|
||||||
bool compatible;
|
bool compatible;
|
||||||
struct plane_data next_data;
|
struct alloc_step next_step;
|
||||||
struct liftoff_layer_property *zpos_prop;
|
struct liftoff_layer_property *zpos_prop;
|
||||||
|
|
||||||
display = output->display;
|
display = output->display;
|
||||||
|
|
||||||
if (data->plane_link == &display->planes) { /* Allocation finished */
|
if (step->plane_link == &display->planes) { /* Allocation finished */
|
||||||
if (data->score > alloc->best_score) {
|
if (step->score > result->best_score) {
|
||||||
/* We found a better allocation */
|
/* We found a better allocation */
|
||||||
alloc->best_score = data->score;
|
result->best_score = step->score;
|
||||||
memcpy(alloc->best, data->alloc,
|
memcpy(result->best, step->alloc,
|
||||||
alloc->planes_len * sizeof(struct liftoff_layer *));
|
result->planes_len * sizeof(struct liftoff_layer *));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plane = liftoff_container_of(data->plane_link, plane, link);
|
plane = liftoff_container_of(step->plane_link, plane, link);
|
||||||
|
|
||||||
remaining_planes = alloc->planes_len - data->plane_idx;
|
remaining_planes = result->planes_len - step->plane_idx;
|
||||||
if (alloc->best_score >= data->score + (int)remaining_planes) {
|
if (result->best_score >= step->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
|
||||||
* find a better allocation. Give up. */
|
* find a better allocation. Give up. */
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor = drmModeAtomicGetCursor(alloc->req);
|
cursor = drmModeAtomicGetCursor(result->req);
|
||||||
|
|
||||||
if (plane->layer != NULL) {
|
if (plane->layer != NULL) {
|
||||||
goto skip;
|
goto skip;
|
||||||
|
@ -560,7 +560,7 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Performing allocation for plane %"PRIu32" (%zu/%zu)\n",
|
fprintf(stderr, "Performing allocation for plane %"PRIu32" (%zu/%zu)\n",
|
||||||
plane->id, data->plane_idx + 1, alloc->planes_len);
|
plane->id, step->plane_idx + 1, result->planes_len);
|
||||||
|
|
||||||
liftoff_list_for_each(layer, &output->layers, link) {
|
liftoff_list_for_each(layer, &output->layers, link) {
|
||||||
if (layer->plane != NULL) {
|
if (layer->plane != NULL) {
|
||||||
|
@ -568,14 +568,14 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip this layer if already allocated */
|
/* Skip this layer if already allocated */
|
||||||
if (is_layer_allocated(data, layer)) {
|
if (is_layer_allocated(step, layer)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
zpos_prop = layer_get_property(layer, "zpos");
|
zpos_prop = layer_get_property(layer, "zpos");
|
||||||
if (zpos_prop != NULL) {
|
if (zpos_prop != NULL) {
|
||||||
if ((int)zpos_prop->value > data->last_layer_zpos &&
|
if ((int)zpos_prop->value > step->last_layer_zpos &&
|
||||||
has_allocated_layer_over(output, data, layer)) {
|
has_allocated_layer_over(output, step, layer)) {
|
||||||
/* This layer needs to be on top of the last
|
/* This layer needs to be on top of the last
|
||||||
* allocated one */
|
* allocated one */
|
||||||
fprintf(stderr, "Layer %p -> plane %"PRIu32": "
|
fprintf(stderr, "Layer %p -> plane %"PRIu32": "
|
||||||
|
@ -583,8 +583,8 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
(void *)layer, plane->id);
|
(void *)layer, plane->id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((int)zpos_prop->value < data->last_layer_zpos &&
|
if ((int)zpos_prop->value < step->last_layer_zpos &&
|
||||||
has_allocated_plane_under(output, data, layer)) {
|
has_allocated_plane_under(output, step, layer)) {
|
||||||
/* This layer needs to be under the last
|
/* This layer needs to be under the last
|
||||||
* allocated one, but this plane isn't under the
|
* allocated one, but this plane isn't under the
|
||||||
* last one (in practice, since planes are
|
* last one (in practice, since planes are
|
||||||
|
@ -598,7 +598,7 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plane->type != DRM_PLANE_TYPE_PRIMARY &&
|
if (plane->type != DRM_PLANE_TYPE_PRIMARY &&
|
||||||
has_composited_layer_over(output, data, layer)) {
|
has_composited_layer_over(output, step, layer)) {
|
||||||
fprintf(stderr, "Layer %p -> plane %"PRIu32": "
|
fprintf(stderr, "Layer %p -> plane %"PRIu32": "
|
||||||
"has composited layer on top\n",
|
"has composited layer on top\n",
|
||||||
(void *)layer, plane->id);
|
(void *)layer, plane->id);
|
||||||
|
@ -608,7 +608,7 @@ 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);
|
||||||
if (!plane_apply(plane, layer, alloc->req, &compatible)) {
|
if (!plane_apply(plane, layer, result->req, &compatible)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!compatible) {
|
if (!compatible) {
|
||||||
|
@ -618,14 +618,14 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = drmModeAtomicCommit(display->drm_fd, alloc->req,
|
ret = drmModeAtomicCommit(display->drm_fd, result->req,
|
||||||
DRM_MODE_ATOMIC_TEST_ONLY, NULL);
|
DRM_MODE_ATOMIC_TEST_ONLY, NULL);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
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 */
|
||||||
plane_data_init_next(&next_data, data, layer);
|
plane_step_init_next(&next_step, step, layer);
|
||||||
if (!output_choose_layers(output, alloc, &next_data)) {
|
if (!output_choose_layers(output, result, &next_step)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (-ret != EINVAL && -ret != ERANGE) {
|
} else if (-ret != EINVAL && -ret != ERANGE) {
|
||||||
|
@ -633,16 +633,16 @@ bool output_choose_layers(struct liftoff_output *output,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
drmModeAtomicSetCursor(alloc->req, cursor);
|
drmModeAtomicSetCursor(result->req, cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
skip:
|
skip:
|
||||||
/* Try not to use the current plane */
|
/* Try not to use the current plane */
|
||||||
plane_data_init_next(&next_data, data, NULL);
|
plane_step_init_next(&next_step, step, NULL);
|
||||||
if (!output_choose_layers(output, alloc, &next_data)) {
|
if (!output_choose_layers(output, result, &next_step)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
drmModeAtomicSetCursor(alloc->req, cursor);
|
drmModeAtomicSetCursor(result->req, cursor);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -652,8 +652,8 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
|
||||||
struct liftoff_output *output;
|
struct liftoff_output *output;
|
||||||
struct liftoff_plane *plane;
|
struct liftoff_plane *plane;
|
||||||
struct liftoff_layer *layer;
|
struct liftoff_layer *layer;
|
||||||
struct plane_alloc alloc;
|
struct alloc_result result;
|
||||||
struct plane_data data;
|
struct alloc_step step;
|
||||||
size_t i;
|
size_t i;
|
||||||
bool compatible;
|
bool compatible;
|
||||||
|
|
||||||
|
@ -678,12 +678,12 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alloc.req = req;
|
result.req = req;
|
||||||
alloc.planes_len = liftoff_list_length(&display->planes);
|
result.planes_len = liftoff_list_length(&display->planes);
|
||||||
|
|
||||||
data.alloc = malloc(alloc.planes_len * sizeof(*data.alloc));
|
step.alloc = malloc(result.planes_len * sizeof(*step.alloc));
|
||||||
alloc.best = malloc(alloc.planes_len * sizeof(*alloc.best));
|
result.best = malloc(result.planes_len * sizeof(*result.best));
|
||||||
if (data.alloc == NULL || alloc.best == NULL) {
|
if (step.alloc == NULL || result.best == NULL) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -699,23 +699,23 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
|
||||||
* some drivers want user-space to enable the primary plane
|
* some drivers want user-space to enable the primary plane
|
||||||
* before any other plane. */
|
* before any other plane. */
|
||||||
|
|
||||||
alloc.best_score = 0;
|
result.best_score = 0;
|
||||||
memset(alloc.best, 0, alloc.planes_len * sizeof(*alloc.best));
|
memset(result.best, 0, result.planes_len * sizeof(*result.best));
|
||||||
data.plane_link = display->planes.next;
|
step.plane_link = display->planes.next;
|
||||||
data.plane_idx = 0;
|
step.plane_idx = 0;
|
||||||
data.score = 0;
|
step.score = 0;
|
||||||
data.last_layer_zpos = INT_MAX;
|
step.last_layer_zpos = INT_MAX;
|
||||||
if (!output_choose_layers(output, &alloc, &data)) {
|
if (!output_choose_layers(output, &result, &step)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Found plane allocation for output %p "
|
fprintf(stderr, "Found plane allocation for output %p "
|
||||||
"with score=%d\n", (void *)output, alloc.best_score);
|
"with score=%d\n", (void *)output, result.best_score);
|
||||||
|
|
||||||
/* Apply the best allocation */
|
/* Apply the best allocation */
|
||||||
i = 0;
|
i = 0;
|
||||||
liftoff_list_for_each(plane, &display->planes, link) {
|
liftoff_list_for_each(plane, &display->planes, link) {
|
||||||
layer = alloc.best[i];
|
layer = result.best[i];
|
||||||
i++;
|
i++;
|
||||||
if (layer == NULL) {
|
if (layer == NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -735,8 +735,8 @@ bool liftoff_display_apply(struct liftoff_display *display, drmModeAtomicReq *re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data.alloc);
|
free(step.alloc);
|
||||||
free(alloc.best);
|
free(result.best);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue