summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING20
-rw-r--r--Makefile2
-rw-r--r--README45
-rw-r--r--src/cursor.c8
-rw-r--r--src/nsfb.h3
-rw-r--r--src/plot/generic.c10
-rw-r--r--src/surface/ram.c37
-rw-r--r--src/surface/wld.c26
-rw-r--r--src/surface/x.c17
9 files changed, 145 insertions, 23 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..a90a8a7
--- a/dev/null
+++ b/COPYING
@@ -0,0 +1,20 @@
+Copyright (C) 2009-2016 Vincent Sanders <vince@netsurf-browser.org>
+Copyright (C) 2009-2016 Michael Drake <tlsa@netsurf-browser.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/Makefile b/Makefile
index d669bae..fed9b5d 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
# Component settings
COMPONENT := nsfb
-COMPONENT_VERSION := 0.1.5
+COMPONENT_VERSION := 0.1.6
# Default to a static library
COMPONENT_TYPE ?= lib-static
diff --git a/README b/README
new file mode 100644
index 0000000..732e850
--- a/dev/null
+++ b/README
@@ -0,0 +1,45 @@
+Libnsfb - NetSurf Framebuffer Library
+=====================================
+
+Overview
+--------
+
+ Libnsfb is a framebuffer drawing library with a simple interface,
+ providing a consistent API across a number of framebuffer implementations.
+
+Requirements
+------------
+
+ Libnsfb requires the following tools:
+
+ + A C99 capable C compiler
+ + GNU make or compatible
+ + Pkg-config
+
+ Libnsfb also requires the following libraries to be installed:
+
+ + SDL 1.2 (for the SDL backend)
+ + libxcb* (for the X11 backend)
+
+Compilation
+-----------
+
+ If necessary, modify the toolchain settings in the Makefile.
+ Invoke make:
+ $ make
+
+Verification
+------------
+
+ To verify that the parser is working, it is necessary to specify a
+ different makefile target than that used for normal compilation, thus:
+
+ $ make test
+
+API documentation
+-----------------
+
+ Currently, there is none. However, the code is well commented and the
+ public API may be found in the "include" directory. The testcase sources
+ may also be of use in working out how to use it.
+
diff --git a/src/cursor.c b/src/cursor.c
index 87633dc..1f107a5 100644
--- a/src/cursor.c
+++ b/src/cursor.c
@@ -99,7 +99,13 @@ bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
sav_size = cursor->sav_width * cursor->sav_height * sizeof(nsfb_colour_t);
if (cursor->sav_size < sav_size) {
- cursor->sav = realloc(cursor->sav, sav_size);
+ nsfb_colour_t *nsav;
+
+ nsav = realloc(cursor->sav, sav_size);
+ if (nsav == NULL) {
+ return false;
+ }
+ cursor->sav = nsav;
cursor->sav_size = sav_size;
}
diff --git a/src/nsfb.h b/src/nsfb.h
index 9a61775..73f6678 100644
--- a/src/nsfb.h
+++ b/src/nsfb.h
@@ -14,7 +14,8 @@
#include <stdint.h>
-/** NS Framebuffer context
+/**
+ * Framebuffer context
*/
struct nsfb_s {
int width; /**< Visible width. */
diff --git a/src/plot/generic.c b/src/plot/generic.c
index 0c3d9e8..a6dd549 100644
--- a/src/plot/generic.c
+++ b/src/plot/generic.c
@@ -799,6 +799,9 @@ path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen)
/* allocate storage for the vertexes */
curpt = pts = malloc(ptc * sizeof(nsfb_point_t));
+ if (curpt == NULL) {
+ return false;
+ }
for (path_loop = 0; path_loop < pathc; path_loop++) {
switch (pathop[path_loop].operation) {
@@ -906,10 +909,15 @@ bool select_plotters(nsfb_t *nsfb)
return false;
}
- if (nsfb->plotter_fns != NULL)
+ if (nsfb->plotter_fns != NULL) {
free(nsfb->plotter_fns);
+ }
nsfb->plotter_fns = calloc(1, sizeof(nsfb_plotter_fns_t));
+ if (nsfb->plotter_fns == NULL) {
+ return false;
+ }
+
memcpy(nsfb->plotter_fns, table, sizeof(nsfb_plotter_fns_t));
/* set the generics */
diff --git a/src/surface/ram.c b/src/surface/ram.c
index 4deabda..da769b6 100644
--- a/src/surface/ram.c
+++ b/src/surface/ram.c
@@ -35,19 +35,35 @@ static int ram_defaults(nsfb_t *nsfb)
static int ram_initialise(nsfb_t *nsfb)
{
- size_t size = (nsfb->width * nsfb->height * nsfb->bpp) / 8;
+ size_t size;
+ uint8_t *fbptr;
- nsfb->ptr = realloc(nsfb->ptr, size);
+ size = (nsfb->width * nsfb->height * nsfb->bpp) / 8;
+ fbptr = realloc(nsfb->ptr, size);
+ if (fbptr == NULL) {
+ return -1;
+ }
+
+ nsfb->ptr = fbptr;
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)
+static int
+ram_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format)
{
int startsize;
int endsize;
+ int prev_width;
+ int prev_height;
+ enum nsfb_format_e prev_format;
+
+ prev_width = nsfb->width;
+ prev_height = nsfb->height;
+ prev_format = nsfb->format;
+
startsize = (nsfb->width * nsfb->height * nsfb->bpp) / 8;
if (width > 0) {
@@ -65,10 +81,23 @@ static int ram_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_forma
/* select soft plotters appropriate for format */
select_plotters(nsfb);
+ /* reallocate surface memory if necessary */
endsize = (nsfb->width * nsfb->height * nsfb->bpp) / 8;
if ((nsfb->ptr != NULL) && (startsize != endsize)) {
- nsfb->ptr = realloc(nsfb->ptr, endsize);
+ uint8_t *fbptr;
+ fbptr = realloc(nsfb->ptr, endsize);
+ if (fbptr == NULL) {
+ /* allocation failed so put everything back as it was */
+ nsfb->width = prev_width;
+ nsfb->height = prev_height;
+ nsfb->format = prev_format;
+ select_plotters(nsfb);
+
+ return -1;
+ }
+ nsfb->ptr = fbptr;
}
+
nsfb->linelen = (nsfb->width * nsfb->bpp) / 8;
return 0;
diff --git a/src/surface/wld.c b/src/surface/wld.c
index 29f9ae2..9ef3c40 100644
--- a/src/surface/wld.c
+++ b/src/surface/wld.c
@@ -48,7 +48,7 @@ struct wld_connection {
struct wl_display *display; /**< connection object */
struct wl_registry *registry; /**< registry object */
- /** compositor object, available once teh registry messages have
+ /** compositor object, available once the registry messages have
* been processed
*/
struct wl_compositor *compositor;
@@ -975,13 +975,14 @@ pointer_handle_motion(void *data,
UNUSED(time);
event = calloc(1, sizeof(struct wld_event));
+ if (event != NULL) {
+ event->event.type = NSFB_EVENT_MOVE_ABSOLUTE;
+ event->event.value.vector.x = wl_fixed_to_int(sx_w);
+ event->event.value.vector.y = wl_fixed_to_int(sy_w);
+ event->event.value.vector.z = 0;
- event->event.type = NSFB_EVENT_MOVE_ABSOLUTE;
- event->event.value.vector.x = wl_fixed_to_int(sx_w);
- event->event.value.vector.y = wl_fixed_to_int(sy_w);
- event->event.value.vector.z = 0;
-
- enqueue_wld_event(input->connection, event);
+ enqueue_wld_event(input->connection, event);
+ }
}
static void
@@ -997,7 +998,9 @@ pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
UNUSED(time);
event = calloc(1, sizeof(struct wld_event));
-
+ if (event == NULL) {
+ return;
+ }
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
event->event.type = NSFB_EVENT_KEY_DOWN;
} else {
@@ -1259,7 +1262,6 @@ new_connection(void)
struct wld_connection* connection;
connection = calloc(1, sizeof(struct wld_connection));
-
if (connection == NULL) {
return NULL;
}
@@ -1456,8 +1458,9 @@ os_create_anonymous_file(off_t size)
}
name = malloc(strlen(path) + sizeof(template));
- if (!name)
+ if (name == NULL) {
return -1;
+ }
strcpy(name, path);
strcat(name, template);
@@ -1657,8 +1660,9 @@ static int x_initialise(nsfb_t *nsfb)
return -1;
xstate = calloc(1, sizeof(xstate_t));
- if (xstate == NULL)
+ if (xstate == NULL) {
return -1; /* no memory */
+ }
/* open connection with the server */
xstate->connection = xcb_connect(NULL, NULL);
diff --git a/src/surface/x.c b/src/surface/x.c
index f5ee01b..c011b38 100644
--- a/src/surface/x.c
+++ b/src/surface/x.c
@@ -846,10 +846,19 @@ static int x_initialise(nsfb_t *nsfb)
mask, values);
/* set size hits on window */
hints = xcb_alloc_size_hints();
- xcb_size_hints_set_max_size(hints, xstate->image->width, xstate->image->height);
- xcb_size_hints_set_min_size(hints, xstate->image->width, xstate->image->height);
- xcb_set_wm_size_hints(xstate->connection, xstate->window, WM_NORMAL_HINTS, hints);
- xcb_free_size_hints(hints);
+ if (hints != NULL) {
+ xcb_size_hints_set_max_size(hints,
+ xstate->image->width,
+ xstate->image->height);
+ xcb_size_hints_set_min_size(hints,
+ xstate->image->width,
+ xstate->image->height);
+ xcb_set_wm_size_hints(xstate->connection,
+ xstate->window,
+ WM_NORMAL_HINTS,
+ hints);
+ xcb_free_size_hints(hints);
+ }
/* create backing pixmap */
xstate->pmap = xcb_generate_id(xstate->connection);