Add newline after function return type

Aligns our style with Linux' and Weston's.
This commit is contained in:
Simon Ser 2021-08-13 22:02:33 +02:00
parent 120ad6fb73
commit 32683879e7
25 changed files with 487 additions and 262 deletions

76
alloc.c
View file

@ -95,9 +95,9 @@ struct alloc_step {
char log_prefix[64]; char log_prefix[64];
}; };
static void plane_step_init_next(struct alloc_step *step, static void
struct alloc_step *prev, plane_step_init_next(struct alloc_step *step, struct alloc_step *prev,
struct liftoff_layer *layer) struct liftoff_layer *layer)
{ {
struct liftoff_plane *plane; struct liftoff_plane *plane;
struct liftoff_layer_property *zpos_prop; struct liftoff_layer_property *zpos_prop;
@ -146,8 +146,8 @@ static void plane_step_init_next(struct alloc_step *step,
} }
} }
static bool is_layer_allocated(struct alloc_step *step, static bool
struct liftoff_layer *layer) is_layer_allocated(struct alloc_step *step, struct liftoff_layer *layer)
{ {
size_t i; size_t i;
@ -161,9 +161,9 @@ static bool is_layer_allocated(struct alloc_step *step,
return false; return false;
} }
static bool has_composited_layer_over(struct liftoff_output *output, static bool
struct alloc_step *step, has_composited_layer_over(struct liftoff_output *output,
struct liftoff_layer *layer) struct alloc_step *step, struct liftoff_layer *layer)
{ {
struct liftoff_layer *other_layer; struct liftoff_layer *other_layer;
struct liftoff_layer_property *zpos_prop, *other_zpos_prop; struct liftoff_layer_property *zpos_prop, *other_zpos_prop;
@ -192,9 +192,9 @@ static bool has_composited_layer_over(struct liftoff_output *output,
return false; return false;
} }
static bool has_allocated_layer_over(struct liftoff_output *output, static bool
struct alloc_step *step, has_allocated_layer_over(struct liftoff_output *output, struct alloc_step *step,
struct liftoff_layer *layer) struct liftoff_layer *layer)
{ {
ssize_t i; ssize_t i;
struct liftoff_plane *other_plane; struct liftoff_plane *other_plane;
@ -238,9 +238,9 @@ static bool has_allocated_layer_over(struct liftoff_output *output,
return false; return false;
} }
static bool has_allocated_plane_under(struct liftoff_output *output, static bool
struct alloc_step *step, has_allocated_plane_under(struct liftoff_output *output,
struct liftoff_layer *layer) struct alloc_step *step, struct liftoff_layer *layer)
{ {
struct liftoff_plane *plane, *other_plane; struct liftoff_plane *plane, *other_plane;
ssize_t i; ssize_t i;
@ -269,9 +269,10 @@ static bool has_allocated_plane_under(struct liftoff_output *output,
return false; return false;
} }
static bool check_layer_plane_compatible(struct alloc_step *step, static bool
struct liftoff_layer *layer, check_layer_plane_compatible(struct alloc_step *step,
struct liftoff_plane *plane) struct liftoff_layer *layer,
struct liftoff_plane *plane)
{ {
struct liftoff_output *output; struct liftoff_output *output;
struct liftoff_layer_property *zpos_prop; struct liftoff_layer_property *zpos_prop;
@ -332,8 +333,8 @@ static bool check_layer_plane_compatible(struct alloc_step *step,
return true; return true;
} }
static bool check_alloc_valid(struct alloc_result *result, static bool
struct alloc_step *step) check_alloc_valid(struct alloc_result *result, struct alloc_step *step)
{ {
/* If composition isn't used, we need to have allocated all /* If composition isn't used, we need to have allocated all
* layers. */ * layers. */
@ -362,9 +363,9 @@ static bool check_alloc_valid(struct alloc_result *result,
return true; return true;
} }
static int output_choose_layers(struct liftoff_output *output, static int
struct alloc_result *result, output_choose_layers(struct liftoff_output *output, struct alloc_result *result,
struct alloc_step *step) struct alloc_step *step)
{ {
struct liftoff_device *device; struct liftoff_device *device;
struct liftoff_plane *plane; struct liftoff_plane *plane;
@ -471,7 +472,8 @@ skip:
return 0; return 0;
} }
static int apply_current(struct liftoff_device *device, drmModeAtomicReq *req) static int
apply_current(struct liftoff_device *device, drmModeAtomicReq *req)
{ {
struct liftoff_plane *plane; struct liftoff_plane *plane;
int cursor, ret; int cursor, ret;
@ -490,7 +492,8 @@ static int apply_current(struct liftoff_device *device, drmModeAtomicReq *req)
return 0; return 0;
} }
static bool layer_needs_realloc(struct liftoff_layer *layer) static bool
layer_needs_realloc(struct liftoff_layer *layer)
{ {
size_t i; size_t i;
struct liftoff_layer_property *prop; struct liftoff_layer_property *prop;
@ -545,8 +548,9 @@ static bool layer_needs_realloc(struct liftoff_layer *layer)
return false; return false;
} }
static int reuse_previous_alloc(struct liftoff_output *output, static int
drmModeAtomicReq *req, uint32_t flags) reuse_previous_alloc(struct liftoff_output *output, drmModeAtomicReq *req,
uint32_t flags)
{ {
struct liftoff_device *device; struct liftoff_device *device;
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -578,7 +582,8 @@ static int reuse_previous_alloc(struct liftoff_output *output,
return ret; return ret;
} }
static void mark_layers_clean(struct liftoff_output *output) static void
mark_layers_clean(struct liftoff_output *output)
{ {
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -589,7 +594,8 @@ static void mark_layers_clean(struct liftoff_output *output)
} }
} }
static void update_layers_priority(struct liftoff_device *device) static void
update_layers_priority(struct liftoff_device *device)
{ {
struct liftoff_output *output; struct liftoff_output *output;
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -608,7 +614,8 @@ static void update_layers_priority(struct liftoff_device *device)
} }
} }
static void log_reuse(struct liftoff_output *output) static void
log_reuse(struct liftoff_output *output)
{ {
if (output->alloc_reused_counter == 0) { if (output->alloc_reused_counter == 0) {
liftoff_log(LIFTOFF_DEBUG, liftoff_log(LIFTOFF_DEBUG,
@ -618,7 +625,8 @@ static void log_reuse(struct liftoff_output *output)
output->alloc_reused_counter++; output->alloc_reused_counter++;
} }
static void log_no_reuse(struct liftoff_output *output) static void
log_no_reuse(struct liftoff_output *output)
{ {
liftoff_log(LIFTOFF_DEBUG, "Computing plane allocation on output %p", liftoff_log(LIFTOFF_DEBUG, "Computing plane allocation on output %p",
(void *)output); (void *)output);
@ -632,7 +640,8 @@ static void log_no_reuse(struct liftoff_output *output)
} }
} }
static size_t non_composition_layers_length(struct liftoff_output *output) static size_t
non_composition_layers_length(struct liftoff_output *output)
{ {
struct liftoff_layer *layer; struct liftoff_layer *layer;
size_t n; size_t n;
@ -648,8 +657,9 @@ static size_t non_composition_layers_length(struct liftoff_output *output)
return n; return n;
} }
int liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req, int
uint32_t flags) liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req,
uint32_t flags)
{ {
struct liftoff_device *device; struct liftoff_device *device;
struct liftoff_plane *plane; struct liftoff_plane *plane;

View file

@ -5,7 +5,8 @@
#include "log.h" #include "log.h"
#include "private.h" #include "private.h"
struct liftoff_device *liftoff_device_create(int drm_fd) struct liftoff_device *
liftoff_device_create(int drm_fd)
{ {
struct liftoff_device *device; struct liftoff_device *device;
drmModeRes *drm_res; drmModeRes *drm_res;
@ -49,7 +50,8 @@ struct liftoff_device *liftoff_device_create(int drm_fd)
return device; return device;
} }
void liftoff_device_destroy(struct liftoff_device *device) void
liftoff_device_destroy(struct liftoff_device *device)
{ {
struct liftoff_plane *plane, *tmp; struct liftoff_plane *plane, *tmp;
@ -65,7 +67,8 @@ void liftoff_device_destroy(struct liftoff_device *device)
free(device); free(device);
} }
int liftoff_device_register_all_planes(struct liftoff_device *device) int
liftoff_device_register_all_planes(struct liftoff_device *device)
{ {
drmModePlaneRes *drm_plane_res; drmModePlaneRes *drm_plane_res;
uint32_t i; uint32_t i;
@ -86,8 +89,9 @@ int liftoff_device_register_all_planes(struct liftoff_device *device)
return 0; return 0;
} }
int device_test_commit(struct liftoff_device *device, int
drmModeAtomicReq *req, uint32_t flags) device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,
uint32_t flags)
{ {
int ret; int ret;

View file

@ -6,7 +6,8 @@
#include <xf86drm.h> #include <xf86drm.h>
#include "common.h" #include "common.h"
drmModeConnector *pick_connector(int drm_fd, drmModeRes *drm_res) drmModeConnector *
pick_connector(int drm_fd, drmModeRes *drm_res)
{ {
int i; int i;
drmModeConnector *connector; drmModeConnector *connector;
@ -22,8 +23,8 @@ drmModeConnector *pick_connector(int drm_fd, drmModeRes *drm_res)
return NULL; return NULL;
} }
drmModeCrtc *pick_crtc(int drm_fd, drmModeRes *drm_res, drmModeCrtc *
drmModeConnector *connector) pick_crtc(int drm_fd, drmModeRes *drm_res, drmModeConnector *connector)
{ {
drmModeEncoder *enc; drmModeEncoder *enc;
uint32_t crtc_id; uint32_t crtc_id;
@ -66,7 +67,8 @@ drmModeCrtc *pick_crtc(int drm_fd, drmModeRes *drm_res,
} }
} }
void disable_all_crtcs_except(int drm_fd, drmModeRes *drm_res, uint32_t crtc_id) void
disable_all_crtcs_except(int drm_fd, drmModeRes *drm_res, uint32_t crtc_id)
{ {
int i; int i;
@ -79,8 +81,9 @@ void disable_all_crtcs_except(int drm_fd, drmModeRes *drm_res, uint32_t crtc_id)
} }
} }
bool dumb_fb_init(struct dumb_fb *fb, int drm_fd, uint32_t format, bool
uint32_t width, uint32_t height) dumb_fb_init(struct dumb_fb *fb, int drm_fd, uint32_t format, uint32_t width,
uint32_t height)
{ {
int ret; int ret;
uint32_t fb_id; uint32_t fb_id;
@ -116,7 +119,8 @@ bool dumb_fb_init(struct dumb_fb *fb, int drm_fd, uint32_t format,
return true; return true;
} }
void *dumb_fb_map(struct dumb_fb *fb, int drm_fd) void *
dumb_fb_map(struct dumb_fb *fb, int drm_fd)
{ {
int ret; int ret;
@ -130,7 +134,8 @@ void *dumb_fb_map(struct dumb_fb *fb, int drm_fd)
map.offset); map.offset);
} }
void dumb_fb_fill(struct dumb_fb *fb, int drm_fd, uint32_t color) void
dumb_fb_fill(struct dumb_fb *fb, int drm_fd, uint32_t color)
{ {
uint32_t *data; uint32_t *data;
size_t i; size_t i;

View file

@ -12,14 +12,23 @@ struct dumb_fb {
uint32_t id; uint32_t id;
}; };
drmModeConnector *pick_connector(int drm_fd, drmModeRes *drm_res); drmModeConnector *
drmModeCrtc *pick_crtc(int drm_fd, drmModeRes *drm_res, pick_connector(int drm_fd, drmModeRes *drm_res);
drmModeConnector *connector);
void disable_all_crtcs_except(int drm_fd, drmModeRes *drm_res, uint32_t crtc_id);
bool dumb_fb_init(struct dumb_fb *fb, int drm_fd, uint32_t format, drmModeCrtc *
uint32_t width, uint32_t height); pick_crtc(int drm_fd, drmModeRes *drm_res, drmModeConnector *connector);
void *dumb_fb_map(struct dumb_fb *fb, int drm_fd);
void dumb_fb_fill(struct dumb_fb *fb, int drm_fd, uint32_t color); void
disable_all_crtcs_except(int drm_fd, drmModeRes *drm_res, uint32_t crtc_id);
bool
dumb_fb_init(struct dumb_fb *fb, int drm_fd, uint32_t format,
uint32_t width, uint32_t height);
void *
dumb_fb_map(struct dumb_fb *fb, int drm_fd);
void
dumb_fb_fill(struct dumb_fb *fb, int drm_fd, uint32_t color);
#endif #endif

View file

@ -25,10 +25,9 @@ static const uint32_t colors[] = {
0xFFFFFF00, /* yellow */ 0xFFFFFF00, /* yellow */
}; };
static struct liftoff_layer *add_layer(int drm_fd, struct liftoff_output *output, static struct liftoff_layer *
int x, int y, int width, int height, add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width,
bool with_alpha, bool white, int height, bool with_alpha, bool white, struct dumb_fb *fb)
struct dumb_fb *fb)
{ {
static size_t color_idx = 0; static size_t color_idx = 0;
uint32_t color; uint32_t color;
@ -65,8 +64,9 @@ static struct liftoff_layer *add_layer(int drm_fd, struct liftoff_output *output
} }
/* Naive compositor for opaque buffers */ /* Naive compositor for opaque buffers */
static void composite(int drm_fd, struct dumb_fb *dst_fb, struct dumb_fb *src_fb, static void
int dst_x, int dst_y) composite(int drm_fd, struct dumb_fb *dst_fb, struct dumb_fb *src_fb, int dst_x,
int dst_y)
{ {
uint8_t *dst, *src; uint8_t *dst, *src;
int i, y, src_width; int i, y, src_width;
@ -97,7 +97,8 @@ static void composite(int drm_fd, struct dumb_fb *dst_fb, struct dumb_fb *src_fb
munmap(src, src_fb->size); munmap(src, src_fb->size);
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int opt; int opt;
size_t layers_len; size_t layers_len;

View file

@ -33,9 +33,10 @@ static struct liftoff_output *output = NULL;
static struct example_layer layers[LAYERS_LEN] = {0}; static struct example_layer layers[LAYERS_LEN] = {0};
static size_t active_layer_idx = 2; static size_t active_layer_idx = 2;
static bool init_layer(int drm_fd, struct example_layer *layer, static bool
struct liftoff_output *output, int width, int height, init_layer(int drm_fd, struct example_layer *layer,
bool with_alpha) struct liftoff_output *output, int width, int height,
bool with_alpha)
{ {
static size_t color_idx = 0; static size_t color_idx = 0;
static float color_value = 1.0; static float color_value = 1.0;
@ -65,7 +66,8 @@ static bool init_layer(int drm_fd, struct example_layer *layer,
return true; return true;
} }
static void draw_layer(int drm_fd, struct example_layer *layer) static void
draw_layer(int drm_fd, struct example_layer *layer)
{ {
uint32_t color; uint32_t color;
struct dumb_fb *fb; struct dumb_fb *fb;
@ -85,7 +87,8 @@ static void draw_layer(int drm_fd, struct example_layer *layer)
liftoff_layer_set_property(layer->layer, "CRTC_Y", layer->y); liftoff_layer_set_property(layer->layer, "CRTC_Y", layer->y);
} }
static bool draw(void) static bool
draw(void)
{ {
struct example_layer *active_layer; struct example_layer *active_layer;
drmModeAtomicReq *req; drmModeAtomicReq *req;
@ -138,13 +141,15 @@ static bool draw(void)
return true; return true;
} }
static void page_flip_handler(int fd, unsigned seq, unsigned tv_sec, static void
unsigned tv_usec, unsigned crtc_id, void *data) page_flip_handler(int fd, unsigned seq, unsigned tv_sec, unsigned tv_usec,
unsigned crtc_id, void *data)
{ {
draw(); draw();
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
drmModeRes *drm_res; drmModeRes *drm_res;
drmModeCrtc *crtc; drmModeCrtc *crtc;

View file

@ -24,9 +24,9 @@ static const uint32_t colors[] = {
0xFFFFFF00, /* yellow */ 0xFFFFFF00, /* yellow */
}; };
static struct liftoff_layer *add_layer(int drm_fd, struct liftoff_output *output, static struct liftoff_layer *
int x, int y, int width, int height, add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width,
bool with_alpha) int height, bool with_alpha)
{ {
static bool first = true; static bool first = true;
static size_t color_idx = 0; static size_t color_idx = 0;
@ -65,7 +65,8 @@ static struct liftoff_layer *add_layer(int drm_fd, struct liftoff_output *output
return layer; return layer;
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int drm_fd; int drm_fd;
struct liftoff_device *device; struct liftoff_device *device;

View file

@ -22,9 +22,9 @@ static const uint32_t colors[] = {
0xFFFFFF00, /* yellow */ 0xFFFFFF00, /* yellow */
}; };
static struct liftoff_layer *add_layer(int drm_fd, struct liftoff_output *output, static struct liftoff_layer *
int x, int y, int width, int height, add_layer(int drm_fd, struct liftoff_output *output, int x, int y, int width,
bool with_alpha) int height, bool with_alpha)
{ {
static bool first = true; static bool first = true;
static size_t color_idx = 0; static size_t color_idx = 0;
@ -63,7 +63,8 @@ static struct liftoff_layer *add_layer(int drm_fd, struct liftoff_output *output
return layer; return layer;
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int drm_fd; int drm_fd;
struct liftoff_device *device; struct liftoff_device *device;

View file

@ -18,13 +18,17 @@ struct liftoff_plane;
* The node is expected to have DRM_CLIENT_CAP_ATOMIC enabled. libliftoff takes * The node is expected to have DRM_CLIENT_CAP_ATOMIC enabled. libliftoff takes
* ownership of the file descriptor. * ownership of the file descriptor.
*/ */
struct liftoff_device *liftoff_device_create(int drm_fd); struct liftoff_device *
liftoff_device_create(int drm_fd);
/** /**
* Destroy a libliftoff device. * Destroy a libliftoff device.
* *
* The caller is expected to destroy the outputs and layers explicitly. * The caller is expected to destroy the outputs and layers explicitly.
*/ */
void liftoff_device_destroy(struct liftoff_device *device); void
liftoff_device_destroy(struct liftoff_device *device);
/** /**
* Register all available hardware planes to be managed by the libliftoff * Register all available hardware planes to be managed by the libliftoff
* device. * device.
@ -34,7 +38,8 @@ void liftoff_device_destroy(struct liftoff_device *device);
* *
* Zero is returned on success, negative errno on error. * Zero is returned on success, negative errno on error.
*/ */
int liftoff_device_register_all_planes(struct liftoff_device *device); int
liftoff_device_register_all_planes(struct liftoff_device *device);
/** /**
* Register a hardware plane to be managed by the libliftoff device. * Register a hardware plane to be managed by the libliftoff device.
@ -42,17 +47,20 @@ int liftoff_device_register_all_planes(struct liftoff_device *device);
* Users should call this function for each plane they don't want to manually * Users should call this function for each plane they don't want to manually
* manage. Registering the same plane twice is an error. * manage. Registering the same plane twice is an error.
*/ */
struct liftoff_plane *liftoff_plane_create(struct liftoff_device *device, struct liftoff_plane *
uint32_t plane_id); liftoff_plane_create(struct liftoff_device *device, uint32_t plane_id);
/** /**
* Unregister a hardware plane. * Unregister a hardware plane.
*/ */
void liftoff_plane_destroy(struct liftoff_plane *plane); void
liftoff_plane_destroy(struct liftoff_plane *plane);
/** /**
* Obtain the object ID of the plane. * Obtain the object ID of the plane.
*/ */
uint32_t liftoff_plane_get_id(struct liftoff_plane *plane); uint32_t
liftoff_plane_get_id(struct liftoff_plane *plane);
/** /**
* Build a layer to plane mapping and append the plane configuration to `req`. * Build a layer to plane mapping and append the plane configuration to `req`.
@ -64,22 +72,26 @@ uint32_t liftoff_plane_get_id(struct liftoff_plane *plane);
* *
* Zero is returned on success, negative errno on error. * Zero is returned on success, negative errno on error.
*/ */
int liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req, int
uint32_t flags); liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req,
uint32_t flags);
/** /**
* Make the device manage a CRTC's planes. * Make the device manage a CRTC's planes.
* *
* The returned output allows callers to attach layers. * The returned output allows callers to attach layers.
*/ */
struct liftoff_output *liftoff_output_create(struct liftoff_device *device, struct liftoff_output *
uint32_t crtc_id); liftoff_output_create(struct liftoff_device *device, uint32_t crtc_id);
/** /**
* Destroy a libliftoff output. * Destroy a libliftoff output.
* *
* The caller is expected to destroy the output's layers explicitly. * The caller is expected to destroy the output's layers explicitly.
*/ */
void liftoff_output_destroy(struct liftoff_output *output); void
liftoff_output_destroy(struct liftoff_output *output);
/** /**
* Indicate on which layer composition can take place. * Indicate on which layer composition can take place.
* *
@ -87,8 +99,10 @@ void liftoff_output_destroy(struct liftoff_output *output);
* this layer. The composition layer won't be used if all other layers have been * this layer. The composition layer won't be used if all other layers have been
* mapped to a plane. There is at most one composition layer per output. * mapped to a plane. There is at most one composition layer per output.
*/ */
void liftoff_output_set_composition_layer(struct liftoff_output *output, void
struct liftoff_layer *layer); liftoff_output_set_composition_layer(struct liftoff_output *output,
struct liftoff_layer *layer);
/** /**
* Check whether this output needs composition. * Check whether this output needs composition.
* *
@ -96,7 +110,8 @@ void liftoff_output_set_composition_layer(struct liftoff_output *output,
* plane. In other words, if an output needs composition, at least one layer * plane. In other words, if an output needs composition, at least one layer
* will return true when `liftoff_layer_needs_composition` is called. * will return true when `liftoff_layer_needs_composition` is called.
*/ */
bool liftoff_output_needs_composition(struct liftoff_output *output); bool
liftoff_output_needs_composition(struct liftoff_output *output);
/** /**
* Create a new layer on an output. * Create a new layer on an output.
@ -106,11 +121,15 @@ bool liftoff_output_needs_composition(struct liftoff_output *output);
* to map layers to hardware planes on a best-effort basis. The user will need * to map layers to hardware planes on a best-effort basis. The user will need
* to manually handle layers that couldn't be mapped to a plane. * to manually handle layers that couldn't be mapped to a plane.
*/ */
struct liftoff_layer *liftoff_layer_create(struct liftoff_output *output); struct liftoff_layer *
liftoff_layer_create(struct liftoff_output *output);
/** /**
* Destroy a layer. * Destroy a layer.
*/ */
void liftoff_layer_destroy(struct liftoff_layer *layer); void
liftoff_layer_destroy(struct liftoff_layer *layer);
/** /**
* Set a property on the layer. * Set a property on the layer.
* *
@ -121,8 +140,10 @@ void liftoff_layer_destroy(struct liftoff_layer *layer);
* *
* Zero is returned on success, negative errno on error. * Zero is returned on success, negative errno on error.
*/ */
int liftoff_layer_set_property(struct liftoff_layer *layer, const char *name, int
uint64_t value); liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
uint64_t value);
/** /**
* Force composition on this layer. * Force composition on this layer.
* *
@ -132,20 +153,25 @@ int liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
* This can be used when no KMS FB ID is available for this layer but it still * This can be used when no KMS FB ID is available for this layer but it still
* needs to be displayed (e.g. the buffer cannot be imported in KMS). * needs to be displayed (e.g. the buffer cannot be imported in KMS).
*/ */
void liftoff_layer_set_fb_composited(struct liftoff_layer *layer); void
liftoff_layer_set_fb_composited(struct liftoff_layer *layer);
/** /**
* Check whether this layer needs composition. * Check whether this layer needs composition.
* *
* A layer needs composition if it's visible and if it couldn't be mapped to a * A layer needs composition if it's visible and if it couldn't be mapped to a
* plane. * plane.
*/ */
bool liftoff_layer_needs_composition(struct liftoff_layer *layer); bool
liftoff_layer_needs_composition(struct liftoff_layer *layer);
/** /**
* Retrieve the plane mapped to this layer. * Retrieve the plane mapped to this layer.
* *
* NULL is returned if no plane is mapped. * NULL is returned if no plane is mapped.
*/ */
struct liftoff_plane *liftoff_layer_get_plane(struct liftoff_layer *layer); struct liftoff_plane *
liftoff_layer_get_plane(struct liftoff_layer *layer);
enum liftoff_log_priority { enum liftoff_log_priority {
LIFTOFF_SILENT, LIFTOFF_SILENT,
@ -162,13 +188,16 @@ typedef void (*liftoff_log_handler)(enum liftoff_log_priority priority,
* Only messages with a priority higher than the provided priority will be * Only messages with a priority higher than the provided priority will be
* logged. The default priority is LIFTOFF_ERROR. * logged. The default priority is LIFTOFF_ERROR.
*/ */
void liftoff_log_set_priority(enum liftoff_log_priority priority); void
liftoff_log_set_priority(enum liftoff_log_priority priority);
/** /**
* Set libliftoff's log handler. * Set libliftoff's log handler.
* *
* The default handler prints messages to stderr. NULL restores the default * The default handler prints messages to stderr. NULL restores the default
* handler. * handler.
*/ */
void liftoff_log_set_handler(liftoff_log_handler handler); void
liftoff_log_set_handler(liftoff_log_handler handler);
#endif #endif

View file

@ -9,11 +9,20 @@ struct liftoff_list {
struct liftoff_list *next; struct liftoff_list *next;
}; };
void liftoff_list_init(struct liftoff_list *list); void
void liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm); liftoff_list_init(struct liftoff_list *list);
void liftoff_list_remove(struct liftoff_list *elm);
size_t liftoff_list_length(const struct liftoff_list *list); void
bool liftoff_list_empty(const struct liftoff_list *list); liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm);
void
liftoff_list_remove(struct liftoff_list *elm);
size_t
liftoff_list_length(const struct liftoff_list *list);
bool
liftoff_list_empty(const struct liftoff_list *list);
#define liftoff_container_of(ptr, sample, member) \ #define liftoff_container_of(ptr, sample, member) \
(__typeof__(sample))((char *)(ptr) - \ (__typeof__(sample))((char *)(ptr) - \

View file

@ -11,10 +11,14 @@
#define _LIFTOFF_ATTRIB_PRINTF(start, end) #define _LIFTOFF_ATTRIB_PRINTF(start, end)
#endif #endif
bool log_has(enum liftoff_log_priority priority); bool
log_has(enum liftoff_log_priority priority);
void liftoff_log(enum liftoff_log_priority priority, void
const char *format, ...) _LIFTOFF_ATTRIB_PRINTF(2, 3); liftoff_log(enum liftoff_log_priority priority, const char *format, ...)
void liftoff_log_errno(enum liftoff_log_priority priority, const char *msg); _LIFTOFF_ATTRIB_PRINTF(2, 3);
void
liftoff_log_errno(enum liftoff_log_priority priority, const char *msg);
#endif #endif

View file

@ -81,23 +81,39 @@ struct liftoff_rect {
int width, height; int width, height;
}; };
int device_test_commit(struct liftoff_device *device, int
drmModeAtomicReq *req, uint32_t flags); device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,
uint32_t flags);
struct liftoff_layer_property *layer_get_property(struct liftoff_layer *layer, struct liftoff_layer_property *
const char *name); 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);
void layer_mark_clean(struct liftoff_layer *layer);
void layer_update_priority(struct liftoff_layer *layer, bool make_current);
bool layer_has_fb(struct liftoff_layer *layer);
bool layer_is_visible(struct liftoff_layer *layer);
struct liftoff_plane_property *plane_get_property(struct liftoff_plane *plane, void
const char *name); layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect);
int plane_apply(struct liftoff_plane *plane, struct liftoff_layer *layer,
drmModeAtomicReq *req);
void output_log_layers(struct liftoff_output *output); bool
layer_intersects(struct liftoff_layer *a, struct liftoff_layer *b);
void
layer_mark_clean(struct liftoff_layer *layer);
void
layer_update_priority(struct liftoff_layer *layer, bool make_current);
bool
layer_has_fb(struct liftoff_layer *layer);
bool
layer_is_visible(struct liftoff_layer *layer);
struct liftoff_plane_property *
plane_get_property(struct liftoff_plane *plane, const char *name);
int
plane_apply(struct liftoff_plane *plane, struct liftoff_layer *layer,
drmModeAtomicReq *req);
void
output_log_layers(struct liftoff_output *output);
#endif #endif

47
layer.c
View file

@ -3,7 +3,8 @@
#include <string.h> #include <string.h>
#include "private.h" #include "private.h"
struct liftoff_layer *liftoff_layer_create(struct liftoff_output *output) struct liftoff_layer *
liftoff_layer_create(struct liftoff_output *output)
{ {
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -18,7 +19,8 @@ struct liftoff_layer *liftoff_layer_create(struct liftoff_output *output)
return layer; return layer;
} }
void liftoff_layer_destroy(struct liftoff_layer *layer) void
liftoff_layer_destroy(struct liftoff_layer *layer)
{ {
if (layer == NULL) { if (layer == NULL) {
return; return;
@ -36,8 +38,8 @@ void liftoff_layer_destroy(struct liftoff_layer *layer)
free(layer); free(layer);
} }
struct liftoff_layer_property *layer_get_property(struct liftoff_layer *layer, struct liftoff_layer_property *
const char *name) layer_get_property(struct liftoff_layer *layer, const char *name)
{ {
size_t i; size_t i;
@ -49,8 +51,9 @@ struct liftoff_layer_property *layer_get_property(struct liftoff_layer *layer,
return NULL; return NULL;
} }
int liftoff_layer_set_property(struct liftoff_layer *layer, const char *name, int
uint64_t value) liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
uint64_t value)
{ {
struct liftoff_layer_property *props; struct liftoff_layer_property *props;
struct liftoff_layer_property *prop; struct liftoff_layer_property *prop;
@ -89,7 +92,8 @@ int liftoff_layer_set_property(struct liftoff_layer *layer, const char *name,
return 0; return 0;
} }
void liftoff_layer_set_fb_composited(struct liftoff_layer *layer) void
liftoff_layer_set_fb_composited(struct liftoff_layer *layer)
{ {
if (layer->force_composition) { if (layer->force_composition) {
return; return;
@ -101,12 +105,14 @@ void liftoff_layer_set_fb_composited(struct liftoff_layer *layer)
layer->changed = true; layer->changed = true;
} }
struct liftoff_plane *liftoff_layer_get_plane(struct liftoff_layer *layer) struct liftoff_plane *
liftoff_layer_get_plane(struct liftoff_layer *layer)
{ {
return layer->plane; return layer->plane;
} }
bool liftoff_layer_needs_composition(struct liftoff_layer *layer) bool
liftoff_layer_needs_composition(struct liftoff_layer *layer)
{ {
if (!layer_is_visible(layer)) { if (!layer_is_visible(layer)) {
return false; return false;
@ -114,7 +120,8 @@ bool liftoff_layer_needs_composition(struct liftoff_layer *layer)
return layer->plane == NULL; return layer->plane == NULL;
} }
void layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect) void
layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect)
{ {
struct liftoff_layer_property *x_prop, *y_prop, *w_prop, *h_prop; struct liftoff_layer_property *x_prop, *y_prop, *w_prop, *h_prop;
@ -129,7 +136,8 @@ void layer_get_rect(struct liftoff_layer *layer, struct liftoff_rect *rect)
rect->height = h_prop != NULL ? h_prop->value : 0; rect->height = h_prop != NULL ? h_prop->value : 0;
} }
bool layer_intersects(struct liftoff_layer *a, struct liftoff_layer *b) bool
layer_intersects(struct liftoff_layer *a, struct liftoff_layer *b)
{ {
struct liftoff_rect ra, rb; struct liftoff_rect ra, rb;
@ -140,7 +148,8 @@ bool layer_intersects(struct liftoff_layer *a, struct liftoff_layer *b)
ra.x + ra.width > rb.x && ra.y + ra.height > rb.y; ra.x + ra.width > rb.x && ra.y + ra.height > rb.y;
} }
void layer_mark_clean(struct liftoff_layer *layer) void
layer_mark_clean(struct liftoff_layer *layer)
{ {
size_t i; size_t i;
@ -151,7 +160,8 @@ void layer_mark_clean(struct liftoff_layer *layer)
} }
} }
static void log_priority(struct liftoff_layer *layer) static void
log_priority(struct liftoff_layer *layer)
{ {
if (layer->current_priority == layer->pending_priority) { if (layer->current_priority == layer->pending_priority) {
return; return;
@ -162,7 +172,9 @@ static void log_priority(struct liftoff_layer *layer)
layer->pending_priority); layer->pending_priority);
} }
void layer_update_priority(struct liftoff_layer *layer, bool make_current) { void
layer_update_priority(struct liftoff_layer *layer, bool make_current)
{
struct liftoff_layer_property *prop; struct liftoff_layer_property *prop;
/* TODO: also bump priority when updating other properties */ /* TODO: also bump priority when updating other properties */
@ -178,14 +190,17 @@ void layer_update_priority(struct liftoff_layer *layer, bool make_current) {
} }
} }
bool layer_has_fb(struct liftoff_layer *layer) { bool
layer_has_fb(struct liftoff_layer *layer)
{
struct liftoff_layer_property *fb_id_prop; struct liftoff_layer_property *fb_id_prop;
fb_id_prop = layer_get_property(layer, "FB_ID"); fb_id_prop = layer_get_property(layer, "FB_ID");
return fb_id_prop != NULL && fb_id_prop->value != 0; return fb_id_prop != NULL && fb_id_prop->value != 0;
} }
bool layer_is_visible(struct liftoff_layer *layer) bool
layer_is_visible(struct liftoff_layer *layer)
{ {
struct liftoff_layer_property *alpha_prop; struct liftoff_layer_property *alpha_prop;

15
list.c
View file

@ -1,12 +1,14 @@
#include "list.h" #include "list.h"
void liftoff_list_init(struct liftoff_list *list) void
liftoff_list_init(struct liftoff_list *list)
{ {
list->prev = list; list->prev = list;
list->next = list; list->next = list;
} }
void liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm) void
liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm)
{ {
elm->prev = list; elm->prev = list;
elm->next = list->next; elm->next = list->next;
@ -14,7 +16,8 @@ void liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm)
elm->next->prev = elm; elm->next->prev = elm;
} }
void liftoff_list_remove(struct liftoff_list *elm) void
liftoff_list_remove(struct liftoff_list *elm)
{ {
elm->prev->next = elm->next; elm->prev->next = elm->next;
elm->next->prev = elm->prev; elm->next->prev = elm->prev;
@ -22,7 +25,8 @@ void liftoff_list_remove(struct liftoff_list *elm)
elm->prev = NULL; elm->prev = NULL;
} }
size_t liftoff_list_length(const struct liftoff_list *list) size_t
liftoff_list_length(const struct liftoff_list *list)
{ {
struct liftoff_list *e; struct liftoff_list *e;
size_t count; size_t count;
@ -37,7 +41,8 @@ size_t liftoff_list_length(const struct liftoff_list *list)
return count; return count;
} }
bool liftoff_list_empty(const struct liftoff_list *list) bool
liftoff_list_empty(const struct liftoff_list *list)
{ {
return list->next == list; return list->next == list;
} }

19
log.c
View file

@ -5,8 +5,8 @@
static enum liftoff_log_priority log_priority = LIFTOFF_ERROR; static enum liftoff_log_priority log_priority = LIFTOFF_ERROR;
static void log_stderr(enum liftoff_log_priority priority, const char *fmt, static void
va_list args) log_stderr(enum liftoff_log_priority priority, const char *fmt, va_list args)
{ {
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -14,12 +14,14 @@ static void log_stderr(enum liftoff_log_priority priority, const char *fmt,
static liftoff_log_handler log_handler = log_stderr; static liftoff_log_handler log_handler = log_stderr;
void liftoff_log_set_priority(enum liftoff_log_priority priority) void
liftoff_log_set_priority(enum liftoff_log_priority priority)
{ {
log_priority = priority; log_priority = priority;
} }
void liftoff_log_set_handler(liftoff_log_handler handler) { void
liftoff_log_set_handler(liftoff_log_handler handler) {
if (handler) { if (handler) {
log_handler = handler; log_handler = handler;
} else { } else {
@ -27,12 +29,14 @@ void liftoff_log_set_handler(liftoff_log_handler handler) {
} }
} }
bool log_has(enum liftoff_log_priority priority) bool
log_has(enum liftoff_log_priority priority)
{ {
return priority <= log_priority; return priority <= log_priority;
} }
void liftoff_log(enum liftoff_log_priority priority, const char *fmt, ...) void
liftoff_log(enum liftoff_log_priority priority, const char *fmt, ...)
{ {
if (!log_has(priority)) { if (!log_has(priority)) {
return; return;
@ -44,7 +48,8 @@ void liftoff_log(enum liftoff_log_priority priority, const char *fmt, ...)
va_end(args); va_end(args);
} }
void liftoff_log_errno(enum liftoff_log_priority priority, const char *msg) void
liftoff_log_errno(enum liftoff_log_priority priority, const char *msg)
{ {
// Ensure errno is still set to its original value when we return // Ensure errno is still set to its original value when we return
int prev_errno = errno; int prev_errno = errno;

View file

@ -5,8 +5,8 @@
#include <sys/types.h> #include <sys/types.h>
#include "private.h" #include "private.h"
struct liftoff_output *liftoff_output_create(struct liftoff_device *device, struct liftoff_output *
uint32_t crtc_id) liftoff_output_create(struct liftoff_device *device, uint32_t crtc_id)
{ {
struct liftoff_output *output; struct liftoff_output *output;
ssize_t crtc_index; ssize_t crtc_index;
@ -35,7 +35,8 @@ struct liftoff_output *liftoff_output_create(struct liftoff_device *device,
return output; return output;
} }
void liftoff_output_destroy(struct liftoff_output *output) void
liftoff_output_destroy(struct liftoff_output *output)
{ {
if (output == NULL) { if (output == NULL) {
return; return;
@ -45,8 +46,9 @@ void liftoff_output_destroy(struct liftoff_output *output)
free(output); free(output);
} }
void liftoff_output_set_composition_layer(struct liftoff_output *output, void
struct liftoff_layer *layer) liftoff_output_set_composition_layer(struct liftoff_output *output,
struct liftoff_layer *layer)
{ {
assert(layer->output == output); assert(layer->output == output);
if (layer != output->composition_layer) { if (layer != output->composition_layer) {
@ -55,7 +57,8 @@ void liftoff_output_set_composition_layer(struct liftoff_output *output,
output->composition_layer = layer; output->composition_layer = layer;
} }
bool liftoff_output_needs_composition(struct liftoff_output *output) bool
liftoff_output_needs_composition(struct liftoff_output *output)
{ {
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -68,11 +71,15 @@ bool liftoff_output_needs_composition(struct liftoff_output *output)
return false; return false;
} }
static double fp16_to_double(uint64_t val) { static double
fp16_to_double(uint64_t val)
{
return (double)(val >> 16) + (double)(val & 0xFFFF) / 0xFFFF; return (double)(val >> 16) + (double)(val & 0xFFFF) / 0xFFFF;
} }
void output_log_layers(struct liftoff_output *output) { void
output_log_layers(struct liftoff_output *output)
{
struct liftoff_layer *layer; struct liftoff_layer *layer;
size_t i; size_t i;
bool is_composition_layer; bool is_composition_layer;

35
plane.c
View file

@ -4,8 +4,9 @@
#include <string.h> #include <string.h>
#include "private.h" #include "private.h"
static int guess_plane_zpos_from_type(struct liftoff_device *device, static int
uint32_t plane_id, uint32_t type) guess_plane_zpos_from_type(struct liftoff_device *device, uint32_t plane_id,
uint32_t type)
{ {
struct liftoff_plane *primary; struct liftoff_plane *primary;
@ -31,8 +32,8 @@ static int guess_plane_zpos_from_type(struct liftoff_device *device,
return 0; return 0;
} }
struct liftoff_plane *liftoff_plane_create(struct liftoff_device *device, struct liftoff_plane *
uint32_t id) liftoff_plane_create(struct liftoff_device *device, uint32_t id)
{ {
struct liftoff_plane *plane, *cur; struct liftoff_plane *plane, *cur;
drmModePlane *drm_plane; drmModePlane *drm_plane;
@ -140,7 +141,8 @@ struct liftoff_plane *liftoff_plane_create(struct liftoff_device *device,
return plane; return plane;
} }
void liftoff_plane_destroy(struct liftoff_plane *plane) void
liftoff_plane_destroy(struct liftoff_plane *plane)
{ {
if (plane->layer != NULL) { if (plane->layer != NULL) {
plane->layer->plane = NULL; plane->layer->plane = NULL;
@ -150,13 +152,14 @@ void liftoff_plane_destroy(struct liftoff_plane *plane)
free(plane); free(plane);
} }
uint32_t liftoff_plane_get_id(struct liftoff_plane *plane) uint32_t
liftoff_plane_get_id(struct liftoff_plane *plane)
{ {
return plane->id; return plane->id;
} }
struct liftoff_plane_property *plane_get_property(struct liftoff_plane *plane, struct liftoff_plane_property *
const char *name) plane_get_property(struct liftoff_plane *plane, const char *name)
{ {
size_t i; size_t i;
@ -168,8 +171,9 @@ struct liftoff_plane_property *plane_get_property(struct liftoff_plane *plane,
return NULL; return NULL;
} }
static int plane_set_prop(struct liftoff_plane *plane, drmModeAtomicReq *req, static int
struct liftoff_plane_property *prop, uint64_t value) plane_set_prop(struct liftoff_plane *plane, drmModeAtomicReq *req,
struct liftoff_plane_property *prop, uint64_t value)
{ {
int ret; int ret;
@ -183,9 +187,9 @@ static int plane_set_prop(struct liftoff_plane *plane, drmModeAtomicReq *req,
return 0; return 0;
} }
static int set_plane_prop_str(struct liftoff_plane *plane, static int
drmModeAtomicReq *req, const char *name, set_plane_prop_str(struct liftoff_plane *plane, drmModeAtomicReq *req,
uint64_t value) const char *name, uint64_t value)
{ {
struct liftoff_plane_property *prop; struct liftoff_plane_property *prop;
@ -200,8 +204,9 @@ static int set_plane_prop_str(struct liftoff_plane *plane,
return plane_set_prop(plane, req, prop, value); return plane_set_prop(plane, req, prop, value);
} }
int plane_apply(struct liftoff_plane *plane, struct liftoff_layer *layer, int
drmModeAtomicReq *req) plane_apply(struct liftoff_plane *plane, struct liftoff_layer *layer,
drmModeAtomicReq *req)
{ {
int cursor, ret; int cursor, ret;
size_t i; size_t i;

View file

@ -11,8 +11,8 @@
#define MAX_PLANES 128 #define MAX_PLANES 128
#define MAX_LAYERS 128 #define MAX_LAYERS 128
static struct liftoff_layer *add_layer(struct liftoff_output *output, static struct liftoff_layer *
int x, int y, int width, int height) add_layer(struct liftoff_output *output, int x, int y, int width, int height)
{ {
uint32_t fb_id; uint32_t fb_id;
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -32,7 +32,8 @@ static struct liftoff_layer *add_layer(struct liftoff_output *output,
return layer; return layer;
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int opt; int opt;
size_t planes_len, layers_len; size_t planes_len, layers_len;

View file

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
#ifdef NDEBUG #ifdef NDEBUG
fprintf(stderr, "NDEBUG is defined, cannot run tests\n"); fprintf(stderr, "NDEBUG is defined, cannot run tests\n");

View file

@ -16,14 +16,26 @@ extern bool liftoff_mock_require_primary_plane;
struct liftoff_layer; struct liftoff_layer;
int liftoff_mock_drm_open(void); int
uint32_t liftoff_mock_drm_create_fb(struct liftoff_layer *layer); liftoff_mock_drm_open(void);
struct liftoff_mock_plane *liftoff_mock_drm_create_plane(int type);
struct liftoff_mock_plane *liftoff_mock_drm_get_plane(uint32_t id); uint32_t
void liftoff_mock_plane_add_compatible_layer(struct liftoff_mock_plane *plane, liftoff_mock_drm_create_fb(struct liftoff_layer *layer);
struct liftoff_layer *layer);
struct liftoff_layer *liftoff_mock_plane_get_layer(struct liftoff_mock_plane *plane); struct liftoff_mock_plane *
uint32_t liftoff_mock_plane_add_property(struct liftoff_mock_plane *plane, liftoff_mock_drm_create_plane(int type);
const drmModePropertyRes *prop);
struct liftoff_mock_plane *
liftoff_mock_drm_get_plane(uint32_t id);
void
liftoff_mock_plane_add_compatible_layer(struct liftoff_mock_plane *plane,
struct liftoff_layer *layer);
struct liftoff_layer *
liftoff_mock_plane_get_layer(struct liftoff_mock_plane *plane);
uint32_t
liftoff_mock_plane_add_property(struct liftoff_mock_plane *plane,
const drmModePropertyRes *prop);
#endif #endif

View file

@ -66,7 +66,8 @@ static drmModePropertyRes plane_props[MAX_PLANE_PROPS] = {0};
static size_t plane_props_len = 0; static size_t plane_props_len = 0;
static void assert_drm_fd(int fd) static void
assert_drm_fd(int fd)
{ {
int ret; int ret;
struct stat stat_got, stat_want; struct stat stat_got, stat_want;
@ -80,7 +81,8 @@ static void assert_drm_fd(int fd)
stat_got.st_ino == stat_want.st_ino); stat_got.st_ino == stat_want.st_ino);
} }
static uint32_t register_prop(const drmModePropertyRes *prop) static uint32_t
register_prop(const drmModePropertyRes *prop)
{ {
drmModePropertyRes *dst; drmModePropertyRes *dst;
@ -93,7 +95,8 @@ static uint32_t register_prop(const drmModePropertyRes *prop)
return dst->prop_id; return dst->prop_id;
} }
static void init_basic_props(void) static void
init_basic_props(void)
{ {
size_t i; size_t i;
@ -108,7 +111,8 @@ static void init_basic_props(void)
} }
} }
int liftoff_mock_drm_open(void) int
liftoff_mock_drm_open(void)
{ {
int ret; int ret;
@ -121,7 +125,8 @@ int liftoff_mock_drm_open(void)
return mock_pipe[0]; return mock_pipe[0];
} }
struct liftoff_mock_plane *liftoff_mock_drm_create_plane(int type) struct liftoff_mock_plane *
liftoff_mock_drm_create_plane(int type)
{ {
struct liftoff_mock_plane *plane; struct liftoff_mock_plane *plane;
size_t i; size_t i;
@ -147,7 +152,8 @@ struct liftoff_mock_plane *liftoff_mock_drm_create_plane(int type)
return plane; return plane;
} }
struct liftoff_mock_plane *liftoff_mock_drm_get_plane(uint32_t id) struct liftoff_mock_plane *
liftoff_mock_drm_get_plane(uint32_t id)
{ {
struct liftoff_mock_plane *plane; struct liftoff_mock_plane *plane;
@ -162,8 +168,9 @@ struct liftoff_mock_plane *liftoff_mock_drm_get_plane(uint32_t id)
abort(); // unreachable abort(); // unreachable
} }
void liftoff_mock_plane_add_compatible_layer(struct liftoff_mock_plane *plane, void
struct liftoff_layer *layer) liftoff_mock_plane_add_compatible_layer(struct liftoff_mock_plane *plane,
struct liftoff_layer *layer)
{ {
size_t i; size_t i;
@ -177,7 +184,8 @@ void liftoff_mock_plane_add_compatible_layer(struct liftoff_mock_plane *plane,
abort(); // unreachable abort(); // unreachable
} }
uint32_t liftoff_mock_drm_create_fb(struct liftoff_layer *layer) uint32_t
liftoff_mock_drm_create_fb(struct liftoff_layer *layer)
{ {
size_t i; size_t i;
@ -191,8 +199,9 @@ uint32_t liftoff_mock_drm_create_fb(struct liftoff_layer *layer)
return 0xFB000000 + i; return 0xFB000000 + i;
} }
static bool mock_atomic_req_get_property(drmModeAtomicReq *req, uint32_t obj_id, static bool
enum plane_prop prop, uint64_t *value) mock_atomic_req_get_property(drmModeAtomicReq *req, uint32_t obj_id,
enum plane_prop prop, uint64_t *value)
{ {
ssize_t i; ssize_t i;
uint32_t prop_id; uint32_t prop_id;
@ -209,7 +218,8 @@ static bool mock_atomic_req_get_property(drmModeAtomicReq *req, uint32_t obj_id,
return false; return false;
} }
static struct liftoff_layer *mock_fb_get_layer(uint32_t fb_id) static struct liftoff_layer *
mock_fb_get_layer(uint32_t fb_id)
{ {
size_t i; size_t i;
@ -225,12 +235,14 @@ static struct liftoff_layer *mock_fb_get_layer(uint32_t fb_id)
return mock_fbs[i]; return mock_fbs[i];
} }
struct liftoff_layer *liftoff_mock_plane_get_layer(struct liftoff_mock_plane *plane) struct liftoff_layer *
liftoff_mock_plane_get_layer(struct liftoff_mock_plane *plane)
{ {
return mock_fb_get_layer(plane->prop_values[PLANE_FB_ID]); return mock_fb_get_layer(plane->prop_values[PLANE_FB_ID]);
} }
static size_t get_prop_index(uint32_t id) static size_t
get_prop_index(uint32_t id)
{ {
size_t i; size_t i;
@ -242,8 +254,9 @@ static size_t get_prop_index(uint32_t id)
return i; return i;
} }
uint32_t liftoff_mock_plane_add_property(struct liftoff_mock_plane *plane, uint32_t
const drmModePropertyRes *prop) liftoff_mock_plane_add_property(struct liftoff_mock_plane *plane,
const drmModePropertyRes *prop)
{ {
uint32_t prop_id; uint32_t prop_id;
@ -255,7 +268,8 @@ uint32_t liftoff_mock_plane_add_property(struct liftoff_mock_plane *plane,
return prop_id; return prop_id;
} }
static void apply_atomic_req(drmModeAtomicReq *req) static void
apply_atomic_req(drmModeAtomicReq *req)
{ {
int i; int i;
size_t prop_index; size_t prop_index;
@ -273,8 +287,9 @@ static void apply_atomic_req(drmModeAtomicReq *req)
} }
} }
int drmModeAtomicCommit(int fd, drmModeAtomicReq *req, uint32_t flags, int
void *user_data) drmModeAtomicCommit(int fd, drmModeAtomicReq *req, uint32_t flags,
void *user_data)
{ {
size_t i, j; size_t i, j;
struct liftoff_mock_plane *plane; struct liftoff_mock_plane *plane;
@ -362,7 +377,8 @@ int drmModeAtomicCommit(int fd, drmModeAtomicReq *req, uint32_t flags,
return 0; return 0;
} }
drmModeRes *drmModeGetResources(int fd) drmModeRes *
drmModeGetResources(int fd)
{ {
drmModeRes *res; drmModeRes *res;
@ -374,12 +390,14 @@ drmModeRes *drmModeGetResources(int fd)
return res; return res;
} }
void drmModeFreeResources(drmModeRes *res) void
drmModeFreeResources(drmModeRes *res)
{ {
free(res); free(res);
} }
drmModePlaneRes *drmModeGetPlaneResources(int fd) drmModePlaneRes *
drmModeGetPlaneResources(int fd)
{ {
static uint32_t plane_ids[MAX_PLANES]; static uint32_t plane_ids[MAX_PLANES];
drmModePlaneRes *res; drmModePlaneRes *res;
@ -400,12 +418,14 @@ drmModePlaneRes *drmModeGetPlaneResources(int fd)
return res; return res;
} }
void drmModeFreePlaneResources(drmModePlaneRes *res) void
drmModeFreePlaneResources(drmModePlaneRes *res)
{ {
free(res); free(res);
} }
drmModePlane *drmModeGetPlane(int fd, uint32_t id) drmModePlane *
drmModeGetPlane(int fd, uint32_t id)
{ {
drmModePlane *plane; drmModePlane *plane;
@ -417,12 +437,13 @@ drmModePlane *drmModeGetPlane(int fd, uint32_t id)
return plane; return plane;
} }
void drmModeFreePlane(drmModePlane *plane) { void
drmModeFreePlane(drmModePlane *plane) {
free(plane); free(plane);
} }
drmModeObjectProperties *drmModeObjectGetProperties(int fd, uint32_t obj_id, drmModeObjectProperties *
uint32_t obj_type) drmModeObjectGetProperties(int fd, uint32_t obj_id, uint32_t obj_type)
{ {
struct liftoff_mock_plane *plane; struct liftoff_mock_plane *plane;
drmModeObjectProperties *props; drmModeObjectProperties *props;
@ -453,35 +474,41 @@ drmModeObjectProperties *drmModeObjectGetProperties(int fd, uint32_t obj_id,
return props; return props;
} }
void drmModeFreeObjectProperties(drmModeObjectProperties *props) { void
drmModeFreeObjectProperties(drmModeObjectProperties *props) {
free(props->props); free(props->props);
free(props->prop_values); free(props->prop_values);
free(props); free(props);
} }
drmModePropertyRes *drmModeGetProperty(int fd, uint32_t id) drmModePropertyRes *
drmModeGetProperty(int fd, uint32_t id)
{ {
assert_drm_fd(fd); assert_drm_fd(fd);
return &plane_props[get_prop_index(id)]; return &plane_props[get_prop_index(id)];
} }
void drmModeFreeProperty(drmModePropertyRes *prop) { void
drmModeFreeProperty(drmModePropertyRes *prop) {
/* Owned by plane_props */ /* Owned by plane_props */
} }
drmModeAtomicReq *drmModeAtomicAlloc(void) drmModeAtomicReq *
drmModeAtomicAlloc(void)
{ {
return calloc(1, sizeof(drmModeAtomicReq)); return calloc(1, sizeof(drmModeAtomicReq));
} }
void drmModeAtomicFree(drmModeAtomicReq *req) void
drmModeAtomicFree(drmModeAtomicReq *req)
{ {
free(req); free(req);
} }
int drmModeAtomicAddProperty(drmModeAtomicReq *req, uint32_t obj_id, int
uint32_t prop_id, uint64_t value) drmModeAtomicAddProperty(drmModeAtomicReq *req, uint32_t obj_id,
uint32_t prop_id, uint64_t value)
{ {
assert((size_t)req->cursor < sizeof(req->props) / sizeof(req->props[0])); assert((size_t)req->cursor < sizeof(req->props) / sizeof(req->props[0]));
req->props[req->cursor].obj_id = obj_id; req->props[req->cursor].obj_id = obj_id;
@ -491,12 +518,14 @@ int drmModeAtomicAddProperty(drmModeAtomicReq *req, uint32_t obj_id,
return req->cursor; return req->cursor;
} }
int drmModeAtomicGetCursor(drmModeAtomicReq *req) int
drmModeAtomicGetCursor(drmModeAtomicReq *req)
{ {
return req->cursor; return req->cursor;
} }
void drmModeAtomicSetCursor(drmModeAtomicReq *req, int cursor) void
drmModeAtomicSetCursor(drmModeAtomicReq *req, int cursor)
{ {
req->cursor = cursor; req->cursor = cursor;
} }

View file

@ -6,8 +6,8 @@
#include <string.h> #include <string.h>
#include "libdrm_mock.h" #include "libdrm_mock.h"
static struct liftoff_layer *add_layer(struct liftoff_output *output, static struct liftoff_layer *
int x, int y, int width, int height) add_layer(struct liftoff_output *output, int x, int y, int width, int height)
{ {
uint32_t fb_id; uint32_t fb_id;
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -606,7 +606,8 @@ static struct test_case tests[] = {
}, },
}; };
static bool test_needs_composition(struct test_layer *test_layers) static bool
test_needs_composition(struct test_layer *test_layers)
{ {
size_t i; size_t i;
@ -619,7 +620,8 @@ static bool test_needs_composition(struct test_layer *test_layers)
return false; return false;
} }
static void run_test(struct test_layer *test_layers) static void
run_test(struct test_layer *test_layers)
{ {
size_t i, j; size_t i, j;
ssize_t plane_index_got, plane_index_want; ssize_t plane_index_got, plane_index_want;
@ -719,7 +721,8 @@ static void run_test(struct test_layer *test_layers)
close(drm_fd); close(drm_fd);
} }
static void test_basic(void) static void
test_basic(void)
{ {
struct liftoff_mock_plane *mock_plane; struct liftoff_mock_plane *mock_plane;
int drm_fd; int drm_fd;
@ -756,7 +759,8 @@ static void test_basic(void)
/* Checks that the library doesn't allocate a plane for a layer without a /* Checks that the library doesn't allocate a plane for a layer without a
* non-zero FB_ID set. */ * non-zero FB_ID set. */
static void test_no_fb_fail(bool zero_fb_id) static void
test_no_fb_fail(bool zero_fb_id)
{ {
struct liftoff_mock_plane *mock_plane; struct liftoff_mock_plane *mock_plane;
int drm_fd; int drm_fd;
@ -796,7 +800,8 @@ static void test_no_fb_fail(bool zero_fb_id)
/* Checks that the library doesn't fallback to composition when a layer doesn't /* Checks that the library doesn't fallback to composition when a layer doesn't
* have a FB. */ * have a FB. */
static void test_composition_zero_fb(void) static void
test_composition_zero_fb(void)
{ {
struct liftoff_mock_plane *mock_plane; struct liftoff_mock_plane *mock_plane;
int drm_fd; int drm_fd;
@ -839,7 +844,9 @@ static void test_composition_zero_fb(void)
close(drm_fd); close(drm_fd);
} }
int main(int argc, char *argv[]) { int
main(int argc, char *argv[])
{
const char *test_name; const char *test_name;
size_t i; size_t i;

View file

@ -19,8 +19,8 @@ struct test_case {
void (*run)(struct context *ctx); void (*run)(struct context *ctx);
}; };
static struct liftoff_layer *add_layer(struct liftoff_output *output, static struct liftoff_layer *
int x, int y, int width, int height) add_layer(struct liftoff_output *output, int x, int y, int width, int height)
{ {
uint32_t fb_id; uint32_t fb_id;
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -40,7 +40,9 @@ static struct liftoff_layer *add_layer(struct liftoff_output *output,
return layer; return layer;
} }
static void first_commit(struct context *ctx) { static void
first_commit(struct context *ctx)
{
drmModeAtomicReq *req; drmModeAtomicReq *req;
int ret; int ret;
@ -62,7 +64,9 @@ static void first_commit(struct context *ctx) {
assert(ctx->commit_count > 1); assert(ctx->commit_count > 1);
} }
static void second_commit(struct context *ctx, bool want_reuse_prev_alloc) { static void
second_commit(struct context *ctx, bool want_reuse_prev_alloc)
{
drmModeAtomicReq *req; drmModeAtomicReq *req;
int ret; int ret;
@ -83,7 +87,9 @@ static void second_commit(struct context *ctx, bool want_reuse_prev_alloc) {
drmModeAtomicFree(req); drmModeAtomicFree(req);
} }
static void run_same(struct context *ctx) { static void
run_same(struct context *ctx)
{
first_commit(ctx); first_commit(ctx);
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
@ -91,7 +97,9 @@ static void run_same(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_change_fb(struct context *ctx) { static void
run_change_fb(struct context *ctx)
{
first_commit(ctx); first_commit(ctx);
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
@ -102,7 +110,9 @@ static void run_change_fb(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_unset_fb(struct context *ctx) { static void
run_unset_fb(struct context *ctx)
{
first_commit(ctx); first_commit(ctx);
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
@ -112,7 +122,9 @@ static void run_unset_fb(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL);
} }
static void run_set_fb(struct context *ctx) { static void
run_set_fb(struct context *ctx)
{
liftoff_layer_set_property(ctx->layer, "FB_ID", 0); liftoff_layer_set_property(ctx->layer, "FB_ID", 0);
first_commit(ctx); first_commit(ctx);
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL);
@ -124,7 +136,9 @@ static void run_set_fb(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_add_layer(struct context *ctx) { static void
run_add_layer(struct context *ctx)
{
first_commit(ctx); first_commit(ctx);
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
@ -134,7 +148,9 @@ static void run_add_layer(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_remove_layer(struct context *ctx) { static void
run_remove_layer(struct context *ctx)
{
first_commit(ctx); first_commit(ctx);
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
@ -145,7 +161,9 @@ static void run_remove_layer(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_change_composition_layer(struct context *ctx) { static void
run_change_composition_layer(struct context *ctx)
{
first_commit(ctx); first_commit(ctx);
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
@ -155,7 +173,9 @@ static void run_change_composition_layer(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_change_alpha(struct context *ctx) { static void
run_change_alpha(struct context *ctx)
{
liftoff_layer_set_property(ctx->layer, "alpha", 42); liftoff_layer_set_property(ctx->layer, "alpha", 42);
first_commit(ctx); first_commit(ctx);
@ -167,7 +187,9 @@ static void run_change_alpha(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_set_alpha_from_opaque(struct context *ctx) { static void
run_set_alpha_from_opaque(struct context *ctx)
{
liftoff_layer_set_property(ctx->layer, "alpha", 0xFFFF); /* opaque */ liftoff_layer_set_property(ctx->layer, "alpha", 0xFFFF); /* opaque */
first_commit(ctx); first_commit(ctx);
@ -179,7 +201,9 @@ static void run_set_alpha_from_opaque(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_set_alpha_from_transparent(struct context *ctx) { static void
run_set_alpha_from_transparent(struct context *ctx)
{
liftoff_layer_set_property(ctx->layer, "alpha", 0); /* transparent */ liftoff_layer_set_property(ctx->layer, "alpha", 0); /* transparent */
first_commit(ctx); first_commit(ctx);
@ -191,7 +215,9 @@ static void run_set_alpha_from_transparent(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_unset_alpha_to_opaque(struct context *ctx) { static void
run_unset_alpha_to_opaque(struct context *ctx)
{
liftoff_layer_set_property(ctx->layer, "alpha", 42); liftoff_layer_set_property(ctx->layer, "alpha", 42);
first_commit(ctx); first_commit(ctx);
@ -203,7 +229,9 @@ static void run_unset_alpha_to_opaque(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_unset_alpha_to_transparent(struct context *ctx) { static void
run_unset_alpha_to_transparent(struct context *ctx)
{
liftoff_layer_set_property(ctx->layer, "alpha", 42); liftoff_layer_set_property(ctx->layer, "alpha", 42);
first_commit(ctx); first_commit(ctx);
@ -215,7 +243,9 @@ static void run_unset_alpha_to_transparent(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == NULL);
} }
static void run_change_in_fence_fd(struct context *ctx) { static void
run_change_in_fence_fd(struct context *ctx)
{
liftoff_layer_set_property(ctx->layer, "IN_FENCE_FD", 42); liftoff_layer_set_property(ctx->layer, "IN_FENCE_FD", 42);
first_commit(ctx); first_commit(ctx);
@ -227,7 +257,9 @@ static void run_change_in_fence_fd(struct context *ctx) {
assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer); assert(liftoff_mock_plane_get_layer(ctx->mock_plane) == ctx->layer);
} }
static void run_change_fb_damage_clips(struct context *ctx) { static void
run_change_fb_damage_clips(struct context *ctx)
{
liftoff_layer_set_property(ctx->layer, "FB_DAMAGE_CLIPS", 42); liftoff_layer_set_property(ctx->layer, "FB_DAMAGE_CLIPS", 42);
first_commit(ctx); first_commit(ctx);
@ -256,7 +288,9 @@ static const struct test_case tests[] = {
{ .name = "change-fb-damage-clips", .run = run_change_fb_damage_clips }, { .name = "change-fb-damage-clips", .run = run_change_fb_damage_clips },
}; };
static void run(const struct test_case *test) { static void
run(const struct test_case *test)
{
struct context ctx = {0}; struct context ctx = {0};
struct liftoff_device *device; struct liftoff_device *device;
const char *prop_name; const char *prop_name;
@ -306,7 +340,9 @@ static void run(const struct test_case *test) {
close(ctx.drm_fd); close(ctx.drm_fd);
} }
int main(int argc, char *argv[]) { int
main(int argc, char *argv[])
{
const char *test_name; const char *test_name;
liftoff_log_set_priority(LIFTOFF_DEBUG); liftoff_log_set_priority(LIFTOFF_DEBUG);

View file

@ -8,8 +8,8 @@
/* Number of page-flips before the plane allocation has stabilized */ /* Number of page-flips before the plane allocation has stabilized */
#define STABILIZE_PAGEFLIP_COUNT 600 /* 10s at 60FPS */ #define STABILIZE_PAGEFLIP_COUNT 600 /* 10s at 60FPS */
static struct liftoff_layer *add_layer(struct liftoff_output *output, static struct liftoff_layer *
int x, int y, int width, int height) add_layer(struct liftoff_output *output, int x, int y, int width, int height)
{ {
uint32_t fb_id; uint32_t fb_id;
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -29,7 +29,9 @@ static struct liftoff_layer *add_layer(struct liftoff_output *output,
return layer; return layer;
} }
int main(int argc, char *argv[]) { int
main(int argc, char *argv[])
{
struct liftoff_mock_plane *mock_plane; struct liftoff_mock_plane *mock_plane;
int drm_fd; int drm_fd;
struct liftoff_device *device; struct liftoff_device *device;

View file

@ -5,8 +5,8 @@
#include <string.h> #include <string.h>
#include "libdrm_mock.h" #include "libdrm_mock.h"
static struct liftoff_layer *add_layer(struct liftoff_output *output, static struct liftoff_layer *
int x, int y, int width, int height) add_layer(struct liftoff_output *output, int x, int y, int width, int height)
{ {
uint32_t fb_id; uint32_t fb_id;
struct liftoff_layer *layer; struct liftoff_layer *layer;
@ -26,7 +26,8 @@ static struct liftoff_layer *add_layer(struct liftoff_output *output,
return layer; return layer;
} }
static int test_prop_default(const char *prop_name) static int
test_prop_default(const char *prop_name)
{ {
struct liftoff_mock_plane *mock_plane_with_prop, struct liftoff_mock_plane *mock_plane_with_prop,
*mock_plane_without_prop; *mock_plane_without_prop;
@ -123,7 +124,8 @@ static int test_prop_default(const char *prop_name)
} }
/* Checks that a fully transparent layer is ignored. */ /* Checks that a fully transparent layer is ignored. */
static int test_ignore_alpha(void) static int
test_ignore_alpha(void)
{ {
struct liftoff_mock_plane *mock_plane; struct liftoff_mock_plane *mock_plane;
drmModePropertyRes prop = {0}; drmModePropertyRes prop = {0};
@ -166,7 +168,9 @@ static int test_ignore_alpha(void)
return 0; return 0;
} }
static int test_immutable_zpos(void) { static int
test_immutable_zpos(void)
{
struct liftoff_mock_plane *mock_plane1, *mock_plane2; struct liftoff_mock_plane *mock_plane1, *mock_plane2;
drmModePropertyRes prop = {0}; drmModePropertyRes prop = {0};
uint64_t prop_value; uint64_t prop_value;
@ -239,7 +243,9 @@ static int test_immutable_zpos(void) {
return 0; return 0;
} }
int main(int argc, char *argv[]) { int
main(int argc, char *argv[])
{
const char *test_name; const char *test_name;
liftoff_log_set_priority(LIFTOFF_DEBUG); liftoff_log_set_priority(LIFTOFF_DEBUG);