[ANN] libdrm - OCaml bindings for Linux mode setting, etc

I’m pleased to announce the first release of libdrm-ocaml (OCaml bindings for the libdrm C library).

libdrm is used by applications such as Wayland compositors to control the physical graphics hardware.

For example, you can use the library to enumerate graphics devices:

utop # Drm.Device.list ();;
- : Drm.Device.Info.t list =
[{primary_node = Some "/dev/dri/card0";
  render_node = Some "/dev/dri/renderD128";
  info = PCI {bus = {domain = 0; bus = 1; dev = 0; func = 0};
              dev = {vendor_id = 0x1002;
                     device_id = 0x67ff;
                     subvendor_id = 0x1458;
                     subdevice_id = 0x230b;
                     revision_id = 0xff}}}]

utop # let dev = Unix.openfile "/dev/dri/card0" [O_CLOEXEC; O_RDWR] 0;;

utop # Drm.Device.Version.get dev;;
- : Drm.Device.Version.t =
{version = 3.61.0; name = "amdgpu"; date = "0"; desc = "AMD GPU"}

Here’s an excerpt configuring a hardware plane to present a framebuffer on a CRT controller:

plane.%{ K.Plane.fb_id } <- Some fb;
(* Source region on frame-buffer: *)
plane.%{ K.Plane.src_x } <- Drm.Ufixed.of_int 0;
plane.%{ K.Plane.src_y } <- Drm.Ufixed.of_int 0;
plane.%{ K.Plane.src_w } <- Drm.Ufixed.of_int (fst size);
plane.%{ K.Plane.src_h } <- Drm.Ufixed.of_int (snd size);
(* Destination region on CRTC: *)
plane.%{ K.Plane.crtc_x } <- 0;
plane.%{ K.Plane.crtc_y } <- 0;
plane.%{ K.Plane.crtc_w } <- fst size;
plane.%{ K.Plane.crtc_h } <- snd size;

For a proper tutorial, see Linux mode setting, from the comfort of OCaml.

15 Likes