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

Commit 110e075

Browse files
committed
Introduce core properties
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
1 parent 70eca07 commit 110e075

6 files changed

Lines changed: 137 additions & 40 deletions

File tree

alloc.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ plane_step_init_next(struct alloc_step *step, struct alloc_step *prev,
125125

126126
zpos_prop = NULL;
127127
if (layer != NULL) {
128-
zpos_prop = layer_get_property(layer, "zpos");
128+
zpos_prop = layer_get_property(layer, LIFTOFF_PROP_ZPOS);
129129
}
130130
if (zpos_prop != NULL && plane->type != DRM_PLANE_TYPE_PRIMARY) {
131131
step->last_layer_zpos = zpos_prop->value;
@@ -168,7 +168,7 @@ has_composited_layer_over(struct liftoff_output *output,
168168
struct liftoff_layer *other_layer;
169169
struct liftoff_layer_property *zpos_prop, *other_zpos_prop;
170170

171-
zpos_prop = layer_get_property(layer, "zpos");
171+
zpos_prop = layer_get_property(layer, LIFTOFF_PROP_ZPOS);
172172
if (zpos_prop == NULL) {
173173
return false;
174174
}
@@ -178,7 +178,8 @@ has_composited_layer_over(struct liftoff_output *output,
178178
continue;
179179
}
180180

181-
other_zpos_prop = layer_get_property(other_layer, "zpos");
181+
other_zpos_prop = layer_get_property(other_layer,
182+
LIFTOFF_PROP_ZPOS);
182183
if (other_zpos_prop == NULL) {
183184
continue;
184185
}
@@ -201,7 +202,7 @@ has_allocated_layer_over(struct liftoff_output *output, struct alloc_step *step,
201202
struct liftoff_layer *other_layer;
202203
struct liftoff_layer_property *zpos_prop, *other_zpos_prop;
203204

204-
zpos_prop = layer_get_property(layer, "zpos");
205+
zpos_prop = layer_get_property(layer, LIFTOFF_PROP_ZPOS);
205206
if (zpos_prop == NULL) {
206207
return false;
207208
}
@@ -221,7 +222,8 @@ has_allocated_layer_over(struct liftoff_output *output, struct alloc_step *step,
221222
continue;
222223
}
223224

224-
other_zpos_prop = layer_get_property(other_layer, "zpos");
225+
other_zpos_prop = layer_get_property(other_layer,
226+
LIFTOFF_PROP_ZPOS);
225227
if (other_zpos_prop == NULL) {
226228
continue;
227229
}
@@ -284,7 +286,7 @@ check_layer_plane_compatible(struct alloc_step *step,
284286
return false;
285287
}
286288

287-
zpos_prop = layer_get_property(layer, "zpos");
289+
zpos_prop = layer_get_property(layer, LIFTOFF_PROP_ZPOS);
288290
if (zpos_prop != NULL) {
289291
if ((int)zpos_prop->value > step->last_layer_zpos &&
290292
has_allocated_layer_over(output, step, layer)) {

device.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,36 @@ device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,
111111

112112
return ret;
113113
}
114+
115+
ssize_t
116+
core_property_index(const char *name)
117+
{
118+
if (strcmp(name, "FB_ID") == 0) {
119+
return LIFTOFF_PROP_FB_ID;
120+
} else if (strcmp(name, "CRTC_ID") == 0) {
121+
return LIFTOFF_PROP_CRTC_ID;
122+
} else if (strcmp(name, "CRTC_X") == 0) {
123+
return LIFTOFF_PROP_CRTC_X;
124+
} else if (strcmp(name, "CRTC_Y") == 0) {
125+
return LIFTOFF_PROP_CRTC_Y;
126+
} else if (strcmp(name, "CRTC_W") == 0) {
127+
return LIFTOFF_PROP_CRTC_W;
128+
} else if (strcmp(name, "CRTC_H") == 0) {
129+
return LIFTOFF_PROP_CRTC_H;
130+
} else if (strcmp(name, "SRC_X") == 0) {
131+
return LIFTOFF_PROP_SRC_X;
132+
} else if (strcmp(name, "SRC_Y") == 0) {
133+
return LIFTOFF_PROP_SRC_Y;
134+
} else if (strcmp(name, "SRC_W") == 0) {
135+
return LIFTOFF_PROP_SRC_W;
136+
} else if (strcmp(name, "SRC_H") == 0) {
137+
return LIFTOFF_PROP_SRC_H;
138+
} else if (strcmp(name, "zpos") == 0) {
139+
return LIFTOFF_PROP_ZPOS;
140+
} else if (strcmp(name, "alpha") == 0) {
141+
return LIFTOFF_PROP_ALPHA;
142+
} else if (strcmp(name, "rotation") == 0) {
143+
return LIFTOFF_PROP_ROTATION;
144+
}
145+
return -1;
146+
}

include/private.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@
22
#define PRIVATE_H
33

44
#include <libliftoff.h>
5+
#include <sys/types.h>
56
#include "list.h"
67
#include "log.h"
78

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

13+
/**
14+
* List of well-known KMS properties.
15+
*
16+
* Keep core_property_index in sync.
17+
*/
18+
enum liftoff_core_property {
19+
LIFTOFF_PROP_FB_ID,
20+
LIFTOFF_PROP_CRTC_ID,
21+
LIFTOFF_PROP_CRTC_X,
22+
LIFTOFF_PROP_CRTC_Y,
23+
LIFTOFF_PROP_CRTC_W,
24+
LIFTOFF_PROP_CRTC_H,
25+
LIFTOFF_PROP_SRC_X,
26+
LIFTOFF_PROP_SRC_Y,
27+
LIFTOFF_PROP_SRC_W,
28+
LIFTOFF_PROP_SRC_H,
29+
LIFTOFF_PROP_ZPOS,
30+
LIFTOFF_PROP_ALPHA,
31+
LIFTOFF_PROP_ROTATION,
32+
LIFTOFF_PROP_LAST, /* keep last */
33+
};
34+
1235
struct liftoff_device {
1336
int drm_fd;
1437

@@ -43,6 +66,7 @@ struct liftoff_layer {
4366

4467
struct liftoff_layer_property *props;
4568
size_t props_len;
69+
ssize_t core_props[LIFTOFF_PROP_LAST];
4670

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

@@ -56,6 +80,7 @@ struct liftoff_layer {
5680
struct liftoff_layer_property {
5781
char name[DRM_PROP_NAME_LEN];
5882
uint64_t value, prev_value;
83+
ssize_t core_index;
5984
};
6085

6186
struct liftoff_plane {
@@ -68,6 +93,7 @@ struct liftoff_plane {
6893

6994
struct liftoff_plane_property *props;
7095
size_t props_len;
96+
struct liftoff_plane_property *core_props[LIFTOFF_PROP_LAST];
7197

7298
struct liftoff_layer *layer;
7399
};
@@ -87,7 +113,7 @@ device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,
87113
uint32_t flags);
88114

89115
struct liftoff_layer_property *
90-
layer_get_property(struct liftoff_layer *layer, const char *name);
116+
layer_get_property(struct liftoff_layer *layer, enum liftoff_core_property prop);
91117

92118
void
93119
layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect);
@@ -114,4 +140,7 @@ plane_apply(struct liftoff_plane *plane, struct liftoff_layer *layer,
114140
void
115141
output_log_layers(struct liftoff_output *output);
116142

143+
ssize_t
144+
core_property_index(const char *name);
145+
117146
#endif

layer.c

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ struct liftoff_layer *
77
liftoff_layer_create(struct liftoff_output *output)
88
{
99
struct liftoff_layer *layer;
10+
size_t i;
1011

1112
layer = calloc(1, sizeof(*layer));
1213
if (layer == NULL) {
1314
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
1415
return NULL;
1516
}
1617
layer->output = output;
18+
for (i = 0; i < LIFTOFF_PROP_LAST; i++) {
19+
layer->core_props[i] = -1;
20+
}
1721
liftoff_list_insert(output->layers.prev, &layer->link);
1822
output->layers_changed = true;
1923
return layer;
@@ -39,16 +43,14 @@ liftoff_layer_destroy(struct liftoff_layer *layer)
3943
}
4044

4145
struct liftoff_layer_property *
42-
layer_get_property(struct liftoff_layer *layer, const char *name)
46+
layer_get_property(struct liftoff_layer *layer, enum liftoff_core_property prop)
4347
{
44-
size_t i;
48+
ssize_t i;
4549

46-
for (i = 0; i < layer->props_len; i++) {
47-
if (strcmp(layer->props[i].name, name) == 0) {
48-
return &layer->props[i];
49-
}
50-
}
51-
return NULL;
50+
i = layer->core_props[prop];
51+
if (i < 0)
52+
return NULL;
53+
return &layer->props[i];
5254
}
5355

5456
int
@@ -57,14 +59,28 @@ liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
5759
{
5860
struct liftoff_layer_property *props;
5961
struct liftoff_layer_property *prop;
62+
ssize_t core_prop_idx;
63+
size_t i;
6064

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

67-
prop = layer_get_property(layer, name);
71+
prop = NULL;
72+
core_prop_idx = core_property_index(name);
73+
if (core_prop_idx >= 0) {
74+
prop = layer_get_property(layer, core_prop_idx);
75+
} else {
76+
for (i = 0; i < layer->props_len; i++) {
77+
if (strcmp(layer->props[i].name, name) == 0) {
78+
prop = &layer->props[i];
79+
break;
80+
}
81+
}
82+
}
83+
6884
if (prop == NULL) {
6985
props = realloc(layer->props, (layer->props_len + 1)
7086
* sizeof(struct liftoff_layer_property));
@@ -75,11 +91,17 @@ liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
7591
layer->props = props;
7692
layer->props_len++;
7793

78-
prop = &layer->props[layer->props_len - 1];
94+
i = layer->props_len - 1;
95+
prop = &layer->props[i];
7996
memset(prop, 0, sizeof(*prop));
8097
strncpy(prop->name, name, sizeof(prop->name) - 1);
98+
prop->core_index = core_prop_idx;
8199

82100
layer->changed = true;
101+
102+
if (core_prop_idx >= 0) {
103+
layer->core_props[core_prop_idx] = i;
104+
}
83105
}
84106

85107
prop->value = value;
@@ -125,10 +147,10 @@ layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect)
125147
{
126148
struct liftoff_layer_property *x_prop, *y_prop, *w_prop, *h_prop;
127149

128-
x_prop = layer_get_property(layer, "CRTC_X");
129-
y_prop = layer_get_property(layer, "CRTC_Y");
130-
w_prop = layer_get_property(layer, "CRTC_W");
131-
h_prop = layer_get_property(layer, "CRTC_H");
150+
x_prop = layer_get_property(layer, LIFTOFF_PROP_CRTC_X);
151+
y_prop = layer_get_property(layer, LIFTOFF_PROP_CRTC_Y);
152+
w_prop = layer_get_property(layer, LIFTOFF_PROP_CRTC_W);
153+
h_prop = layer_get_property(layer, LIFTOFF_PROP_CRTC_H);
132154

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

180202
/* TODO: also bump priority when updating other properties */
181-
prop = layer_get_property(layer, "FB_ID");
203+
prop = layer_get_property(layer, LIFTOFF_PROP_FB_ID);
182204
if (prop != NULL && prop->prev_value != prop->value) {
183205
layer->pending_priority++;
184206
}
@@ -195,7 +217,7 @@ layer_has_fb(struct liftoff_layer *layer)
195217
{
196218
struct liftoff_layer_property *fb_id_prop;
197219

198-
fb_id_prop = layer_get_property(layer, "FB_ID");
220+
fb_id_prop = layer_get_property(layer, LIFTOFF_PROP_FB_ID);
199221
return fb_id_prop != NULL && fb_id_prop->value != 0;
200222
}
201223

@@ -204,7 +226,7 @@ layer_is_visible(struct liftoff_layer *layer)
204226
{
205227
struct liftoff_layer_property *alpha_prop;
206228

207-
alpha_prop = layer_get_property(layer, "alpha");
229+
alpha_prop = layer_get_property(layer, LIFTOFF_PROP_ALPHA);
208230
if (alpha_prop != NULL && alpha_prop->value == 0) {
209231
return false; /* fully transparent */
210232
}

0 commit comments

Comments
 (0)