summaryrefslogtreecommitdiff
path: root/src/libnsfb.c
blob: 21661cdbfc753c7eb7117d26234f44196e9e917d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * 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 <stdlib.h>

#include "libnsfb.h"
#include "libnsfb_plot.h"
#include "libnsfb_event.h"
#include "nsfb.h"
#include "surface.h"

/* exported interface documented in libnsfb.h */
nsfb_t*
nsfb_new(const enum nsfb_type_e surface_type)
{
    nsfb_t *newfb;
    newfb = calloc(1, sizeof(nsfb_t));
    if (newfb == NULL)
        return NULL;

    /* obtain surface routines */
    newfb->surface_rtns = nsfb_surface_get_rtns(surface_type);
    if (newfb->surface_rtns == NULL) {
        free(newfb);
        return NULL;
    }

    newfb->surface_rtns->defaults(newfb);

    return newfb;
}

/* exported interface documented in libnsfb.h */
int
nsfb_init(nsfb_t *nsfb)
{
    return nsfb->surface_rtns->initialise(nsfb);
}

/* exported interface documented in libnsfb.h */
int 
nsfb_free(nsfb_t *nsfb)
{
    int ret;
    ret = nsfb->surface_rtns->finalise(nsfb);
    free(nsfb);
    return ret;
}

/* exported interface documented in libnsfb.h */
bool 
nsfb_event(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
{
    return nsfb->surface_rtns->input(nsfb, event, timeout);
}

/* exported interface documented in libnsfb.h */
int 
nsfb_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
{
    return nsfb->surface_rtns->claim(nsfb, box);
}

/* exported interface documented in libnsfb.h */
int 
nsfb_update(nsfb_t *nsfb, nsfb_bbox_t *box)
{
    return nsfb->surface_rtns->update(nsfb, box);
}

/* exported interface documented in libnsfb.h */
int 
nsfb_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format) 
{
    if (width <= 0)
        width = nsfb->width;        

    if (height <= 0)
        height = nsfb->height;        

    if (format == NSFB_FMT_ANY)
	    format = nsfb->format; 

    return nsfb->surface_rtns->geometry(nsfb, width, height, format);
}

/* exported interface documented in libnsfb.h */
int 
nsfb_get_geometry(nsfb_t *nsfb, int *width, int *height, enum nsfb_format_e *format) 
{
    if (width != NULL)
        *width = nsfb->width;

    if (height != NULL)
        *height = nsfb->height;

    if (format != NULL)
        *format = nsfb->format;

    return 0;
}

/* exported interface documented in libnsfb.h */
int 
nsfb_get_buffer(nsfb_t *nsfb, uint8_t **ptr, int *linelen) 
{
    if (ptr != NULL) {
	*ptr = nsfb->ptr;
    }
    if (linelen != NULL) {
	*linelen = nsfb->linelen;
    }
    return 0;
}


/*
 * Local variables:
 *  c-basic-offset: 4
 *  tab-width: 8
 * End:
 */