1

can we display same framebuffer side by side on screen simultaneously using DRM(direct rendering manager) APIs in linux?


constraints:

  • need to use single plane and single framebuffer

what I already tried and failed:

  • i used two setplane calls for left and right halves of screen respectively in a single vblank.
  • in the above case the second setplane call was resetting the left half of screen. hence only right half is being displayed finally.

resolutions: framebuffer: 1920 * 1080 screen: 3840 * 2160

1 Answer 1

1

To implement side-by-side framebuffer display using Linux's DRM API, it is necessary to:

  • create and configure framebuffers
  • interact with DRM to acess graphics hardware
  • set up and position planes for each framebuffer segment
  • manage scaling and refresh operations

Here's my example:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xf86drm.h>
#include <xf86drmMode.h>

int main(int argc, char **argv) {
    int fd = drmOpen("i915", NULL); // Replace "i915" with your GPU driver
    if (fd < 0) {
        perror("drmOpen");
        return 1;
    }

    drmModeRes *res = drmModeGetResources(fd);
    if (!res) {
        perror("drmModeGetResources");
        drmClose(fd);
        return 1;
    }

    // Assuming the first connected connector and its encoder and CRTC
    drmModeConnector *connector = drmModeGetConnector(fd, res->connectors[0]);
    drmModeEncoder *encoder = drmModeGetEncoder(fd, connector->encoder_id);
    drmModeCrtc *orig_crtc = drmModeGetCrtc(fd, encoder->crtc_id);

    uint32_t buffer_id;
    // Assume a framebuffer is already created and filled with data, use its ID here
    buffer_id = YOUR_FRAMEBUFFER_ID;

    // Display the buffer in two parts side by side
    for (int i = 0; i < 2; i++) {
        drmModeSetPlane(fd, res->planes[i], orig_crtc->crtc_id, buffer_id, 0,
                        1920 * i, 0, 1920, 1080,   // Destination rectangle
                        0, 0, 1920 << 16, 1080 << 16);  // Source rectangle (fixed-point format)
    }

    // Main loop or further processing
    printf("Framebuffers displayed side by side.\n");

    // Clean up resources
    drmModeFreeCrtc(orig_crtc);
    drmModeFreeEncoder(encoder);
    drmModeFreeConnector(connector);
    drmModeFreeResources(res);
    drmClose(fd);

    return 0;
}
1
  • In my original query, I did not explain the constraints and what I already tried. I have edited the query now. Please check. Commented Jun 15 at 6:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.