Signed-off-by: Tapani Pälli <tapani.pa...@intel.com>
---
 src/util/disk_cache.c | 39 +++++++++++++++++++++++++++++++++++++++
 src/util/disk_cache.h | 19 +++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 7ebfa8c045..b71363bcf3 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -99,6 +99,9 @@ struct disk_cache {
    /* Driver cache keys. */
    uint8_t *driver_keys_blob;
    size_t driver_keys_blob_size;
+
+   disk_cache_set_cb blob_set_cb;
+   disk_cache_get_cb blob_get_cb;
 };
 
 struct disk_cache_put_job {
@@ -995,6 +998,11 @@ disk_cache_put(struct disk_cache *cache, const cache_key 
key,
                const void *data, size_t size,
                struct cache_item_metadata *cache_item_metadata)
 {
+   if (cache->blob_set_cb) {
+      cache->blob_set_cb(key, CACHE_KEY_SIZE, data, size);
+      return;
+   }
+
    struct disk_cache_put_job *dc_job =
       create_put_job(cache, key, data, size, cache_item_metadata);
 
@@ -1057,6 +1065,29 @@ disk_cache_get(struct disk_cache *cache, const cache_key 
key, size_t *size)
    if (size)
       *size = 0;
 
+   if (cache->blob_get_cb) {
+/* This is what Android EGL defines as the maxValueSize in egl_cache_t
+ * class implementation.
+ */
+#define MAX_BLOB_SIZE 64 * 1024
+      void *blob = malloc(MAX_BLOB_SIZE);
+      if (!blob)
+         return NULL;
+
+      signed long bytes =
+         cache->blob_get_cb(key, CACHE_KEY_SIZE, blob, MAX_BLOB_SIZE);
+
+      if (!bytes) {
+         free(blob);
+         return NULL;
+      }
+
+      if (size)
+         *size = bytes;
+      return blob;
+#undef MAX_BLOB_SIZE
+   }
+
    filename = get_cache_file(cache, key);
    if (filename == NULL)
       goto fail;
@@ -1209,4 +1240,12 @@ disk_cache_compute_key(struct disk_cache *cache, const 
void *data, size_t size,
    _mesa_sha1_final(&ctx, key);
 }
 
+void
+disk_cache_set_callbacks(struct disk_cache *cache, disk_cache_set_cb set,
+                         disk_cache_get_cb get)
+{
+   cache->blob_set_cb = set;
+   cache->blob_get_cb = get;
+}
+
 #endif /* ENABLE_SHADER_CACHE */
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index 488b297ead..3fae8a1358 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -50,6 +50,14 @@ typedef uint8_t cache_key[CACHE_KEY_SIZE];
 #define CACHE_ITEM_TYPE_UNKNOWN  0x0
 #define CACHE_ITEM_TYPE_GLSL     0x1
 
+typedef void
+(*disk_cache_set_cb) (const void *key, signed long keySize,
+                      const void *value, signed long valueSize);
+
+typedef signed long
+(*disk_cache_get_cb) (const void *key, signed long keySize,
+                      void *value, signed long valueSize);
+
 struct cache_item_metadata {
    /**
     * The cache item type. This could be used to identify a GLSL cache item,
@@ -207,6 +215,10 @@ void
 disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size,
                        cache_key key);
 
+void
+disk_cache_set_callbacks(struct disk_cache *cache, disk_cache_set_cb set,
+                         disk_cache_get_cb get);
+
 #else
 
 static inline struct disk_cache *
@@ -260,6 +272,13 @@ disk_cache_compute_key(struct disk_cache *cache, const 
void *data, size_t size,
    return;
 }
 
+static inline void
+disk_cache_set_callbacks(struct disk_cache *cache, disk_cache_set_cb set,
+                         disk_cache_get_cb get)
+{
+   return;
+}
+
 #endif /* ENABLE_SHADER_CACHE */
 
 #ifdef __cplusplus
-- 
2.14.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to