aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'xf86drmMode.c')
-rw-r--r--xf86drmMode.c153
1 files changed, 153 insertions, 0 deletions
diff --git a/xf86drmMode.c b/xf86drmMode.c
index f08e6480..da7b4620 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -255,6 +255,29 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
255 return 0; 255 return 0;
256} 256}
257 257
258int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
259 uint32_t pixel_format, uint32_t bo_handles[4],
260 uint32_t pitches[4], uint32_t offsets[4],
261 uint32_t *buf_id, uint32_t flags)
262{
263 struct drm_mode_fb_cmd2 f;
264 int ret;
265
266 f.width = width;
267 f.height = height;
268 f.pixel_format = pixel_format;
269 f.flags = flags;
270 memcpy(f.handles, bo_handles, sizeof(bo_handles));
271 memcpy(f.pitches, pitches, sizeof(pitches));
272 memcpy(f.offsets, offsets, sizeof(offsets));
273
274 if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f)))
275 return ret;
276
277 *buf_id = f.fb_id;
278 return 0;
279}
280
258int drmModeRmFB(int fd, uint32_t bufferId) 281int drmModeRmFB(int fd, uint32_t bufferId)
259{ 282{
260 return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId); 283 return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
@@ -806,3 +829,133 @@ int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id,
806 829
807 return DRM_IOCTL(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip); 830 return DRM_IOCTL(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip);
808} 831}
832
833int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
834 uint32_t fb_id, uint32_t flags,
835 uint32_t crtc_x, uint32_t crtc_y,
836 uint32_t crtc_w, uint32_t crtc_h,
837 uint32_t src_x, uint32_t src_y,
838 uint32_t src_w, uint32_t src_h)
839
840{
841 struct drm_mode_set_plane s;
842
843 s.plane_id = plane_id;
844 s.crtc_id = crtc_id;
845 s.fb_id = fb_id;
846 s.flags = flags;
847 s.crtc_x = crtc_x;
848 s.crtc_y = crtc_y;
849 s.crtc_w = crtc_w;
850 s.crtc_h = crtc_h;
851 s.src_x = src_x;
852 s.src_y = src_y;
853 s.src_w = src_w;
854 s.src_h = src_h;
855
856 return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s);
857}
858
859
860drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id)
861{
862 struct drm_mode_get_plane ovr, counts;
863 drmModePlanePtr r = 0;
864
865retry:
866 memset(&ovr, 0, sizeof(struct drm_mode_get_plane));
867 ovr.plane_id = plane_id;
868 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
869 return 0;
870
871 counts = ovr;
872
873 if (ovr.count_format_types) {
874 ovr.format_type_ptr = VOID2U64(drmMalloc(ovr.count_format_types *
875 sizeof(uint32_t)));
876 if (!ovr.format_type_ptr)
877 goto err_allocs;
878 }
879
880 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr))
881 goto err_allocs;
882
883 if (counts.count_format_types < ovr.count_format_types) {
884 drmFree(U642VOID(ovr.format_type_ptr));
885 goto retry;
886 }
887
888 if (!(r = drmMalloc(sizeof(*r))))
889 goto err_allocs;
890
891 r->count_formats = ovr.count_format_types;
892 r->plane_id = ovr.plane_id;
893 r->crtc_id = ovr.crtc_id;
894 r->fb_id = ovr.fb_id;
895 r->possible_crtcs = ovr.possible_crtcs;
896 r->gamma_size = ovr.gamma_size;
897 r->formats = drmAllocCpy(U642VOID(ovr.format_type_ptr),
898 ovr.count_format_types, sizeof(uint32_t));
899 if (ovr.count_format_types && !r->formats) {
900 drmFree(r->formats);
901 r = 0;
902 }
903
904err_allocs:
905 drmFree(U642VOID(ovr.format_type_ptr));
906
907 return r;
908}
909
910void drmModeFreePlane(drmModePlanePtr ptr)
911{
912 if (!ptr)
913 return;
914
915 drmFree(ptr->formats);
916 drmFree(ptr);
917}
918
919drmModePlaneResPtr drmModeGetPlaneResources(int fd)
920{
921 struct drm_mode_get_plane_res res, counts;
922 drmModePlaneResPtr r = 0;
923
924retry:
925 memset(&res, 0, sizeof(struct drm_mode_get_plane_res));
926 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
927 return 0;
928
929 counts = res;
930
931 if (res.count_planes) {
932 res.plane_id_ptr = VOID2U64(drmMalloc(res.count_planes *
933 sizeof(uint32_t)));
934 if (!res.plane_id_ptr)
935 goto err_allocs;
936 }
937
938 if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res))
939 goto err_allocs;
940
941 if (counts.count_planes < res.count_planes) {
942 drmFree(U642VOID(res.plane_id_ptr));
943 goto retry;
944 }
945
946 if (!(r = drmMalloc(sizeof(*r))))
947 goto err_allocs;
948
949 r->count_planes = res.count_planes;
950 r->planes = drmAllocCpy(U642VOID(res.plane_id_ptr),
951 res.count_planes, sizeof(uint32_t));
952 if (res.count_planes && !r->planes) {
953 drmFree(r->planes);
954 r = 0;
955 }
956
957err_allocs:
958 drmFree(U642VOID(res.plane_id_ptr));
959
960 return r;
961}