1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #include "core_alloc.h"
26 #include "string-extra.h"
28 #include "wps_internals.h"
29 #include "skin_engine.h"
31 #if !defined(__PCTOOL__) && defined(HAVE_BACKDROP_IMAGE)
33 #define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
34 static struct skin_backdrop
{
37 enum screen_type screen
;
41 } backdrops
[NB_BDROPS
];
43 #define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
44 static int handle_being_loaded
;
45 static int current_lcd_backdrop
[NB_SCREENS
];
47 static int buflib_move_callback(int handle
, void* current
, void* new)
49 if (handle
== handle_being_loaded
)
50 return BUFLIB_CB_CANNOT_MOVE
;
51 for (int i
=0; i
<NB_BDROPS
; i
++)
53 if (backdrops
[i
].buffer
== current
)
55 backdrops
[i
].buffer
= new;
60 skin_backdrop_show(current_lcd_backdrop
[i
]);
63 static struct buflib_callbacks buflib_ops
= {buflib_move_callback
, NULL
, NULL
};
64 static bool first_go
= true;
65 void skin_backdrop_init(void)
69 for (int i
=0; i
<NB_BDROPS
; i
++)
71 backdrops
[i
].buflib_handle
= -1;
72 backdrops
[i
].name
[0] = '\0';
73 backdrops
[i
].buffer
= NULL
;
74 backdrops
[i
].loaded
= false;
75 backdrops
[i
].ref_count
= 0;
78 current_lcd_backdrop
[i
] = -1;
79 handle_being_loaded
= -1;
84 int skin_backdrop_assign(char* backdrop
, char *bmpdir
,
85 enum screen_type screen
)
87 char filename
[MAX_PATH
];
91 if (backdrop
[0] == '-')
95 filename
[2] = '\0'; /* we check this later to see if we actually have an
96 image to load. != '\0' means display the image */
98 else if (!strcmp(backdrop
, BACKDROP_BUFFERNAME
))
100 strcpy(filename
, backdrop
);
104 get_image_filename(backdrop
, bmpdir
, filename
, sizeof(filename
));
106 for (i
=0; i
<NB_BDROPS
; i
++)
108 if (!backdrops
[i
].name
[0] && free
< 0)
113 else if (!strcmp(backdrops
[i
].name
, filename
) && backdrops
[i
].screen
== screen
)
115 backdrops
[i
].ref_count
++;
121 strlcpy(backdrops
[free
].name
, filename
, MAX_PATH
);
122 backdrops
[free
].buffer
= NULL
;
123 backdrops
[free
].screen
= screen
;
124 backdrops
[free
].ref_count
= 1;
127 else if (i
< NB_BDROPS
)
132 bool skin_backdrops_preload(void)
137 for (i
=0; i
<NB_BDROPS
; i
++)
139 if (backdrops
[i
].name
[0] && !backdrops
[i
].buffer
)
142 enum screen_type screen
= backdrops
[i
].screen
;
143 #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
144 if (screen
== SCREEN_REMOTE
)
145 buf_size
= REMOTE_LCD_BACKDROP_BYTES
;
148 buf_size
= LCD_BACKDROP_BYTES
;
150 filename
= backdrops
[i
].name
;
151 if (screen
== SCREEN_MAIN
&& global_settings
.backdrop_file
[0] &&
152 global_settings
.backdrop_file
[0] != '-' && filename
[0] == '-')
154 filename
= global_settings
.backdrop_file
;
156 if (*filename
&& *filename
!= '-')
158 backdrops
[i
].buflib_handle
= core_alloc_ex(filename
, buf_size
, &buflib_ops
);
159 if (backdrops
[i
].buflib_handle
> 0)
161 backdrops
[i
].buffer
= core_get_data(backdrops
[i
].buflib_handle
);
162 handle_being_loaded
= backdrops
[i
].buflib_handle
;
163 if (strcmp(filename
, BACKDROP_BUFFERNAME
))
165 backdrops
[i
].loaded
=
166 screens
[screen
].backdrop_load(filename
, backdrops
[i
].buffer
);
167 handle_being_loaded
= -1;
168 if (!backdrops
[i
].loaded
)
170 core_free(backdrops
[i
].buflib_handle
);
171 backdrops
[i
].buflib_handle
= -1;
176 backdrops
[i
].loaded
= true;
181 if (backdrops
[i
].name
[0] == '-' && backdrops
[i
].loaded
)
182 backdrops
[i
].name
[2] = '.';
188 void* skin_backdrop_get_buffer(int backdrop_id
)
192 return backdrops
[backdrop_id
].buffer
;
195 void skin_backdrop_show(int backdrop_id
)
199 screens
[0].backdrop_show(NULL
);
200 current_lcd_backdrop
[0] = -1;
203 enum screen_type screen
= backdrops
[backdrop_id
].screen
;
204 if ((backdrops
[backdrop_id
].loaded
== false) ||
205 (backdrops
[backdrop_id
].name
[0] == '-' &&
206 backdrops
[backdrop_id
].name
[2] == '\0'))
208 screens
[screen
].backdrop_show(NULL
);
209 current_lcd_backdrop
[screen
] = -1;
211 else if (backdrops
[backdrop_id
].buffer
)
213 screens
[screen
].backdrop_show(backdrops
[backdrop_id
].buffer
);
214 current_lcd_backdrop
[screen
] = backdrop_id
;
218 void skin_backdrop_unload(int backdrop_id
)
220 backdrops
[backdrop_id
].ref_count
--;
221 if (backdrops
[backdrop_id
].ref_count
<= 0)
223 if (backdrops
[backdrop_id
].buflib_handle
> 0)
224 core_free(backdrops
[backdrop_id
].buflib_handle
);
225 backdrops
[backdrop_id
].buffer
= NULL
;
226 backdrops
[backdrop_id
].buflib_handle
= -1;
227 backdrops
[backdrop_id
].loaded
= false;
228 backdrops
[backdrop_id
].name
[0] = '\0';
229 backdrops
[backdrop_id
].ref_count
= 0;
233 void skin_backdrop_load_setting(void)
236 for(i
=0;i
<SKINNABLE_SCREENS_COUNT
*NB_SCREENS
;i
++)
238 if (backdrops
[i
].name
[0] == '-' && backdrops
[i
].screen
== SCREEN_MAIN
)
240 if (global_settings
.backdrop_file
[0] &&
241 global_settings
.backdrop_file
[0] != '-')
243 if (!backdrops
[i
].buflib_handle
<= 0)
245 backdrops
[i
].buflib_handle
=
246 core_alloc_ex(global_settings
.backdrop_file
,
247 LCD_BACKDROP_BYTES
, &buflib_ops
);
248 if (backdrops
[i
].buflib_handle
<= 0)
252 backdrops
[i
].buffer
= core_get_data(backdrops
[i
].buflib_handle
);
253 handle_being_loaded
= backdrops
[i
].buflib_handle
;
254 loaded
= screens
[SCREEN_MAIN
].backdrop_load(
255 global_settings
.backdrop_file
,
256 backdrops
[i
].buffer
);
257 handle_being_loaded
= -1;
258 backdrops
[i
].name
[2] = loaded
? '.' : '\0';
259 backdrops
[i
].loaded
= loaded
;
263 backdrops
[i
].name
[2] = '\0';
266 else if (backdrops
[i
].name
[0] == '-')
268 backdrops
[i
].name
[2] = '\0';
274 #elif defined(__PCTOOL__)
276 int skin_backdrop_assign(char* backdrop
, char *bmpdir
,
277 enum screen_type screen
)
284 void skin_backdrop_unload(int backdrop_id
)
290 void skin_backdrop_init(void)