From 2dd32c7adb7116f1ad9ab2632d9fcf57a31e9fa2 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 21 Nov 2011 08:44:10 +0000 Subject: Improve API to allow for RAM surfaces instead of direct blitting Improve and update tests Fix RAM surface Fix VNC surface svn path=/trunk/libnsfb/; revision=13158 --- include/frontend.h | 47 ------------------------- include/libnsfb.h | 94 ++++++++++++++++++++++++++++++++----------------- include/libnsfb_event.h | 26 +++++++++++++- include/libnsfb_plot.h | 2 +- include/nsfb.h | 28 ++++++++++++--- include/surface.h | 61 ++++++++++++++++++++++++++++++++ 6 files changed, 172 insertions(+), 86 deletions(-) delete mode 100644 include/frontend.h create mode 100644 include/surface.h (limited to 'include') diff --git a/include/frontend.h b/include/frontend.h deleted file mode 100644 index fba407f..0000000 --- a/include/frontend.h +++ /dev/null @@ -1,47 +0,0 @@ -/* libnsfb framebuffer frontend support */ - -#include "libnsfb.h" -#include "libnsfb_plot.h" -#include "nsfb.h" - -/* frontend default options */ -typedef int (nsfb_fendfn_defaults_t)(nsfb_t *nsfb); -/* frontend init */ -typedef int (nsfb_fendfn_init_t)(nsfb_t *nsfb); -/* frontend finalise */ -typedef int (nsfb_fendfn_fini_t)(nsfb_t *nsfb); -/* frontend set geometry */ -typedef int (nsfb_fendfn_geometry_t)(nsfb_t *nsfb, int width, int height, int bpp); -/* frontend input */ -typedef bool (nsfb_fendfn_input_t)(nsfb_t *nsfb, nsfb_event_t *event, int timeout); -/* frontend area claim */ -typedef int (nsfb_fendfn_claim_t)(nsfb_t *nsfb, nsfb_bbox_t *box); -/* frontend area update */ -typedef int (nsfb_fendfn_update_t)(nsfb_t *nsfb, nsfb_bbox_t *box); -/* frontend cursor display */ -typedef int (nsfb_fendfn_cursor_t)(nsfb_t *nsfb, struct nsfb_cursor_s *cursor); - -typedef struct nsfb_frontend_rtns_s { - nsfb_fendfn_defaults_t *defaults; - nsfb_fendfn_init_t *initialise; - nsfb_fendfn_fini_t *finalise; - nsfb_fendfn_geometry_t *geometry; - nsfb_fendfn_input_t *input; - nsfb_fendfn_claim_t *claim; - nsfb_fendfn_update_t *update; - nsfb_fendfn_cursor_t *cursor; -} nsfb_frontend_rtns_t; - -void _nsfb_register_frontend(const enum nsfb_frontend_e type, const nsfb_frontend_rtns_t *rtns, const char *name); - - -/* macro which adds a builtin command with no argument limits */ -#define NSFB_FRONTEND_DEF(__name, __type, __rtns) \ - static void __name##_register_frontend(void) __attribute__((constructor)); \ - void __name##_register_frontend(void) { \ - _nsfb_register_frontend(__type, __rtns, #__name); \ - } - -/* Obtain routines for a frontend */ -nsfb_frontend_rtns_t *nsfb_frontend_get_rtns(enum nsfb_frontend_e type); - diff --git a/include/libnsfb.h b/include/libnsfb.h index 3f4a4e7..330c476 100644 --- a/include/libnsfb.h +++ b/include/libnsfb.h @@ -31,46 +31,60 @@ typedef struct nsfb_bbox_s { int y1; } nsfb_bbox_t; -/** The type of frontend for a framebuffer context. */ -enum nsfb_frontend_e { - NSFB_FRONTEND_NONE = 0, /**< Empty frontend. */ - NSFB_FRONTEND_SDL, /**< SDL frontend */ - NSFB_FRONTEND_LINUX, /**< Linux frontend */ - NSFB_FRONTEND_VNC, /**< VNC frontend */ - NSFB_FRONTEND_ABLE, /**< ABLE frontend */ - NSFB_FRONTEND_RAM, /**< RAM frontend */ - NSFB_FRONTEND_X /**< X windows frontend */ +/** The type of framebuffer surface. */ +enum nsfb_type_e { + NSFB_SURFACE_NONE = 0, /**< No surface */ + NSFB_SURFACE_RAM, /**< RAM surface */ + NSFB_SURFACE_SDL, /**< SDL surface */ + NSFB_SURFACE_LINUX, /**< Linux framebuffer surface */ + NSFB_SURFACE_VNC, /**< VNC surface */ + NSFB_SURFACE_ABLE, /**< ABLE framebuffer surface */ + NSFB_SURFACE_X /**< X windows surface */ }; -/** Initialise nsfb context. - * - * This initialises a framebuffer context. - * - * @param frontend The type of frontend to create a context for. +enum nsfb_format_e { + NSFB_FMT_ANY = 0, /* No specific format - use surface default */ + NSFB_FMT_XBGR8888, /* 32bpp Blue Green Red */ + NSFB_FMT_XRGB8888, /* 32bpp Red Green Blue */ + NSFB_FMT_ABGR8888, /* 32bpp Alpga Blue Green Red */ + NSFB_FMT_ARGB8888, /* 32bpp Alpga Red Green Blue */ + NSFB_FMT_RGB888, /* 24 bpp Alpga Red Green Blue */ + NSFB_FMT_ARGB1555, /* 16 bpp 555 */ + NSFB_FMT_RGB565, /* 16 bpp 565 */ + NSFB_FMT_I8, /* 8bpp indexed */ + NSFB_FMT_I4, /* 4bpp indexed */ + NSFB_FMT_I1, /* black and white */ +}; + +/** Select frontend type from a name. + * + * @param name The name to select a frontend. + * @return The surface type or NSFB_SURFACE_NONE if frontend with specified + * name was not available */ -nsfb_t *nsfb_init(enum nsfb_frontend_e frontend); +enum nsfb_type_e nsfb_type_from_name(const char *name); -/** Finalise nsfb. +/** Create a nsfb context. * - * This shuts down and releases all resources associated with an nsfb context. + * This creates a framebuffer surface context. * - * @param nsfb The context returned from ::nsfb_init tofinalise + * @param surface_type The type of surface to create a context for. */ -int nsfb_finalise(nsfb_t *nsfb); +nsfb_t *nsfb_new(const enum nsfb_type_e surface_type); -/** Initialise selected frontend. +/** Initialise selected surface context. * * @param nsfb The context returned from ::nsfb_init */ -int nsfb_init_frontend(nsfb_t *nsfb); +int nsfb_init(nsfb_t *nsfb); -/** Select frontend type from a name. - * - * @param name The name to select a frontend. - * @return The frontend type or NSFB_FRONTEND_NONE if frontend with specified - * name was not available +/** Free nsfb context. + * + * This shuts down and releases all resources associated with an nsfb context. + * + * @param nsfb The context returned from ::nsfb_new to free */ -enum nsfb_frontend_e nsfb_frontend_from_name(const char *name); +int nsfb_free(nsfb_t *nsfb); /** Claim an area of screen to be redrawn. * @@ -86,7 +100,7 @@ int nsfb_claim(nsfb_t *nsfb, nsfb_bbox_t *box); /** Update an area of screen which has been redrawn. * * Informs the nsfb library that an area of screen has been directly - * updated by the user program. Some frontends only show the update on + * updated by the user program. Some surfaces only show the update on * notification. The area updated does not neccisarrily have to * corelate with a previous ::nsfb_claim bounding box, however if the * redrawn area is larger than the claimed area pointer plotting @@ -100,9 +114,9 @@ int nsfb_update(nsfb_t *nsfb, nsfb_bbox_t *box); * * @param width a variable to store the framebuffer width in or NULL * @param height a variable to store the framebuffer height in or NULL - * @param bpp a variable to store the framebuffer bpp in or NULL + * @param format a variable to store the framebuffer format in or NULL */ -int nsfb_get_geometry(nsfb_t *nsfb, int *width, int *height, int *bpp); +int nsfb_get_geometry(nsfb_t *nsfb, int *width, int *height, enum nsfb_format_e *format); /** Alter the geometry of a framebuffer context * @@ -111,10 +125,24 @@ int nsfb_get_geometry(nsfb_t *nsfb, int *width, int *height, int *bpp); * @param height The new display height. * @param bpp The new display depth. */ -int nsfb_set_geometry(nsfb_t *nsfb, int width, int height, int bpp); +int nsfb_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format); -/** Obtain the framebuffer memory base and stride. +/** Obtain the buffer memory base and stride. + * + * @param nsfb The context to read. */ -int nsfb_get_framebuffer(nsfb_t *nsfb, uint8_t **ptr, int *linelen); +int nsfb_get_buffer(nsfb_t *nsfb, uint8_t **ptr, int *linelen); + +/** Dump the surface to fd in PPM format + */ +bool nsfb_dump(nsfb_t *nsfb, int fd); + #endif + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/include/libnsfb_event.h b/include/libnsfb_event.h index ea2b2bf..6944654 100644 --- a/include/libnsfb_event.h +++ b/include/libnsfb_event.h @@ -1,3 +1,16 @@ +/* + * Copyright 2009 Vincent Sanders + * + * This file is part of libnsfb, http://www.netsurf-browser.org/ + * Licenced under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * This is the exported interface for the libnsfb graphics library. + */ + +#ifndef _LIBNSFB_EVENT_H +#define _LIBNSFB_EVENT_H 1 + enum nsfb_event_type_e { NSFB_EVENT_NONE, NSFB_EVENT_CONTROL, @@ -13,6 +26,7 @@ enum nsfb_key_code_e { NSFB_KEY_UNKNOWN = 0, NSFB_KEY_BACKSPACE = 8, NSFB_KEY_TAB = 9, + NSFB_KEY_LF = 10, NSFB_KEY_CLEAR = 12, NSFB_KEY_RETURN = 13, NSFB_KEY_PAUSE = 19, @@ -166,7 +180,8 @@ enum nsfb_key_code_e { enum nsfb_control_e { NSFB_CONTROL_NONE, - NSFB_CONTROL_QUIT, + NSFB_CONTROL_TIMEOUT, /* timeout event */ + NSFB_CONTROL_QUIT, /* surface handler quit event */ }; struct nsfb_event_s { @@ -193,3 +208,12 @@ struct nsfb_event_s { * @return If the /a event structure is updated true else false. */ bool nsfb_event(nsfb_t *nsfb, nsfb_event_t *event, int timeout); + +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/include/libnsfb_plot.h b/include/libnsfb_plot.h index 931243d..b3f86d1 100644 --- a/include/libnsfb_plot.h +++ b/include/libnsfb_plot.h @@ -148,7 +148,7 @@ bool nsfb_plot_path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_pl * * Copy an area of the display. */ -bool nsfb_plot_copy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox); +bool nsfb_plot_copy(nsfb_t *srcfb, nsfb_bbox_t *srcbox, nsfb_t *dstfb, nsfb_bbox_t *dstbox); /** Plot bitmap. */ diff --git a/include/nsfb.h b/include/nsfb.h index 7b28fcb..9b1619c 100644 --- a/include/nsfb.h +++ b/include/nsfb.h @@ -1,3 +1,13 @@ +/* + * Copyright 2009 Vincent Sanders + * + * This file is part of libnsfb, http://www.netsurf-browser.org/ + * Licenced under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * + * This is the internal interface for the libnsfb graphics library. + */ + #ifndef _NSFB_H #define _NSFB_H 1 @@ -9,10 +19,13 @@ struct nsfb_s { int width; /**< Visible width. */ int height; /**< Visible height. */ - int bpp; /**< Bits per pixel. */ + + int bpp; + + enum nsfb_format_e format; /**< Framebuffer format */ int refresh; /**< Desired refresh rate for physical displays. */ - char *output_dev; /**> Path to output device for frontends that require it. */ + char *output_dev; /**> Path to output device for surfaces that require it. */ uint8_t *ptr; /**< Base of video memory. */ int linelen; /**< length of a video line. */ @@ -20,8 +33,8 @@ struct nsfb_s { nsfb_colour_t palette[256]; /**< palette for index modes */ nsfb_cursor_t *cursor; /**< cursor */ - struct nsfb_frontend_rtns_s *frontend_rtns; /**< frontend routines. */ - void *frontend_priv; /**< frontend opaque data. */ + struct nsfb_surface_rtns_s *surface_rtns; /**< surface routines. */ + void *surface_priv; /**< surface opaque data. */ nsfb_bbox_t clip; /**< current clipping rectangle for plotters */ struct nsfb_plotter_fns_s *plotter_fns; /**< Plotter methods */ @@ -29,3 +42,10 @@ struct nsfb_s { #endif + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/include/surface.h b/include/surface.h new file mode 100644 index 0000000..d0c6c5a --- /dev/null +++ b/include/surface.h @@ -0,0 +1,61 @@ +/* libnsfb framebuffer surface support */ + +#include "libnsfb.h" +#include "libnsfb_plot.h" +#include "nsfb.h" + +/* surface default options */ +typedef int (nsfb_fendfn_defaults_t)(nsfb_t *nsfb); + +/* surface init */ +typedef int (nsfb_fendfn_init_t)(nsfb_t *nsfb); + +/* surface finalise */ +typedef int (nsfb_fendfn_fini_t)(nsfb_t *nsfb); + +/* surface set geometry */ +typedef int (nsfb_fendfn_geometry_t)(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format); + +/* surface input */ +typedef bool (nsfb_fendfn_input_t)(nsfb_t *nsfb, nsfb_event_t *event, int timeout); + +/* surface area claim */ +typedef int (nsfb_fendfn_claim_t)(nsfb_t *nsfb, nsfb_bbox_t *box); + +/* surface area update */ +typedef int (nsfb_fendfn_update_t)(nsfb_t *nsfb, nsfb_bbox_t *box); + +/* surface cursor display */ +typedef int (nsfb_fendfn_cursor_t)(nsfb_t *nsfb, struct nsfb_cursor_s *cursor); + +typedef struct nsfb_surface_rtns_s { + nsfb_fendfn_defaults_t *defaults; + nsfb_fendfn_init_t *initialise; + nsfb_fendfn_fini_t *finalise; + nsfb_fendfn_geometry_t *geometry; + nsfb_fendfn_input_t *input; + nsfb_fendfn_claim_t *claim; + nsfb_fendfn_update_t *update; + nsfb_fendfn_cursor_t *cursor; +} nsfb_surface_rtns_t; + +void _nsfb_register_surface(const enum nsfb_type_e type, const nsfb_surface_rtns_t *rtns, const char *name); + + +/* macro which adds a builtin command with no argument limits */ +#define NSFB_SURFACE_DEF(__name, __type, __rtns) \ + static void __name##_register_surface(void) __attribute__((constructor)); \ + void __name##_register_surface(void) { \ + _nsfb_register_surface(__type, __rtns, #__name); \ + } + +/** Obtain routines for a surface + * + * Obtain a vlist of methods for a surface type. + * + * @param type The surface type. + * @return A vtable of routines which teh caller must deallocate or + * NULL on error + */ +nsfb_surface_rtns_t *nsfb_surface_get_rtns(enum nsfb_type_e type); + -- cgit v1.2.1