summaryrefslogtreecommitdiff
path: root/src/surface/surface.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/surface/surface.c')
-rw-r--r--src/surface/surface.c139
1 files changed, 79 insertions, 60 deletions
diff --git a/src/surface/surface.c b/src/surface/surface.c
index 6fa65a8..b2cf769 100644
--- a/src/surface/surface.c
+++ b/src/surface/surface.c
@@ -12,40 +12,41 @@
#include <stdlib.h>
#include <string.h>
-#include "frontend.h"
+#include "surface.h"
#include "plot.h"
-#define MAX_FRONTENDS 16
+#define MAX_SURFACES 16
-struct nsfb_frontend_s {
- enum nsfb_frontend_e type;
- const nsfb_frontend_rtns_t *rtns;
+struct nsfb_surface_s {
+ enum nsfb_type_e type;
+ const nsfb_surface_rtns_t *rtns;
const char *name;
};
-static struct nsfb_frontend_s frontends[MAX_FRONTENDS];
-static int frontend_count = 0;
+static struct nsfb_surface_s surfaces[MAX_SURFACES];
+static int surface_count = 0;
-/* internal routine which lets frontends register their presence at runtime */
-void _nsfb_register_frontend(const enum nsfb_frontend_e type,
- const nsfb_frontend_rtns_t *rtns,
+/* internal routine which lets surfaces register their presence at runtime */
+void _nsfb_register_surface(const enum nsfb_type_e type,
+ const nsfb_surface_rtns_t *rtns,
const char *name)
{
- if (frontend_count >= MAX_FRONTENDS)
- return; /* no space for additional frontends */
+ if (surface_count >= MAX_SURFACES)
+ return; /* no space for additional surfaces */
- frontends[frontend_count].type = type;
- frontends[frontend_count].rtns = rtns;
- frontends[frontend_count].name = name;
- frontend_count++;
+ surfaces[surface_count].type = type;
+ surfaces[surface_count].rtns = rtns;
+ surfaces[surface_count].name = name;
+ surface_count++;
}
-/* default frontend implementations */
-static int frontend_defaults(nsfb_t *nsfb)
+/* default surface implementations */
+
+static int surface_defaults(nsfb_t *nsfb)
{
nsfb->width = 800;
nsfb->height = 600;
- nsfb->bpp = 32;
+ nsfb->format = NSFB_FMT_XRGB8888;
/* select default sw plotters for bpp */
select_plotters(nsfb);
@@ -53,75 +54,93 @@ static int frontend_defaults(nsfb_t *nsfb)
return 0;
}
-static int frontend_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
+static int surface_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
{
nsfb=nsfb;
box=box;
return 0;
}
-static int frontend_update(nsfb_t *nsfb, nsfb_bbox_t *box)
+static int surface_update(nsfb_t *nsfb, nsfb_bbox_t *box)
{
nsfb=nsfb;
box=box;
return 0;
}
-static int frontend_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
+static int surface_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
{
nsfb=nsfb;
cursor=cursor;
return 0;
}
-nsfb_frontend_rtns_t *nsfb_frontend_get_rtns(enum nsfb_frontend_e type)
+/* exported interface documented in surface.h */
+nsfb_surface_rtns_t *
+nsfb_surface_get_rtns(enum nsfb_type_e type)
{
int fend_loop;
- nsfb_frontend_rtns_t *rtns = NULL;
-
- for (fend_loop = 0; fend_loop < frontend_count; fend_loop++) {
- if (frontends[fend_loop].type == type) {
- rtns = malloc(sizeof(nsfb_frontend_rtns_t));
- memcpy(rtns,
- frontends[fend_loop].rtns,
- sizeof(nsfb_frontend_rtns_t));
-
- /* frontend must have an initialisor, finaliser and input method */
- if ((rtns->initialise == NULL) ||
- (rtns->finalise == NULL) ||
- (rtns->input == NULL) ) {
- free(rtns);
- rtns = NULL;
- } else {
- /* The rest may be empty but to avoid the null check every time
- * provide default implementations.
- */
- if (rtns->defaults == NULL)
- rtns->defaults = frontend_defaults;
-
- if (rtns->claim == NULL)
- rtns->claim = frontend_claim;
-
- if (rtns->update == NULL)
- rtns->update = frontend_update;
-
- if (rtns->cursor == NULL)
- rtns->cursor = frontend_cursor;
- }
-
+ nsfb_surface_rtns_t *rtns = NULL;
+
+ for (fend_loop = 0; fend_loop < surface_count; fend_loop++) {
+ /* surface type must match and have a initialisor, finaliser
+ * and input method
+ */
+ if ((surfaces[fend_loop].type == type) &&
+ (surfaces[fend_loop].rtns->initialise != NULL) &&
+ (surfaces[fend_loop].rtns->finalise != NULL) &&
+ (surfaces[fend_loop].rtns->input != NULL) ) {
+
+ rtns = malloc(sizeof(nsfb_surface_rtns_t));
+ if (rtns == NULL) {
+ continue;
+ }
+
+ memcpy(rtns,
+ surfaces[fend_loop].rtns,
+ sizeof(nsfb_surface_rtns_t));
+
+ /* The rest may be empty but to avoid the null check every time
+ * provide default implementations.
+ */
+ if (rtns->defaults == NULL) {
+ rtns->defaults = surface_defaults;
+ }
+
+ if (rtns->claim == NULL) {
+ rtns->claim = surface_claim;
+ }
+
+ if (rtns->update == NULL) {
+ rtns->update = surface_update;
+ }
+
+ if (rtns->cursor == NULL) {
+ rtns->cursor = surface_cursor;
+ }
+
break;
}
}
return rtns;
}
-enum nsfb_frontend_e nsfb_frontend_from_name(const char *name)
+/* exported interface defined in libnsfb.h */
+enum nsfb_type_e
+nsfb_type_from_name(const char *name)
{
int fend_loop;
- for (fend_loop = 0; fend_loop < frontend_count; fend_loop++) {
- if (strcmp(frontends[fend_loop].name, name) == 0)
- return frontends[fend_loop].type;
+ for (fend_loop = 0; fend_loop < surface_count; fend_loop++) {
+ if (strcmp(surfaces[fend_loop].name, name) == 0)
+ return surfaces[fend_loop].type;
}
- return NSFB_FRONTEND_NONE;
+ return NSFB_SURFACE_NONE;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * End:
+ */