summaryrefslogtreecommitdiff
path: root/xf86drmMode.c
diff options
context:
space:
mode:
Diffstat (limited to 'xf86drmMode.c')
-rw-r--r--xf86drmMode.c133
1 files changed, 133 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)