Add layer_intersects

This will be useful for implementing optimizations in case planes don't collide.
In these cases we can ignore some zpos constraints.

References: https://github.com/emersion/libliftoff/issues/3
This commit is contained in:
Simon Ser 2019-09-15 17:00:48 +03:00
parent b447a3bc34
commit e85a1a5ecf
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 33 additions and 0 deletions

View file

@ -57,7 +57,14 @@ struct liftoff_plane_property {
uint32_t id;
};
struct liftoff_rect {
int x, y;
int width, height;
};
struct liftoff_layer_property *layer_get_property(struct liftoff_layer *layer,
const char *name);
void layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect);
bool layer_intersects(struct liftoff_layer *a, struct liftoff_layer *b);
#endif

26
layer.c
View file

@ -74,3 +74,29 @@ uint32_t liftoff_layer_get_plane_id(struct liftoff_layer *layer)
}
return layer->plane->id;
}
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;
}