update framebuffer to new plotter API

This commit is contained in:
Vincent Sanders 2017-02-09 12:02:28 +00:00
parent 0f43b23270
commit 386951ecfc
2 changed files with 462 additions and 264 deletions

View File

@ -98,6 +98,11 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
int padding; int padding;
int scroll = 0; int scroll = 0;
bool caret = false; bool caret = false;
struct redraw_context ctx = {
.interactive = true,
.background_images = true,
.plot = &fb_plotters
};
fb_text_font_style(widget, &fh, &padding, &font_style); fb_text_font_style(widget, &fh, &padding, &font_style);
@ -142,8 +147,11 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
} }
/* Call the fb text plotting, baseline is 3/4 down the font */ /* Call the fb text plotting, baseline is 3/4 down the font */
fb_plotters.text(x, y, widget->u.text.text, ctx.plot->text(&ctx,
widget->u.text.len, &font_style); &font_style,
x, y,
widget->u.text.text,
widget->u.text.len);
} }
if (caret) { if (caret) {
@ -209,6 +217,11 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
int fh; int fh;
int border; int border;
fbtk_widget_t *root = fbtk_get_root_widget(widget); fbtk_widget_t *root = fbtk_get_root_widget(widget);
struct redraw_context ctx = {
.interactive = true,
.background_images = true,
.plot = &fb_plotters
};
fb_text_font_style(widget, &fh, &border, &font_style); fb_text_font_style(widget, &fh, &border, &font_style);
@ -256,11 +269,12 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.text != NULL) { if (widget->u.text.text != NULL) {
/* Call the fb text plotting, baseline is 3/4 down the font */ /* Call the fb text plotting, baseline is 3/4 down the font */
fb_plotters.text(bbox.x0 + border, ctx.plot->text(&ctx,
bbox.y0 + ((fh * 3) / 4) + border, &font_style,
widget->u.text.text, bbox.x0 + border,
widget->u.text.len, bbox.y0 + ((fh * 3) / 4) + border,
&font_style); widget->u.text.text,
widget->u.text.len);
} }
nsfb_update(root->u.root.fb, &bbox); nsfb_update(root->u.root.fb, &bbox);

View File

@ -45,89 +45,439 @@
static nsfb_t *nsfb; static nsfb_t *nsfb;
static bool /**
framebuffer_plot_disc(int x, int y, int radius, const plot_style_t *style) * \brief Sets a clip rectangle for subsequent plot operations.
*
* \param ctx The current redraw context.
* \param clip The rectangle to limit all subsequent plot
* operations within.
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
{ {
nsfb_bbox_t ellipse; nsfb_bbox_t nsfb_clip;
ellipse.x0 = x - radius; nsfb_clip.x0 = clip->x0;
ellipse.y0 = y - radius; nsfb_clip.y0 = clip->y0;
ellipse.x1 = x + radius; nsfb_clip.x1 = clip->x1;
ellipse.y1 = y + radius; nsfb_clip.y1 = clip->y1;
if (style->fill_type != PLOT_OP_TYPE_NONE) { if (!nsfb_plot_set_clip(nsfb, &nsfb_clip)) {
nsfb_plot_ellipse_fill(nsfb, &ellipse, style->fill_colour); return NSERROR_INVALID;
} }
return NSERROR_OK;
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
nsfb_plot_ellipse(nsfb, &ellipse, style->stroke_colour);
}
return true;
} }
static bool
framebuffer_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style) /**
* Plots an arc
*
* plot an arc segment around (x,y), anticlockwise from angle1
* to angle2. Angles are measured anticlockwise from
* horizontal, in degrees.
*
* \param ctx The current redraw context.
* \param pstyle Style controlling the arc plot.
* \param x The x coordinate of the arc.
* \param y The y coordinate of the arc.
* \param radius The radius of the arc.
* \param angle1 The start angle of the arc.
* \param angle2 The finish angle of the arc.
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_arc(const struct redraw_context *ctx,
const plot_style_t *style,
int x, int y, int radius, int angle1, int angle2)
{ {
return nsfb_plot_arc(nsfb, x, y, radius, angle1, angle2, style->fill_colour); if (!nsfb_plot_arc(nsfb, x, y, radius, angle1, angle2, style->fill_colour)) {
return NSERROR_INVALID;
}
return NSERROR_OK;
} }
static bool
framebuffer_plot_polygon(const int *p, unsigned int n, const plot_style_t *style) /**
* Plots a circle
*
* Plot a circle centered on (x,y), which is optionally filled.
*
* \param ctx The current redraw context.
* \param pstyle Style controlling the circle plot.
* \param x x coordinate of circle centre.
* \param y y coordinate of circle centre.
* \param radius circle radius.
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_disc(const struct redraw_context *ctx,
const plot_style_t *style,
int x, int y, int radius)
{ {
return nsfb_plot_polygon(nsfb, p, n, style->fill_colour); nsfb_bbox_t ellipse;
ellipse.x0 = x - radius;
ellipse.y0 = y - radius;
ellipse.x1 = x + radius;
ellipse.y1 = y + radius;
if (style->fill_type != PLOT_OP_TYPE_NONE) {
nsfb_plot_ellipse_fill(nsfb, &ellipse, style->fill_colour);
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
nsfb_plot_ellipse(nsfb, &ellipse, style->stroke_colour);
}
return NSERROR_OK;
}
/**
* Plots a line
*
* plot a line from (x0,y0) to (x1,y1). Coordinates are at
* centre of line width/thickness.
*
* \param ctx The current redraw context.
* \param pstyle Style controlling the line plot.
* \param line A rectangle defining the line to be drawn
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_line(const struct redraw_context *ctx,
const plot_style_t *style,
const struct rect *line)
{
nsfb_bbox_t rect;
nsfb_plot_pen_t pen;
rect.x0 = line->x0;
rect.y0 = line->y0;
rect.x1 = line->x1;
rect.y1 = line->y1;
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
if (style->stroke_type == PLOT_OP_TYPE_DOT) {
pen.stroke_type = NFSB_PLOT_OPTYPE_PATTERN;
pen.stroke_pattern = 0xAAAAAAAA;
} else if (style->stroke_type == PLOT_OP_TYPE_DASH) {
pen.stroke_type = NFSB_PLOT_OPTYPE_PATTERN;
pen.stroke_pattern = 0xF0F0F0F0;
} else {
pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
}
pen.stroke_colour = style->stroke_colour;
pen.stroke_width = style->stroke_width;
nsfb_plot_line(nsfb, &rect, &pen);
}
return NSERROR_OK;
}
/**
* Plots a rectangle.
*
* The rectangle can be filled an outline or both controlled
* by the plot style The line can be solid, dotted or
* dashed. Top left corner at (x0,y0) and rectangle has given
* width and height.
*
* \param ctx The current redraw context.
* \param pstyle Style controlling the rectangle plot.
* \param nsrect A rectangle defining the line to be drawn
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_rectangle(const struct redraw_context *ctx,
const plot_style_t *style,
const struct rect *nsrect)
{
nsfb_bbox_t rect;
bool dotted = false;
bool dashed = false;
rect.x0 = nsrect->x0;
rect.y0 = nsrect->y0;
rect.x1 = nsrect->x1;
rect.y1 = nsrect->y1;
if (style->fill_type != PLOT_OP_TYPE_NONE) {
nsfb_plot_rectangle_fill(nsfb, &rect, style->fill_colour);
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
if (style->stroke_type == PLOT_OP_TYPE_DOT) {
dotted = true;
}
if (style->stroke_type == PLOT_OP_TYPE_DASH) {
dashed = true;
}
nsfb_plot_rectangle(nsfb, &rect, style->stroke_width, style->stroke_colour, dotted, dashed);
}
return NSERROR_OK;
}
/**
* Plot a 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 the non-zero winding
* rule.
*
* \param ctx The current redraw context.
* \param pstyle Style controlling the polygon plot.
* \param p verticies of polygon
* \param n number of verticies.
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_polygon(const struct redraw_context *ctx,
const plot_style_t *style,
const int *p,
unsigned int n)
{
if (!nsfb_plot_polygon(nsfb, p, n, style->fill_colour)) {
return NSERROR_INVALID;
}
return NSERROR_OK;
}
/**
* Plots a path.
*
* Path plot consisting of cubic Bezier curves. Line and fill colour is
* controlled by the plot style.
*
* \param ctx The current redraw context.
* \param pstyle Style controlling the path plot.
* \param p elements of path
* \param n nunber of elements on path
* \param width The width of the path
* \param transform A transform to apply to the path.
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_path(const struct redraw_context *ctx,
const plot_style_t *pstyle,
const float *p,
unsigned int n,
float width,
const float transform[6])
{
LOG("path unimplemented");
return NSERROR_OK;
}
/**
* Plot a bitmap
*
* Tiled plot of a bitmap image. (x,y) gives the top left
* coordinate of an explicitly placed tile. From this tile the
* image can repeat in all four directions -- up, down, left
* and right -- to the extents given by the current clip
* rectangle.
*
* The bitmap_flags say whether to tile in the x and y
* directions. If not tiling in x or y directions, the single
* image is plotted. The width and height give the dimensions
* the image is to be scaled to.
*
* \param ctx The current redraw context.
* \param bitmap The bitmap to plot
* \param x The x coordinate to plot the bitmap
* \param y The y coordiante to plot the bitmap
* \param width The width of area to plot the bitmap into
* \param height The height of area to plot the bitmap into
* \param bg the background colour to alpha blend into
* \param flags the flags controlling the type of plot operation
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_bitmap(const struct redraw_context *ctx,
struct bitmap *bitmap,
int x, int y,
int width,
int height,
colour bg,
bitmap_flags_t flags)
{
nsfb_bbox_t loc;
nsfb_bbox_t clipbox;
bool repeat_x = (flags & BITMAPF_REPEAT_X);
bool repeat_y = (flags & BITMAPF_REPEAT_Y);
int bmwidth;
int bmheight;
int bmstride;
enum nsfb_format_e bmformat;
unsigned char *bmptr;
nsfb_t *bm = (nsfb_t *)bitmap;
/* x and y define coordinate of top left of of the initial explicitly
* placed tile. The width and height are the image scaling and the
* bounding box defines the extent of the repeat (which may go in all
* four directions from the initial tile).
*/
if (!(repeat_x || repeat_y)) {
/* Not repeating at all, so just plot it */
loc.x0 = x;
loc.y0 = y;
loc.x1 = loc.x0 + width;
loc.y1 = loc.y0 + height;
return nsfb_plot_copy(bm, NULL, nsfb, &loc);
}
nsfb_plot_get_clip(nsfb, &clipbox);
nsfb_get_geometry(bm, &bmwidth, &bmheight, &bmformat);
nsfb_get_buffer(bm, &bmptr, &bmstride);
/* Optimise tiled plots of 1x1 bitmaps by replacing with a flat fill
* of the area. Can only be done when image is fully opaque. */
if ((bmwidth == 1) && (bmheight == 1)) {
if ((*(nsfb_colour_t *)bmptr & 0xff000000) != 0) {
if (!nsfb_plot_rectangle_fill(nsfb, &clipbox,
*(nsfb_colour_t *)bmptr)) {
return NSERROR_INVALID;
}
return NSERROR_OK;
}
}
/* Optimise tiled plots of bitmaps scaled to 1x1 by replacing with
* a flat fill of the area. Can only be done when image is fully
* opaque. */
if ((width == 1) && (height == 1)) {
if (framebuffer_bitmap_get_opaque(bm)) {
/** TODO: Currently using top left pixel. Maybe centre
* pixel or average value would be better. */
if (!nsfb_plot_rectangle_fill(nsfb, &clipbox,
*(nsfb_colour_t *)bmptr)) {
return NSERROR_INVALID;
}
return NSERROR_OK;
}
}
/* get left most tile position */
if (repeat_x) {
for (; x > clipbox.x0; x -= width);
}
/* get top most tile position */
if (repeat_y) {
for (; y > clipbox.y0; y -= height);
}
/* set up top left tile location */
loc.x0 = x;
loc.y0 = y;
loc.x1 = loc.x0 + width;
loc.y1 = loc.y0 + height;
/* plot tiling across and down to extents */
nsfb_plot_bitmap_tiles(nsfb, &loc,
repeat_x ? ((clipbox.x1 - x) + width - 1) / width : 1,
repeat_y ? ((clipbox.y1 - y) + height - 1) / height : 1,
(nsfb_colour_t *)bmptr, bmwidth, bmheight,
bmstride * 8 / 32, bmformat == NSFB_FMT_ABGR8888);
return NSERROR_OK;
} }
#ifdef FB_USE_FREETYPE #ifdef FB_USE_FREETYPE
static bool /**
framebuffer_plot_text(int x, int y, const char *text, size_t length, * Text plotting.
const plot_font_style_t *fstyle) *
* \param ctx The current redraw context.
* \param fstyle plot style for this text
* \param x x coordinate
* \param y y coordinate
* \param text UTF-8 string to plot
* \param length length of string, in bytes
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_text(const struct redraw_context *ctx,
const struct plot_font_style *fstyle,
int x,
int y,
const char *text,
size_t length)
{ {
uint32_t ucs4; uint32_t ucs4;
size_t nxtchr = 0; size_t nxtchr = 0;
FT_Glyph glyph; FT_Glyph glyph;
FT_BitmapGlyph bglyph; FT_BitmapGlyph bglyph;
nsfb_bbox_t loc; nsfb_bbox_t loc;
while (nxtchr < length) { while (nxtchr < length) {
ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr); ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr);
nxtchr = utf8_next(text, length, nxtchr); nxtchr = utf8_next(text, length, nxtchr);
glyph = fb_getglyph(fstyle, ucs4); glyph = fb_getglyph(fstyle, ucs4);
if (glyph == NULL) if (glyph == NULL)
continue; continue;
if (glyph->format == FT_GLYPH_FORMAT_BITMAP) { if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
bglyph = (FT_BitmapGlyph)glyph; bglyph = (FT_BitmapGlyph)glyph;
loc.x0 = x + bglyph->left; loc.x0 = x + bglyph->left;
loc.y0 = y - bglyph->top; loc.y0 = y - bglyph->top;
loc.x1 = loc.x0 + bglyph->bitmap.width; loc.x1 = loc.x0 + bglyph->bitmap.width;
loc.y1 = loc.y0 + bglyph->bitmap.rows; loc.y1 = loc.y0 + bglyph->bitmap.rows;
/* now, draw to our target surface */ /* now, draw to our target surface */
if (bglyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { if (bglyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {
nsfb_plot_glyph1(nsfb, nsfb_plot_glyph1(nsfb,
&loc, &loc,
bglyph->bitmap.buffer, bglyph->bitmap.buffer,
bglyph->bitmap.pitch, bglyph->bitmap.pitch,
fstyle->foreground); fstyle->foreground);
} else { } else {
nsfb_plot_glyph8(nsfb, nsfb_plot_glyph8(nsfb,
&loc, &loc,
bglyph->bitmap.buffer, bglyph->bitmap.buffer,
bglyph->bitmap.pitch, bglyph->bitmap.pitch,
fstyle->foreground); fstyle->foreground);
} }
} }
x += glyph->advance.x >> 16; x += glyph->advance.x >> 16;
} }
return true; return NSERROR_OK;
} }
#else #else
static bool framebuffer_plot_text(int x, int y, const char *text, size_t length,
const plot_font_style_t *fstyle) /**
* Text plotting.
*
* \param ctx The current redraw context.
* \param fstyle plot style for this text
* \param x x coordinate
* \param y y coordinate
* \param text UTF-8 string to plot
* \param length length of string, in bytes
* \return NSERROR_OK on success else error code.
*/
static nserror
framebuffer_plot_text(const struct redraw_context *ctx,
const struct plot_font_style *fstyle,
int x,
int y,
const char *text,
size_t length)
{ {
enum fb_font_style style = fb_get_font_style(fstyle); enum fb_font_style style = fb_get_font_style(fstyle);
int size = fb_get_font_size(fstyle); int size = fb_get_font_size(fstyle);
@ -145,196 +495,30 @@ static bool framebuffer_plot_text(int x, int y, const char *text, size_t length,
y += 1; y += 1;
while (nxtchr < length) { while (nxtchr < length) {
ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr); ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr);
nxtchr = utf8_next(text, length, nxtchr); nxtchr = utf8_next(text, length, nxtchr);
if (!codepoint_displayable(ucs4)) if (!codepoint_displayable(ucs4))
continue; continue;
loc.x0 = x; loc.x0 = x;
loc.y0 = y; loc.y0 = y;
loc.x1 = loc.x0 + w; loc.x1 = loc.x0 + w;
loc.y1 = loc.y0 + h; loc.y1 = loc.y0 + h;
chrp = fb_get_glyph(ucs4, style, size); chrp = fb_get_glyph(ucs4, style, size);
nsfb_plot_glyph1(nsfb, &loc, chrp, p, fstyle->foreground); nsfb_plot_glyph1(nsfb, &loc, chrp, p, fstyle->foreground);
x += w; x += w;
} }
return true; return NSERROR_OK;
} }
#endif #endif
static bool /** framebuffer plot operation table */
framebuffer_plot_bitmap(int x, int y,
int width, int height,
struct bitmap *bitmap, colour bg,
bitmap_flags_t flags)
{
nsfb_bbox_t loc;
nsfb_bbox_t clipbox;
bool repeat_x = (flags & BITMAPF_REPEAT_X);
bool repeat_y = (flags & BITMAPF_REPEAT_Y);
int bmwidth;
int bmheight;
int bmstride;
enum nsfb_format_e bmformat;
unsigned char *bmptr;
nsfb_t *bm = (nsfb_t *)bitmap;
/* x and y define coordinate of top left of of the initial explicitly
* placed tile. The width and height are the image scaling and the
* bounding box defines the extent of the repeat (which may go in all
* four directions from the initial tile).
*/
if (!(repeat_x || repeat_y)) {
/* Not repeating at all, so just plot it */
loc.x0 = x;
loc.y0 = y;
loc.x1 = loc.x0 + width;
loc.y1 = loc.y0 + height;
return nsfb_plot_copy(bm, NULL, nsfb, &loc);
}
nsfb_plot_get_clip(nsfb, &clipbox);
nsfb_get_geometry(bm, &bmwidth, &bmheight, &bmformat);
nsfb_get_buffer(bm, &bmptr, &bmstride);
/* Optimise tiled plots of 1x1 bitmaps by replacing with a flat fill
* of the area. Can only be done when image is fully opaque. */
if ((bmwidth == 1) && (bmheight == 1)) {
if ((*(nsfb_colour_t *)bmptr & 0xff000000) != 0) {
return nsfb_plot_rectangle_fill(nsfb, &clipbox,
*(nsfb_colour_t *)bmptr);
}
}
/* Optimise tiled plots of bitmaps scaled to 1x1 by replacing with
* a flat fill of the area. Can only be done when image is fully
* opaque. */
if ((width == 1) && (height == 1)) {
if (framebuffer_bitmap_get_opaque(bm)) {
/** TODO: Currently using top left pixel. Maybe centre
* pixel or average value would be better. */
return nsfb_plot_rectangle_fill(nsfb, &clipbox,
*(nsfb_colour_t *)bmptr);
}
}
/* get left most tile position */
if (repeat_x)
for (; x > clipbox.x0; x -= width);
/* get top most tile position */
if (repeat_y)
for (; y > clipbox.y0; y -= height);
/* set up top left tile location */
loc.x0 = x;
loc.y0 = y;
loc.x1 = loc.x0 + width;
loc.y1 = loc.y0 + height;
/* plot tiling across and down to extents */
nsfb_plot_bitmap_tiles(nsfb, &loc,
repeat_x ? ((clipbox.x1 - x) + width - 1) / width : 1,
repeat_y ? ((clipbox.y1 - y) + height - 1) / height : 1,
(nsfb_colour_t *)bmptr, bmwidth, bmheight,
bmstride * 8 / 32, bmformat == NSFB_FMT_ABGR8888);
return true;
}
static bool
framebuffer_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
nsfb_bbox_t rect;
bool dotted = false;
bool dashed = false;
rect.x0 = x0;
rect.y0 = y0;
rect.x1 = x1;
rect.y1 = y1;
if (style->fill_type != PLOT_OP_TYPE_NONE) {
nsfb_plot_rectangle_fill(nsfb, &rect, style->fill_colour);
}
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
if (style->stroke_type == PLOT_OP_TYPE_DOT)
dotted = true;
if (style->stroke_type == PLOT_OP_TYPE_DASH)
dashed = true;
nsfb_plot_rectangle(nsfb, &rect, style->stroke_width, style->stroke_colour, dotted, dashed);
}
return true;
}
static bool
framebuffer_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
{
nsfb_bbox_t rect;
nsfb_plot_pen_t pen;
rect.x0 = x0;
rect.y0 = y0;
rect.x1 = x1;
rect.y1 = y1;
if (style->stroke_type != PLOT_OP_TYPE_NONE) {
if (style->stroke_type == PLOT_OP_TYPE_DOT) {
pen.stroke_type = NFSB_PLOT_OPTYPE_PATTERN;
pen.stroke_pattern = 0xAAAAAAAA;
} else if (style->stroke_type == PLOT_OP_TYPE_DASH) {
pen.stroke_type = NFSB_PLOT_OPTYPE_PATTERN;
pen.stroke_pattern = 0xF0F0F0F0;
} else {
pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
}
pen.stroke_colour = style->stroke_colour;
pen.stroke_width = style->stroke_width;
nsfb_plot_line(nsfb, &rect, &pen);
}
return true;
}
static bool
framebuffer_plot_path(const float *p,
unsigned int n,
colour fill,
float width,
colour c,
const float transform[6])
{
LOG("path unimplemented");
return true;
}
static bool
framebuffer_plot_clip(const struct rect *clip)
{
nsfb_bbox_t nsfb_clip;
nsfb_clip.x0 = clip->x0;
nsfb_clip.y0 = clip->y0;
nsfb_clip.x1 = clip->x1;
nsfb_clip.y1 = clip->y1;
return nsfb_plot_set_clip(nsfb, &nsfb_clip);
}
const struct plotter_table fb_plotters = { const struct plotter_table fb_plotters = {
.clip = framebuffer_plot_clip, .clip = framebuffer_plot_clip,
.arc = framebuffer_plot_arc, .arc = framebuffer_plot_arc,
@ -345,7 +529,7 @@ const struct plotter_table fb_plotters = {
.path = framebuffer_plot_path, .path = framebuffer_plot_path,
.bitmap = framebuffer_plot_bitmap, .bitmap = framebuffer_plot_bitmap,
.text = framebuffer_plot_text, .text = framebuffer_plot_text,
.option_knockout = true, .option_knockout = true,
}; };
@ -394,33 +578,33 @@ framebuffer_initialise(const char *fename, int width, int height, int bpp)
/* bpp is a proxy for the framebuffer format */ /* bpp is a proxy for the framebuffer format */
if (framebuffer_format_from_bpp(bpp, &fbfmt) == false) { if (framebuffer_format_from_bpp(bpp, &fbfmt) == false) {
return NULL; return NULL;
} }
fbtype = nsfb_type_from_name(fename); fbtype = nsfb_type_from_name(fename);
if (fbtype == NSFB_SURFACE_NONE) { if (fbtype == NSFB_SURFACE_NONE) {
LOG("The %s surface is not available from libnsfb\n", fename); LOG("The %s surface is not available from libnsfb\n", fename);
return NULL; return NULL;
} }
nsfb = nsfb_new(fbtype); nsfb = nsfb_new(fbtype);
if (nsfb == NULL) { if (nsfb == NULL) {
LOG("Unable to create %s fb surface\n", fename); LOG("Unable to create %s fb surface\n", fename);
return NULL; return NULL;
} }
if (nsfb_set_geometry(nsfb, width, height, fbfmt) == -1) { if (nsfb_set_geometry(nsfb, width, height, fbfmt) == -1) {
LOG("Unable to set surface geometry\n"); LOG("Unable to set surface geometry\n");
nsfb_free(nsfb); nsfb_free(nsfb);
return NULL; return NULL;
} }
nsfb_cursor_init(nsfb); nsfb_cursor_init(nsfb);
if (nsfb_init(nsfb) == -1) { if (nsfb_init(nsfb) == -1) {
LOG("Unable to initialise nsfb surface\n"); LOG("Unable to initialise nsfb surface\n");
nsfb_free(nsfb); nsfb_free(nsfb);
return NULL; return NULL;
} }
return nsfb; return nsfb;
@ -434,12 +618,12 @@ framebuffer_resize(nsfb_t *nsfb, int width, int height, int bpp)
/* bpp is a proxy for the framebuffer format */ /* bpp is a proxy for the framebuffer format */
if (framebuffer_format_from_bpp(bpp, &fbfmt) == false) { if (framebuffer_format_from_bpp(bpp, &fbfmt) == false) {
return false; return false;
} }
if (nsfb_set_geometry(nsfb, width, height, fbfmt) == -1) { if (nsfb_set_geometry(nsfb, width, height, fbfmt) == -1) {
LOG("Unable to change surface geometry\n"); LOG("Unable to change surface geometry\n");
return false; return false;
} }
return true; return true;
@ -449,14 +633,14 @@ framebuffer_resize(nsfb_t *nsfb, int width, int height, int bpp)
void void
framebuffer_finalise(void) framebuffer_finalise(void)
{ {
nsfb_free(nsfb); nsfb_free(nsfb);
} }
bool bool
framebuffer_set_cursor(struct fbtk_bitmap *bm) framebuffer_set_cursor(struct fbtk_bitmap *bm)
{ {
return nsfb_cursor_set(nsfb, (nsfb_colour_t *)bm->pixdata, bm->width, bm->height, bm->width, bm->hot_x, bm->hot_y); return nsfb_cursor_set(nsfb, (nsfb_colour_t *)bm->pixdata, bm->width, bm->height, bm->width, bm->hot_x, bm->hot_y);
} }
nsfb_t *framebuffer_set_surface(nsfb_t *new_nsfb) nsfb_t *framebuffer_set_surface(nsfb_t *new_nsfb)
{ {