NetSurf
Functions | Variables
framebuffer.c File Reference
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <libnsfb.h>
#include <libnsfb_plot.h>
#include <libnsfb_event.h>
#include <libnsfb_cursor.h>
#include "utils/utils.h"
#include "utils/log.h"
#include "utils/utf8.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "netsurf/bitmap.h"
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
#include "framebuffer/framebuffer.h"
#include "framebuffer/font.h"
#include "framebuffer/bitmap.h"
Include dependency graph for framebuffer.c:

Go to the source code of this file.

Functions

static nserror framebuffer_plot_clip (const struct redraw_context *ctx, const struct rect *clip)
 Sets a clip rectangle for subsequent plot operations. More...
 
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)
 Plots an arc. More...
 
static nserror framebuffer_plot_disc (const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius)
 Plots a circle. More...
 
static nserror framebuffer_plot_line (const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
 Plots a line. More...
 
static nserror framebuffer_plot_rectangle (const struct redraw_context *ctx, const plot_style_t *style, const struct rect *nsrect)
 Plots a rectangle. More...
 
static nserror framebuffer_plot_polygon (const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
 Plot a polygon. More...
 
static nserror framebuffer_plot_path (const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
 Plots a path. More...
 
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)
 Plot a bitmap. More...
 
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)
 Text plotting. More...
 
static bool framebuffer_format_from_bpp (int bpp, enum nsfb_format_e *fmt)
 
nsfb_t * framebuffer_initialise (const char *fename, int width, int height, int bpp)
 
bool framebuffer_resize (nsfb_t *nsfb, int width, int height, int bpp)
 
void framebuffer_finalise (void)
 
bool framebuffer_set_cursor (struct fbtk_bitmap *bm)
 
nsfb_t * framebuffer_set_surface (nsfb_t *new_nsfb)
 Set framebuffer surface to render into. More...
 

Variables

static nsfb_t * nsfb
 
const struct plotter_table fb_plotters
 framebuffer plot operation table More...
 

Function Documentation

◆ framebuffer_finalise()

void framebuffer_finalise ( void  )

Definition at line 638 of file framebuffer.c.

References nsfb.

Referenced by gui_quit().

Here is the caller graph for this function:

◆ framebuffer_format_from_bpp()

static bool framebuffer_format_from_bpp ( int  bpp,
enum nsfb_format_e *  fmt 
)
static

Definition at line 539 of file framebuffer.c.

References NSLOG.

Referenced by framebuffer_initialise(), and framebuffer_resize().

Here is the caller graph for this function:

◆ framebuffer_initialise()

nsfb_t * framebuffer_initialise ( const char *  fename,
int  width,
int  height,
int  bpp 
)

Definition at line 577 of file framebuffer.c.

References fename, framebuffer_format_from_bpp(), height, nsfb, NSLOG, and width.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ framebuffer_plot_arc()

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 
)
static

Plots an arc.

plot an arc segment around (x,y), anticlockwise from angle1 to angle2. Angles are measured anticlockwise from horizontal, in degrees.

Parameters
ctxThe current redraw context.
styleStyle controlling the arc plot.
xThe x coordinate of the arc.
yThe y coordinate of the arc.
radiusThe radius of the arc.
angle1The start angle of the arc.
angle2The finish angle of the arc.
Returns
NSERROR_OK on success else error code.

Definition at line 89 of file framebuffer.c.

References plot_style_s::fill_colour, NSERROR_INVALID, NSERROR_OK, and nsfb.

◆ framebuffer_plot_bitmap()

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 
)
static

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.

Parameters
ctxThe current redraw context.
bitmapThe bitmap to plot
xThe x coordinate to plot the bitmap
yThe y coordiante to plot the bitmap
widthThe width of area to plot the bitmap into
heightThe height of area to plot the bitmap into
bgthe background colour to alpha blend into
flagsthe flags controlling the type of plot operation
Returns
NSERROR_OK on success else error code.

TODO: Currently using top left pixel. Maybe centre pixel or average value would be better.

Definition at line 304 of file framebuffer.c.

References BITMAPF_REPEAT_X, BITMAPF_REPEAT_Y, framebuffer_bitmap_get_opaque(), height, NSERROR_INVALID, NSERROR_OK, nsfb, and width.

Here is the call graph for this function:

◆ framebuffer_plot_clip()

static nserror framebuffer_plot_clip ( const struct redraw_context ctx,
const struct rect clip 
)
static

Sets a clip rectangle for subsequent plot operations.

Parameters
ctxThe current redraw context.
clipThe rectangle to limit all subsequent plot operations within.
Returns
NSERROR_OK on success else error code.

Definition at line 57 of file framebuffer.c.

References clip(), NSERROR_INVALID, NSERROR_OK, and nsfb.

Here is the call graph for this function:

◆ framebuffer_plot_disc()

static nserror framebuffer_plot_disc ( const struct redraw_context ctx,
const plot_style_t style,
int  x,
int  y,
int  radius 
)
static

Plots a circle.

Plot a circle centered on (x,y), which is optionally filled.

Parameters
ctxThe current redraw context.
styleStyle controlling the circle plot.
xx coordinate of circle centre.
yy coordinate of circle centre.
radiuscircle radius.
Returns
NSERROR_OK on success else error code.

Definition at line 113 of file framebuffer.c.

References plot_style_s::fill_colour, plot_style_s::fill_type, NSERROR_OK, nsfb, PLOT_OP_TYPE_NONE, plot_style_s::stroke_colour, and plot_style_s::stroke_type.

◆ framebuffer_plot_line()

static nserror framebuffer_plot_line ( const struct redraw_context ctx,
const plot_style_t style,
const struct rect line 
)
static

Plots a line.

plot a line from (x0,y0) to (x1,y1). Coordinates are at centre of line width/thickness.

Parameters
ctxThe current redraw context.
styleStyle controlling the line plot.
lineA rectangle defining the line to be drawn
Returns
NSERROR_OK on success else error code.

Definition at line 146 of file framebuffer.c.

References line(), NSERROR_OK, nsfb, PLOT_OP_TYPE_DASH, PLOT_OP_TYPE_DOT, PLOT_OP_TYPE_NONE, plot_style_fixed_to_int, plot_style_s::stroke_colour, plot_style_s::stroke_type, plot_style_s::stroke_width, rect::x0, rect::x1, rect::y0, and rect::y1.

Here is the call graph for this function:

◆ framebuffer_plot_path()

static nserror framebuffer_plot_path ( const struct redraw_context ctx,
const plot_style_t pstyle,
const float *  p,
unsigned int  n,
const float  transform[6] 
)
static

Plots a path.

Path plot consisting of cubic Bezier curves. Line and fill colour is controlled by the plot style.

Parameters
ctxThe current redraw context.
pstyleStyle controlling the path plot.
pelements of path
nnunber of elements on path
transformA transform to apply to the path.
Returns
NSERROR_OK on success else error code.

Definition at line 268 of file framebuffer.c.

References NSERROR_OK, and NSLOG.

◆ framebuffer_plot_polygon()

static nserror framebuffer_plot_polygon ( const struct redraw_context ctx,
const plot_style_t style,
const int *  p,
unsigned int  n 
)
static

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.

Parameters
ctxThe current redraw context.
styleStyle controlling the polygon plot.
pverticies of polygon
nnumber of verticies.
Returns
NSERROR_OK on success else error code.

Definition at line 242 of file framebuffer.c.

References plot_style_s::fill_colour, NSERROR_INVALID, NSERROR_OK, and nsfb.

◆ framebuffer_plot_rectangle()

static nserror framebuffer_plot_rectangle ( const struct redraw_context ctx,
const plot_style_t style,
const struct rect nsrect 
)
static

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.

Parameters
ctxThe current redraw context.
styleStyle controlling the rectangle plot.
nsrectA rectangle defining the line to be drawn
Returns
NSERROR_OK on success else error code.

Definition at line 193 of file framebuffer.c.

References plot_style_s::fill_colour, plot_style_s::fill_type, NSERROR_OK, nsfb, PLOT_OP_TYPE_DASH, PLOT_OP_TYPE_DOT, PLOT_OP_TYPE_NONE, plot_style_fixed_to_int, plot_style_s::stroke_colour, plot_style_s::stroke_type, plot_style_s::stroke_width, rect::x0, rect::x1, rect::y0, and rect::y1.

◆ framebuffer_plot_text()

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 
)
static

Text plotting.

Parameters
ctxThe current redraw context.
fstyleplot style for this text
xx coordinate
yy coordinate
textUTF-8 string to plot
lengthlength of string, in bytes
Returns
NSERROR_OK on success else error code.

Definition at line 478 of file framebuffer.c.

References codepoint_displayable, FB_FONT_HEIGHT, FB_FONT_PITCH, FB_FONT_WIDTH, fb_get_font_size(), fb_get_font_style(), fb_get_glyph(), plot_font_style::foreground, NSERROR_OK, nsfb, text(), utf8_next(), and utf8_to_ucs4().

Here is the call graph for this function:

◆ framebuffer_resize()

bool framebuffer_resize ( nsfb_t *  nsfb,
int  width,
int  height,
int  bpp 
)

Definition at line 619 of file framebuffer.c.

References framebuffer_format_from_bpp(), height, nsfb, NSLOG, and width.

Referenced by gui_resize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ framebuffer_set_cursor()

bool framebuffer_set_cursor ( struct fbtk_bitmap bm)

Definition at line 644 of file framebuffer.c.

References fbtk_bitmap::height, fbtk_bitmap::hot_x, fbtk_bitmap::hot_y, nsfb, fbtk_bitmap::pixdata, and fbtk_bitmap::width.

Referenced by fb_url_move(), gui_window_set_pointer(), main(), and set_ptr_default_move().

Here is the caller graph for this function:

◆ framebuffer_set_surface()

nsfb_t * framebuffer_set_surface ( nsfb_t *  new_nsfb)

Set framebuffer surface to render into.

Returns
return old surface

Definition at line 649 of file framebuffer.c.

References nsfb.

Referenced by bitmap_render().

Here is the caller graph for this function:

Variable Documentation

◆ fb_plotters

const struct plotter_table fb_plotters
Initial value:
= {
.option_knockout = true,
}
static nserror framebuffer_plot_path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: framebuffer.c:268
static nserror framebuffer_plot_line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
Definition: framebuffer.c:146
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)
Plot a bitmap.
Definition: framebuffer.c:304
static nserror framebuffer_plot_polygon(const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
Plot a polygon.
Definition: framebuffer.c:242
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)
Text plotting.
Definition: framebuffer.c:478
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)
Plots an arc.
Definition: framebuffer.c:89
static nserror framebuffer_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: framebuffer.c:57
static nserror framebuffer_plot_rectangle(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *nsrect)
Plots a rectangle.
Definition: framebuffer.c:193
static nserror framebuffer_plot_disc(const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius)
Plots a circle.
Definition: framebuffer.c:113

framebuffer plot operation table

Definition at line 525 of file framebuffer.c.

Referenced by bitmap_render(), fb_local_history_draw(), fb_redraw(), fb_redraw_text(), and fb_redraw_text_button().

◆ nsfb

nsfb_t* nsfb
static