source: libcaca/trunk/caca/caca_internals.h @ 4095

Last change on this file since 4095 was 4095, checked in by sam, 4 years ago

Increase profiling timers' sliding mean accuracy.

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  $Id$
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#ifndef __CACA_INTERNALS_H__
16#define __CACA_INTERNALS_H__
17
18#include "caca_stubs.h"
19#include "caca_debug.h"
20#include "caca_prof.h"
21
22typedef struct caca_timer caca_timer_t;
23typedef struct caca_privevent caca_privevent_t;
24typedef struct caca_figfont caca_figfont_t;
25
26#if !defined(_DOXYGEN_SKIP_ME)
27#   define STAT_VALUES 32
28#   define EVENTBUF_LEN 10
29#   define MAX_DIRTY_COUNT 8
30#endif
31
32struct caca_frame
33{
34    /* Frame size */
35    int width, height;
36
37    /* Cell information */
38    uint32_t *chars;
39    uint32_t *attrs;
40
41    /* Painting context */
42    int x, y;
43    int handlex, handley;
44    uint32_t curattr;
45
46    /* Frame name */
47    char *name;
48};
49
50struct caca_canvas
51{
52    /* XXX: look at caca_set_canvas_boundaries() before adding anything
53     * to this structure. The function is quite hacky. */
54
55    /* Frame information */
56    int frame, framecount;
57    struct caca_frame *frames;
58
59    /* Canvas management */
60    int refcount;
61    int autoinc;
62    int (*resize_callback)(void *);
63    void *resize_data;
64
65    /* Dirty rectangles */
66    int ndirty, dirty_disabled;
67    struct
68    {
69        int xmin, ymin, xmax, ymax;
70    }
71    dirty[MAX_DIRTY_COUNT + 1];
72
73    /* Shortcut to the active frame information */
74    int width, height;
75    uint32_t *chars;
76    uint32_t *attrs;
77    uint32_t curattr;
78
79    /* FIGfont management */
80    caca_figfont_t *ff;
81};
82
83/* Graphics driver */
84enum caca_driver
85{
86    CACA_DRIVER_NULL = 0,
87    CACA_DRIVER_RAW = 1,
88#if defined(USE_COCOA)
89    CACA_DRIVER_COCOA = 2,
90#endif
91#if defined(USE_CONIO)
92    CACA_DRIVER_CONIO = 3,
93#endif
94#if defined(USE_GL)
95    CACA_DRIVER_GL = 4,
96#endif
97#if defined(USE_NCURSES)
98    CACA_DRIVER_NCURSES = 5,
99#endif
100#if defined(USE_SLANG)
101    CACA_DRIVER_SLANG = 6,
102#endif
103#if defined(USE_VGA)
104    CACA_DRIVER_VGA = 7,
105#endif
106#if defined(USE_WIN32)
107    CACA_DRIVER_WIN32 = 8,
108#endif
109#if defined(USE_X11)
110    CACA_DRIVER_X11 = 9,
111#endif
112};
113
114/* Available external drivers */
115#if defined(USE_COCOA)
116int cocoa_install(caca_display_t *);
117#endif
118#if defined(USE_CONIO)
119int conio_install(caca_display_t *);
120#endif
121#if defined(USE_GL)
122int gl_install(caca_display_t *);
123#endif
124#if defined(USE_NCURSES)
125int ncurses_install(caca_display_t *);
126#endif
127int null_install(caca_display_t *);
128int raw_install(caca_display_t *);
129#if defined(USE_SLANG)
130int slang_install(caca_display_t *);
131#endif
132#if defined(USE_VGA)
133int vga_install(caca_display_t *);
134#endif
135#if defined(USE_WIN32)
136int win32_install(caca_display_t *);
137#endif
138#if defined(USE_X11)
139int x11_install(caca_display_t *);
140#endif
141
142/* Timer structure */
143struct caca_timer
144{
145    int last_sec, last_usec;
146};
147
148/* Statistic structure for profiling */
149struct caca_stat
150{
151    int itable[STAT_VALUES];
152    int64_t imean;
153    char *name;
154};
155
156/* Private event structure */
157struct caca_privevent
158{
159    enum caca_event_type type;
160
161    union
162    {
163        struct { int x, y, button; } mouse;
164        struct { int w, h; } resize;
165        struct { int ch; uint32_t utf32; char utf8[8]; } key;
166    } data;
167};
168
169/* Internal caca display context */
170struct caca_display
171{
172    /* A link to our caca canvas */
173    caca_canvas_t *cv;
174    int autorelease;
175
176#if defined(USE_PLUGINS)
177    void *plugin;
178#endif
179
180    /* Device-specific functions */
181    struct drv
182    {
183        char const * driver;
184        enum caca_driver id;
185        struct driver_private *p;
186
187        int (* init_graphics) (caca_display_t *);
188        int (* end_graphics) (caca_display_t *);
189        int (* set_display_title) (caca_display_t *, char const *);
190        int (* get_display_width) (caca_display_t const *);
191        int (* get_display_height) (caca_display_t const *);
192        void (* display) (caca_display_t *);
193        void (* handle_resize) (caca_display_t *);
194        int (* get_event) (caca_display_t *, caca_privevent_t *);
195        void (* set_mouse) (caca_display_t *, int);
196        void (* set_cursor) (caca_display_t *, int);
197    } drv;
198
199    /* Mouse position */
200    struct mouse
201    {
202        int x, y;
203    } mouse;
204
205    /* Window resize handling */
206    struct resize
207    {
208        int resized;   /* A resize event was requested */
209        int allow;     /* The display driver allows resizing */
210        int w, h; /* Requested width and height */
211    } resize;
212
213    /* Framerate handling */
214    int delay, rendertime;
215    caca_timer_t timer;
216#if defined PROF
217    struct caca_stat display_stat, wait_stat;
218    struct caca_stat ev_sys_stat, ev_wait_stat;
219#endif
220    int lastticks;
221
222    struct events
223    {
224#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
225        caca_privevent_t buf[EVENTBUF_LEN];
226        int queue;
227#endif
228#if defined(USE_SLANG) || defined(USE_NCURSES)
229        caca_timer_t key_timer;
230        int last_key_ticks;
231        int autorepeat_ticks;
232        caca_privevent_t last_key_event;
233#endif
234#if defined(USE_WIN32)
235        uint8_t not_empty_struct;
236#endif
237    } events;
238};
239
240/* Dirty rectangle functions */
241extern void _caca_clip_dirty_rect_list(caca_canvas_t *);
242
243/* Colour functions */
244extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
245extern uint32_t _caca_attr_to_rgb24bg(uint32_t);
246
247/* Frames functions */
248extern void _caca_save_frame_info(caca_canvas_t *);
249extern void _caca_load_frame_info(caca_canvas_t *);
250
251/* Internal timer functions */
252extern void _caca_sleep(int);
253extern int _caca_getticks(caca_timer_t *);
254
255/* Internal event functions */
256extern void _caca_handle_resize(caca_display_t *);
257#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
258extern void _push_event(caca_display_t *, caca_privevent_t *);
259extern int _pop_event(caca_display_t *, caca_privevent_t *);
260#endif
261
262/* Internal window functions */
263extern void _caca_set_term_title(char const *);
264
265/* Profiling functions */
266#if defined PROF
267extern void _caca_dump_stats(void);
268extern void _caca_init_stat(struct caca_stat *, char const *, ...);
269extern void _caca_fini_stat(struct caca_stat *);
270#endif
271
272#endif /* __CACA_INTERNALS_H__ */
Note: See TracBrowser for help on using the repository browser.