summaryrefslogtreecommitdiff
path: root/src/modules/evas
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-01-19 12:15:10 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-01-19 18:18:29 +0900
commitc8baf41149e59dde626ce64b56c7961efb6b8ab0 (patch)
tree355f445981ca03351a6ed591def5132a04966d74 /src/modules/evas
parente472f97d9670207896635985cebd3119fcb21b89 (diff)
Evas GL: Fix shader binaries cache
It was completetly broken due to a misuse of mkstemp.
Diffstat (limited to 'src/modules/evas')
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_shader.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_shader.c b/src/modules/evas/engines/gl_common/evas_gl_shader.c
index 6a7209cd8b..2b7fa42681 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_shader.c
@@ -240,17 +240,19 @@ error:
240static int 240static int
241_evas_gl_common_shader_binary_save(Evas_GL_Shared *shared) 241_evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
242{ 242{
243 // FIXME: Save should happen early, before shutdown.
244
245 char bin_dir_path[PATH_MAX]; 243 char bin_dir_path[PATH_MAX];
246 char bin_file_path[PATH_MAX]; 244 char bin_file_path[PATH_MAX];
247 char tmp_file[PATH_MAX]; 245 char tmp_file_name[PATH_MAX];
248 int tmpfd, res = 0, copy; 246 int tmpfd = -1, res = 0, copy;
247 Eina_Tmpstr *tmp_file_path = NULL;
249 Eet_File *ef = NULL; 248 Eet_File *ef = NULL;
250 Evas_GL_Program *p; 249 Evas_GL_Program *p;
251 Eina_Iterator *it; 250 Eina_Iterator *it;
252 char pname[32]; 251 char pname[32];
253 252
253 /* use eet */
254 if (!eet_init()) return 0;
255
254 if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path))) 256 if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path)))
255 { 257 {
256 res = evas_gl_common_file_cache_mkpath(bin_dir_path); 258 res = evas_gl_common_file_cache_mkpath(bin_dir_path);
@@ -261,19 +263,15 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
261 sizeof(bin_dir_path)); 263 sizeof(bin_dir_path));
262 264
263 /* use mkstemp for writing */ 265 /* use mkstemp for writing */
264 snprintf(tmp_file, sizeof(tmp_file), "%s.XXXXXX.cache", bin_file_path); 266 snprintf(tmp_file_name, sizeof(tmp_file_name), "%s.XXXXXX.cache", bin_file_path);
265 tmpfd = eina_file_mkstemp(tmp_file, NULL); 267 tmpfd = eina_file_mkstemp(tmp_file_name, &tmp_file_path);
266 if (tmpfd < 0) return 0; 268 if (tmpfd < 0) goto error;
267 close(tmpfd);
268
269 /* use eet */
270 if (!eet_init()) return 0;
271 269
272 /* copy old file */ 270 /* copy old file */
273 if (copy) 271 if (copy)
274 eina_file_copy(bin_file_path, tmp_file, EINA_FILE_COPY_DATA, NULL, NULL); 272 eina_file_copy(bin_file_path, tmp_file_path, EINA_FILE_COPY_DATA, NULL, NULL);
275 273
276 ef = eet_open(tmp_file, EET_FILE_MODE_READ_WRITE); 274 ef = eet_open(tmp_file_path, EET_FILE_MODE_READ_WRITE);
277 if (!ef) goto error; 275 if (!ef) goto error;
278 276
279 it = eina_hash_iterator_data_new(shared->shaders_hash); 277 it = eina_hash_iterator_data_new(shared->shaders_hash);
@@ -300,16 +298,23 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
300 } 298 }
301 299
302 if (eet_close(ef) != EET_ERROR_NONE) goto destroyed; 300 if (eet_close(ef) != EET_ERROR_NONE) goto destroyed;
303 if (rename(tmp_file, bin_file_path) < 0) goto destroyed; 301 if (rename(tmp_file_path, bin_file_path) < 0) goto destroyed;
304 302 eina_tmpstr_del(tmp_file_path);
303 close(tmpfd);
305 eet_shutdown(); 304 eet_shutdown();
305
306 shared->needs_shaders_flush = 0;
306 return 1; 307 return 1;
307 308
308 destroyed: 309 destroyed:
309 ef = NULL; 310 ef = NULL;
311
310 error: 312 error:
313 if (tmpfd >= 0) close(tmpfd);
311 if (ef) eet_close(ef); 314 if (ef) eet_close(ef);
312 if (evas_gl_common_file_cache_file_exists(tmp_file)) unlink(tmp_file); 315 if (evas_gl_common_file_cache_file_exists(tmp_file_path))
316 unlink(tmp_file_path);
317 eina_tmpstr_del(tmp_file_path);
313 eet_shutdown(); 318 eet_shutdown();
314 return 0; 319 return 0;
315} 320}