summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-05-02 19:42:23 -0500
committerDudemanguy <random342@airmail.cc>2023-05-09 20:37:17 +0000
commit4502522a7aee093c923e79a65e4684ea2634af30 (patch)
treed7855be2c4cfb6a16edc784da0e6f3dad29ee667 /video/out
parent7c4c9bc86f55f4d1224814fbeafdee8f1c3c3108 (diff)
downloadmpv-4502522a7aee093c923e79a65e4684ea2634af30.tar.bz2
mpv-4502522a7aee093c923e79a65e4684ea2634af30.tar.xz
player: use XDG_CACHE_HOME by default
This adds cache as a possible path for mpv to internally pick (~/.cache/mpv for non-darwin unix-like systems, the usual config directory for everyone else). For gpu shader cache and icc cache, controlling whether or not to write such files is done with the new --gpu-shader-cache and --icc-cache options respectively. Additionally, --cache-on-disk no longer requires explicitly setting the --cache-dir option. The old options, --cache-dir, --gpu-shader-cache-dir, and --icc-cache-dir simply set an override for the directory to save cache files. If unset, then the cache is saved in XDG_CACHE_HOME.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/gpu/lcms.c12
-rw-r--r--video/out/gpu/lcms.h1
-rw-r--r--video/out/gpu/shader_cache.c7
-rw-r--r--video/out/gpu/shader_cache.h2
-rw-r--r--video/out/gpu/video.c4
-rw-r--r--video/out/gpu/video.h1
-rw-r--r--video/out/vo_gpu_next.c18
7 files changed, 35 insertions, 10 deletions
diff --git a/video/out/gpu/lcms.c b/video/out/gpu/lcms.c
index bbf857d968..be65dc965e 100644
--- a/video/out/gpu/lcms.c
+++ b/video/out/gpu/lcms.c
@@ -332,7 +332,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d,
cmsContext cms = NULL;
char *cache_file = NULL;
- if (p->opts->cache_dir && p->opts->cache_dir[0]) {
+ if (p->opts->cache) {
// Gamma is included in the header to help uniquely identify it,
// because we may change the parameter in the future or make it
// customizable, same for the primaries.
@@ -352,7 +352,13 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d,
av_sha_final(sha, hash);
av_free(sha);
- char *cache_dir = mp_get_user_path(tmp, p->global, p->opts->cache_dir);
+ char *cache_dir = p->opts->cache_dir;
+ if (cache_dir && cache_dir[0]) {
+ cache_dir = mp_get_user_path(NULL, p->global, cache_dir);
+ } else {
+ cache_dir = mp_find_user_file(NULL, p->global, "cache", "");
+ }
+
cache_file = talloc_strdup(tmp, "");
for (int i = 0; i < sizeof(hash); i++)
cache_file = talloc_asprintf_append(cache_file, "%02X", hash[i]);
@@ -494,13 +500,13 @@ const struct m_sub_options mp_icc_conf = {
{"use-embedded-icc-profile", OPT_BOOL(use_embedded)},
{"icc-profile", OPT_STRING(profile), .flags = M_OPT_FILE},
{"icc-profile-auto", OPT_BOOL(profile_auto)},
+ {"icc-cache", OPT_BOOL(cache)},
{"icc-cache-dir", OPT_STRING(cache_dir), .flags = M_OPT_FILE},
{"icc-intent", OPT_INT(intent)},
{"icc-force-contrast", OPT_CHOICE(contrast, {"no", 0}, {"inf", -1}),
M_RANGE(0, 1000000)},
{"icc-3dlut-size", OPT_STRING_VALIDATE(size_str, validate_3dlut_size_opt)},
{"3dlut-size", OPT_REPLACED("icc-3dlut-size")},
- {"icc-cache", OPT_REMOVED("see icc-cache-dir")},
{"icc-contrast", OPT_REMOVED("see icc-force-contrast")},
{0}
},
diff --git a/video/out/gpu/lcms.h b/video/out/gpu/lcms.h
index bd4b16175a..442c829333 100644
--- a/video/out/gpu/lcms.h
+++ b/video/out/gpu/lcms.h
@@ -13,6 +13,7 @@ struct mp_icc_opts {
bool use_embedded;
char *profile;
bool profile_auto;
+ bool cache;
char *cache_dir;
char *size_str;
int intent;
diff --git a/video/out/gpu/shader_cache.c b/video/out/gpu/shader_cache.c
index 9eedb1cd07..a046831f80 100644
--- a/video/out/gpu/shader_cache.c
+++ b/video/out/gpu/shader_cache.c
@@ -557,9 +557,14 @@ static void update_uniform(struct gl_shader_cache *sc, struct sc_entry *e,
}
}
-void gl_sc_set_cache_dir(struct gl_shader_cache *sc, const char *dir)
+void gl_sc_set_cache_dir(struct gl_shader_cache *sc, char *dir)
{
talloc_free(sc->cache_dir);
+ if (dir && dir[0]) {
+ dir = mp_get_user_path(NULL, sc->global, dir);
+ } else {
+ dir = mp_find_user_file(NULL, sc->global, "cache", "");
+ }
sc->cache_dir = talloc_strdup(sc, dir);
}
diff --git a/video/out/gpu/shader_cache.h b/video/out/gpu/shader_cache.h
index 3c87513b2b..7c51c7aead 100644
--- a/video/out/gpu/shader_cache.h
+++ b/video/out/gpu/shader_cache.h
@@ -63,4 +63,4 @@ struct mp_pass_perf gl_sc_dispatch_compute(struct gl_shader_cache *sc,
// The application can call this on errors, to reset the current shader. This
// is normally done implicitly by gl_sc_dispatch_*
void gl_sc_reset(struct gl_shader_cache *sc);
-void gl_sc_set_cache_dir(struct gl_shader_cache *sc, const char *dir);
+void gl_sc_set_cache_dir(struct gl_shader_cache *sc, char *dir);
diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c
index cfd864680b..2d16d8435e 100644
--- a/video/out/gpu/video.c
+++ b/video/out/gpu/video.c
@@ -465,6 +465,7 @@ const struct m_sub_options gl_video_conf = {
{"gpu-tex-pad-x", OPT_INT(tex_pad_x), M_RANGE(0, 4096)},
{"gpu-tex-pad-y", OPT_INT(tex_pad_y), M_RANGE(0, 4096)},
{"", OPT_SUBSTRUCT(icc_opts, mp_icc_conf)},
+ {"gpu-shader-cache", OPT_BOOL(shader_cache)},
{"gpu-shader-cache-dir", OPT_STRING(shader_cache_dir), .flags = M_OPT_FILE},
{"gpu-hwdec-interop",
OPT_STRING_VALIDATE(hwdec_interop, ra_hwdec_validate_opt)},
@@ -4099,7 +4100,8 @@ static void reinit_from_options(struct gl_video *p)
check_gl_features(p);
uninit_rendering(p);
- gl_sc_set_cache_dir(p->sc, p->opts.shader_cache_dir);
+ if (p->opts.shader_cache)
+ gl_sc_set_cache_dir(p->sc, p->opts.shader_cache_dir);
p->ra->use_pbo = p->opts.pbo;
gl_video_setup_hooks(p);
reinit_osd(p);
diff --git a/video/out/gpu/video.h b/video/out/gpu/video.h
index 0ef4618790..5a974f9ee0 100644
--- a/video/out/gpu/video.h
+++ b/video/out/gpu/video.h
@@ -171,6 +171,7 @@ struct gl_video_opts {
float unsharp;
int tex_pad_x, tex_pad_y;
struct mp_icc_opts *icc_opts;
+ bool shader_cache;
int early_flush;
char *shader_cache_dir;
char *hwdec_interop;
diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c
index fbee007cc8..8416f4f2f7 100644
--- a/video/out/vo_gpu_next.c
+++ b/video/out/vo_gpu_next.c
@@ -1348,10 +1348,15 @@ static void wait_events(struct vo *vo, int64_t until_time_us)
static char *get_cache_file(struct priv *p)
{
struct gl_video_opts *opts = p->opts_cache->opts;
- if (!opts->shader_cache_dir || !opts->shader_cache_dir[0])
+ if (!opts->shader_cache)
return NULL;
- char *dir = mp_get_user_path(NULL, p->global, opts->shader_cache_dir);
+ char *dir = opts->shader_cache_dir;
+ if (dir && dir[0]) {
+ dir = mp_get_user_path(NULL, p->global, dir);
+ } else {
+ dir = mp_find_user_file(NULL, p->global, "cache", "");
+ }
char *file = mp_path_join(NULL, dir, "libplacebo.cache");
mp_mkdirp(dir);
talloc_free(dir);
@@ -1575,7 +1580,7 @@ static const struct pl_hook *load_hook(struct priv *p, const char *path)
static stream_t *icc_open_cache(struct priv *p, uint64_t sig, int flags)
{
const struct gl_video_opts *opts = p->opts_cache->opts;
- if (!opts->icc_opts->cache_dir || !opts->icc_opts->cache_dir[0])
+ if (!opts->icc_opts->cache)
return NULL;
char cache_name[16+1];
@@ -1585,7 +1590,12 @@ static stream_t *icc_open_cache(struct priv *p, uint64_t sig, int flags)
}
cache_name[16] = '\0';
- char *cache_dir = mp_get_user_path(NULL, p->global, opts->icc_opts->cache_dir);
+ char *cache_dir = opts->icc_opts->cache_dir;
+ if (cache_dir && cache_dir[0]) {
+ cache_dir = mp_get_user_path(NULL, p->global, cache_dir);
+ } else {
+ cache_dir = mp_find_user_file(NULL, p->global, "cache", "");
+ }
char *path = mp_path_join(NULL, cache_dir, cache_name);
stream_t *stream = NULL;