diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-02-16 05:24:27 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-02-16 05:24:27 +0000 |
commit | 877d378710337e7b89b015e3901e467fbcff53be (patch) | |
tree | e372499593369a7dd64f2f8dc72994bc183a829e /apps/gui/skin_engine/skin_backdrops.c | |
parent | 82f05895af2e361b983aa782e4294a641b287429 (diff) | |
download | rockbox-877d378710337e7b89b015e3901e467fbcff53be.tar.gz rockbox-877d378710337e7b89b015e3901e467fbcff53be.zip |
Reuse the backdrop buffers if 2 skins use the same backdrop (on the same screen of course)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24690 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/skin_engine/skin_backdrops.c')
-rw-r--r-- | apps/gui/skin_engine/skin_backdrops.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c new file mode 100644 index 0000000000..b057935241 --- /dev/null +++ b/apps/gui/skin_engine/skin_backdrops.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: skin_tokens.c 24526 2010-02-05 23:58:53Z jdgordon $ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | #include <stdlib.h> | ||
26 | |||
27 | #include "settings.h" | ||
28 | #include "skin_buffer.h" | ||
29 | #include "wps_internals.h" | ||
30 | #include "skin_engine.h" | ||
31 | |||
32 | #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) | ||
33 | |||
34 | static struct skin_backdrop { | ||
35 | char name[MAX_FILENAME+1]; | ||
36 | char *buffer; | ||
37 | enum screen_type screen; | ||
38 | } backdrops[SKINNABLE_SCREENS_COUNT*NB_SCREENS]; | ||
39 | |||
40 | void skin_backdrop_init(void) | ||
41 | { | ||
42 | int i; | ||
43 | for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++) | ||
44 | { | ||
45 | backdrops[i].name[0] = '\0'; | ||
46 | backdrops[i].buffer = NULL; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | /* load a backdrop into the skin buffer. | ||
51 | * reuse buffers if the file is already loaded */ | ||
52 | char* skin_backdrop_load(char* backdrop, char *bmpdir, enum screen_type screen) | ||
53 | { | ||
54 | int i; | ||
55 | struct skin_backdrop *bdrop = NULL; | ||
56 | char filename[MAX_PATH]; | ||
57 | size_t buf_size; | ||
58 | bool loaded = false; | ||
59 | #if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) | ||
60 | if (screen == SCREEN_REMOTE) | ||
61 | buf_size = REMOTE_LCD_BACKDROP_BYTES; | ||
62 | else | ||
63 | #endif | ||
64 | buf_size = LCD_BACKDROP_BYTES; | ||
65 | |||
66 | if (backdrop[0] == '-') | ||
67 | { | ||
68 | #if NB_SCREENS > 1 | ||
69 | if (screen == SCREEN_REMOTE) | ||
70 | { | ||
71 | return NULL; /* remotes don't have a backdrop setting (yet!) */ | ||
72 | } | ||
73 | else | ||
74 | #endif | ||
75 | { | ||
76 | if (!global_settings.backdrop_file[0]) | ||
77 | { | ||
78 | return NULL; /* backdrop setting not set */ | ||
79 | } | ||
80 | snprintf(filename, sizeof(filename), "%s/%s.bmp", | ||
81 | BACKDROP_DIR, global_settings.backdrop_file); | ||
82 | } | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | get_image_filename(backdrop, bmpdir, filename, sizeof(filename)); | ||
87 | } | ||
88 | |||
89 | for(i=0;i<SKINNABLE_SCREENS_COUNT*NB_SCREENS;i++) | ||
90 | { | ||
91 | if (!strcmp(backdrops[i].name, backdrop) && backdrops[i].screen == screen) | ||
92 | { | ||
93 | return backdrops[i].buffer; | ||
94 | } | ||
95 | else if (backdrops[i].buffer == NULL) | ||
96 | { | ||
97 | bdrop = &backdrops[i]; | ||
98 | } | ||
99 | } | ||
100 | if (!bdrop) | ||
101 | return NULL; /* too many backdrops loaded */ | ||
102 | |||
103 | bdrop->buffer = skin_buffer_alloc(buf_size); | ||
104 | if (!bdrop->buffer) | ||
105 | return NULL; | ||
106 | loaded = screens[screen].backdrop_load(filename, bdrop->buffer); | ||
107 | bdrop->screen = screen; | ||
108 | strlcpy(bdrop->name, backdrop, MAX_FILENAME+1); | ||
109 | bdrop->name[MAX_FILENAME] = '\0'; | ||
110 | |||
111 | return loaded ? bdrop->buffer : NULL; | ||
112 | } | ||
113 | #else | ||
114 | |||
115 | void skin_backdrop_init(void) | ||
116 | { | ||
117 | } | ||
118 | #endif | ||
119 | |||