From: Daniel Stone <daniels@xxxxxxxxxxxxx> Add a wrapper around the getfb2 ioctl, which returns extended framebuffer information mirroring addfb2, including multiple planes and modifiers. This depends on unmerged kernel API so should not be merged. Changes since v1: - functions should be drm_public - modifier for should 64 bits - update ioctl number Signed-off-by: Juston Li <juston.li@xxxxxxxxx> --- include/drm/drm.h | 2 ++ xf86drmMode.c | 40 ++++++++++++++++++++++++++++++++++++++++ xf86drmMode.h | 15 +++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/include/drm/drm.h b/include/drm/drm.h index 438abde3621d..340a1b4e9cf6 100644 --- a/include/drm/drm.h +++ b/include/drm/drm.h @@ -941,6 +941,8 @@ extern "C" { #define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct drm_syncobj_transfer) #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL DRM_IOWR(0xCD, struct drm_syncobj_timeline_array) +#define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2) + /** * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x9f. diff --git a/xf86drmMode.c b/xf86drmMode.c index 207d7be91caa..6c5f6cc2a075 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -1594,3 +1594,43 @@ drmModeRevokeLease(int fd, uint32_t lessee_id) return 0; return -errno; } + +drm_public drmModeFB2Ptr +drmModeGetFB2(int fd, uint32_t fb_id) +{ + struct drm_mode_fb_cmd2 get; + drmModeFB2Ptr ret; + int err; + + memclear(get); + get.fb_id = fb_id; + + err = DRM_IOCTL(fd, DRM_IOCTL_MODE_GETFB2, &get); + if (err != 0) + return NULL; + + ret = drmMalloc(sizeof(drmModeFB2)); + if (!ret) + return NULL; + + ret->fb_id = fb_id; + ret->width = get.width; + ret->height = get.height; + ret->pixel_format = get.pixel_format; + ret->flags = get.flags; + ret->modifier = get.modifier[0]; + memcpy(ret->handles, get.handles, sizeof(uint32_t) * 4); + memcpy(ret->pitches, get.pitches, sizeof(uint32_t) * 4); + memcpy(ret->offsets, get.offsets, sizeof(uint32_t) * 4); + + return ret; +} + +drm_public void drmModeFreeFB2(drmModeFB2Ptr ptr) +{ + if (!ptr) + return; + + /* we might add more frees later. */ + drmFree(ptr); +} diff --git a/xf86drmMode.h b/xf86drmMode.h index a32902f73289..07c98f42555d 100644 --- a/xf86drmMode.h +++ b/xf86drmMode.h @@ -223,6 +223,19 @@ typedef struct _drmModeFB { uint32_t handle; } drmModeFB, *drmModeFBPtr; +typedef struct _drmModeFB2 { + uint32_t fb_id; + uint32_t width, height; + uint32_t pixel_format; /* fourcc code from drm_fourcc.h */ + uint64_t modifier; /* applies to all buffers */ + uint32_t flags; + + /* per-plane GEM handle; may be duplicate entries for multiple planes */ + uint32_t handles[4]; + uint32_t pitches[4]; /* bytes */ + uint32_t offsets[4]; /* bytes */ +} drmModeFB2, *drmModeFB2Ptr; + typedef struct drm_clip_rect drmModeClip, *drmModeClipPtr; typedef struct _drmModePropertyBlob { @@ -341,6 +354,7 @@ typedef struct _drmModePlaneRes { extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr ); extern void drmModeFreeResources( drmModeResPtr ptr ); extern void drmModeFreeFB( drmModeFBPtr ptr ); +extern void drmModeFreeFB2( drmModeFB2Ptr ptr ); extern void drmModeFreeCrtc( drmModeCrtcPtr ptr ); extern void drmModeFreeConnector( drmModeConnectorPtr ptr ); extern void drmModeFreeEncoder( drmModeEncoderPtr ptr ); @@ -360,6 +374,7 @@ extern drmModeResPtr drmModeGetResources(int fd); * Retrieve information about framebuffer bufferId */ extern drmModeFBPtr drmModeGetFB(int fd, uint32_t bufferId); +extern drmModeFB2Ptr drmModeGetFB2(int fd, uint32_t bufferId); /** * Creates a new framebuffer with an buffer object as its scanout buffer. -- 2.21.0 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel