drmModeGetResources(3)

πŸ’– drmModeGetResources β€” a.k.a. drmModeGetResources(3), Direct Rendering Manager, section 3 of your man pages πŸŽ€

okay so bestie, sit down, grab a strawb πŸ“, because we're about to meet the function that tells you literally everything about how your display is set up right now.


✨ NAME ✨

drmModeGetResources β€” retrieve current display configuration information. that's it. that's the whole job. she just... hands you the tea β˜• about your screens.


🌸 SYNOPSIS 🌸

#include <xf86drm.h>

#include <xf86drmMode.h>

drmModeResPtr drmModeGetResources(int fd);

πŸ¦‹ DESCRIPTION πŸ¦‹

so drmModeGetResources allocates, populates, and returns a drmModeRes structure containing info about the current display configuration. like she builds the whole thing for you, no cap. πŸ’…

the structure has these fields, and yes you need all of them:

typedef struct _drmModeRes {
    int count_fbs;
    uint32_t *fbs;

    int count_crtcs;
    uint32_t *crtcs;

    int count_connectors;
    uint32_t *connectors;

    int count_encoders;
    uint32_t *encoders;

    uint32_t min_width, max_width;
    uint32_t min_height, max_height;
} drmModeRes, *drmModeResPtr;

now let's break down every single one, because each of these is a whole personality πŸ‘‘

  • count_fbs and fbs β€” these tell you the number of currently allocated framebuffer objects. i.e., objects that can be attached to a given CRTC or sprite for display. they're the things that actually get shown on screen πŸ–ΌοΈ
  • count_crtcs and crtcs β€” these list the available CRTCs in the configuration. and what's a CRTC? it's simply an object that can scan out a framebuffer to a display sink, and it contains mode timing and relative position information. CRTCs drive encoders, which are the ones responsible for converting the pixel stream into a specific display protocol (e.g., MIPI or HDMI). so like, CRTC is the vibe-setter, encoder is the translator 🧚
  • count_connectors and connectors β€” these list the available physical connectors on the system. ⚠️ note that some of these may not be exposed from the chassis (e.g., LVDS or eDP). sorry bestie, not every connector is an extrovert. Connectors are attached to encoders and contain information about the attached display sink (e.g., width and height in mm, subpixel ordering, and various other properties). so they know the ~deets~ of what's plugged in πŸ’–
  • count_encoders and encoders β€” these list the available encoders on the device. Each encoder may be associated with a CRTC, and may be used to drive a particular encoder. yes, that's what it says. encoders containing multitudes, icon behavior honestly ✨
  • min_* and max_* β€” the min_width, max_width, min_height, max_height fields indicate the maximum size of a framebuffer for this device (i.e., the scanout size limit). so like, this is the ceiling, the absolute limit, the "don't even try it" zone πŸ“

πŸ”₯ RETURN VALUE πŸ”₯

drmModeGetResources returns a drmModeRes structure pointer on success, and NULL on failure. 😭

🚨 IMPORTANT β€” the returned structure must be freed with drmModeFreeResources(3). do not just leave her hanging. free your resources bestie, that's self care πŸ’…

πŸ› REPORTING BUGS πŸ›

found a bug in this function? don't suffer in silence, report it to <https://gitlab.freedesktop.org/mesa/libdrm/-/issues> 🫢


πŸ‘€ SEE ALSO πŸ‘€

the whole friend group shows up here:

  • drm(7)
  • drm-kms(7)
  • drmModeGetFB(3)
  • drmModeAddFB(3)
  • drmModeAddFB2(3)
  • drmModeRmFB(3)
  • drmModeDirtyFB(3)
  • drmModeGetCrtc(3)
  • drmModeSetCrtc(3)
  • drmModeGetEncoder (3)
  • drmModeGetConnector(3)

🌈 and that's the whole page, bestie!! go forth and query your display config. ily, stay hydrated, and always free your structs πŸ’œ

this lil page is from September 2012, Direct Rendering Manager, page drmModeGetResources(3) β€” vintage but still serving βœ¨πŸ‘‘