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

Last change on this file since 4328 was 4095, checked in by Sam Hocevar, 11 years ago

Increase profiling timers' sliding mean accuracy.

  • Property svn:keywords set to Id
File size: 6.3 KB
RevLine 
[159]1/*
[672]2 *  libcaca       Colour ASCII-Art library
[4094]3 *  Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
[268]4 *                All Rights Reserved
[159]5 *
[769]6 *  $Id: caca_internals.h 4095 2009-12-07 01:05:31Z sam $
7 *
[1462]8 *  This library is free software. It comes without any warranty, to
[1452]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
[522]12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
[159]13 */
14
[193]15#ifndef __CACA_INTERNALS_H__
16#define __CACA_INTERNALS_H__
[159]17
[2896]18#include "caca_stubs.h"
[3904]19#include "caca_debug.h"
[3905]20#include "caca_prof.h"
[540]21
[777]22typedef struct caca_timer caca_timer_t;
[2049]23typedef struct caca_privevent caca_privevent_t;
[2821]24typedef struct caca_figfont caca_figfont_t;
[777]25
[541]26#if !defined(_DOXYGEN_SKIP_ME)
[4095]27#   define STAT_VALUES 32
[541]28#   define EVENTBUF_LEN 10
[3580]29#   define MAX_DIRTY_COUNT 8
[541]30#endif
31
[2821]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
[3471]65    /* Dirty rectangles */
[3583]66    int ndirty, dirty_disabled;
[3568]67    struct
68    {
[3580]69        int xmin, ymin, xmax, ymax;
[3568]70    }
[3580]71    dirty[MAX_DIRTY_COUNT + 1];
[3448]72
[2821]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
[265]83/* Graphics driver */
84enum caca_driver
85{
[3570]86    CACA_DRIVER_NULL = 0,
[699]87    CACA_DRIVER_RAW = 1,
[1396]88#if defined(USE_COCOA)
89    CACA_DRIVER_COCOA = 2,
90#endif
[265]91#if defined(USE_CONIO)
[1396]92    CACA_DRIVER_CONIO = 3,
[265]93#endif
[699]94#if defined(USE_GL)
[1396]95    CACA_DRIVER_GL = 4,
[699]96#endif
[265]97#if defined(USE_NCURSES)
[1396]98    CACA_DRIVER_NCURSES = 5,
[265]99#endif
100#if defined(USE_SLANG)
[1396]101    CACA_DRIVER_SLANG = 6,
[265]102#endif
[699]103#if defined(USE_VGA)
[1396]104    CACA_DRIVER_VGA = 7,
[265]105#endif
[335]106#if defined(USE_WIN32)
[1396]107    CACA_DRIVER_WIN32 = 8,
[335]108#endif
[699]109#if defined(USE_X11)
[1396]110    CACA_DRIVER_X11 = 9,
[483]111#endif
[265]112};
113
[699]114/* Available external drivers */
[1396]115#if defined(USE_COCOA)
116int cocoa_install(caca_display_t *);
117#endif
[539]118#if defined(USE_CONIO)
[811]119int conio_install(caca_display_t *);
[539]120#endif
121#if defined(USE_GL)
[811]122int gl_install(caca_display_t *);
[539]123#endif
124#if defined(USE_NCURSES)
[811]125int ncurses_install(caca_display_t *);
[539]126#endif
[3570]127int null_install(caca_display_t *);
[811]128int raw_install(caca_display_t *);
[539]129#if defined(USE_SLANG)
[811]130int slang_install(caca_display_t *);
[539]131#endif
[699]132#if defined(USE_VGA)
[811]133int vga_install(caca_display_t *);
[699]134#endif
[539]135#if defined(USE_WIN32)
[811]136int win32_install(caca_display_t *);
[539]137#endif
138#if defined(USE_X11)
[811]139int x11_install(caca_display_t *);
[539]140#endif
[684]141
[331]142/* Timer structure */
143struct caca_timer
144{
145    int last_sec, last_usec;
146};
147
[4094]148/* Statistic structure for profiling */
149struct caca_stat
150{
[4095]151    int itable[STAT_VALUES];
152    int64_t imean;
[4094]153    char *name;
154};
155
[2049]156/* Private event structure */
157struct caca_privevent
158{
159    enum caca_event_type type;
160
161    union
162    {
[2305]163        struct { int x, y, button; } mouse;
164        struct { int w, h; } resize;
165        struct { int ch; uint32_t utf32; char utf8[8]; } key;
[2049]166    } data;
167};
168
[811]169/* Internal caca display context */
170struct caca_display
[524]171{
[2821]172    /* A link to our caca canvas */
173    caca_canvas_t *cv;
[2061]174    int autorelease;
[265]175
[1208]176#if defined(USE_PLUGINS)
177    void *plugin;
178#endif
179
[551]180    /* Device-specific functions */
[550]181    struct drv
[539]182    {
[2138]183        char const * driver;
184        enum caca_driver id;
[550]185        struct driver_private *p;
[539]186
[811]187        int (* init_graphics) (caca_display_t *);
188        int (* end_graphics) (caca_display_t *);
[819]189        int (* set_display_title) (caca_display_t *, char const *);
[2305]190        int (* get_display_width) (caca_display_t const *);
191        int (* get_display_height) (caca_display_t const *);
[811]192        void (* display) (caca_display_t *);
193        void (* handle_resize) (caca_display_t *);
[2049]194        int (* get_event) (caca_display_t *, caca_privevent_t *);
[811]195        void (* set_mouse) (caca_display_t *, int);
[1430]196        void (* set_cursor) (caca_display_t *, int);
[550]197    } drv;
[539]198
[551]199    /* Mouse position */
200    struct mouse
201    {
[2305]202        int x, y;
[551]203    } mouse;
[524]204
[551]205    /* Window resize handling */
[553]206    struct resize
207    {
208        int resized;   /* A resize event was requested */
[2055]209        int allow;     /* The display driver allows resizing */
[2305]210        int w, h; /* Requested width and height */
[553]211    } resize;
[524]212
[551]213    /* Framerate handling */
[2305]214    int delay, rendertime;
[777]215    caca_timer_t timer;
[4094]216#if defined PROF
217    struct caca_stat display_stat, wait_stat;
218    struct caca_stat ev_sys_stat, ev_wait_stat;
219#endif
[527]220    int lastticks;
[524]221
[527]222    struct events
223    {
[681]224#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
[2049]225        caca_privevent_t buf[EVENTBUF_LEN];
[541]226        int queue;
227#endif
[527]228#if defined(USE_SLANG) || defined(USE_NCURSES)
[777]229        caca_timer_t key_timer;
[2305]230        int last_key_ticks;
231        int autorepeat_ticks;
[2049]232        caca_privevent_t last_key_event;
[527]233#endif
[775]234#if defined(USE_WIN32)
[2305]235        uint8_t not_empty_struct;
[775]236#endif
[527]237    } events;
[524]238};
239
[3568]240/* Dirty rectangle functions */
241extern void _caca_clip_dirty_rect_list(caca_canvas_t *);
242
[2821]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
[645]251/* Internal timer functions */
[2305]252extern void _caca_sleep(int);
253extern int _caca_getticks(caca_timer_t *);
[331]254
[645]255/* Internal event functions */
[811]256extern void _caca_handle_resize(caca_display_t *);
[681]257#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
[2049]258extern void _push_event(caca_display_t *, caca_privevent_t *);
259extern int _pop_event(caca_display_t *, caca_privevent_t *);
[645]260#endif
261
[1392]262/* Internal window functions */
263extern void _caca_set_term_title(char const *);
264
[4094]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
[193]272#endif /* __CACA_INTERNALS_H__ */
Note: See TracBrowser for help on using the repository browser.