Quoting Daniele Ceraolo Spurio (2017-10-12 23:30:41) > The same code to create and import a vgem object is used in a couple of > places and a couple more are coming up in the next patches so extract > the code into a common function > > Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@xxxxxxxxx> > --- > lib/igt_dummyload.c | 10 ++-------- > lib/igt_vgem.c | 35 +++++++++++++++++++++++++++++++++ > lib/igt_vgem.h | 2 ++ > tests/prime_vgem.c | 56 +++++++++++++---------------------------------------- > 4 files changed, 52 insertions(+), 51 deletions(-) > > diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c > index 913cc93..03541f7 100644 > --- a/lib/igt_dummyload.c > +++ b/lib/igt_dummyload.c > @@ -317,23 +317,17 @@ igt_cork_t *igt_cork_new(int fd) > { > igt_cork_t *cork; > struct vgem_bo bo; > - int dmabuf; > > cork = calloc(1, sizeof(igt_cork_t)); > igt_assert(cork); > > cork->device = drm_open_driver(DRIVER_VGEM); > > - igt_require(vgem_has_fences(cork->device)); > - > bo.width = bo.height = 1; > bo.bpp = 4; > - vgem_create(cork->device, &bo); > - cork->fence = vgem_fence_attach(cork->device, &bo, VGEM_FENCE_WRITE); > > - dmabuf = prime_handle_to_fd(cork->device, bo.handle); > - cork->handle = prime_fd_to_handle(fd, dmabuf); > - close(dmabuf); > + cork->handle = vgem_create_and_import(cork->device, &bo, fd, > + &cork->fence); > > return cork; > } > diff --git a/lib/igt_vgem.c b/lib/igt_vgem.c > index 7f933b2..7fc62f2 100644 > --- a/lib/igt_vgem.c > +++ b/lib/igt_vgem.c > @@ -66,6 +66,41 @@ void vgem_create(int fd, struct vgem_bo *bo) > igt_assert_eq(__vgem_create(fd, bo), 0); > } > > +/** > + * vgem_create_and_import: > + * @vgem_fd: open vgem file descriptor > + * @bo: vgem_bo struct containing width, height and bpp of the object to open > + * @import_fd: open drm file descriptor to be used to import the vgem bo > + * @fence: optional return variable to store a fence attached to the vgem bo > + * > + * This function creates a vgem bo and imports it to the provided device. If > + * the fence parameter if provided a fence is attached to the bo and returned. > + * The provided vgem_bo struct is updated as in vgem_create. > + * > + * Returns: > + * Handle of the imported bo. > + */ > +uint32_t vgem_create_and_import(int vgem_fd, struct vgem_bo *bo, int import_fd, > + uint32_t *fence) > +{ > + int dmabuf; > + uint32_t handle; > + > + vgem_create(vgem_fd, bo); > + > + if (fence) { > + igt_require(vgem_has_fences(vgem_fd)); > + *fence = vgem_fence_attach(vgem_fd, bo, VGEM_FENCE_WRITE); > + } Leave this to the caller. Don't have overly specific functions, try to provide tools for writing future tests. > + dmabuf = prime_handle_to_fd(vgem_fd, bo->handle); > + handle = prime_fd_to_handle(import_fd, dmabuf); > + igt_assert(handle); Not your concern. Add it to prime_fd_to_handle() if you want. > + close(dmabuf); > + This is common enough to be refactored, import_handle = prime_link(export_fd, export_handle, import_fd); ? > + return handle; > +} _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx