Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Introduce core properties
Browse files Browse the repository at this point in the history
This is a set of well-known KMS standard properties, either used
by libliftoff itself or commonly used by compositors. Adding
special cases for these allows us to access them without having
to iterate over a list.

This roughly improves performance by ~50% when leaving out the
atomic test-only commits.

Closes: #1
  • Loading branch information
emersion committed Sep 30, 2021
1 parent 70eca07 commit 110e075
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 40 deletions.
14 changes: 8 additions & 6 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ plane_step_init_next(struct alloc_step *step, struct alloc_step *prev,

zpos_prop = NULL;
if (layer != NULL) {
zpos_prop = layer_get_property(layer, "zpos");
zpos_prop = layer_get_property(layer, LIFTOFF_PROP_ZPOS);
}
if (zpos_prop != NULL && plane->type != DRM_PLANE_TYPE_PRIMARY) {
step->last_layer_zpos = zpos_prop->value;
Expand Down Expand Up @@ -168,7 +168,7 @@ has_composited_layer_over(struct liftoff_output *output,
struct liftoff_layer *other_layer;
struct liftoff_layer_property *zpos_prop, *other_zpos_prop;

zpos_prop = layer_get_property(layer, "zpos");
zpos_prop = layer_get_property(layer, LIFTOFF_PROP_ZPOS);
if (zpos_prop == NULL) {
return false;
}
Expand All @@ -178,7 +178,8 @@ has_composited_layer_over(struct liftoff_output *output,
continue;
}

other_zpos_prop = layer_get_property(other_layer, "zpos");
other_zpos_prop = layer_get_property(other_layer,
LIFTOFF_PROP_ZPOS);
if (other_zpos_prop == NULL) {
continue;
}
Expand All @@ -201,7 +202,7 @@ has_allocated_layer_over(struct liftoff_output *output, struct alloc_step *step,
struct liftoff_layer *other_layer;
struct liftoff_layer_property *zpos_prop, *other_zpos_prop;

zpos_prop = layer_get_property(layer, "zpos");
zpos_prop = layer_get_property(layer, LIFTOFF_PROP_ZPOS);
if (zpos_prop == NULL) {
return false;
}
Expand All @@ -221,7 +222,8 @@ has_allocated_layer_over(struct liftoff_output *output, struct alloc_step *step,
continue;
}

other_zpos_prop = layer_get_property(other_layer, "zpos");
other_zpos_prop = layer_get_property(other_layer,
LIFTOFF_PROP_ZPOS);
if (other_zpos_prop == NULL) {
continue;
}
Expand Down Expand Up @@ -284,7 +286,7 @@ check_layer_plane_compatible(struct alloc_step *step,
return false;
}

zpos_prop = layer_get_property(layer, "zpos");
zpos_prop = layer_get_property(layer, LIFTOFF_PROP_ZPOS);
if (zpos_prop != NULL) {
if ((int)zpos_prop->value > step->last_layer_zpos &&
has_allocated_layer_over(output, step, layer)) {
Expand Down
33 changes: 33 additions & 0 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,36 @@ device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,

return ret;
}

ssize_t
core_property_index(const char *name)
{
if (strcmp(name, "FB_ID") == 0) {
return LIFTOFF_PROP_FB_ID;
} else if (strcmp(name, "CRTC_ID") == 0) {
return LIFTOFF_PROP_CRTC_ID;
} else if (strcmp(name, "CRTC_X") == 0) {
return LIFTOFF_PROP_CRTC_X;
} else if (strcmp(name, "CRTC_Y") == 0) {
return LIFTOFF_PROP_CRTC_Y;
} else if (strcmp(name, "CRTC_W") == 0) {
return LIFTOFF_PROP_CRTC_W;
} else if (strcmp(name, "CRTC_H") == 0) {
return LIFTOFF_PROP_CRTC_H;
} else if (strcmp(name, "SRC_X") == 0) {
return LIFTOFF_PROP_SRC_X;
} else if (strcmp(name, "SRC_Y") == 0) {
return LIFTOFF_PROP_SRC_Y;
} else if (strcmp(name, "SRC_W") == 0) {
return LIFTOFF_PROP_SRC_W;
} else if (strcmp(name, "SRC_H") == 0) {
return LIFTOFF_PROP_SRC_H;
} else if (strcmp(name, "zpos") == 0) {
return LIFTOFF_PROP_ZPOS;
} else if (strcmp(name, "alpha") == 0) {
return LIFTOFF_PROP_ALPHA;
} else if (strcmp(name, "rotation") == 0) {
return LIFTOFF_PROP_ROTATION;
}
return -1;
}
31 changes: 30 additions & 1 deletion include/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@
#define PRIVATE_H

#include <libliftoff.h>
#include <sys/types.h>
#include "list.h"
#include "log.h"

/* Layer priority is assigned depending on the number of updates during a
* given number of page-flips */
#define LIFTOFF_PRIORITY_PERIOD 60

/**
* List of well-known KMS properties.
*
* Keep core_property_index in sync.
*/
enum liftoff_core_property {
LIFTOFF_PROP_FB_ID,
LIFTOFF_PROP_CRTC_ID,
LIFTOFF_PROP_CRTC_X,
LIFTOFF_PROP_CRTC_Y,
LIFTOFF_PROP_CRTC_W,
LIFTOFF_PROP_CRTC_H,
LIFTOFF_PROP_SRC_X,
LIFTOFF_PROP_SRC_Y,
LIFTOFF_PROP_SRC_W,
LIFTOFF_PROP_SRC_H,
LIFTOFF_PROP_ZPOS,
LIFTOFF_PROP_ALPHA,
LIFTOFF_PROP_ROTATION,
LIFTOFF_PROP_LAST, /* keep last */
};

struct liftoff_device {
int drm_fd;

Expand Down Expand Up @@ -43,6 +66,7 @@ struct liftoff_layer {

struct liftoff_layer_property *props;
size_t props_len;
ssize_t core_props[LIFTOFF_PROP_LAST];

bool force_composition; /* FB needs to be composited */

Expand All @@ -56,6 +80,7 @@ struct liftoff_layer {
struct liftoff_layer_property {
char name[DRM_PROP_NAME_LEN];
uint64_t value, prev_value;
ssize_t core_index;
};

struct liftoff_plane {
Expand All @@ -68,6 +93,7 @@ struct liftoff_plane {

struct liftoff_plane_property *props;
size_t props_len;
struct liftoff_plane_property *core_props[LIFTOFF_PROP_LAST];

struct liftoff_layer *layer;
};
Expand All @@ -87,7 +113,7 @@ device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,
uint32_t flags);

struct liftoff_layer_property *
layer_get_property(struct liftoff_layer *layer, const char *name);
layer_get_property(struct liftoff_layer *layer, enum liftoff_core_property prop);

void
layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect);
Expand All @@ -114,4 +140,7 @@ plane_apply(struct liftoff_plane *plane, struct liftoff_layer *layer,
void
output_log_layers(struct liftoff_output *output);

ssize_t
core_property_index(const char *name);

#endif
56 changes: 39 additions & 17 deletions layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ struct liftoff_layer *
liftoff_layer_create(struct liftoff_output *output)
{
struct liftoff_layer *layer;
size_t i;

layer = calloc(1, sizeof(*layer));
if (layer == NULL) {
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
return NULL;
}
layer->output = output;
for (i = 0; i < LIFTOFF_PROP_LAST; i++) {
layer->core_props[i] = -1;
}
liftoff_list_insert(output->layers.prev, &layer->link);
output->layers_changed = true;
return layer;
Expand All @@ -39,16 +43,14 @@ liftoff_layer_destroy(struct liftoff_layer *layer)
}

struct liftoff_layer_property *
layer_get_property(struct liftoff_layer *layer, const char *name)
layer_get_property(struct liftoff_layer *layer, enum liftoff_core_property prop)
{
size_t i;
ssize_t i;

for (i = 0; i < layer->props_len; i++) {
if (strcmp(layer->props[i].name, name) == 0) {
return &layer->props[i];
}
}
return NULL;
i = layer->core_props[prop];
if (i < 0)
return NULL;
return &layer->props[i];
}

int
Expand All @@ -57,14 +59,28 @@ liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
{
struct liftoff_layer_property *props;
struct liftoff_layer_property *prop;
ssize_t core_prop_idx;
size_t i;

if (strcmp(name, "CRTC_ID") == 0) {
liftoff_log(LIFTOFF_ERROR,
"refusing to set a layer's CRTC_ID");
return -EINVAL;
}

prop = layer_get_property(layer, name);
prop = NULL;
core_prop_idx = core_property_index(name);
if (core_prop_idx >= 0) {
prop = layer_get_property(layer, core_prop_idx);
} else {
for (i = 0; i < layer->props_len; i++) {
if (strcmp(layer->props[i].name, name) == 0) {
prop = &layer->props[i];
break;
}
}
}

if (prop == NULL) {
props = realloc(layer->props, (layer->props_len + 1)
* sizeof(struct liftoff_layer_property));
Expand All @@ -75,11 +91,17 @@ liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
layer->props = props;
layer->props_len++;

prop = &layer->props[layer->props_len - 1];
i = layer->props_len - 1;
prop = &layer->props[i];
memset(prop, 0, sizeof(*prop));
strncpy(prop->name, name, sizeof(prop->name) - 1);
prop->core_index = core_prop_idx;

layer->changed = true;

if (core_prop_idx >= 0) {
layer->core_props[core_prop_idx] = i;
}
}

prop->value = value;
Expand Down Expand Up @@ -125,10 +147,10 @@ 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");
x_prop = layer_get_property(layer, LIFTOFF_PROP_CRTC_X);
y_prop = layer_get_property(layer, LIFTOFF_PROP_CRTC_Y);
w_prop = layer_get_property(layer, LIFTOFF_PROP_CRTC_W);
h_prop = layer_get_property(layer, LIFTOFF_PROP_CRTC_H);

rect->x = x_prop != NULL ? x_prop->value : 0;
rect->y = y_prop != NULL ? y_prop->value : 0;
Expand Down Expand Up @@ -178,7 +200,7 @@ layer_update_priority(struct liftoff_layer *layer, bool make_current)
struct liftoff_layer_property *prop;

/* TODO: also bump priority when updating other properties */
prop = layer_get_property(layer, "FB_ID");
prop = layer_get_property(layer, LIFTOFF_PROP_FB_ID);
if (prop != NULL && prop->prev_value != prop->value) {
layer->pending_priority++;
}
Expand All @@ -195,7 +217,7 @@ layer_has_fb(struct liftoff_layer *layer)
{
struct liftoff_layer_property *fb_id_prop;

fb_id_prop = layer_get_property(layer, "FB_ID");
fb_id_prop = layer_get_property(layer, LIFTOFF_PROP_FB_ID);
return fb_id_prop != NULL && fb_id_prop->value != 0;
}

Expand All @@ -204,7 +226,7 @@ layer_is_visible(struct liftoff_layer *layer)
{
struct liftoff_layer_property *alpha_prop;

alpha_prop = layer_get_property(layer, "alpha");
alpha_prop = layer_get_property(layer, LIFTOFF_PROP_ALPHA);
if (alpha_prop != NULL && alpha_prop->value == 0) {
return false; /* fully transparent */
}
Expand Down
Loading

0 comments on commit 110e075

Please sign in to comment.