diff options
Diffstat (limited to 'apps/gui/skin_engine/skin_buffer.c')
-rw-r--r-- | apps/gui/skin_engine/skin_buffer.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/apps/gui/skin_engine/skin_buffer.c b/apps/gui/skin_engine/skin_buffer.c new file mode 100644 index 0000000000..2d10a931ec --- /dev/null +++ b/apps/gui/skin_engine/skin_buffer.c | |||
@@ -0,0 +1,100 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: wps_parser.c 19880 2009-01-29 20:49:43Z mcuelenaere $ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * Copyright (C) 2009 Jonathan Gordon | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | #include <stdlib.h> | ||
26 | #include "config.h" | ||
27 | #include "buffer.h" | ||
28 | #include "settings.h" | ||
29 | #include "screen_access.h" | ||
30 | |||
31 | /* skin buffer management. | ||
32 | * This module is used to allocate space in a single global skin buffer for | ||
33 | * tokens for both/all screens. | ||
34 | * | ||
35 | * This is mostly just copy/paste from firmware/buffer.c | ||
36 | */ | ||
37 | |||
38 | #define IMG_BUFSIZE (((LCD_HEIGHT*LCD_WIDTH*LCD_DEPTH/8) \ | ||
39 | + (2*LCD_HEIGHT*LCD_WIDTH/8)) * NB_SCREENS) | ||
40 | |||
41 | static unsigned char buffer_start[IMG_BUFSIZE], *buffer_pos = NULL; | ||
42 | static size_t buf_size = IMG_BUFSIZE; | ||
43 | |||
44 | void skin_buffer_init(void) | ||
45 | { | ||
46 | #if 0 /* this will go in again later probably */ | ||
47 | if (buffer_start == NULL) | ||
48 | { | ||
49 | buf_size = IMG_BUFSIZE;/* global_settings.skin_buf_size */ | ||
50 | |||
51 | buffer_start = buffer_alloc(buf_size); | ||
52 | buffer_pos = buffer_start; | ||
53 | } | ||
54 | else | ||
55 | #endif | ||
56 | { | ||
57 | /* reset the buffer.... */ | ||
58 | buffer_pos = buffer_start; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /* get the number of bytes currently being used */ | ||
63 | size_t skin_buffer_usage(void) | ||
64 | { | ||
65 | return buffer_pos-buffer_start; | ||
66 | } | ||
67 | |||
68 | /* Allocate size bytes from the buffer */ | ||
69 | void* skin_buffer_alloc(size_t size) | ||
70 | { | ||
71 | void* retval = buffer_pos; | ||
72 | if (skin_buffer_usage()+size >= buf_size) | ||
73 | { | ||
74 | return NULL; | ||
75 | } | ||
76 | buffer_pos += size; | ||
77 | /* 32-bit aligned */ | ||
78 | buffer_pos = (void *)(((unsigned long)buffer_pos + 3) & ~3); | ||
79 | return retval; | ||
80 | } | ||
81 | |||
82 | /* Get a pointer to the skin buffer and the count of how much is free | ||
83 | * used to do your own buffer management. | ||
84 | * Any memory used will be overwritten next time wps_buffer_alloc() | ||
85 | * is called unless skin_buffer_increment() is called first | ||
86 | */ | ||
87 | void* skin_buffer_grab(size_t *freespace) | ||
88 | { | ||
89 | *freespace = buf_size - skin_buffer_usage(); | ||
90 | return buffer_pos; | ||
91 | } | ||
92 | |||
93 | /* Use after skin_buffer_grab() to specify how much buffer was used */ | ||
94 | void skin_buffer_increment(size_t used) | ||
95 | { | ||
96 | buffer_pos += used; | ||
97 | /* 32-bit aligned */ | ||
98 | buffer_pos = (void *)(((unsigned long)buffer_pos + 3) & ~3); | ||
99 | } | ||
100 | |||