jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=4caad3f4eafa9ae5c80bb55e82985b0f1dccba5e

commit 4caad3f4eafa9ae5c80bb55e82985b0f1dccba5e
Author: Jean-Philippe Andre <jp.an...@samsung.com>
Date:   Thu Jan 21 10:59:22 2016 +0900

    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.
---
 .../evas/engines/gl_common/evas_gl_common.h        |  2 +-
 .../evas/engines/gl_common/evas_gl_context.c       |  2 +-
 .../evas/engines/gl_common/evas_gl_shader.c        | 64 ++++++++++++++++++----
 3 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h 
b/src/modules/evas/engines/gl_common/evas_gl_common.h
index eab1c50..e4b14f3 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -191,7 +191,7 @@ struct _Evas_GL_Shared
 
    Eet_File           *shaders_cache;
    Eina_Hash          *shaders_hash;
-   Eina_Stringshare   *shaders_cache_name;
+   Eina_Stringshare   *shaders_checksum;
 
 #ifdef GL_GLES
    // FIXME: hack.
diff --git a/src/modules/evas/engines/gl_common/evas_gl_context.c 
b/src/modules/evas/engines/gl_common/evas_gl_context.c
index cf38234..6680f44 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -1041,7 +1041,7 @@ evas_gl_common_context_free(Evas_Engine_GL_Context *gc)
         eina_hash_free(gc->shared->native_wl_hash);
         eina_hash_free(gc->shared->native_tbm_hash);
         eina_hash_free(gc->shared->native_evasgl_hash);
-        eina_stringshare_del(gc->shared->shaders_cache_name);
+        eina_stringshare_del(gc->shared->shaders_checksum);
         free(gc->shared);
         shared = NULL;
      }
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 61ede1d..88944c2 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 @@
 #define SHADER_FLAG_MASKSAM_BITSHIFT 6
 #define SHADER_PROG_NAME_FMT "/shader/%08x"
 #define SHADER_BINARY_EET_COMPRESS 1
+#define SHADER_EET_CHECKSUM "/shader/checksum"
+#define SHADER_EET_CACHENAME "binary_shader"
 
 #define P(i) ((void*)(intptr_t)i)
 #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)
 static void
 _evas_gl_common_shader_binary_hash(Evas_GL_Shared *shared)
 {
-   if (shared->shaders_cache_name)
+   if (shared->shaders_checksum)
      return;
 
    /* This hash makes it sure that if the shaders code changes, then we
     * will not reuse the old binaries. */
-   shared->shaders_cache_name = eina_stringshare_printf
-         ("%#x:%#x::binary_shader",
+   shared->shaders_checksum = eina_stringshare_printf
+         ("%#x:%#x",
           eina_hash_superfast(fragment_glsl, strlen(fragment_glsl)),
           eina_hash_superfast(vertex_glsl, strlen(vertex_glsl)));
 }
 
+static Eina_Bool
+_evas_gl_common_shader_binary_checksum_check(Evas_GL_Shared *shared, Eet_File 
*ef)
+{
+   Eina_Bool ret = EINA_FALSE;
+   const char *old_hash;
+   int len = 0;
+
+   if (!ef) return EINA_FALSE;
+   _evas_gl_common_shader_binary_hash(shared);
+   old_hash = eet_read_direct(ef, SHADER_EET_CHECKSUM, &len);
+   if (old_hash &&
+       (len == (eina_stringshare_strlen(shared->shaders_checksum) + 1)) &&
+       (!strcmp(shared->shaders_checksum, old_hash)))
+     ret = EINA_TRUE;
+
+   return ret;
+}
+
+static Eina_Bool
+_evas_gl_common_shader_binary_checksum_write(Evas_GL_Shared *shared, Eet_File 
*ef)
+{
+   int ret, len;
+
+   if (!ef) return EINA_FALSE;
+   _evas_gl_common_shader_binary_hash(shared);
+   len = eina_stringshare_strlen(shared->shaders_checksum) + 1;
+   ret = eet_write(ef, SHADER_EET_CHECKSUM, shared->shaders_checksum, len, 0);
+
+   return (ret == len);
+}
+
 static int
 _evas_gl_common_shader_binary_init(Evas_GL_Shared *shared)
 {
@@ -234,14 +267,14 @@ _evas_gl_common_shader_binary_init(Evas_GL_Shared *shared)
    if (!evas_gl_common_file_cache_dir_check(bin_dir_path, 
sizeof(bin_dir_path)))
      return 0;
 
-   _evas_gl_common_shader_binary_hash(shared);
-   if (!evas_gl_common_file_cache_file_check(bin_dir_path, 
shared->shaders_cache_name,
+   if (!evas_gl_common_file_cache_file_check(bin_dir_path, 
SHADER_EET_CACHENAME,
                                              bin_file_path, 
sizeof(bin_dir_path)))
      return 0;
 
    if (!eet_init()) return 0;
    ef = eet_open(bin_file_path, EET_FILE_MODE_READ);
-   if (!ef) goto error;
+   if (!_evas_gl_common_shader_binary_checksum_check(shared, ef))
+     goto error;
 
    shared->shaders_cache = ef;
    return 1;
@@ -274,8 +307,7 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
           return 0; /* we can't make directory */
      }
 
-   _evas_gl_common_shader_binary_hash(shared);
-   copy = evas_gl_common_file_cache_file_check(bin_dir_path, 
shared->shaders_cache_name,
+   copy = evas_gl_common_file_cache_file_check(bin_dir_path, 
SHADER_EET_CACHENAME,
                                                bin_file_path, 
sizeof(bin_dir_path));
 
    /* use mkstemp for writing */
@@ -285,11 +317,23 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
 
    /* copy old file */
    if (copy)
-     eina_file_copy(bin_file_path, tmp_file_path, EINA_FILE_COPY_DATA, NULL, 
NULL);
+     {
+        ef = eet_open(tmp_file_path, EET_FILE_MODE_READ);
+        if (!ef) goto save;
+        if (!_evas_gl_common_shader_binary_checksum_check(shared, ef))
+          copy = EINA_FALSE;
+        eet_close(ef);
+        if (copy)
+          eina_file_copy(bin_file_path, tmp_file_path, EINA_FILE_COPY_DATA, 
NULL, NULL);
+     }
 
-   ef = eet_open(tmp_file_path, EET_FILE_MODE_READ_WRITE);
+save:
+   ef = eet_open(tmp_file_path, copy ? EET_FILE_MODE_READ_WRITE : 
EET_FILE_MODE_WRITE);
    if (!ef) goto error;
 
+   if (!_evas_gl_common_shader_binary_checksum_write(shared, ef))
+     goto error;
+
    it = eina_hash_iterator_data_new(shared->shaders_hash);
    EINA_ITERATOR_FOREACH(it, p)
      {

-- 


Reply via email to