summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING20
-rw-r--r--Makefile10
-rw-r--r--README47
-rw-r--r--src/cursor.c8
-rw-r--r--src/nsfb.h3
-rw-r--r--src/plot/common.c2
-rw-r--r--src/plot/generic.c1369
-rw-r--r--src/surface/Makefile2
-rw-r--r--src/surface/able.c59
-rw-r--r--src/surface/linux.c272
-rw-r--r--src/surface/ram.c37
-rw-r--r--src/surface/wld.c42
-rw-r--r--src/surface/x.c17
-rw-r--r--test/polystar.c5
-rw-r--r--test/polystar2.c5
15 files changed, 853 insertions, 1045 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..a90a8a7
--- /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..f956e6a 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
@@ -48,14 +48,6 @@ $(eval $(call pkg_config_package_available,NSFB_SDL_AVAILABLE,sdl))
$(eval $(call pkg_config_package_available,NSFB_XCB_AVAILABLE,$(NSFB_XCB_PKG_NAMES)))
$(eval $(call pkg_config_package_available,NSFB_WLD_AVAILABLE,wayland-client))
-# surfaces not detectable via pkg-config
-NSFB_ABLE_AVAILABLE := no
-ifeq ($(findstring linux,$(HOST)),linux)
- NSFB_LINUX_AVAILABLE := yes
-else
- NSFB_LINUX_AVAILABLE := no
-endif
-
# Flags and setup for each support library
ifeq ($(NSFB_SDL_AVAILABLE),yes)
$(eval $(call pkg_config_package_add_flags,sdl,CFLAGS))
diff --git a/README b/README
new file mode 100644
index 0000000..b4a1685
--- /dev/null
+++ b/README
@@ -0,0 +1,47 @@
+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
+
+ The following libraries may also be installed:
+
+ + SDL 1.2 (for the SDL surface)
+ + libxcb* (for the X11 surface)
+ * wayland-client (for wayland surface)
+ * libvncserver (for vnc surface)
+
+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/common.c b/src/plot/common.c
index b051131..5f55686 100644
--- a/src/plot/common.c
+++ b/src/plot/common.c
@@ -213,7 +213,7 @@ glyph8(nsfb_t *nsfb,
for (yloop = 0; yloop < height; yloop++) {
for (xloop = 0; xloop < width; xloop++) {
- abpixel = (pixel[((yoff + yloop) * pitch) + xloop + xoff] << 24) | fgcol;
+ abpixel = ((unsigned)pixel[((yoff + yloop) * pitch) + xloop + xoff] << 24) | fgcol;
if ((abpixel & 0xFF000000) != 0) {
/* pixel is not transparent */
if ((abpixel & 0xFF000000) != 0xFF000000) {
diff --git a/src/plot/generic.c b/src/plot/generic.c
index 0c3d9e8..ea0bb04 100644
--- a/src/plot/generic.c
+++ b/src/plot/generic.c
@@ -33,34 +33,34 @@ extern const nsfb_plotter_fns_t _nsfb_32bpp_xbgr8888_plotters;
static bool set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
{
- nsfb_bbox_t fbarea;
-
- /* screen area */
- fbarea.x0 = 0;
- fbarea.y0 = 0;
- fbarea.x1 = nsfb->width;
- fbarea.y1 = nsfb->height;
-
- if (clip == NULL) {
- nsfb->clip = fbarea;
- } else {
- if (!nsfb_plot_clip(&fbarea, clip))
- return false;
-
- nsfb->clip = *clip;
- }
- return true;
+ nsfb_bbox_t fbarea;
+
+ /* screen area */
+ fbarea.x0 = 0;
+ fbarea.y0 = 0;
+ fbarea.x1 = nsfb->width;
+ fbarea.y1 = nsfb->height;
+
+ if (clip == NULL) {
+ nsfb->clip = fbarea;
+ } else {
+ if (!nsfb_plot_clip(&fbarea, clip))
+ return false;
+
+ nsfb->clip = *clip;
+ }
+ return true;
}
static bool get_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
{
- *clip = nsfb->clip;
- return true;
+ *clip = nsfb->clip;
+ return true;
}
static bool clg(nsfb_t *nsfb, nsfb_colour_t c)
{
- return nsfb->plotter_fns->fill(nsfb, &nsfb->clip, c);
+ return nsfb->plotter_fns->fill(nsfb, &nsfb->clip, c);
}
/**
@@ -98,20 +98,20 @@ static bool clg(nsfb_t *nsfb, nsfb_colour_t c)
* evenness of the total.
*/
static bool establish_crossing_value(int x, int y, int x0, int y0,
- int x1, int y1)
+ int x1, int y1)
{
- bool v1 = (x == x0 && y == y0); /* whether we're crossing 1st vertex */
- bool v2 = (x == x1 && y == y1); /* whether we're crossing 2nd vertex */
+ bool v1 = (x == x0 && y == y0); /* whether we're crossing 1st vertex */
+ bool v2 = (x == x1 && y == y1); /* whether we're crossing 2nd vertex */
- if ((v1 && (y0 < y1)) || (v2 && (y1 < y0))) {
- /* crossing top vertex */
- return true;
- } else if (!v1 && !v2) {
- /* Intersection with current y level is not at a vertex.
- * Normal crossing. */
- return true;
- }
- return false;
+ if ((v1 && (y0 < y1)) || (v2 && (y1 < y0))) {
+ /* crossing top vertex */
+ return true;
+ } else if (!v1 && !v2) {
+ /* Intersection with current y level is not at a vertex.
+ * Normal crossing. */
+ return true;
+ }
+ return false;
}
@@ -128,125 +128,128 @@ static bool establish_crossing_value(int x, int y, int x0, int y0,
*/
static bool find_span(const int *p, int n, int x, int y, int *x0, int *x1)
{
- int i;
- int p_x0, p_y0;
- int p_x1, p_y1;
- int x0_min, x1_min;
- int x_new;
- unsigned int x0c, x1c; /* counters for crossings at span end points */
- bool crossing_value;
- bool found_span_start = false;
-
- x0_min = x1_min = INT_MIN;
- x0c = x1c = 0;
- *x0 = *x1 = INT_MAX;
-
- /* search row for next span, returning it if one exists */
- do {
- /* reset endpoint info, if valid span endpoints not found */
- if (!found_span_start)
- *x0 = INT_MAX;
- *x1 = INT_MAX;
-
- /* search all lines in polygon */
- for (i = 0; i < n; i = i + 2) {
- /* get line endpoints */
- if (i != n - 2) {
- /* not the last line */
- p_x0 = p[i]; p_y0 = p[i + 1];
- p_x1 = p[i + 2]; p_y1 = p[i + 3];
- } else {
- /* last line; 2nd endpoint is first vertex */
- p_x0 = p[i]; p_y0 = p[i + 1];
- p_x1 = p[0]; p_y1 = p[1];
- }
- /* ignore horizontal lines */
- if (p_y0 == p_y1)
- continue;
-
- /* ignore lines that don't cross this y level */
- if ((y < p_y0 && y < p_y1) || (y > p_y0 && y > p_y1))
- continue;
-
- if (p_x0 == p_x1) {
- /* vertical line, x is constant */
- x_new = p_x0;
- } else {
- /* find crossing (intersection of this line and
- * current y level) */
- int num = (y - p_y0) * (p_x1 - p_x0);
- int den = (p_y1 - p_y0);
-
- /* To round to nearest (rather than down)
- * half the denominator is either added to
- * or subtracted from the numerator,
- * depending on whether the numerator and
- * denominator have the same sign. */
- num = ((num < 0) == (den < 0)) ?
- num + (den / 2) :
- num - (den / 2);
- x_new = p_x0 + num / den;
- }
-
- /* ignore crossings before current x */
- if (x_new < x ||
- (!found_span_start && x_new < x0_min) ||
- (found_span_start && x_new < x1_min))
- continue;
-
- crossing_value = establish_crossing_value(x_new, y,
- p_x0, p_y0, p_x1, p_y1);
-
-
- /* set nearest intersections as filled area endpoints */
- if (!found_span_start &&
- x_new < *x0 && crossing_value) {
- /* nearer than first endpoint */
- *x1 = *x0;
- x1c = x0c;
- *x0 = x_new;
- x0c = 1;
- } else if (!found_span_start &&
- x_new == *x0 && crossing_value) {
- /* same as first endpoint */
- x0c++;
- } else if (x_new < *x1 && crossing_value) {
- /* nearer than second endpoint */
- *x1 = x_new;
- x1c = 1;
- } else if (x_new == *x1 && crossing_value) {
- /* same as second endpoint */
- x1c++;
- }
- }
- /* check whether the span endpoints have been found */
- if (!found_span_start && x0c % 2 == 1) {
- /* valid fill start found */
- found_span_start = true;
-
- }
- if (x1c % 2 == 1) {
- /* valid fill endpoint found */
- if (!found_span_start) {
- /* not got a start yet; use this as start */
- found_span_start = true;
- x0c = x1c;
- *x0 = *x1;
- } else {
- /* got valid end of span */
- return true;
- }
- }
- /* if current positions aren't valid endpoints, set new
- * minimums after current positions */
- if (!found_span_start)
- x0_min = *x0 + 1;
- x1_min = *x1 + 1;
-
- } while (*x1 != INT_MAX);
-
- /* no spans found */
- return false;
+ enum {
+ NO_MIN = INT_MIN + 1,
+ NO_MAX = INT_MAX - 1,
+ };
+ int i;
+ int p_x0, p_y0;
+ int p_x1, p_y1;
+ int x0_min, x1_min;
+ int x_new;
+ unsigned int x0c, x1c; /* counters for crossings at span end points */
+ bool crossing_value;
+ bool found_span_start = false;
+
+ x0_min = x1_min = NO_MIN;
+ x0c = x1c = 0;
+
+ /* search row for next span, returning it if one exists */
+ do {
+ /* reset endpoint info, if valid span endpoints not found */
+ if (!found_span_start) {
+ *x0 = NO_MAX;
+ }
+ *x1 = NO_MAX;
+
+ /* search all lines in polygon */
+ for (i = 0; i < n; i = i + 2) {
+ /* get line endpoints */
+ if (i != n - 2) {
+ /* not the last line */
+ p_x0 = p[i]; p_y0 = p[i + 1];
+ p_x1 = p[i + 2]; p_y1 = p[i + 3];
+ } else {
+ /* last line; 2nd endpoint is first vertex */
+ p_x0 = p[i]; p_y0 = p[i + 1];
+ p_x1 = p[0]; p_y1 = p[1];
+ }
+ /* ignore horizontal lines */
+ if (p_y0 == p_y1)
+ continue;
+
+ /* ignore lines that don't cross this y level */
+ if ((y < p_y0 && y < p_y1) || (y > p_y0 && y > p_y1))
+ continue;
+
+ if (p_x0 == p_x1) {
+ /* vertical line, x is constant */
+ x_new = p_x0;
+ } else {
+ /* find crossing (intersection of this line and
+ * current y level) */
+ int num = (y - p_y0) * (p_x1 - p_x0);
+ int den = (p_y1 - p_y0);
+
+ /* To round to nearest (rather than down)
+ * half the denominator is either added to
+ * or subtracted from the numerator,
+ * depending on whether the numerator and
+ * denominator have the same sign. */
+ num = ((num < 0) == (den < 0)) ?
+ num + (den / 2) :
+ num - (den / 2);
+ x_new = p_x0 + num / den;
+ }
+
+ /* ignore crossings before current x */
+ if (x_new < x ||
+ (!found_span_start && x_new < x0_min) ||
+ (found_span_start && x_new < x1_min))
+ continue;
+
+ crossing_value = establish_crossing_value(x_new, y,
+ p_x0, p_y0, p_x1, p_y1);
+
+ /* set nearest intersections as filled area endpoints */
+ if (!found_span_start &&
+ x_new < *x0 && crossing_value) {
+ /* nearer than first endpoint */
+ *x1 = *x0;
+ x1c = x0c;
+ *x0 = x_new;
+ x0c = 1;
+ } else if (!found_span_start &&
+ x_new == *x0 && crossing_value) {
+ /* same as first endpoint */
+ x0c++;
+ } else if (x_new < *x1 && crossing_value) {
+ /* nearer than second endpoint */
+ *x1 = x_new;
+ x1c = 1;
+ } else if (x_new == *x1 && crossing_value) {
+ /* same as second endpoint */
+ x1c++;
+ }
+ }
+ /* check whether the span endpoints have been found */
+ if (!found_span_start && x0c % 2 == 1) {
+ /* valid fill start found */
+ found_span_start = true;
+
+ }
+ if (x1c % 2 == 1) {
+ /* valid fill endpoint found */
+ if (!found_span_start) {
+ /* not got a start yet; use this as start */
+ found_span_start = true;
+ x0c = x1c;
+ *x0 = *x1;
+ } else {
+ /* got valid end of span */
+ return true;
+ }
+ }
+ /* if current positions aren't valid endpoints, set new
+ * minimums after current positions */
+ if (!found_span_start)
+ x0_min = *x0 + 1;
+ x1_min = *x1 + 1;
+
+ } while (*x1 != NO_MAX);
+
+ /* no spans found */
+ return false;
}
@@ -261,87 +264,87 @@ static bool find_span(const int *p, int n, int x, int y, int *x0, int *x1)
*/
static bool polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t c)
{
- int poly_x0, poly_y0; /* Bounding box top left corner */
- int poly_x1, poly_y1; /* Bounding box bottom right corner */
- int i, j; /* indexes */
- int x0, x1; /* filled span extents */
- int y; /* current y coordinate */
- int y_max; /* bottom of plot area */
- nsfb_bbox_t fline;
- nsfb_plot_pen_t pen;
-
- /* find no. of vertex values */
- int v = n * 2;
-
- /* Can't plot polygons with 2 or fewer vertices */
- if (n <= 2)
- return true;
-
- pen.stroke_colour = c;
-
- /* Find polygon bounding box */
- poly_x0 = poly_x1 = *p;
- poly_y0 = poly_y1 = p[1];
- for (i = 2; i < v; i = i + 2) {
- j = i + 1;
- if (p[i] < poly_x0)
- poly_x0 = p[i];
- else if (p[i] > poly_x1)
- poly_x1 = p[i];
- if (p[j] < poly_y0)
- poly_y0 = p[j];
- else if (p[j] > poly_y1)
- poly_y1 = p[j];
- }
-
- /* Don't try to plot it if it's outside the clip rectangle */
- if (nsfb->clip.y1 < poly_y0 ||
- nsfb->clip.y0 > poly_y1 ||
- nsfb->clip.x1 < poly_x0 ||
- nsfb->clip.x0 > poly_x1)
- return true;
-
- /* Find the top of the important area */
- if (poly_y0 > nsfb->clip.y0)
- y = poly_y0;
- else
- y = nsfb->clip.y0;
-
- /* Find the bottom of the important area */
- if (poly_y1 < nsfb->clip.y1)
- y_max = poly_y1;
- else
- y_max = nsfb->clip.y1;
-
- for (; y < y_max; y++) {
- x1 = poly_x0 - 1;
- /* For each row */
- while (find_span(p, v, x1 + 1, y, &x0, &x1)) {
- /* don't draw anything outside clip region */
- if (x1 < nsfb->clip.x0)
- continue;
- else if (x0 < nsfb->clip.x0)
- x0 = nsfb->clip.x0;
- if (x0 > nsfb->clip.x1)
- break;
- else if (x1 > nsfb->clip.x1)
- x1 = nsfb->clip.x1;
+ int poly_x0, poly_y0; /* Bounding box top left corner */
+ int poly_x1, poly_y1; /* Bounding box bottom right corner */
+ int i, j; /* indexes */
+ int x0, x1; /* filled span extents */
+ int y; /* current y coordinate */
+ int y_max; /* bottom of plot area */
+ nsfb_bbox_t fline;
+ nsfb_plot_pen_t pen;
+
+ /* find no. of vertex values */
+ int v = n * 2;
+
+ /* Can't plot polygons with 2 or fewer vertices */
+ if (n <= 2)
+ return true;
- fline.x0 = x0;
- fline.y0 = y;
- fline.x1 = x1;
- fline.y1 = y;
+ pen.stroke_colour = c;
+
+ /* Find polygon bounding box */
+ poly_x0 = poly_x1 = *p;
+ poly_y0 = poly_y1 = p[1];
+ for (i = 2; i < v; i = i + 2) {
+ j = i + 1;
+ if (p[i] < poly_x0)
+ poly_x0 = p[i];
+ else if (p[i] > poly_x1)
+ poly_x1 = p[i];
+ if (p[j] < poly_y0)
+ poly_y0 = p[j];
+ else if (p[j] > poly_y1)
+ poly_y1 = p[j];
+ }
- /* draw this filled span on current row */
- nsfb->plotter_fns->line(nsfb, 1, &fline, &pen);
+ /* Don't try to plot it if it's outside the clip rectangle */
+ if (nsfb->clip.y1 < poly_y0 ||
+ nsfb->clip.y0 > poly_y1 ||
+ nsfb->clip.x1 < poly_x0 ||
+ nsfb->clip.x0 > poly_x1)
+ return true;
- /* don't look for more spans if already at end of clip
- * region or polygon */
- if (x1 == nsfb->clip.x1 || x1 == poly_x1)
- break;
+ /* Find the top of the important area */
+ if (poly_y0 > nsfb->clip.y0)
+ y = poly_y0;
+ else
+ y = nsfb->clip.y0;
+
+ /* Find the bottom of the important area */
+ if (poly_y1 < nsfb->clip.y1)
+ y_max = poly_y1;
+ else
+ y_max = nsfb->clip.y1;
+
+ for (; y < y_max; y++) {
+ x1 = poly_x0 - 1;
+ /* For each row */
+ while (find_span(p, v, x1 + 1, y, &x0, &x1)) {
+ /* don't draw anything outside clip region */
+ if (x1 < nsfb->clip.x0)
+ continue;
+ else if (x0 < nsfb->clip.x0)
+ x0 = nsfb->clip.x0;
+ if (x0 > nsfb->clip.x1)
+ break;
+ else if (x1 > nsfb->clip.x1)
+ x1 = nsfb->clip.x1;
+
+ fline.x0 = x0;
+ fline.y0 = y;
+ fline.x1 = x1;
+ fline.y1 = y;
+
+ /* draw this filled span on current row */
+ nsfb->plotter_fns->line(nsfb, 1, &fline, &pen);
+
+ /* don't look for more spans if already at end of clip
+ * region or polygon */
+ if (x1 == nsfb->clip.x1 || x1 == poly_x1)
+ break;
+ }
}
- }
- return true;
+ return true;
}
static bool
@@ -349,54 +352,54 @@ rectangle(nsfb_t *nsfb, nsfb_bbox_t *rect,
int line_width, nsfb_colour_t c,
bool dotted, bool dashed)
{
- nsfb_bbox_t side[4];
- nsfb_plot_pen_t pen;
-
- pen.stroke_colour = c;
- pen.stroke_width = line_width;
- if (dotted || dashed) {
- pen.stroke_type = NFSB_PLOT_OPTYPE_PATTERN;
- } else {
- pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
- }
-
- side[0] = *rect;
- side[1] = *rect;
- side[2] = *rect;
- side[3] = *rect;
-
- side[0].y1 = side[0].y0;
- side[1].y0 = side[1].y1;
- side[2].x1 = side[2].x0;
- side[3].x0 = side[3].x1;
-
- return nsfb->plotter_fns->line(nsfb, 4, side, &pen);
+ nsfb_bbox_t side[4];
+ nsfb_plot_pen_t pen;
+
+ pen.stroke_colour = c;
+ pen.stroke_width = line_width;
+ if (dotted || dashed) {
+ pen.stroke_type = NFSB_PLOT_OPTYPE_PATTERN;
+ } else {
+ pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
+ }
+
+ side[0] = *rect;
+ side[1] = *rect;
+ side[2] = *rect;
+ side[3] = *rect;
+
+ side[0].y1 = side[0].y0;
+ side[1].y0 = side[1].y1;
+ side[2].x1 = side[2].x0;
+ side[3].x0 = side[3].x1;
+
+ return nsfb->plotter_fns->line(nsfb, 4, side, &pen);
}
/* plotter routine for ellipse points */
static void
ellipsepoints(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c)
{
- nsfb->plotter_fns->point(nsfb, cx + x, cy + y, c);
- nsfb->plotter_fns->point(nsfb, cx - x, cy + y, c);
- nsfb->plotter_fns->point(nsfb, cx + x, cy - y, c);
- nsfb->plotter_fns->point(nsfb, cx - x, cy - y, c);
+ nsfb->plotter_fns->point(nsfb, cx + x, cy + y, c);
+ nsfb->plotter_fns->point(nsfb, cx - x, cy + y, c);
+ nsfb->plotter_fns->point(nsfb, cx + x, cy - y, c);
+ nsfb->plotter_fns->point(nsfb, cx - x, cy - y, c);
}
static void
ellipsefill(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c)
{
- nsfb_bbox_t fline[2];
- nsfb_plot_pen_t pen;
+ nsfb_bbox_t fline[2];
+ nsfb_plot_pen_t pen;
- pen.stroke_colour = c;
+ pen.stroke_colour = c;
- fline[0].x0 = fline[1].x0 = cx - x;
- fline[0].x1 = fline[1].x1 = cx + x;
- fline[0].y0 = fline[0].y1 = cy + y;
- fline[1].y0 = fline[1].y1 = cy - y;
+ fline[0].x0 = fline[1].x0 = cx - x;
+ fline[0].x1 = fline[1].x1 = cx + x;
+ fline[0].y0 = fline[0].y1 = cy + y;
+ fline[1].y0 = fline[1].y1 = cy - y;
- nsfb->plotter_fns->line(nsfb, 2, fline, &pen);
+ nsfb->plotter_fns->line(nsfb, 2, fline, &pen);
}
@@ -411,48 +414,48 @@ ellipse_midpoint(nsfb_t *nsfb,
nsfb_colour_t c,
void (ellipsefn)(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c))
{
- int rx2 = rx * rx;
- int ry2 = ry * ry;
- int tworx2 = 2 * rx2;
- int twory2 = 2 * ry2;
- int p;
- int x = 0;
- int y = ry;
- int px = 0;
- int py = tworx2 * y;
-
- ellipsefn(nsfb, cx, cy, x, y, c);
-
- /* region 1 */
- p = ROUND(ry2 - (rx2 * ry) + (0.25 * rx2));
- while (px < py) {
- x++;
- px += twory2;
- if (p <0) {
- p+=ry2 + px;
- } else {
- y--;
- py -= tworx2;
- p+=ry2 + px - py;
- }
- ellipsefn(nsfb, cx, cy, x, y, c);
- }
-
- /* region 2 */
- p = ROUND(ry2*(x+0.5)*(x+0.5) + rx2*(y-1)*(y-1) - rx2*ry2);
- while (y > 0) {
- y--;
- py -= tworx2;
- if (p > 0) {
- p+=rx2 - py;
- } else {
- x++;
- px += twory2;
- p+=rx2 - py + px;
- }
- ellipsefn(nsfb, cx, cy, x, y, c);
- }
- return true;
+ int rx2 = rx * rx;
+ int ry2 = ry * ry;
+ int tworx2 = 2 * rx2;
+ int twory2 = 2 * ry2;
+ int p;
+ int x = 0;
+ int y = ry;
+ int px = 0;
+ int py = tworx2 * y;
+
+ ellipsefn(nsfb, cx, cy, x, y, c);
+
+ /* region 1 */
+ p = ROUND(ry2 - (rx2 * ry) + (0.25 * rx2));
+ while (px < py) {
+ x++;
+ px += twory2;
+ if (p <0) {
+ p+=ry2 + px;
+ } else {
+ y--;
+ py -= tworx2;
+ p+=ry2 + px - py;
+ }
+ ellipsefn(nsfb, cx, cy, x, y, c);
+ }
+
+ /* region 2 */
+ p = ROUND(ry2*(x+0.5)*(x+0.5) + rx2*(y-1)*(y-1) - rx2*ry2);
+ while (y > 0) {
+ y--;
+ py -= tworx2;
+ if (p > 0) {
+ p+=rx2 - py;
+ } else {
+ x++;
+ px += twory2;
+ p+=rx2 - py + px;
+ }
+ ellipsefn(nsfb, cx, cy, x, y, c);
+ }
+ return true;
}
@@ -460,86 +463,92 @@ ellipse_midpoint(nsfb_t *nsfb,
static void
circlepoints(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c)
{
- nsfb->plotter_fns->point(nsfb, cx + x, cy + y, c);
- nsfb->plotter_fns->point(nsfb, cx - x, cy + y, c);
- nsfb->plotter_fns->point(nsfb, cx + x, cy - y, c);
- nsfb->plotter_fns->point(nsfb, cx - x, cy - y, c);
- nsfb->plotter_fns->point(nsfb, cx + y, cy + x, c);
- nsfb->plotter_fns->point(nsfb, cx - y, cy + x, c);
- nsfb->plotter_fns->point(nsfb, cx + y, cy - x, c);
- nsfb->plotter_fns->point(nsfb, cx - y, cy - x, c);
+ nsfb->plotter_fns->point(nsfb, cx + x, cy + y, c);
+ nsfb->plotter_fns->point(nsfb, cx - x, cy + y, c);
+ nsfb->plotter_fns->point(nsfb, cx + x, cy - y, c);
+ nsfb->plotter_fns->point(nsfb, cx - x, cy - y, c);
+ nsfb->plotter_fns->point(nsfb, cx + y, cy + x, c);
+ nsfb->plotter_fns->point(nsfb, cx - y, cy + x, c);
+ nsfb->plotter_fns->point(nsfb, cx + y, cy - x, c);
+ nsfb->plotter_fns->point(nsfb, cx - y, cy - x, c);
}
static void
circlefill(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c)
{
- nsfb_bbox_t fline[4];
- nsfb_plot_pen_t pen;
+ nsfb_bbox_t fline[4];
+ nsfb_plot_pen_t pen;
- pen.stroke_colour = c;
+ pen.stroke_colour = c;
- fline[0].x0 = fline[1].x0 = cx - x;
- fline[0].x1 = fline[1].x1 = cx + x;
- fline[0].y0 = fline[0].y1 = cy + y;
- fline[1].y0 = fline[1].y1 = cy - y;
+ fline[0].x0 = fline[1].x0 = cx - x;
+ fline[0].x1 = fline[1].x1 = cx + x;
+ fline[0].y0 = fline[0].y1 = cy + y;
+ fline[1].y0 = fline[1].y1 = cy - y;
- fline[2].x0 = fline[3].x0 = cx - y;
- fline[2].x1 = fline[3].x1 = cx + y;
- fline[2].y0 = fline[2].y1 = cy + x;
- fline[3].y0 = fline[3].y1 = cy - x;
+ fline[2].x0 = fline[3].x0 = cx - y;
+ fline[2].x1 = fline[3].x1 = cx + y;
+ fline[2].y0 = fline[2].y1 = cy + x;
+ fline[3].y0 = fline[3].y1 = cy - x;
- nsfb->plotter_fns->line(nsfb, 4, fline, &pen);
+ nsfb->plotter_fns->line(nsfb, 4, fline, &pen);
}
static bool circle_midpoint(nsfb_t *nsfb,
- int cx,
- int cy,
- int r,
- nsfb_colour_t c,
- void (circfn)(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c))
+ int cx,
+ int cy,
+ int r,
+ nsfb_colour_t c,
+ void (circfn)(nsfb_t *nsfb, int cx, int cy, int x, int y, nsfb_colour_t c))
{
- int x = 0;
- int y = r;
- int p = 1 - r;
-
- circfn(nsfb, cx, cy, x, y, c);
- while (x < y) {
- x++;
- if (p < 0) {
- p += 2 * x + 1;
- } else {
- y--;
- p += 2 * (x - y) + 1;
- }
- circfn(nsfb, cx, cy, x, y, c);
- }
- return true;
+ int x = 0;
+ int y = r;
+ int p = 1 - r;
+
+ circfn(nsfb, cx, cy, x, y, c);
+ while (x < y) {
+ x++;
+ if (p < 0) {
+ p += 2 * x + 1;
+ } else {
+ y--;
+ p += 2 * (x - y) + 1;
+ }
+ circfn(nsfb, cx, cy, x, y, c);
+ }
+ return true;
}
static bool ellipse(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c)
{
- int width = (ellipse->x1 - ellipse->x0)>>1;
- int height = (ellipse->y1 - ellipse->y0)>>1;
-
- if (width == height) {
- /* circle */
- return circle_midpoint(nsfb, ellipse->x0 + width, ellipse->y0 + height, width, c, circlepoints);
- } else {
- return ellipse_midpoint(nsfb, ellipse->x0 + width, ellipse->y0 + height, width, height, c, ellipsepoints);
- }
+ int width = (ellipse->x1 - ellipse->x0)>>1;
+ int height = (ellipse->y1 - ellipse->y0)>>1;
+
+ if (width == height) {
+ /* circle */
+ return circle_midpoint(nsfb, ellipse->x0 + width,
+ ellipse->y0 + height, width, c, circlepoints);
+ } else {
+ return ellipse_midpoint(nsfb, ellipse->x0 + width,
+ ellipse->y0 + height, width, height, c,
+ ellipsepoints);
+ }
}
static bool ellipse_fill(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c)
{
- int width = (ellipse->x1 - ellipse->x0) >> 1;
- int height = (ellipse->y1 - ellipse->y0) >> 1;
-
- if (width == height) {
- /* circle */
- return circle_midpoint(nsfb, ellipse->x0 + width, ellipse->y0 + height, width, c, circlefill);
- } else {
- return ellipse_midpoint(nsfb, ellipse->x0 + width, ellipse->y0 + height, width, height, c, ellipsefill);
- }
+ int width = (ellipse->x1 - ellipse->x0) >> 1;
+ int height = (ellipse->y1 - ellipse->y0) >> 1;
+
+ if (width == height) {
+ /* circle */
+ return circle_midpoint(nsfb, ellipse->x0 + width,
+ ellipse->y0 + height, width, c, circlefill);
+ } else {
+ return ellipse_midpoint(nsfb, ellipse->x0 + width,
+ ellipse->y0 + height, width, height, c,
+ ellipsefill);
+ }
}
@@ -551,122 +560,123 @@ static bool ellipse_fill(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c)
static bool
copy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox)
{
- int srcx = srcbox->x0;
- int srcy = srcbox->y0;
- int dstx = dstbox->x0;
- int dsty = dstbox->y0;
- int width = dstbox->x1 - dstbox->x0;
- int height = dstbox->y1 - dstbox->y0;
- uint8_t *srcptr;
- uint8_t *dstptr;
- int hloop;
- nsfb_bbox_t allbox;
-
- nsfb_plot_add_rect(srcbox, dstbox, &allbox);
-
- nsfb->surface_rtns->claim(nsfb, &allbox);
-
- srcptr = (nsfb->ptr +
- (srcy * nsfb->linelen) +
- ((srcx * nsfb->bpp) / 8));
-
- dstptr = (nsfb->ptr +
- (dsty * nsfb->linelen) +
- ((dstx * nsfb->bpp) / 8));
-
-
- if (width == nsfb->width) {
- /* take shortcut and use memmove */
- memmove(dstptr, srcptr, (width * height * nsfb->bpp) / 8);
- } else {
- if (srcy > dsty) {
- for (hloop = height; hloop > 0; hloop--) {
- memmove(dstptr, srcptr, (width * nsfb->bpp) / 8);
- srcptr += nsfb->linelen;
- dstptr += nsfb->linelen;
- }
- } else {
- srcptr += height * nsfb->linelen;
- dstptr += height * nsfb->linelen;
- for (hloop = height; hloop > 0; hloop--) {
- srcptr -= nsfb->linelen;
- dstptr -= nsfb->linelen;
- memmove(dstptr, srcptr, (width * nsfb->bpp) / 8);
- }
- }
- }
-
- nsfb->surface_rtns->update(nsfb, dstbox);
-
- return true;
+ int srcx = srcbox->x0;
+ int srcy = srcbox->y0;
+ int dstx = dstbox->x0;
+ int dsty = dstbox->y0;
+ int width = dstbox->x1 - dstbox->x0;
+ int height = dstbox->y1 - dstbox->y0;
+ uint8_t *srcptr;
+ uint8_t *dstptr;
+ int hloop;
+ nsfb_bbox_t allbox;
+
+ nsfb_plot_add_rect(srcbox, dstbox, &allbox);
+
+ nsfb->surface_rtns->claim(nsfb, &allbox);
+
+ srcptr = (nsfb->ptr +
+ (srcy * nsfb->linelen) +
+ ((srcx * nsfb->bpp) / 8));
+
+ dstptr = (nsfb->ptr +
+ (dsty * nsfb->linelen) +
+ ((dstx * nsfb->bpp) / 8));
+
+
+ if (width == nsfb->width) {
+ /* take shortcut and use memmove */
+ memmove(dstptr, srcptr, (width * height * nsfb->bpp) / 8);
+ } else {
+ if (srcy > dsty) {
+ for (hloop = height; hloop > 0; hloop--) {
+ memmove(dstptr, srcptr, (width * nsfb->bpp) / 8);
+ srcptr += nsfb->linelen;
+ dstptr += nsfb->linelen;
+ }
+ } else {
+ srcptr += height * nsfb->linelen;
+ dstptr += height * nsfb->linelen;
+ for (hloop = height; hloop > 0; hloop--) {
+ srcptr -= nsfb->linelen;
+ dstptr -= nsfb->linelen;
+ memmove(dstptr, srcptr, (width * nsfb->bpp) / 8);
+ }
+ }
+ }
+
+ nsfb->surface_rtns->update(nsfb, dstbox);
+
+ return true;
}
-static bool arc(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle2, nsfb_colour_t c)
+static bool arc(nsfb_t *nsfb, int x, int y, int radius, int angle1,
+ int angle2, nsfb_colour_t c)
{
- nsfb=nsfb;
- x = x;
- y = y;
- radius = radius;
- c = c;
- angle1=angle1;
- angle2=angle2;
- return true;
+ nsfb=nsfb;
+ x = x;
+ y = y;
+ radius = radius;
+ c = c;
+ angle1=angle1;
+ angle2=angle2;
+ return true;
}
#define N_SEG 30
static int
cubic_points(unsigned int pointc,
- nsfb_point_t *point,
- nsfb_bbox_t *curve,
- nsfb_point_t *ctrla,
- nsfb_point_t *ctrlb)
+ nsfb_point_t *point,
+ nsfb_bbox_t *curve,
+ nsfb_point_t *ctrla,
+ nsfb_point_t *ctrlb)
{
- unsigned int seg_loop;
- double t;
- double one_minus_t;
- double a;
- double b;
- double c;
- double d;
- double x;
- double y;
- int cur_point;
-
- point[0].x = curve->x0;
- point[0].y = curve->y0;
- cur_point = 1;
- pointc--;
-
- for (seg_loop = 1; seg_loop < pointc; ++seg_loop) {
- t = (double)seg_loop / (double)pointc;
-
- one_minus_t = 1.0 - t;
-
- a = one_minus_t * one_minus_t * one_minus_t;
- b = 3.0 * t * one_minus_t * one_minus_t;
- c = 3.0 * t * t * one_minus_t;
- d = t * t * t;
-
- x = a * curve->x0 + b * ctrla->x + c * ctrlb->x + d * curve->x1;
- y = a * curve->y0 + b * ctrla->y + c * ctrlb->y + d * curve->y1;
-
- point[cur_point].x = x;
- point[cur_point].y = y;
- if ((point[cur_point].x != point[cur_point - 1].x) ||
- (point[cur_point].y != point[cur_point - 1].y))
- cur_point++;
- }
-
- point[cur_point].x = curve->x1;
- point[cur_point].y = curve->y1;
- if ((point[cur_point].x != point[cur_point - 1].x) ||
- (point[cur_point].y != point[cur_point - 1].y))
- cur_point++;
-
- return cur_point;
+ unsigned int seg_loop;
+ double t;
+ double one_minus_t;
+ double a;
+ double b;
+ double c;
+ double d;
+ double x;
+ double y;
+ int cur_point;
+
+ point[0].x = curve->x0;
+ point[0].y = curve->y0;
+ cur_point = 1;
+ pointc--;
+
+ for (seg_loop = 1; seg_loop < pointc; ++seg_loop) {
+ t = (double)seg_loop / (double)pointc;
+
+ one_minus_t = 1.0 - t;
+
+ a = one_minus_t * one_minus_t * one_minus_t;
+ b = 3.0 * t * one_minus_t * one_minus_t;
+ c = 3.0 * t * t * one_minus_t;
+ d = t * t * t;
+
+ x = a * curve->x0 + b * ctrla->x + c * ctrlb->x + d * curve->x1;
+ y = a * curve->y0 + b * ctrla->y + c * ctrlb->y + d * curve->y1;
+
+ point[cur_point].x = x;
+ point[cur_point].y = y;
+ if ((point[cur_point].x != point[cur_point - 1].x) ||
+ (point[cur_point].y != point[cur_point - 1].y))
+ cur_point++;
+ }
+
+ point[cur_point].x = curve->x1;
+ point[cur_point].y = curve->y1;
+ if ((point[cur_point].x != point[cur_point - 1].x) ||
+ (point[cur_point].y != point[cur_point - 1].y))
+ cur_point++;
+
+ return cur_point;
}
/* calculate a series of points which describe a quadratic bezier spline.
@@ -679,261 +689,272 @@ cubic_points(unsigned int pointc,
*/
static int
quadratic_points(unsigned int pointc,
- nsfb_point_t *point,
- nsfb_bbox_t *curve,
- nsfb_point_t *ctrla)
+ nsfb_point_t *point,
+ nsfb_bbox_t *curve,
+ nsfb_point_t *ctrla)
{
- unsigned int seg_loop;
- double t;
- double one_minus_t;
- double a;
- double b;
- double c;
- double x;
- double y;
- int cur_point;
-
- point[0].x = curve->x0;
- point[0].y = curve->y0;
- cur_point = 1;
- pointc--; /* we have added the start point, one less point in the curve */
-
- for (seg_loop = 1; seg_loop < pointc; ++seg_loop) {
- t = (double)seg_loop / (double)pointc;
-
- one_minus_t = 1.0 - t;
-
- a = one_minus_t * one_minus_t;
- b = 2.0 * t * one_minus_t;
- c = t * t;
-
- x = a * curve->x0 + b * ctrla->x + c * curve->x1;
- y = a * curve->y0 + b * ctrla->y + c * curve->y1;
-
- point[cur_point].x = x;
- point[cur_point].y = y;
- if ((point[cur_point].x != point[cur_point - 1].x) ||
- (point[cur_point].y != point[cur_point - 1].y))
- cur_point++;
- }
-
- point[cur_point].x = curve->x1;
- point[cur_point].y = curve->y1;
- if ((point[cur_point].x != point[cur_point - 1].x) ||
- (point[cur_point].y != point[cur_point - 1].y))
- cur_point++;
-
- return cur_point;
+ unsigned int seg_loop;
+ double t;
+ double one_minus_t;
+ double a;
+ double b;
+ double c;
+ double x;
+ double y;
+ int cur_point;
+
+ point[0].x = curve->x0;
+ point[0].y = curve->y0;
+ cur_point = 1;
+ pointc--; /* we have added the start point, one less point in the curve */
+
+ for (seg_loop = 1; seg_loop < pointc; ++seg_loop) {
+ t = (double)seg_loop / (double)pointc;
+
+ one_minus_t = 1.0 - t;
+
+ a = one_minus_t * one_minus_t;
+ b = 2.0 * t * one_minus_t;
+ c = t * t;
+
+ x = a * curve->x0 + b * ctrla->x + c * curve->x1;
+ y = a * curve->y0 + b * ctrla->y + c * curve->y1;
+
+ point[cur_point].x = x;
+ point[cur_point].y = y;
+ if ((point[cur_point].x != point[cur_point - 1].x) ||
+ (point[cur_point].y != point[cur_point - 1].y))
+ cur_point++;
+ }
+
+ point[cur_point].x = curve->x1;
+ point[cur_point].y = curve->y1;
+ if ((point[cur_point].x != point[cur_point - 1].x) ||
+ (point[cur_point].y != point[cur_point - 1].y))
+ cur_point++;
+
+ return cur_point;
}
static bool
polylines(nsfb_t *nsfb,
- int pointc,
- const nsfb_point_t *points,
- nsfb_plot_pen_t *pen)
+ int pointc,
+ const nsfb_point_t *points,
+ nsfb_plot_pen_t *pen)
{
- int point_loop;
- nsfb_bbox_t line;
-
- if (pen->stroke_type != NFSB_PLOT_OPTYPE_NONE) {
- for (point_loop = 0; point_loop < (pointc - 1); point_loop++) {
- line = *(nsfb_bbox_t *)&points[point_loop];
- nsfb->plotter_fns->line(nsfb, 1, &line, pen);
+ int point_loop;
+ nsfb_bbox_t line;
+
+ if (pen->stroke_type != NFSB_PLOT_OPTYPE_NONE) {
+ for (point_loop = 0; point_loop < (pointc - 1); point_loop++) {
+ line = *(nsfb_bbox_t *)&points[point_loop];
+ nsfb->plotter_fns->line(nsfb, 1, &line, pen);
+ }
}
- }
- return true;
+ return true;
}
static bool
quadratic(nsfb_t *nsfb,
- nsfb_bbox_t *curve,
- nsfb_point_t *ctrla,
- nsfb_plot_pen_t *pen)
+ nsfb_bbox_t *curve,
+ nsfb_point_t *ctrla,
+ nsfb_plot_pen_t *pen)
{
- nsfb_point_t points[N_SEG];
+ nsfb_point_t points[N_SEG];
- if (pen->stroke_type == NFSB_PLOT_OPTYPE_NONE)
- return false;
+ if (pen->stroke_type == NFSB_PLOT_OPTYPE_NONE)
+ return false;
- return polylines(nsfb, quadratic_points(N_SEG, points, curve, ctrla), points, pen);
+ return polylines(nsfb, quadratic_points(N_SEG, points, curve, ctrla),
+ points, pen);
}
static bool
cubic(nsfb_t *nsfb,
- nsfb_bbox_t *curve,
- nsfb_point_t *ctrla,
- nsfb_point_t *ctrlb,
- nsfb_plot_pen_t *pen)
+ nsfb_bbox_t *curve,
+ nsfb_point_t *ctrla,
+ nsfb_point_t *ctrlb,
+ nsfb_plot_pen_t *pen)
{
- nsfb_point_t points[N_SEG];
+ nsfb_point_t points[N_SEG];
- if (pen->stroke_type == NFSB_PLOT_OPTYPE_NONE)
- return false;
+ if (pen->stroke_type == NFSB_PLOT_OPTYPE_NONE)
+ return false;
- return polylines(nsfb, cubic_points(N_SEG, points, curve, ctrla,ctrlb), points, pen);
+ return polylines(nsfb, cubic_points(N_SEG, points, curve, ctrla,ctrlb),
+ points, pen);
}
static bool
path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen)
{
- int path_loop;
- nsfb_point_t *pts;
- nsfb_point_t *curpt;
- int ptc = 0;
- nsfb_bbox_t curve;
- nsfb_point_t ctrla;
- nsfb_point_t ctrlb;
- int added_count = 0;
- int bpts;
-
- /* count the verticies in the path and add N_SEG extra for curves */
- for (path_loop = 0; path_loop < pathc; path_loop++) {
- ptc++;
- if ((pathop[path_loop].operation == NFSB_PLOT_PATHOP_QUAD) ||
- (pathop[path_loop].operation == NFSB_PLOT_PATHOP_CUBIC))
- ptc += N_SEG;
- }
-
- /* allocate storage for the vertexes */
- curpt = pts = malloc(ptc * sizeof(nsfb_point_t));
-
- for (path_loop = 0; path_loop < pathc; path_loop++) {
- switch (pathop[path_loop].operation) {
- case NFSB_PLOT_PATHOP_QUAD:
- curpt-=2;
- added_count -= 2;
- curve.x0 = pathop[path_loop - 2].point.x;
- curve.y0 = pathop[path_loop - 2].point.y;
- ctrla.x = pathop[path_loop - 1].point.x;
- ctrla.y = pathop[path_loop - 1].point.y;
- curve.x1 = pathop[path_loop].point.x;
- curve.y1 = pathop[path_loop].point.y;
- bpts = quadratic_points(N_SEG, curpt, &curve, &ctrla);
- curpt += bpts;
- added_count += bpts;
- break;
-
- case NFSB_PLOT_PATHOP_CUBIC:
- curpt-=3;
- added_count -=3;
- curve.x0 = pathop[path_loop - 3].point.x;
- curve.y0 = pathop[path_loop - 3].point.y;
- ctrla.x = pathop[path_loop - 2].point.x;
- ctrla.y = pathop[path_loop - 2].point.y;
- ctrlb.x = pathop[path_loop - 1].point.x;
- ctrlb.y = pathop[path_loop - 1].point.y;
- curve.x1 = pathop[path_loop].point.x;
- curve.y1 = pathop[path_loop].point.y;
- bpts = cubic_points(N_SEG, curpt, &curve, &ctrla, &ctrlb);
- curpt += bpts;
- added_count += bpts;
- break;
-
- default:
- *curpt = pathop[path_loop].point;
- curpt++;
- added_count ++;
- break;
- }
- }
-
- if (pen->fill_type != NFSB_PLOT_OPTYPE_NONE) {
- polygon(nsfb, (int *)pts, added_count, pen->fill_colour);
- }
-
- if (pen->stroke_type != NFSB_PLOT_OPTYPE_NONE) {
- polylines(nsfb, added_count, pts, pen);
- }
-
- free(pts);
-
- return true;
+ int path_loop;
+ nsfb_point_t *pts;
+ nsfb_point_t *curpt;
+ int ptc = 0;
+ nsfb_bbox_t curve;
+ nsfb_point_t ctrla;
+ nsfb_point_t ctrlb;
+ int added_count = 0;
+ int bpts;
+
+ /* count the verticies in the path and add N_SEG extra for curves */
+ for (path_loop = 0; path_loop < pathc; path_loop++) {
+ ptc++;
+ if ((pathop[path_loop].operation == NFSB_PLOT_PATHOP_QUAD) ||
+ (pathop[path_loop].operation ==
+ NFSB_PLOT_PATHOP_CUBIC))
+ ptc += N_SEG;
+ }
+
+ /* 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) {
+ case NFSB_PLOT_PATHOP_QUAD:
+ curpt-=2;
+ added_count -= 2;
+ curve.x0 = pathop[path_loop - 2].point.x;
+ curve.y0 = pathop[path_loop - 2].point.y;
+ ctrla.x = pathop[path_loop - 1].point.x;
+ ctrla.y = pathop[path_loop - 1].point.y;
+ curve.x1 = pathop[path_loop].point.x;
+ curve.y1 = pathop[path_loop].point.y;
+ bpts = quadratic_points(N_SEG, curpt, &curve, &ctrla);
+ curpt += bpts;
+ added_count += bpts;
+ break;
+
+ case NFSB_PLOT_PATHOP_CUBIC:
+ curpt-=3;
+ added_count -=3;
+ curve.x0 = pathop[path_loop - 3].point.x;
+ curve.y0 = pathop[path_loop - 3].point.y;
+ ctrla.x = pathop[path_loop - 2].point.x;
+ ctrla.y = pathop[path_loop - 2].point.y;
+ ctrlb.x = pathop[path_loop - 1].point.x;
+ ctrlb.y = pathop[path_loop - 1].point.y;
+ curve.x1 = pathop[path_loop].point.x;
+ curve.y1 = pathop[path_loop].point.y;
+ bpts = cubic_points(N_SEG, curpt, &curve, &ctrla, &ctrlb);
+ curpt += bpts;
+ added_count += bpts;
+ break;
+
+ default:
+ *curpt = pathop[path_loop].point;
+ curpt++;
+ added_count ++;
+ break;
+ }
+ }
+
+ if (pen->fill_type != NFSB_PLOT_OPTYPE_NONE) {
+ polygon(nsfb, (int *)pts, added_count, pen->fill_colour);
+ }
+
+ if (pen->stroke_type != NFSB_PLOT_OPTYPE_NONE) {
+ polylines(nsfb, added_count, pts, pen);
+ }
+
+ free(pts);
+
+ return true;
}
bool select_plotters(nsfb_t *nsfb)
{
- const nsfb_plotter_fns_t *table = NULL;
+ const nsfb_plotter_fns_t *table = NULL;
- switch (nsfb->format) {
+ switch (nsfb->format) {
- case NSFB_FMT_XBGR8888: /* 32bpp Unused Blue Green Red */
- case NSFB_FMT_ABGR8888: /* 32bpp Alpha Blue Green Red */
- table = &_nsfb_32bpp_xbgr8888_plotters;
- nsfb->bpp = 32;
- break;
+ case NSFB_FMT_XBGR8888: /* 32bpp Unused Blue Green Red */
+ case NSFB_FMT_ABGR8888: /* 32bpp Alpha Blue Green Red */
+ table = &_nsfb_32bpp_xbgr8888_plotters;
+ nsfb->bpp = 32;
+ break;
- case NSFB_FMT_XRGB8888: /* 32bpp Unused Red Green Blue */
- case NSFB_FMT_ARGB8888: /* 32bpp Alpha Red Green Blue */
- table = &_nsfb_32bpp_xrgb8888_plotters;
- nsfb->bpp = 32;
- break;
+ case NSFB_FMT_XRGB8888: /* 32bpp Unused Red Green Blue */
+ case NSFB_FMT_ARGB8888: /* 32bpp Alpha Red Green Blue */
+ table = &_nsfb_32bpp_xrgb8888_plotters;
+ nsfb->bpp = 32;
+ break;
- case NSFB_FMT_RGB888: /* 24 bpp Alpha Red Green Blue */
+ case NSFB_FMT_RGB888: /* 24 bpp Alpha Red Green Blue */
#ifdef ENABLE_24_BPP
- table = &_nsfb_24bpp_plotters;
- nsfb->bpp = 24;
- break;
+ table = &_nsfb_24bpp_plotters;
+ nsfb->bpp = 24;
+ break;
#else
- return false;
+ return false;
#endif
- case NSFB_FMT_ARGB1555: /* 16 bpp 555 */
- case NSFB_FMT_RGB565: /* 16 bpp 565 */
- table = &_nsfb_16bpp_plotters;
- nsfb->bpp = 16;
- break;
+ case NSFB_FMT_ARGB1555: /* 16 bpp 555 */
+ case NSFB_FMT_RGB565: /* 16 bpp 565 */
+ table = &_nsfb_16bpp_plotters;
+ nsfb->bpp = 16;
+ break;
- case NSFB_FMT_I8: /* 8bpp indexed */
- table = &_nsfb_8bpp_plotters;
- nsfb->bpp = 8;
- break;
+ case NSFB_FMT_I8: /* 8bpp indexed */
+ table = &_nsfb_8bpp_plotters;
+ nsfb->bpp = 8;
+ break;
- case NSFB_FMT_I1: /* black and white */
+ case NSFB_FMT_I1: /* black and white */
#ifdef ENABLE_1_BPP
- table = &_nsfb_1bpp_plotters;
- nsfb->bpp = 1
- break;
+ table = &_nsfb_1bpp_plotters;
+ nsfb->bpp = 1
+ break;
#else
- return false;
+ return false;
#endif
- case NSFB_FMT_ANY: /* No specific format - use surface default */
- default:
- return false;
- }
-
- if (nsfb->plotter_fns != NULL)
- free(nsfb->plotter_fns);
-
- nsfb->plotter_fns = calloc(1, sizeof(nsfb_plotter_fns_t));
- memcpy(nsfb->plotter_fns, table, sizeof(nsfb_plotter_fns_t));
-
- /* set the generics */
- nsfb->plotter_fns->clg = clg;
- nsfb->plotter_fns->set_clip = set_clip;
- nsfb->plotter_fns->get_clip = get_clip;
- nsfb->plotter_fns->polygon = polygon;
- nsfb->plotter_fns->rectangle = rectangle;
- nsfb->plotter_fns->ellipse = ellipse;
- nsfb->plotter_fns->ellipse_fill = ellipse_fill;
- nsfb->plotter_fns->copy = copy;
- nsfb->plotter_fns->arc = arc;
- nsfb->plotter_fns->quadratic = quadratic;
- nsfb->plotter_fns->cubic = cubic;
- nsfb->plotter_fns->path = path;
- nsfb->plotter_fns->polylines = polylines;
-
- /* set default clip rectangle to size of framebuffer */
- nsfb->clip.x0 = 0;
- nsfb->clip.y0 = 0;
- nsfb->clip.x1 = nsfb->width;
- nsfb->clip.y1 = nsfb->height;
-
- return true;
+ case NSFB_FMT_ANY: /* No specific format - use surface default */
+ default:
+ return false;
+ }
+
+ 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 */
+ nsfb->plotter_fns->clg = clg;
+ nsfb->plotter_fns->set_clip = set_clip;
+ nsfb->plotter_fns->get_clip = get_clip;
+ nsfb->plotter_fns->polygon = polygon;
+ nsfb->plotter_fns->rectangle = rectangle;
+ nsfb->plotter_fns->ellipse = ellipse;
+ nsfb->plotter_fns->ellipse_fill = ellipse_fill;
+ nsfb->plotter_fns->copy = copy;
+ nsfb->plotter_fns->arc = arc;
+ nsfb->plotter_fns->quadratic = quadratic;
+ nsfb->plotter_fns->cubic = cubic;
+ nsfb->plotter_fns->path = path;
+ nsfb->plotter_fns->polylines = polylines;
+
+ /* set default clip rectangle to size of framebuffer */
+ nsfb->clip.x0 = 0;
+ nsfb->clip.y0 = 0;
+ nsfb->clip.x1 = nsfb->width;
+ nsfb->clip.y1 = nsfb->height;
+
+ return true;
}
/*
diff --git a/src/surface/Makefile b/src/surface/Makefile
index ad23cc4..848c3d4 100644
--- a/src/surface/Makefile
+++ b/src/surface/Makefile
@@ -4,8 +4,6 @@
SURFACE_HANDLER_yes := surface.c ram.c
# optional surface handlers
-SURFACE_HANDLER_$(NSFB_ABLE_AVAILABLE) += able.c
-SURFACE_HANDLER_$(NSFB_LINUX_AVAILABLE) += linux.c
SURFACE_HANDLER_$(NSFB_SDL_AVAILABLE) += sdl.c
SURFACE_HANDLER_$(NSFB_XCB_AVAILABLE) += x.c
SURFACE_HANDLER_$(NSFB_VNC_AVAILABLE) += vnc.c
diff --git a/src/surface/able.c b/src/surface/able.c
deleted file mode 100644
index dd4c340..0000000
--- a/src/surface/able.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
- *
- * This file is part of libnsfb, http://www.netsurf-browser.org/
- * Licenced under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- */
-
-#include <stdbool.h>
-#include <stdio.h>
-
-#include "libnsfb.h"
-#include "libnsfb_plot.h"
-#include "libnsfb_event.h"
-#include "nsfb.h"
-#include "surface.h"
-
-#define UNUSED(x) ((x) = (x))
-
-static int able_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format)
-{
- if (nsfb->surface_priv != NULL)
- return -1; /* if were already initialised fail */
-
- nsfb->width = width;
- nsfb->height = height;
- nsfb->format = format;
-
- return 0;
-}
-
-static int able_initialise(nsfb_t *nsfb)
-{
- UNUSED(nsfb);
- return 0;
-}
-
-static int able_finalise(nsfb_t *nsfb)
-{
- UNUSED(nsfb);
- return 0;
-}
-
-static bool able_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
-{
- UNUSED(nsfb);
- UNUSED(event);
- UNUSED(timeout);
- return false;
-}
-
-const nsfb_surface_rtns_t able_rtns = {
- .initialise = able_initialise,
- .finalise = able_finalise,
- .input = able_input,
- .geometry = able_set_geometry,
-};
-
-NSFB_SURFACE_DEF(able, NSFB_SURFACE_ABLE, &able_rtns)
diff --git a/src/surface/linux.c b/src/surface/linux.c
deleted file mode 100644
index b5bf8ad..0000000
--- a/src/surface/linux.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright 2012 Vincent Sanders <vince@simtec.co.uk>
- *
- * This file is part of libnsfb, http://www.netsurf-browser.org/
- * Licenced under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- */
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/mman.h>
-
-#include <linux/fb.h>
-
-
-#include "libnsfb.h"
-#include "libnsfb_event.h"
-#include "libnsfb_plot.h"
-#include "libnsfb_plot_util.h"
-
-#include "nsfb.h"
-#include "plot.h"
-#include "surface.h"
-#include "cursor.h"
-
-
-
-#define UNUSED(x) ((x) = (x))
-
-#define FB_NAME "/dev/fb0"
-
-struct lnx_priv {
- struct fb_fix_screeninfo FixInfo;
- struct fb_var_screeninfo VarInfo;
- int fd;
-};
-
-static int linux_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format)
-{
- if (nsfb->surface_priv != NULL) {
- return -1; /* if we are already initialised fail */
- }
-
- nsfb->width = width;
- nsfb->height = height;
- nsfb->format = format;
-
- /* select default sw plotters for bpp */
- if (select_plotters(nsfb) != true) {
- return -1;
- }
-
- return 0;
-}
-
-static enum nsfb_format_e
-format_from_lstate(struct lnx_priv *lstate)
-{
- enum nsfb_format_e fmt = NSFB_FMT_ANY;
-
- switch(lstate->VarInfo.bits_per_pixel) {
- case 32:
- if (lstate->VarInfo.transp.length == 0)
- fmt = NSFB_FMT_XBGR8888;
- else
- fmt = NSFB_FMT_ABGR8888;
- break;
-
- case 24:
- fmt = NSFB_FMT_RGB888;
- break;
-
- case 16:
- fmt = NSFB_FMT_RGB565;
- break;
-
- case 8:
- fmt = NSFB_FMT_I8;
- break;
-
- case 1:
- fmt = NSFB_FMT_RGB565;
- break;
-
- }
-
-
- return fmt;
-}
-
-static int linux_initialise(nsfb_t *nsfb)
-{
- int iFrameBufferSize;
- struct lnx_priv *lstate;
- enum nsfb_format_e lformat;
-
- if (nsfb->surface_priv != NULL)
- return -1;
-
- lstate = calloc(1, sizeof(struct lnx_priv));
- if (lstate == NULL) {
- return -1;
- }
-
- /* Open the framebuffer device in read write */
- lstate->fd = open(FB_NAME, O_RDWR);
- if (lstate->fd < 0) {
- printf("Unable to open %s.\n", FB_NAME);
- free(lstate);
- return -1;
- }
-
- /* Do Ioctl. Retrieve fixed screen info. */
- if (ioctl(lstate->fd, FBIOGET_FSCREENINFO, &lstate->FixInfo) < 0) {
- printf("get fixed screen info failed: %s\n",
- strerror(errno));
- close(lstate->fd);
- free(lstate);
- return -1;
- }
-
- /* Do Ioctl. Get the variable screen info. */
- if (ioctl(lstate->fd, FBIOGET_VSCREENINFO, &lstate->VarInfo) < 0) {
- printf("Unable to retrieve variable screen info: %s\n",
- strerror(errno));
- close(lstate->fd);
- free(lstate);
- return -1;
- }
-
- /* Calculate the size to mmap */
- iFrameBufferSize = lstate->FixInfo.line_length * lstate->VarInfo.yres;
-
- /* Now mmap the framebuffer. */
- nsfb->ptr = mmap(NULL, iFrameBufferSize, PROT_READ | PROT_WRITE,
- MAP_SHARED, lstate->fd, 0);
- if (nsfb->ptr == NULL) {
- printf("mmap failed:\n");
- close(lstate->fd);
- free(lstate);
- return -1;
- }
-
- nsfb->linelen = lstate->FixInfo.line_length;
-
- nsfb->width = lstate->VarInfo.xres;
- nsfb->height = lstate->VarInfo.yres;
-
- lformat = format_from_lstate(lstate);
-
- if (nsfb->format != lformat) {
- nsfb->format = lformat;
-
- /* select default sw plotters for format */
- if (select_plotters(nsfb) != true) {
- munmap(nsfb->ptr, 0);
- close(lstate->fd);
- free(lstate);
- return -1;
- }
- }
-
- nsfb->surface_priv = lstate;
-
- return 0;
-}
-
-static int linux_finalise(nsfb_t *nsfb)
-{
- struct lnx_priv *lstate = nsfb->surface_priv;
-
- if (lstate != NULL) {
- munmap(nsfb->ptr, 0);
- close(lstate->fd);
- free(lstate);
- }
-
- return 0;
-}
-
-static bool linux_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
-{
- UNUSED(nsfb);
- UNUSED(event);
- UNUSED(timeout);
- return false;
-}
-
-static int linux_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
-{
- struct nsfb_cursor_s *cursor = nsfb->cursor;
-
- if ((cursor != NULL) &&
- (cursor->plotted == true) &&
- (nsfb_plot_bbox_intersect(box, &cursor->loc))) {
-
- nsfb->plotter_fns->bitmap(nsfb,
- &cursor->savloc,
- cursor->sav,
- cursor->sav_width,
- cursor->sav_height,
- cursor->sav_width,
- false);
- cursor->plotted = false;
- }
- return 0;
-}
-
-static int linux_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
-{
- nsfb_bbox_t sclip;
-
- if ((cursor != NULL) && (cursor->plotted == true)) {
- sclip = nsfb->clip;
-
- nsfb->plotter_fns->set_clip(nsfb, NULL);
-
- nsfb->plotter_fns->bitmap(nsfb,
- &cursor->savloc,
- cursor->sav,
- cursor->sav_width,
- cursor->sav_height,
- cursor->sav_width,
- false);
-
- nsfb_cursor_plot(nsfb, cursor);
-
- nsfb->clip = sclip;
- }
- return true;
-}
-
-
-static int linux_update(nsfb_t *nsfb, nsfb_bbox_t *box)
-{
- struct nsfb_cursor_s *cursor = nsfb->cursor;
-
- UNUSED(box);
-
- if ((cursor != NULL) && (cursor->plotted == false)) {
- nsfb_cursor_plot(nsfb, cursor);
- }
-
- return 0;
-}
-
-const nsfb_surface_rtns_t linux_rtns = {
- .initialise = linux_initialise,
- .finalise = linux_finalise,
- .input = linux_input,
- .claim = linux_claim,
- .update = linux_update,
- .cursor = linux_cursor,
- .geometry = linux_set_geometry,
-};
-
-NSFB_SURFACE_DEF(linux, NSFB_SURFACE_LINUX, &linux_rtns)
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * tab-width: 8
- * End:
- */
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..51389b4 100644
--- a/src/surface/wld.c
+++ b/src/surface/wld.c
@@ -8,8 +8,14 @@
#define _XOPEN_SOURCE 500
+/* deal with using -std=c99 and glibc changed to no have mkostemp with it set */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include <stdbool.h>
#include <stdlib.h>
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -48,7 +54,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 +981,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 +1004,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 {
@@ -1074,11 +1083,11 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer,
}
static const struct wl_pointer_listener pointer_listener = {
- pointer_handle_enter,
- pointer_handle_leave,
- pointer_handle_motion,
- pointer_handle_button,
- pointer_handle_axis,
+ .enter = pointer_handle_enter,
+ .leave = pointer_handle_leave,
+ .motion = pointer_handle_motion,
+ .button = pointer_handle_button,
+ .axis = pointer_handle_axis,
};
static void
@@ -1259,7 +1268,6 @@ new_connection(void)
struct wld_connection* connection;
connection = calloc(1, sizeof(struct wld_connection));
-
if (connection == NULL) {
return NULL;
}
@@ -1456,8 +1464,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 +1666,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);
diff --git a/test/polystar.c b/test/polystar.c
index 136b6aa..a9ac11c 100644
--- a/test/polystar.c
+++ b/test/polystar.c
@@ -118,7 +118,10 @@ int main(int argc, char **argv)
}
nsfb_update(nsfb, &box);
- sleepMilli(100);
+
+ if (fetype != NSFB_SURFACE_RAM) {
+ sleepMilli(400);
+ }
}
/* wait for quit event or timeout */
diff --git a/test/polystar2.c b/test/polystar2.c
index a843f9d..4644ed5 100644
--- a/test/polystar2.c
+++ b/test/polystar2.c
@@ -112,7 +112,10 @@ int main(int argc, char **argv)
sides += 2;
nsfb_update(nsfb, &box);
- sleepMilli(400);
+
+ if (fetype != NSFB_SURFACE_RAM) {
+ sleepMilli(400);
+ }
}
/* wait for quit event or timeout */