diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2013-06-24 13:20:50 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2013-06-27 10:18:32 +0200 |
commit | e4c95910f138da1985168e86c0320b5222ce6462 (patch) | |
tree | e9a1628460031d1cf141041f8a8cf994dae7b35b | |
parent | 7a65321722ce14ced68576e0f413a77f865cf846 (diff) |
live source libdrm
-rw-r--r-- | xf86drmMode.c | 133 | ||||
-rw-r--r-- | xf86drmMode.h | 27 |
2 files changed, 160 insertions, 0 deletions
diff --git a/xf86drmMode.c b/xf86drmMode.c index f603ceb2..4c5d6068 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -978,6 +978,139 @@ void drmModeFreePlaneResources(drmModePlaneResPtr ptr) drmFree(ptr); } +int drmModeSetSource(int fd, uint32_t source_id, uint32_t plane_id, + uint32_t width, uint32_t height, + uint32_t pixel_format) +{ + struct drm_mode_set_live_source s; + + s.source_id = source_id; + s.plane_id = plane_id; + s.width = width; + s.height = height; + s.pixel_format = pixel_format; + + return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETSOURCE, &s); +} + +drmModeSourcePtr drmModeGetSource(int fd, uint32_t source_id) +{ + struct drm_mode_get_live_source src; + uint32_t count_format_types; + drmModeSourcePtr r = 0; + +retry: + memset(&src, 0, sizeof(src)); + src.source_id = source_id; + if (drmIoctl(fd, DRM_IOCTL_MODE_GETSOURCE, &src)) + return 0; + + count_format_types = src.count_format_types; + + if (src.count_format_types) { + src.format_type_ptr = VOID2U64(drmMalloc(src.count_format_types * + sizeof(uint32_t))); + if (!src.format_type_ptr) + goto err_allocs; + } + + if (drmIoctl(fd, DRM_IOCTL_MODE_GETSOURCE, &src)) + return 0; + + if (count_format_types < src.count_format_types) { + drmFree(U642VOID(src.format_type_ptr)); + goto retry; + } + + if (!(r = drmMalloc(sizeof(*r)))) + return NULL; + + r->source_id = src.source_id; + strncpy(r->name, src.name, DRM_SOURCE_NAME_LEN); + r->name[DRM_SOURCE_NAME_LEN-1] = 0; + r->plane_id = src.plane_id; + r->possible_planes = src.possible_planes; + r->width = src.width; + r->height = src.height; + r->pixel_format = src.pixel_format; + + r->count_formats = src.count_format_types; + r->formats = drmAllocCpy(U642VOID(src.format_type_ptr), + src.count_format_types, sizeof(uint32_t)); + if (src.count_format_types && !r->formats) { + drmFree(r->formats); + drmFree(r); + r = NULL; + } + +err_allocs: + drmFree(U642VOID(src.format_type_ptr)); + return r; +} + +void drmModeFreeSource(drmModeSourcePtr ptr) +{ + if (!ptr) + return; + + drmFree(ptr->formats); + drmFree(ptr); +} + +drmModeSourceResPtr drmModeGetSourceResources(int fd) +{ + struct drm_mode_get_live_source_res res, counts; + drmModeSourceResPtr r = 0; + +retry: + memset(&res, 0, sizeof(res)); + if (drmIoctl(fd, DRM_IOCTL_MODE_GETSOURCERESOURCES, &res)) + return 0; + + counts = res; + + if (res.count_sources) { + res.source_id_ptr = VOID2U64(drmMalloc(res.count_sources * + sizeof(uint32_t))); + if (!res.source_id_ptr) + goto err_allocs; + } + + if (drmIoctl(fd, DRM_IOCTL_MODE_GETSOURCERESOURCES, &res)) + goto err_allocs; + + if (counts.count_sources < res.count_sources) { + drmFree(U642VOID(res.source_id_ptr)); + goto retry; + } + + if (!(r = drmMalloc(sizeof(*r)))) + goto err_allocs; + + r->count_sources = res.count_sources; + r->sources = drmAllocCpy(U642VOID(res.source_id_ptr), + res.count_sources, sizeof(uint32_t)); + if (res.count_sources && !r->sources) { + drmFree(r->sources); + drmFree(r); + r = 0; + } + +err_allocs: + drmFree(U642VOID(res.source_id_ptr)); + + return r; +} + +void drmModeFreeSourceResources(drmModeSourceResPtr ptr) +{ + if (!ptr) + return; + + drmFree(ptr->sources); + drmFree(ptr); +} + drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd, uint32_t object_id, uint32_t object_type) diff --git a/xf86drmMode.h b/xf86drmMode.h index 8e400340..c5f1b4a7 100644 --- a/xf86drmMode.h +++ b/xf86drmMode.h @@ -70,6 +70,7 @@ extern "C" { #define DRM_CONNECTOR_NAME_LEN 32 #define DRM_DISPLAY_MODE_LEN 32 #define DRM_PROP_NAME_LEN 32 +#define DRM_SOURCE_NAME_LEN 32 #define DRM_MODE_TYPE_BUILTIN (1<<0) #define DRM_MODE_TYPE_CLOCK_C ((1<<1) | DRM_MODE_TYPE_BUILTIN) @@ -307,6 +308,24 @@ typedef struct _drmModePlaneRes { uint32_t *planes; } drmModePlaneRes, *drmModePlaneResPtr; +typedef struct _drmModeSource { + uint32_t source_id; + char name[DRM_SOURCE_NAME_LEN]; + + uint32_t plane_id; + uint32_t possible_planes; + uint32_t count_formats; + uint32_t *formats; + + uint32_t width, height; + uint32_t pixel_format; +} drmModeSource, *drmModeSourcePtr; + +typedef struct _drmModeSourceRes { + uint32_t count_sources; + uint32_t *sources; +} drmModeSourceRes, *drmModeSourceResPtr; + extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr ); extern void drmModeFreeResources( drmModeResPtr ptr ); extern void drmModeFreeFB( drmModeFBPtr ptr ); @@ -315,6 +334,8 @@ extern void drmModeFreeConnector( drmModeConnectorPtr ptr ); extern void drmModeFreeEncoder( drmModeEncoderPtr ptr ); extern void drmModeFreePlane( drmModePlanePtr ptr ); extern void drmModeFreePlaneResources(drmModePlaneResPtr ptr); +extern void drmModeFreeSource( drmModeSourcePtr ptr ); +extern void drmModeFreeSourceResources(drmModeSourceResPtr ptr); /** * Retrives all of the resources associated with a card. @@ -434,6 +455,12 @@ extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h); +extern drmModeSourceResPtr drmModeGetSourceResources(int fd); +extern drmModeSourcePtr drmModeGetSource(int fd, uint32_t source_id); +extern int drmModeSetSource(int fd, uint32_t source_id, uint32_t plane_id, + uint32_t width, uint32_t height, + uint32_t pixel_format); + extern drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd, uint32_t object_id, uint32_t object_type); |