[Mesa-dev] [RFC 10/10] egl: XXX debug framework for EGL_ANDROID_blob_cache

Tapani Pälli tapani.palli at intel.com
Tue Jan 9 07:48:22 UTC 2018


Patch disables EGL_ANDROID_blob_cache and sets own get/set
cache functions internally, this makes any EGL app to utilize
cache automatically.

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
---
 src/egl/drivers/dri2/egl_dri2.c |  3 --
 src/egl/main/eglapi.c           | 77 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index f9d0223fe2..e24dab1589 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -728,9 +728,6 @@ dri2_setup_screen(_EGLDisplay *disp)
       }
    }
 
-   if (dri2_dpy->blob)
-      disp->Extensions.ANDROID_blob_cache = EGL_TRUE;
-
    disp->Extensions.KHR_reusable_sync = EGL_TRUE;
 
    if (dri2_dpy->image) {
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index b8d64a913c..5cd70c1afe 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -790,6 +790,80 @@ eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
    RETURN_EGL_EVAL(disp, ret);
 }
 
+static void*
+_load_file(const char *path, uint64_t *size)
+{
+  FILE *in = fopen(path, "r");
+
+  if (!in)
+    return NULL;
+
+  fseek(in, 0, SEEK_END);
+  long file_size = ftell(in);
+  rewind(in);
+
+  printf("%s: %s, size is %ld\n", __func__, path, file_size);
+
+  char *data = (char *) malloc (file_size);
+
+  fread(data, file_size, 1, in);
+  fclose(in);
+
+  *size = file_size;
+  return data;
+}
+
+static void
+_save_file(const char *path, const void *data, uint64_t size)
+{
+  printf("%s: %s, size is %ld\n", __func__, path, size);
+
+  FILE *out = fopen(path, "w");
+
+  if (!out) {
+    fprintf(stderr, "failed to open file for writing:\npath (%s)\n", path);
+    return;
+  }
+
+  fwrite(data, size, 1, out);
+  fclose(out);
+}
+
+static void
+mesa_set(const void* key, EGLsizeiANDROID keySize, const void* value, EGLsizeiANDROID valueSize)
+{
+  if (valueSize < 2000)
+    return;
+
+  char tmp[256];
+  snprintf(tmp, 256, "/tmp/%s", key);
+
+  _save_file(tmp, value, valueSize);
+}
+
+static EGLsizeiANDROID
+mesa_get(const void* key, EGLsizeiANDROID keySize, void* value, EGLsizeiANDROID valueSize)
+{
+  uint64_t size;
+
+  char tmp[256];
+  snprintf(tmp, 256, "/tmp/%s", key);
+
+  void *data = _load_file(tmp, &size);
+
+  if (!data)
+    return 0;
+
+  if (size > valueSize) {
+    free(data);
+    return 0;
+  }
+
+  memcpy(value, data, size);
+  free(data);
+  return size;
+}
+
 
 EGLBoolean EGLAPIENTRY
 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
@@ -845,6 +919,9 @@ eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
 
    ret = drv->API.MakeCurrent(drv, disp, draw_surf, read_surf, context);
 
+   /* Debug EGL_ANDROID_blob_cache */
+   drv->API.SetBlobCacheFuncsANDROID(drv, disp, mesa_set, mesa_get);
+
    RETURN_EGL_EVAL(disp, ret);
 }
 
-- 
2.14.3



More information about the mesa-dev mailing list