summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_image_load.c
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-04-25 15:07:11 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-05-06 19:02:04 +0900
commit6f802ab2340b95d9c6422b814bc71e5707ed9353 (patch)
tree39876765b687227356a29259c67c363c6e5f7dc7 /src/lib/evas/common/evas_image_load.c
parentc5b0d28d73d2e5a534d071e9e14b34ec9b4c2726 (diff)
evas: start work on making the loader module a public API.
Goal is to be able to remove all internal Evas call from inside all loader module. To do so we are going to open and hold a reference to the file from outside of the module, read the header, create the image data, load the data, close that reference. Once that done, the next step is to let the file remain open as soon as the filename/key is set and add an API to set an Eina_File directly. This way edje can maintain the same file open as it use for an edje object, keeping things in sync and avoid rendering glitch during update.
Diffstat (limited to 'src/lib/evas/common/evas_image_load.c')
-rw-r--r--src/lib/evas/common/evas_image_load.c126
1 files changed, 70 insertions, 56 deletions
diff --git a/src/lib/evas/common/evas_image_load.c b/src/lib/evas/common/evas_image_load.c
index 3bea0f5662..bc90940694 100644
--- a/src/lib/evas/common/evas_image_load.c
+++ b/src/lib/evas/common/evas_image_load.c
@@ -137,34 +137,83 @@ struct evas_image_foreach_loader_data
137 Evas_Module *em; 137 Evas_Module *em;
138}; 138};
139 139
140
141static Eina_Bool 140static Eina_Bool
142_evas_image_foreach_loader(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata) 141_evas_image_file_header(Evas_Module *em, Image_Entry *ie, int *error)
143{ 142{
144 Evas_Image_Load_Func *evas_image_load_func = NULL; 143 Evas_Image_Load_Func *evas_image_load_func = NULL;
145 Evas_Module *em = data; 144 Eina_Bool r = EINA_TRUE;
146 struct evas_image_foreach_loader_data *d = fdata; 145
147 Image_Entry *ie = d->ie; 146 if (!evas_module_load(em)) goto load_error;
148
149 if (!evas_module_load(em)) return EINA_TRUE;
150 evas_image_load_func = em->functions; 147 evas_image_load_func = em->functions;
151 evas_module_use(em); 148 evas_module_use(em);
152 *(d->error) = EVAS_LOAD_ERROR_NONE; 149 *error = EVAS_LOAD_ERROR_NONE;
153 if (evas_image_load_func && 150 if (evas_image_load_func)
154 evas_image_load_func->file_head(ie, ie->file, ie->key, d->error) &&
155 (*(d->error) == EVAS_LOAD_ERROR_NONE))
156 { 151 {
157 d->em = em; 152 Evas_Image_Property property;
158 return EINA_FALSE; 153 Eina_File *f;
154
155 f = eina_file_open(ie->file, EINA_FALSE);
156 if (!f)
157 {
158 *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
159 return EINA_TRUE;
160 }
161
162 memset(&property, 0, sizeof (Evas_Image_Property));
163 if (evas_image_load_func->file_head(f, ie->key, &property,
164 &ie->load_opts, &ie->animated,
165 error) &&
166 (*error == EVAS_LOAD_ERROR_NONE))
167 {
168 DBG("loaded file head using module '%s' (%p): %s",
169 em->definition->name, em, ie->file);
170
171 ie->w = property.w;
172 ie->h = property.h;
173 ie->scale = property.scale;
174 ie->flags.alpha = property.alpha;
175 if (ie->load_opts.orientation &&
176 ie->load_opts.degree != 0)
177 ie->flags.rotated = EINA_TRUE;
178 r = EINA_FALSE;
179 }
180 else
181 {
182 evas_module_unload(em);
183 INF("failed to load file head using module '%s' (%p): "
184 "%s (%s)",
185 em->definition->name, em, ie->file, evas_load_error_str(*error));
186 }
187 eina_file_close(f);
188 }
189 else
190 {
191 load_error:
192 evas_module_unload(em);
193 WRN("failed to load module '%s'.", em->definition->name);
159 } 194 }
160 195
161 return EINA_TRUE; 196 return r;
197}
198
199static Eina_Bool
200_evas_image_foreach_loader(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata)
201{
202 struct evas_image_foreach_loader_data *d = fdata;
203 Evas_Module *em = data;
204 Image_Entry *ie = d->ie;
205 Eina_Bool r;
206
207 r = _evas_image_file_header(em, ie, d->error);
208
209 if (!r)
210 d->em = em;
211 return r;
162} 212}
163 213
164EAPI int 214EAPI int
165evas_common_load_rgba_image_module_from_file(Image_Entry *ie) 215evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
166{ 216{
167 Evas_Image_Load_Func *evas_image_load_func = NULL;
168 const char *loader = NULL, *end; 217 const char *loader = NULL, *end;
169 Evas_Module *em; 218 Evas_Module *em;
170 struct stat st; 219 struct stat st;
@@ -212,24 +261,8 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
212 if (em) 261 if (em)
213 { 262 {
214 DBG("found image loader '%s' (%p)", loader, em); 263 DBG("found image loader '%s' (%p)", loader, em);
215 if (evas_module_load(em)) 264 if (!_evas_image_file_header(em, ie, &ret))
216 { 265 goto end;
217 evas_module_use(em);
218 evas_image_load_func = em->functions;
219 ret = EVAS_LOAD_ERROR_NONE;
220 if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret))
221 {
222 DBG("loaded file head using module '%s' (%p): %s",
223 loader, em, ie->file);
224 goto end;
225 }
226 evas_module_unload(em);
227 INF("failed to load file head using module '%s' (%p): "
228 "%s (%s)",
229 loader, em, ie->file, evas_load_error_str(ret));
230 }
231 else
232 WRN("failed to load module '%s' (%p)", loader, em);
233 } 266 }
234 else 267 else
235 INF("image loader '%s' is not enabled or missing!", loader); 268 INF("image loader '%s' is not enabled or missing!", loader);
@@ -241,7 +274,6 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
241 ret = EVAS_LOAD_ERROR_NONE; 274 ret = EVAS_LOAD_ERROR_NONE;
242 evas_module_foreach_image_loader(_evas_image_foreach_loader, &fdata); 275 evas_module_foreach_image_loader(_evas_image_foreach_loader, &fdata);
243 em = fdata.em; 276 em = fdata.em;
244 evas_image_load_func = em ? em->functions : NULL;
245 if (em) goto end; 277 if (em) goto end;
246 278
247 /* This is our last chance, try all known image loader. */ 279 /* This is our last chance, try all known image loader. */
@@ -251,26 +283,8 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
251 em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loaders_name[i]); 283 em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loaders_name[i]);
252 if (em) 284 if (em)
253 { 285 {
254 if (evas_module_load(em)) 286 if (!_evas_image_file_header(em, ie, &ret))
255 { 287 goto end;
256 evas_module_use(em);
257 evas_image_load_func = em->functions;
258 ret = EVAS_LOAD_ERROR_NONE;
259 if (evas_image_load_func->file_head(ie, ie->file, ie->key, &ret))
260 {
261 DBG("brute force loader '%s' (%p) worked on %s",
262 loaders_name[i], em, ie->file);
263 goto end;
264 }
265 else
266 INF("brute force loader '%s' (%p) failed on %s (%s)",
267 loaders_name[i], em, ie->file,
268 evas_load_error_str(ret));
269
270 evas_module_unload(em);
271 }
272 else
273 INF("failed to load module '%s' (%p)", loaders_name[i], em);
274 } 288 }
275 else 289 else
276 DBG("could not find module '%s'", loaders_name[i]); 290 DBG("could not find module '%s'", loaders_name[i]);
@@ -304,7 +318,7 @@ evas_common_load_rgba_image_module_from_file(Image_Entry *ie)
304 ie->file); 318 ie->file);
305 319
306 ie->info.module = (void*) em; 320 ie->info.module = (void*) em;
307 ie->info.loader = (void*) evas_image_load_func; 321 ie->info.loader = (void*) em ? em->functions : NULL;
308 evas_module_ref((Evas_Module*) ie->info.module); 322 evas_module_ref((Evas_Module*) ie->info.module);
309 return ret; 323 return ret;
310} 324}
@@ -315,7 +329,7 @@ evas_common_load_rgba_image_data_from_file(Image_Entry *ie)
315 Evas_Image_Load_Func *evas_image_load_func = NULL; 329 Evas_Image_Load_Func *evas_image_load_func = NULL;
316 int ret = EVAS_LOAD_ERROR_NONE; 330 int ret = EVAS_LOAD_ERROR_NONE;
317 331
318 if ((ie->flags.loaded) && (!ie->flags.animated)) return EVAS_LOAD_ERROR_GENERIC; 332 if ((ie->flags.loaded) && (!ie->animated.animated)) return EVAS_LOAD_ERROR_GENERIC;
319 333
320#ifdef EVAS_CSERVE2 334#ifdef EVAS_CSERVE2
321 if (ie->data1) 335 if (ie->data1)