summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2009-04-08 10:17:09 +0000
committerVincent Sanders <vince@netsurf-browser.org>2009-04-08 10:17:09 +0000
commit056e1ebed94379db41ebb2e40cc88a873cfb4411 (patch)
treed1d01c4b9f9d4c2c2b1db4b705e631d49cf2e6b0 /include
downloadlibnsfb-056e1ebed94379db41ebb2e40cc88a873cfb4411.tar.gz
libnsfb-056e1ebed94379db41ebb2e40cc88a873cfb4411.tar.bz2
initial commit of netsurf framebuffer library
svn path=/trunk/libnsfb/; revision=7060
Diffstat (limited to 'include')
-rw-r--r--include/frontend.h35
-rw-r--r--include/libnsfb.h75
-rw-r--r--include/libnsfb_plot.h72
-rw-r--r--include/nsfb.h30
-rw-r--r--include/nsfb_plot.h88
-rw-r--r--include/plot_util.h24
-rw-r--r--include/plotters.h1
7 files changed, 325 insertions, 0 deletions
diff --git a/include/frontend.h b/include/frontend.h
new file mode 100644
index 0000000..ee76632
--- /dev/null
+++ b/include/frontend.h
@@ -0,0 +1,35 @@
+#include "libnsfb.h" /* exported interface */
+#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 input */
+typedef int (nsfb_fendfn_input_t)(nsfb_t *nsfb);
+/* frontend area claim */
+typedef int (nsfb_fendfn_claim_t)(nsfb_t *nsfb, nsfb_bbox_t *box);
+/* frontend area release */
+typedef int (nsfb_fendfn_release_t)(nsfb_t *nsfb, nsfb_bbox_t *box);
+
+typedef struct nsfb_frontend_rtns_s {
+ nsfb_fendfn_defaults_t *defaults;
+ nsfb_fendfn_init_t *initialise;
+ nsfb_fendfn_fini_t *finalise;
+ nsfb_fendfn_input_t *input;
+ nsfb_fendfn_claim_t *claim;
+ nsfb_fendfn_release_t *release;
+} nsfb_frontend_rtns_t;
+
+void _nsfb_register_frontend(const enum nsfb_frontend_e type, const nsfb_frontend_rtns_t *rtns, const char *name);
+
+nsfb_frontend_rtns_t *nsfb_frontend_get_rtns(enum nsfb_frontend_e type);
+
+/* 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); \
+ }
diff --git a/include/libnsfb.h b/include/libnsfb.h
new file mode 100644
index 0000000..0af8ab3
--- /dev/null
+++ b/include/libnsfb.h
@@ -0,0 +1,75 @@
+#ifndef _LIBNSFB_H
+#define _LIBNSFB_H 1
+
+#include <stdint.h>
+
+typedef struct nsfb_cursor_s nsfb_cursor_t;
+typedef struct nsfb_s nsfb_t;
+typedef uint32_t nsfb_colour_t;
+
+/* bounding box */
+typedef struct nsfb_bbox_s {
+ int x0;
+ int y0;
+ int x1;
+ 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,
+ NSFB_FRONTEND_LINUX,
+ NSFB_FRONTEND_VNC,
+ NSFB_FRONTEND_ABLE,
+ NSFB_FRONTEND_RAM,
+};
+
+/** Initialise nsfb context.
+ *
+ * This initialises a framebuffer context.
+ *
+ * @param frontend The type of frontend to create a context for.
+ */
+nsfb_t *nsfb_init(enum nsfb_frontend_e frontend);
+
+/** Initialise selected frontend.
+ *
+ * @param nsfb The context frturned from ::nsfb_init
+ */
+int nsfb_init_frontend(nsfb_t *nsfb);
+
+/** Process input from a frontend.
+ */
+int nsfb_input(nsfb_t *nsfb);
+
+/** Claim an area of screen to be redrawn.
+ *
+ * Informs the nsfb library that an area of screen will be updated by the user
+ * program, used for soft cursor plotting.
+ *
+ * @param box The bounding box of the area which might be altered.
+ */
+int nsfb_claim(nsfb_t *nsfb, nsfb_bbox_t *box);
+
+/** Release an area of screen which has been redrawn.
+ *
+ * Informs the nsfb library that an area of screen has been updated by the user
+ * program. Some frontends only update on area release.
+ *
+ * @param box The bounding box of the area which has been altered.
+ */
+int nsfb_release(nsfb_t *nsfb, nsfb_bbox_t *box);
+
+/** Obtain the geometry of a nsfb context.
+ *
+ * @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
+ */
+int nsfb_get_geometry(nsfb_t *nsfb, int *width, int *height, int *bpp);
+
+/** Obtain the framebuffer memory base and stride. */
+int nsfb_get_framebuffer(nsfb_t *nsfb, uint8_t **ptr, int *linelen);
+
+#endif
diff --git a/include/libnsfb_plot.h b/include/libnsfb_plot.h
new file mode 100644
index 0000000..64aa729
--- /dev/null
+++ b/include/libnsfb_plot.h
@@ -0,0 +1,72 @@
+/** Sets a clip rectangle for subsequent plots.
+ *
+ * Sets a clipping area which constrains all subsequent plotting operations.
+ * The clipping area must lie within the framebuffer visible screen or false
+ * will be returned and the new clipping area not set.
+ */
+bool nsfb_plot_set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip);
+
+/** Clears plotting area to a flat colour.
+ */
+bool nsfb_plot_clg(nsfb_t *nsfb, nsfb_colour_t c);
+
+/** Plots a rectangle outline.
+ *
+ * The line can be solid, dotted or dashed. Top left corner at (x0,y0) and
+ * rectangle has given width and height.
+ */
+bool nsfb_plot_rectangle(nsfb_t *nsfb, nsfb_bbox_t *rect, int line_width, nsfb_colour_t c, bool dotted, bool dashed);
+
+/** Plots a filled rectangle. Top left corner at (x0,y0), bottom
+ * right corner at (x1,y1). Note: (x0,y0) is inside filled area,
+ * but (x1,y1) is below and to the right. See diagram below.
+ */
+bool nsfb_plot_rectangle_fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c);
+
+/** Plots a line.
+ *
+ * Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line
+ * width/thickness.
+ */
+bool nsfb_plot_line(nsfb_t *nsfb, nsfb_bbox_t *line, int line_width, nsfb_colour_t c, bool dotted, bool dashed);
+
+/** Plots a filled polygon.
+ *
+ * Plots a filled polygon with straight lines between points. The lines around
+ * the edge of the ploygon are not plotted. The polygon is filled with a
+ * non-zero winding rule.
+ *
+ *
+ */
+bool nsfb_plot_polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t fill);
+
+/** Plot an ellipse.
+ */
+bool nsfb_plot_ellipse(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c);
+
+/** Plot a filled ellipse.
+ */
+bool nsfb_plot_ellipse_fill(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c);
+
+/** Plots an arc.
+ *
+ * around (x,y), from anticlockwise from angle1 to angle2. Angles are measured
+ * anticlockwise from horizontal, in degrees.
+ */
+bool nsfb_plot_arc(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle2, nsfb_colour_t c);
+
+/** Plots an alpha blended pixel.
+ *
+ * plots an alpha blended pixel.
+ */
+bool nsfb_plot_point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c);
+
+/** copy an area of screen
+ *
+ * Copy an area of the display.
+ */
+bool nsfb_plot_copy(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int dstx, int dsty);
+
+/** Plot bitmap.
+ */
+bool nsfb_plot_bitmap(nsfb_t *nsfb, nsfb_bbox_t *loc, nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha);
diff --git a/include/nsfb.h b/include/nsfb.h
new file mode 100644
index 0000000..cec4a63
--- /dev/null
+++ b/include/nsfb.h
@@ -0,0 +1,30 @@
+#ifndef _NSFB_H
+#define _NSFB_H 1
+
+#include <stdint.h>
+
+/** NS Framebuffer context
+ */
+struct nsfb_s {
+ int width; /**< Visible width. */
+ int height; /**< Visible height. */
+ int bpp; /**< Bits per pixel. */
+
+ int refresh; /**< Desired refresh rate for physical displays. */
+ char *output_dev; /**> Path to output device for frontends that require it. */
+
+ uint8_t *ptr; /**< Base of video memory. */
+ int linelen; /**< length of a video line. */
+
+ nsfb_colour_t palette[256]; /**< palette for index modes */
+ nsfb_cursor_t *cursor;
+
+ struct nsfb_frontend_rtns_s *frontend_rtns; /**< frontend routines. */
+ void *frontend_priv;
+
+ nsfb_bbox_t clip; /**< current clipping rectangle for plotters */
+ struct nsfb_plotter_fns_s *plotter_fns; /**< Plotter methods */
+};
+
+
+#endif
diff --git a/include/nsfb_plot.h b/include/nsfb_plot.h
new file mode 100644
index 0000000..2dbd22a
--- /dev/null
+++ b/include/nsfb_plot.h
@@ -0,0 +1,88 @@
+
+
+/** Clears plotting area to a flat colour (if needed)
+ */
+typedef bool (nsfb_plotfn_clg_t)(nsfb_t *nsfb, nsfb_colour_t c);
+
+/** Plots a rectangle outline. The line can be solid, dotted or
+ * dashed. Top left corner at (x0,y0) and rectangle has given
+ * width and height.
+ */
+typedef bool (nsfb_plotfn_rectangle_t)(nsfb_t *nsfb, nsfb_bbox_t *rect, int line_width, nsfb_colour_t c, bool dotted, bool dashed);
+
+/** Plots a line from (x0,y0) to (x1,y1). Coordinates are at
+ * centre of line width/thickness.
+ */
+typedef bool (nsfb_plotfn_line_t)(nsfb_t *nsfb, nsfb_bbox_t *line, int line_width, nsfb_colour_t c, bool dotted, bool dashed);
+
+/** Plots a filled polygon with straight lines between points.
+ * The lines around the edge of the ploygon are not plotted. The
+ * polygon is filled with the non-zero winding rule.
+ */
+typedef bool (nsfb_plotfn_polygon_t)(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t fill);
+
+/** Plots a filled rectangle. Top left corner at (x0,y0), bottom
+ * right corner at (x1,y1). Note: (x0,y0) is inside filled area,
+ * but (x1,y1) is below and to the right. See diagram below.
+ */
+typedef bool (nsfb_plotfn_fill_t)(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c);
+
+/** Sets a clip rectangle for subsequent plots.
+ */
+typedef bool (nsfb_plotfn_clip_t)(nsfb_t *nsfb, nsfb_bbox_t *clip);
+
+/** Plots an arc, around (x,y), from anticlockwise from angle1 to
+ * angle2. Angles are measured anticlockwise from horizontal, in
+ * degrees.
+ */
+typedef bool (nsfb_plotfn_arc_t)(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle2, nsfb_colour_t c);
+
+/** Plots a point.
+ *
+ * Plot a single alpha blended pixel.
+ */
+typedef bool (nsfb_plotfn_point_t)(nsfb_t *nsfb, int x, int y, nsfb_colour_t c);
+
+/** Plot an ellipse.
+ *
+ * plot an ellipse outline, note if teh bounding box is square this will plot a
+ * circle.
+ */
+typedef bool (nsfb_plotfn_ellipse_t)(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c);
+
+/** Plot a filled ellipse.
+ *
+ * plot a filled ellipse, note if the bounding box is square this will plot a
+ * circle.
+ */
+typedef bool (nsfb_plotfn_ellipse_fill_t)(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c);
+
+
+/** Plot bitmap
+ */
+typedef bool (nsfb_plotfn_bitmap_t)(nsfb_t *nsfb, nsfb_bbox_t *loc, nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha);
+
+
+/** Copy an area of screen
+ *
+ * Copy an area of the display.
+ */
+typedef bool (nsfb_plotfn_copy_t)(nsfb_t *nsfb, int srcx, int srcy, int width, int height, int dstx, int dsty);
+
+/** plotter function table. */
+typedef struct nsfb_plotter_fns_s {
+ nsfb_plotfn_clg_t *clg;
+ nsfb_plotfn_rectangle_t *rectangle;
+ nsfb_plotfn_line_t *line;
+ nsfb_plotfn_polygon_t *polygon;
+ nsfb_plotfn_fill_t *fill;
+ nsfb_plotfn_clip_t *clip;
+ nsfb_plotfn_ellipse_t *ellipse;
+ nsfb_plotfn_ellipse_fill_t *ellipse_fill;
+ nsfb_plotfn_arc_t *arc;
+ nsfb_plotfn_bitmap_t *bitmap;
+ nsfb_plotfn_point_t *point;
+ nsfb_plotfn_copy_t *copy;
+} nsfb_plotter_fns_t;
+
+
diff --git a/include/plot_util.h b/include/plot_util.h
new file mode 100644
index 0000000..6565cb1
--- /dev/null
+++ b/include/plot_util.h
@@ -0,0 +1,24 @@
+/* alpha blend two pixels together */
+static inline nsfb_colour_t
+nsfb_plot_ablend(nsfb_colour_t pixel, nsfb_colour_t scrpixel)
+{
+ int opacity = pixel >> 24;
+ int transp = 0x100 - opacity;
+ uint32_t rb, g;
+
+ rb = ((pixel & 0xFF00FF) * opacity +
+ (scrpixel & 0xFF00FF) * transp) >> 8;
+ g = ((pixel & 0x00FF00) * opacity +
+ (scrpixel & 0x00FF00) * transp) >> 8;
+
+ return (rb & 0xFF00FF) | (g & 0xFF00);
+}
+
+
+bool nsfb_plot_clip(const nsfb_bbox_t * restrict clip, nsfb_bbox_t * restrict rect);
+
+bool nsfb_plot_clip_ctx(nsfb_t *nsfb, nsfb_bbox_t * restrict rect);
+
+bool nsfb_plot_clip_line(const nsfb_bbox_t * restrict clip, nsfb_bbox_t * restrict line);
+
+bool nsfb_plot_clip_line_ctx(nsfb_t *nsfb, nsfb_bbox_t * restrict line);
diff --git a/include/plotters.h b/include/plotters.h
new file mode 100644
index 0000000..dc4648b
--- /dev/null
+++ b/include/plotters.h
@@ -0,0 +1 @@
+bool select_plotters(nsfb_t *nsfb);