mirror of
https://gitlab.freedesktop.org/emersion/libliftoff.git
synced 2024-12-25 21:59:11 +01:00
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:
parent
b447a3bc34
commit
e85a1a5ecf
2 changed files with 33 additions and 0 deletions
|
@ -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
26
layer.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue