summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/gl_common/evas_gl_shader.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-01-21 10:59:22 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-01-21 11:11:24 +0900
commit4caad3f4eafa9ae5c80bb55e82985b0f1dccba5e (patch)
tree32d595180abeba946a02ce7bad8d09184523417c /src/modules/evas/engines/gl_common/evas_gl_shader.c
parentc4cd3f19bfc64ec8a7068c28a0ddc662fd9e76a7 (diff)
Evas GL: Actually save the checksum inside the file
This would be cleaner than adding it as a suffix to the filename. Use simple write and read_direct for simplicity. This is an improvement on 3dcd903a537e29342121c and should make sure everyone is actually using the latest version of the shaders even if they track master or the alpha/beta releases.
Diffstat (limited to '')
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_shader.c64
1 files changed, 54 insertions, 10 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 61ede1de55..88944c272e 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_shader.c
@@ -6,6 +6,8 @@
6#define SHADER_FLAG_MASKSAM_BITSHIFT 6 6#define SHADER_FLAG_MASKSAM_BITSHIFT 6
7#define SHADER_PROG_NAME_FMT "/shader/%08x" 7#define SHADER_PROG_NAME_FMT "/shader/%08x"
8#define SHADER_BINARY_EET_COMPRESS 1 8#define SHADER_BINARY_EET_COMPRESS 1
9#define SHADER_EET_CHECKSUM "/shader/checksum"
10#define SHADER_EET_CACHENAME "binary_shader"
9 11
10#define P(i) ((void*)(intptr_t)i) 12#define P(i) ((void*)(intptr_t)i)
11#define I(p) ((int)(intptr_t)p) 13#define I(p) ((int)(intptr_t)p)
@@ -207,17 +209,48 @@ _evas_gl_common_shader_program_binary_save(Evas_GL_Program *p, Eet_File *ef)
207static void 209static void
208_evas_gl_common_shader_binary_hash(Evas_GL_Shared *shared) 210_evas_gl_common_shader_binary_hash(Evas_GL_Shared *shared)
209{ 211{
210 if (shared->shaders_cache_name) 212 if (shared->shaders_checksum)
211 return; 213 return;
212 214
213 /* This hash makes it sure that if the shaders code changes, then we 215 /* This hash makes it sure that if the shaders code changes, then we
214 * will not reuse the old binaries. */ 216 * will not reuse the old binaries. */
215 shared->shaders_cache_name = eina_stringshare_printf 217 shared->shaders_checksum = eina_stringshare_printf
216 ("%#x:%#x::binary_shader", 218 ("%#x:%#x",
217 eina_hash_superfast(fragment_glsl, strlen(fragment_glsl)), 219 eina_hash_superfast(fragment_glsl, strlen(fragment_glsl)),
218 eina_hash_superfast(vertex_glsl, strlen(vertex_glsl))); 220 eina_hash_superfast(vertex_glsl, strlen(vertex_glsl)));
219} 221}
220 222
223static Eina_Bool
224_evas_gl_common_shader_binary_checksum_check(Evas_GL_Shared *shared, Eet_File *ef)
225{
226 Eina_Bool ret = EINA_FALSE;
227 const char *old_hash;
228 int len = 0;
229
230 if (!ef) return EINA_FALSE;
231 _evas_gl_common_shader_binary_hash(shared);
232 old_hash = eet_read_direct(ef, SHADER_EET_CHECKSUM, &len);
233 if (old_hash &&
234 (len == (eina_stringshare_strlen(shared->shaders_checksum) + 1)) &&
235 (!strcmp(shared->shaders_checksum, old_hash)))
236 ret = EINA_TRUE;
237
238 return ret;
239}
240
241static Eina_Bool
242_evas_gl_common_shader_binary_checksum_write(Evas_GL_Shared *shared, Eet_File *ef)
243{
244 int ret, len;
245
246 if (!ef) return EINA_FALSE;
247 _evas_gl_common_shader_binary_hash(shared);
248 len = eina_stringshare_strlen(shared->shaders_checksum) + 1;
249 ret = eet_write(ef, SHADER_EET_CHECKSUM, shared->shaders_checksum, len, 0);
250
251 return (ret == len);
252}
253
221static int 254static int
222_evas_gl_common_shader_binary_init(Evas_GL_Shared *shared) 255_evas_gl_common_shader_binary_init(Evas_GL_Shared *shared)
223{ 256{
@@ -234,14 +267,14 @@ _evas_gl_common_shader_binary_init(Evas_GL_Shared *shared)
234 if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path))) 267 if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path)))
235 return 0; 268 return 0;
236 269
237 _evas_gl_common_shader_binary_hash(shared); 270 if (!evas_gl_common_file_cache_file_check(bin_dir_path, SHADER_EET_CACHENAME,
238 if (!evas_gl_common_file_cache_file_check(bin_dir_path, shared->shaders_cache_name,
239 bin_file_path, sizeof(bin_dir_path))) 271 bin_file_path, sizeof(bin_dir_path)))
240 return 0; 272 return 0;
241 273
242 if (!eet_init()) return 0; 274 if (!eet_init()) return 0;
243 ef = eet_open(bin_file_path, EET_FILE_MODE_READ); 275 ef = eet_open(bin_file_path, EET_FILE_MODE_READ);
244 if (!ef) goto error; 276 if (!_evas_gl_common_shader_binary_checksum_check(shared, ef))
277 goto error;
245 278
246 shared->shaders_cache = ef; 279 shared->shaders_cache = ef;
247 return 1; 280 return 1;
@@ -274,8 +307,7 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
274 return 0; /* we can't make directory */ 307 return 0; /* we can't make directory */
275 } 308 }
276 309
277 _evas_gl_common_shader_binary_hash(shared); 310 copy = evas_gl_common_file_cache_file_check(bin_dir_path, SHADER_EET_CACHENAME,
278 copy = evas_gl_common_file_cache_file_check(bin_dir_path, shared->shaders_cache_name,
279 bin_file_path, sizeof(bin_dir_path)); 311 bin_file_path, sizeof(bin_dir_path));
280 312
281 /* use mkstemp for writing */ 313 /* use mkstemp for writing */
@@ -285,11 +317,23 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
285 317
286 /* copy old file */ 318 /* copy old file */
287 if (copy) 319 if (copy)
288 eina_file_copy(bin_file_path, tmp_file_path, EINA_FILE_COPY_DATA, NULL, NULL); 320 {
321 ef = eet_open(tmp_file_path, EET_FILE_MODE_READ);
322 if (!ef) goto save;
323 if (!_evas_gl_common_shader_binary_checksum_check(shared, ef))
324 copy = EINA_FALSE;
325 eet_close(ef);
326 if (copy)
327 eina_file_copy(bin_file_path, tmp_file_path, EINA_FILE_COPY_DATA, NULL, NULL);
328 }
289 329
290 ef = eet_open(tmp_file_path, EET_FILE_MODE_READ_WRITE); 330save:
331 ef = eet_open(tmp_file_path, copy ? EET_FILE_MODE_READ_WRITE : EET_FILE_MODE_WRITE);
291 if (!ef) goto error; 332 if (!ef) goto error;
292 333
334 if (!_evas_gl_common_shader_binary_checksum_write(shared, ef))
335 goto error;
336
293 it = eina_hash_iterator_data_new(shared->shaders_hash); 337 it = eina_hash_iterator_data_new(shared->shaders_hash);
294 EINA_ITERATOR_FOREACH(it, p) 338 EINA_ITERATOR_FOREACH(it, p)
295 { 339 {