diff options
Diffstat (limited to 'src/surface/ram.c')
-rw-r--r-- | src/surface/ram.c | 71 |
1 files changed, 60 insertions, 11 deletions
diff --git a/src/surface/ram.c b/src/surface/ram.c index 0948a5d..4deabda 100644 --- a/src/surface/ram.c +++ b/src/surface/ram.c @@ -8,36 +8,77 @@ #include <stdbool.h> #include <stdio.h> +#include <stdlib.h> #include "libnsfb.h" #include "libnsfb_plot.h" #include "libnsfb_event.h" + #include "nsfb.h" -#include "frontend.h" +#include "surface.h" +#include "plot.h" #define UNUSED(x) ((x) = (x)) -static int ram_set_geometry(nsfb_t *nsfb, int width, int height, int bpp) +static int ram_defaults(nsfb_t *nsfb) { - if (nsfb->frontend_priv != NULL) - return -1; /* if were already initialised fail */ + nsfb->width = 0; + nsfb->height = 0; + nsfb->format = NSFB_FMT_ABGR8888; - nsfb->width = width; - nsfb->height = height; - nsfb->bpp = bpp; + /* select default sw plotters for bpp */ + select_plotters(nsfb); return 0; } + static int ram_initialise(nsfb_t *nsfb) { - UNUSED(nsfb); + size_t size = (nsfb->width * nsfb->height * nsfb->bpp) / 8; + + nsfb->ptr = realloc(nsfb->ptr, size); + nsfb->linelen = (nsfb->width * nsfb->bpp) / 8; + + return 0; +} + +static int ram_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format) +{ + int startsize; + int endsize; + + startsize = (nsfb->width * nsfb->height * nsfb->bpp) / 8; + + if (width > 0) { + nsfb->width = width; + } + + if (height > 0) { + nsfb->height = height; + } + + if (format != NSFB_FMT_ANY) { + nsfb->format = format; + } + + /* select soft plotters appropriate for format */ + select_plotters(nsfb); + + endsize = (nsfb->width * nsfb->height * nsfb->bpp) / 8; + if ((nsfb->ptr != NULL) && (startsize != endsize)) { + nsfb->ptr = realloc(nsfb->ptr, endsize); + } + nsfb->linelen = (nsfb->width * nsfb->bpp) / 8; + return 0; } + static int ram_finalise(nsfb_t *nsfb) { - UNUSED(nsfb); + free(nsfb->ptr); + return 0; } @@ -49,11 +90,19 @@ static bool ram_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout) return false; } -const nsfb_frontend_rtns_t ram_rtns = { +const nsfb_surface_rtns_t ram_rtns = { + .defaults = ram_defaults, .initialise = ram_initialise, .finalise = ram_finalise, .input = ram_input, .geometry = ram_set_geometry, }; -NSFB_FRONTEND_DEF(ram, NSFB_FRONTEND_RAM, &ram_rtns) +NSFB_SURFACE_DEF(ram, NSFB_SURFACE_RAM, &ram_rtns) + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ |