Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 98d4183b authored by Aaron Kling's avatar Aaron Kling Committed by Michael Bestas
Browse files

minui: Support secondary framebuffers

On devices with multiple detachable displays, fb0 may be invalid while a
different framebuffer is available. Check all available framebuffers and
use the first one that is valid.

Change-Id: Ic51f8ec5701d3e63dd33c5805e64e95b22d24579
parent 6eaebf3c
Loading
Loading
Loading
Loading
+50 −37
Original line number Diff line number Diff line
@@ -69,21 +69,20 @@ void MinuiBackendFbdev::SetDisplayedFramebuffer(size_t n) {
}

GRSurface* MinuiBackendFbdev::Init() {
  android::base::unique_fd fd(open("/dev/graphics/fb0", O_RDWR | O_CLOEXEC));
  if (fd == -1) {
    perror("cannot open fb0");
    return nullptr;
  }

  fb_fix_screeninfo fi;
  void* bits = nullptr;
  uint8_t fb_count = 0;
  std::string fb_path = "/dev/graphics/fb0";
  android::base::unique_fd fd(open(fb_path.c_str(), O_RDWR | O_CLOEXEC));
  while (fd != -1) {
    if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) {
    perror("failed to get fb0 info");
    return nullptr;
      perror("failed to get fb info");
      goto next_fb;
    }

    if (ioctl(fd, FBIOGET_VSCREENINFO, &vi) < 0) {
    perror("failed to get fb0 info");
    return nullptr;
      perror("failed to get fb info");
      goto next_fb;
    }

    // We print this out for informational purposes only, but
@@ -98,17 +97,31 @@ GRSurface* MinuiBackendFbdev::Init() {
    // (ie, BGRX, or 565), patches welcome...

    printf(
      "fb0 reports (possibly inaccurate):\n"
        "fb%d reports (possibly inaccurate):\n"
        "  vi.bits_per_pixel = %d\n"
        "  vi.red.offset   = %3d   .length = %3d\n"
        "  vi.green.offset = %3d   .length = %3d\n"
        "  vi.blue.offset  = %3d   .length = %3d\n",
      vi.bits_per_pixel, vi.red.offset, vi.red.length, vi.green.offset, vi.green.length,
      vi.blue.offset, vi.blue.length);
        fb_count, vi.bits_per_pixel, vi.red.offset, vi.red.length, vi.green.offset,
        vi.green.length, vi.blue.offset, vi.blue.length);

  void* bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (bits == MAP_FAILED) {
      perror("failed to mmap framebuffer");
      goto next_fb;
    }

    // Found a valid fb
    break;

next_fb:
    fb_count++;
    fb_path.replace(fb_path.length()-1, 1, std::to_string(fb_count));
    fd.reset(open(fb_path.c_str(), O_RDWR | O_CLOEXEC));
  }

  if (fd == -1) {
    perror("cannot open any framebuffer");
    return nullptr;
  }