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

Commit 51219614 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "minui: Clean up graphics_fbdev.cpp."

parents d592e1d5 acf4dd15
Loading
Loading
Loading
Loading
+129 −139
Original line number Diff line number Diff line
@@ -14,20 +14,15 @@
 * limitations under the License.
 */

#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <fcntl.h>
#include <linux/fb.h>
#include <stdio.h>

#include <sys/cdefs.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>

#include <linux/fb.h>
#include <linux/kd.h>
#include <unistd.h>

#include "minui/minui.h"
#include "graphics.h"
@@ -39,7 +34,7 @@ static void fbdev_exit(minui_backend*);

static GRSurface gr_framebuffer[2];
static bool double_buffered;
static GRSurface* gr_draw = NULL;
static GRSurface* gr_draw = nullptr;
static int displayed_buffer;

static fb_var_screeninfo vi;
@@ -56,17 +51,14 @@ minui_backend* open_fbdev() {
  return &my_backend;
}

static void fbdev_blank(minui_backend* backend __unused, bool blank)
{
    int ret;

    ret = ioctl(fb_fd, FBIOBLANK, blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK);
    if (ret < 0)
static void fbdev_blank(minui_backend* backend __unused, bool blank) {
  int ret = ioctl(fb_fd, FBIOBLANK, blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK);
  if (ret < 0) {
    perror("ioctl(): blank");
  }
}

static void set_displayed_framebuffer(unsigned n)
{
static void set_displayed_framebuffer(unsigned n) {
  if (n > 1 || !double_buffered) return;

  vi.yres_virtual = gr_framebuffer[0].height * 2;
@@ -82,20 +74,20 @@ static GRSurface* fbdev_init(minui_backend* backend) {
  int fd = open("/dev/graphics/fb0", O_RDWR);
  if (fd == -1) {
    perror("cannot open fb0");
        return NULL;
    return nullptr;
  }

  fb_fix_screeninfo fi;
  if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) {
    perror("failed to get fb0 info");
    close(fd);
        return NULL;
    return nullptr;
  }

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

  // We print this out for informational purposes only, but
@@ -109,21 +101,20 @@ static GRSurface* fbdev_init(minui_backend* backend) {
  // If you have a device that actually *needs* another pixel format
  // (ie, BGRX, or 565), patches welcome...

    printf("fb0 reports (possibly inaccurate):\n"
  printf(
      "fb0 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.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);
  if (bits == MAP_FAILED) {
    perror("failed to mmap framebuffer");
    close(fd);
        return NULL;
    return nullptr;
  }

  memset(bits, 0, fi.smem_len);
@@ -140,8 +131,8 @@ static GRSurface* fbdev_init(minui_backend* backend) {
    double_buffered = true;

    memcpy(gr_framebuffer + 1, gr_framebuffer, sizeof(GRSurface));
        gr_framebuffer[1].data = gr_framebuffer[0].data +
            gr_framebuffer[0].height * gr_framebuffer[0].row_bytes;
    gr_framebuffer[1].data =
        gr_framebuffer[0].data + gr_framebuffer[0].height * gr_framebuffer[0].row_bytes;

    gr_draw = gr_framebuffer + 1;

@@ -152,12 +143,12 @@ static GRSurface* fbdev_init(minui_backend* backend) {
    // draw in, and then "flipping" the buffer consists of a
    // memcpy from the buffer we allocated to the framebuffer.

        gr_draw = (GRSurface*) malloc(sizeof(GRSurface));
    gr_draw = static_cast<GRSurface*>(malloc(sizeof(GRSurface)));
    memcpy(gr_draw, gr_framebuffer, sizeof(GRSurface));
        gr_draw->data = (unsigned char*) malloc(gr_draw->height * gr_draw->row_bytes);
    gr_draw->data = static_cast<unsigned char*>(malloc(gr_draw->height * gr_draw->row_bytes));
    if (!gr_draw->data) {
      perror("failed to allocate in-memory surface");
            return NULL;
      return nullptr;
    }
  }

@@ -182,8 +173,7 @@ static GRSurface* fbdev_flip(minui_backend* backend __unused) {
    set_displayed_framebuffer(1 - displayed_buffer);
  } else {
    // Copy from the in-memory surface to the framebuffer.
        memcpy(gr_framebuffer[0].data, gr_draw->data,
               gr_draw->height * gr_draw->row_bytes);
    memcpy(gr_framebuffer[0].data, gr_draw->data, gr_draw->height * gr_draw->row_bytes);
  }
  return gr_draw;
}
@@ -196,5 +186,5 @@ static void fbdev_exit(minui_backend* backend __unused) {
    free(gr_draw->data);
    free(gr_draw);
  }
    gr_draw = NULL;
  gr_draw = nullptr;
}