2018-07-25 16:00 GMT+02:00 Benjamin Gaignard :
> If "-a" option is set this make modetest use atomic API instead
> of legacy API.
>
> Test the frame rate ("-v") it does a loop and swap between two
> framebuffer for each active planes.
>
> Signed-off-by: Benjamin Gaignard
> ---
>
> version 3:
> - merge atomic code into modetest itself
> - do not change build systems
Gentle ping to help me to progress in this topic.
Thanks
Benjamin
>
> version 2 :
> - make modetest_atomic compile with meson and Android
>
> version 1:
> - add dedicated modetest_atomic tool to test atomic API
>
> tests/modetest/modetest.c | 349
> ++
> 1 file changed, 321 insertions(+), 28 deletions(-)
>
> diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
> index 62957d84..975dcbcd 100644
> --- a/tests/modetest/modetest.c
> +++ b/tests/modetest/modetest.c
> @@ -119,6 +119,9 @@ struct device {
> struct bo *bo;
> struct bo *cursor_bo;
> } mode;
> +
> + int use_atomic;
> + drmModeAtomicReq *req;
> };
>
> static inline int64_t U642I64(uint64_t val)
> @@ -805,7 +808,9 @@ struct plane_arg {
> uint32_t w, h;
> double scale;
> unsigned int fb_id;
> + unsigned int old_fb_id;
> struct bo *bo;
> + struct bo *old_bo;
> char format_str[5]; /* need to leave room for terminating \0 */
> unsigned int fourcc;
> };
> @@ -999,8 +1004,12 @@ static void set_property(struct device *dev, struct
> property_arg *p)
>
> p->prop_id = props->props[i];
>
> - ret = drmModeObjectSetProperty(dev->fd, p->obj_id, p->obj_type,
> - p->prop_id, p->value);
> + if (!dev->use_atomic)
> + ret = drmModeObjectSetProperty(dev->fd, p->obj_id,
> p->obj_type,
> +
> p->prop_id, p->value);
> + else
> + ret = drmModeAtomicAddProperty(dev->req, p->obj_id,
> p->prop_id, p->value);
> +
> if (ret < 0)
> fprintf(stderr, "failed to set %s %i property %s to %" PRIu64
> ": %s\n",
> obj_type, p->obj_id, p->name, p->value,
> strerror(errno));
> @@ -1049,6 +1058,94 @@ static bool format_support(const drmModePlanePtr ovr,
> uint32_t fmt)
> return false;
> }
>
> +static void add_property(struct device *dev, uint32_t obj_id,
> + const char *name, uint64_t value)
> +{
> + struct property_arg p;
> +
> + p.obj_id = obj_id;
> + strcpy(p.name, name);
> + p.value = value;
> +
> + set_property(dev, );
> +}
> +
> +static int atomic_set_plane(struct device *dev, struct plane_arg *p,
> + int pattern, bool
> update)
> +{
> + uint32_t handles[4] = {0}, pitches[4] = {0}, offsets[4] = {0};
> + struct bo *plane_bo;
> + int crtc_x, crtc_y, crtc_w, crtc_h;
> + struct crtc *crtc = NULL;
> + unsigned int i;
> + unsigned int old_fb_id;
> +
> + /* Find an unused plane which can be connected to our CRTC. Find the
> +* CRTC index first, then iterate over available planes.
> +*/
> + for (i = 0; i < (unsigned int)dev->resources->res->count_crtcs; i++) {
> + if (p->crtc_id == dev->resources->res->crtcs[i]) {
> + crtc = >resources->crtcs[i];
> + break;
> + }
> + }
> +
> + if (!crtc) {
> + fprintf(stderr, "CRTC %u not found\n", p->crtc_id);
> + return -1;
> + }
> +
> + if (!update)
> + fprintf(stderr, "testing %dx%d@%s on plane %u, crtc %u\n",
> + p->w, p->h, p->format_str, p->plane_id, p->crtc_id);
> +
> + plane_bo = p->old_bo;
> + p->old_bo = p->bo;
> +
> + if (!plane_bo) {
> + plane_bo = bo_create(dev->fd, p->fourcc, p->w, p->h,
> +handles, pitches, offsets, pattern);
> +
> + if (plane_bo == NULL)
> + return -1;
> +
> + if (drmModeAddFB2(dev->fd, p->w, p->h, p->fourcc,
> + handles, pitches, offsets, >fb_id, 0)) {
> + fprintf(stderr, "failed to add fb: %s\n",
> strerror(errno));
> + return -1;
> + }
> + }
> +
> + p->bo = plane_bo;
> +
> + old_fb_id = p->fb_id;
> + p->old_fb_id = old_fb_id;
> +
> + crtc_w = p->w * p->scale;
> + crtc_h = p->h * p->scale;
> + if (!p->has_position) {
> + /* Default to the middle of the screen */
> + crtc_x = (crtc->mode->hdisplay - crtc_w) / 2;
> + crtc_y = (crtc->mode->vdisplay - crtc_h) / 2;
> + } else {
> + crtc_x = p->x;
> + crtc_y = p->y;
> + }
>