summaryrefslogtreecommitdiffstats
path: root/src/util/disk_cache.c
diff options
context:
space:
mode:
authorTapani Pälli <[email protected]>2018-02-07 08:13:00 +0200
committerTapani Pälli <[email protected]>2018-02-07 14:45:34 +0200
commitae00ef270233d7ba44e1a751333db16338b816f2 (patch)
treef75f0befdc3a7a6aa39a321dadd905188e7107a0 /src/util/disk_cache.c
parent6a651b6b77b68db71a027c826abccc843ace88ef (diff)
disk cache: add callback functionality
v2: add disk_cache_has_key, disk_cache_put_key support using blob cache (Nicolai, Jordan) v3: rename set_cb as put_cb to match existing naming (Timothy) Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Jordan Justen <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src/util/disk_cache.c')
-rw-r--r--src/util/disk_cache.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index dec5a67a795..ea6808aaf8b 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -101,6 +101,9 @@ struct disk_cache {
/* Driver cache keys. */
uint8_t *driver_keys_blob;
size_t driver_keys_blob_size;
+
+ disk_cache_put_cb blob_put_cb;
+ disk_cache_get_cb blob_get_cb;
};
struct disk_cache_put_job {
@@ -1012,6 +1015,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_put_cb) {
+ cache->blob_put_cb(key, CACHE_KEY_SIZE, data, size);
+ return;
+ }
+
/* Initialize path if not initialized yet. */
if (cache->path_init_failed ||
(!cache->path && !disk_cache_path_init(cache)))
@@ -1079,6 +1087,28 @@ 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.
+ */
+ const signed long 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;
+ }
+
filename = get_cache_file(cache, key);
if (filename == NULL)
goto fail;
@@ -1194,6 +1224,11 @@ disk_cache_put_key(struct disk_cache *cache, const cache_key key)
int i = CPU_TO_LE32(*key_chunk) & CACHE_INDEX_KEY_MASK;
unsigned char *entry;
+ if (cache->blob_put_cb) {
+ cache->blob_put_cb(key, CACHE_KEY_SIZE, key_chunk, sizeof(uint32_t));
+ return;
+ }
+
if (!cache->path) {
assert(!"disk_cache_put_key called with no path set");
return;
@@ -1218,6 +1253,11 @@ disk_cache_has_key(struct disk_cache *cache, const cache_key key)
int i = CPU_TO_LE32(*key_chunk) & CACHE_INDEX_KEY_MASK;
unsigned char *entry;
+ if (cache->blob_get_cb) {
+ uint32_t blob;
+ return cache->blob_get_cb(key, CACHE_KEY_SIZE, &blob, sizeof(uint32_t));
+ }
+
/* Initialize path if not initialized yet. */
if (cache->path_init_failed ||
(!cache->path && !disk_cache_path_init(cache)))
@@ -1241,4 +1281,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_put_cb put,
+ disk_cache_get_cb get)
+{
+ cache->blob_put_cb = put;
+ cache->blob_get_cb = get;
+}
+
#endif /* ENABLE_SHADER_CACHE */