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

Commit 23017c5d authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Switch minui over to C++."

parents 5d1630a9 07cfb8fe
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
    events.cpp \
    graphics.c \
    graphics_adf.c \
    graphics_fbdev.c \
    resources.c \
    graphics.cpp \
    graphics_adf.cpp \
    graphics_fbdev.cpp \
    resources.cpp \

LOCAL_WHOLE_STATIC_LIBRARIES += libadf
LOCAL_STATIC_LIBRARIES += libpng
+6 −6
Original line number Diff line number Diff line
@@ -39,10 +39,10 @@ struct fd_info {
};

static int g_epoll_fd;
static struct epoll_event polledevents[MAX_DEVICES + MAX_MISC_FDS];
static epoll_event polledevents[MAX_DEVICES + MAX_MISC_FDS];
static int npolledevents;

static struct fd_info ev_fdinfo[MAX_DEVICES + MAX_MISC_FDS];
static fd_info ev_fdinfo[MAX_DEVICES + MAX_MISC_FDS];

static unsigned ev_count = 0;
static unsigned ev_dev_count = 0;
@@ -62,7 +62,7 @@ int ev_init(ev_callback input_cb, void* data) {

    DIR* dir = opendir("/dev/input");
    if (dir != NULL) {
        struct dirent* de;
        dirent* de;
        while ((de = readdir(dir))) {
            unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)];

@@ -83,7 +83,7 @@ int ev_init(ev_callback input_cb, void* data) {
                continue;
            }

            struct epoll_event ev;
            epoll_event ev;
            ev.events = EPOLLIN | EPOLLWAKEUP;
            ev.data.ptr = &ev_fdinfo[ev_count];
            if (epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) {
@@ -121,7 +121,7 @@ int ev_add_fd(int fd, ev_callback cb, void* data) {
        return -1;
    }

    struct epoll_event ev;
    epoll_event ev;
    ev.events = EPOLLIN | EPOLLWAKEUP;
    ev.data.ptr = (void *)&ev_fdinfo[ev_count];
    int ret = epoll_ctl(g_epoll_fd, EPOLL_CTL_ADD, fd, &ev);
@@ -163,7 +163,7 @@ void ev_dispatch(void) {
    }
}

int ev_get_input(int fd, uint32_t epevents, struct input_event* ev) {
int ev_get_input(int fd, uint32_t epevents, input_event* ev) {
    if (epevents & EPOLLIN) {
        ssize_t r = read(fd, ev, sizeof(*ev));
        if (r == sizeof(*ev)) {
+6 −6
Original line number Diff line number Diff line
@@ -35,11 +35,11 @@
#include "minui.h"
#include "graphics.h"

typedef struct {
struct GRFont {
    GRSurface* texture;
    int cwidth;
    int cheight;
} GRFont;
};

static GRFont* gr_font = NULL;
static minui_backend* gr_backend = NULL;
@@ -269,7 +269,7 @@ unsigned int gr_get_height(GRSurface* surface) {

static void gr_init_font(void)
{
    gr_font = calloc(sizeof(*gr_font), 1);
    gr_font = reinterpret_cast<GRFont*>(calloc(sizeof(*gr_font), 1));

    int res = res_create_alpha_surface("font", &(gr_font->texture));
    if (res == 0) {
@@ -282,14 +282,14 @@ static void gr_init_font(void)
        printf("failed to read font: res=%d\n", res);

        // fall back to the compiled-in font.
        gr_font->texture = malloc(sizeof(*gr_font->texture));
        gr_font->texture = reinterpret_cast<GRSurface*>(malloc(sizeof(*gr_font->texture)));
        gr_font->texture->width = font.width;
        gr_font->texture->height = font.height;
        gr_font->texture->row_bytes = font.width;
        gr_font->texture->pixel_bytes = 1;

        unsigned char* bits = malloc(font.width * font.height);
        gr_font->texture->data = (void*) bits;
        unsigned char* bits = reinterpret_cast<unsigned char*>(malloc(font.width * font.height));
        gr_font->texture->data = reinterpret_cast<unsigned char*>(bits);

        unsigned char data;
        unsigned char* in = font.rundata;
+7 −15
Original line number Diff line number Diff line
@@ -17,34 +17,26 @@
#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include "minui.h"

typedef struct minui_backend {
// TODO: lose the function pointers.
struct minui_backend {
    // Initializes the backend and returns a gr_surface to draw into.
    gr_surface (*init)(struct minui_backend*);
    gr_surface (*init)(minui_backend*);

    // Causes the current drawing surface (returned by the most recent
    // call to flip() or init()) to be displayed, and returns a new
    // drawing surface.
    gr_surface (*flip)(struct minui_backend*);
    gr_surface (*flip)(minui_backend*);

    // Blank (or unblank) the screen.
    void (*blank)(struct minui_backend*, bool);
    void (*blank)(minui_backend*, bool);

    // Device cleanup when drawing is done.
    void (*exit)(struct minui_backend*);
} minui_backend;
    void (*exit)(minui_backend*);
};

minui_backend* open_fbdev();
minui_backend* open_adf();

#ifdef __cplusplus
}
#endif

#endif
+21 −22
Original line number Diff line number Diff line
@@ -44,15 +44,13 @@ struct adf_pdata {

    unsigned int current_surface;
    unsigned int n_surfaces;
    struct adf_surface_pdata surfaces[2];
    adf_surface_pdata surfaces[2];
};

static gr_surface adf_flip(struct minui_backend *backend);
static void adf_blank(struct minui_backend *backend, bool blank);
static gr_surface adf_flip(minui_backend *backend);
static void adf_blank(minui_backend *backend, bool blank);

static int adf_surface_init(struct adf_pdata *pdata,
        struct drm_mode_modeinfo *mode, struct adf_surface_pdata *surf)
{
static int adf_surface_init(adf_pdata *pdata, drm_mode_modeinfo *mode, adf_surface_pdata *surf) {
    memset(surf, 0, sizeof(*surf));

    surf->fd = adf_interface_simple_buffer_alloc(pdata->intf_fd, mode->hdisplay,
@@ -65,8 +63,9 @@ static int adf_surface_init(struct adf_pdata *pdata,
    surf->base.row_bytes = surf->pitch;
    surf->base.pixel_bytes = (pdata->format == DRM_FORMAT_RGB565) ? 2 : 4;

    surf->base.data = mmap(NULL, surf->pitch * surf->base.height, PROT_WRITE,
            MAP_SHARED, surf->fd, surf->offset);
    surf->base.data = reinterpret_cast<uint8_t*>(mmap(NULL,
                                                      surf->pitch * surf->base.height, PROT_WRITE,
                                                      MAP_SHARED, surf->fd, surf->offset));
    if (surf->base.data == MAP_FAILED) {
        close(surf->fd);
        return -errno;
@@ -75,9 +74,9 @@ static int adf_surface_init(struct adf_pdata *pdata,
    return 0;
}

static int adf_interface_init(struct adf_pdata *pdata)
static int adf_interface_init(adf_pdata *pdata)
{
    struct adf_interface_data intf_data;
    adf_interface_data intf_data;
    int ret = 0;
    int err;

@@ -107,7 +106,7 @@ done:
    return ret;
}

static int adf_device_init(struct adf_pdata *pdata, struct adf_device *dev)
static int adf_device_init(adf_pdata *pdata, adf_device *dev)
{
    adf_id_t intf_id;
    int intf_fd;
@@ -137,7 +136,7 @@ static int adf_device_init(struct adf_pdata *pdata, struct adf_device *dev)

static gr_surface adf_init(minui_backend *backend)
{
    struct adf_pdata *pdata = (struct adf_pdata *)backend;
    adf_pdata *pdata = (adf_pdata *)backend;
    adf_id_t *dev_ids = NULL;
    ssize_t n_dev_ids, i;
    gr_surface ret;
@@ -164,7 +163,7 @@ static gr_surface adf_init(minui_backend *backend)
    pdata->intf_fd = -1;

    for (i = 0; i < n_dev_ids && pdata->intf_fd < 0; i++) {
        struct adf_device dev;
        adf_device dev;

        int err = adf_device_open(dev_ids[i], O_RDWR, &dev);
        if (err < 0) {
@@ -194,10 +193,10 @@ static gr_surface adf_init(minui_backend *backend)
    return ret;
}

static gr_surface adf_flip(struct minui_backend *backend)
static gr_surface adf_flip(minui_backend *backend)
{
    struct adf_pdata *pdata = (struct adf_pdata *)backend;
    struct adf_surface_pdata *surf = &pdata->surfaces[pdata->current_surface];
    adf_pdata *pdata = (adf_pdata *)backend;
    adf_surface_pdata *surf = &pdata->surfaces[pdata->current_surface];

    int fence_fd = adf_interface_simple_post(pdata->intf_fd, pdata->eng_id,
            surf->base.width, surf->base.height, pdata->format, surf->fd,
@@ -209,22 +208,22 @@ static gr_surface adf_flip(struct minui_backend *backend)
    return &pdata->surfaces[pdata->current_surface].base;
}

static void adf_blank(struct minui_backend *backend, bool blank)
static void adf_blank(minui_backend *backend, bool blank)
{
    struct adf_pdata *pdata = (struct adf_pdata *)backend;
    adf_pdata *pdata = (adf_pdata *)backend;
    adf_interface_blank(pdata->intf_fd,
            blank ? DRM_MODE_DPMS_OFF : DRM_MODE_DPMS_ON);
}

static void adf_surface_destroy(struct adf_surface_pdata *surf)
static void adf_surface_destroy(adf_surface_pdata *surf)
{
    munmap(surf->base.data, surf->pitch * surf->base.height);
    close(surf->fd);
}

static void adf_exit(struct minui_backend *backend)
static void adf_exit(minui_backend *backend)
{
    struct adf_pdata *pdata = (struct adf_pdata *)backend;
    adf_pdata *pdata = (adf_pdata *)backend;
    unsigned int i;

    for (i = 0; i < pdata->n_surfaces; i++)
@@ -236,7 +235,7 @@ static void adf_exit(struct minui_backend *backend)

minui_backend *open_adf()
{
    struct adf_pdata *pdata = calloc(1, sizeof(*pdata));
    adf_pdata* pdata = reinterpret_cast<adf_pdata*>(calloc(1, sizeof(*pdata)));
    if (!pdata) {
        perror("allocating adf backend failed");
        return NULL;
Loading