diff options
Diffstat (limited to 'video/out/opengl/video.c')
-rw-r--r-- | video/out/opengl/video.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 8d6776ce0e..45528d138a 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -37,6 +37,7 @@ #include "utils.h" #include "hwdec.h" #include "osd.h" +#include "stream/stream.h" #include "video_shaders.h" #include "video/out/filter_kernels.h" #include "video/out/aspect.h" @@ -118,6 +119,11 @@ struct src_tex { struct mp_rect_f src; }; +struct cached_file { + char *path; + char *body; +}; + struct gl_video { GL *gl; @@ -197,6 +203,9 @@ struct gl_video { int last_dither_matrix_size; float *last_dither_matrix; + struct cached_file files[10]; + int num_files; + struct gl_hwdec *hwdec; bool hwdec_active; }; @@ -472,6 +481,35 @@ static const struct fmt_entry *find_tex_format(GL *gl, int bytes_per_comp, return &fmts[n_channels - 1 + (bytes_per_comp - 1) * 4]; } +static const char *load_cached_file(struct gl_video *p, const char *path) +{ + if (!path || !path[0]) + return NULL; + for (int n = 0; n < p->num_files; n++) { + if (strcmp(p->files[n].path, path) == 0) + return p->files[n].body; + } + // not found -> load it + if (p->num_files == MP_ARRAY_SIZE(p->files)) { + // empty cache when it overflows + for (int n = 0; n < p->num_files; n++) { + talloc_free(p->files[n].path); + talloc_free(p->files[n].body); + } + p->num_files = 0; + } + struct bstr s = stream_read_file(path, p, p->global, 100000); // 100 kB + if (s.len) { + struct cached_file *new = &p->files[p->num_files++]; + *new = (struct cached_file) { + .path = talloc_strdup(p, path), + .body = s.start + }; + return new->body; + } + return NULL; +} + static void debug_check_gl(struct gl_video *p, const char *msg) { if (p->gl_debug) @@ -868,7 +906,7 @@ static bool apply_shaders(struct gl_video *p, char **shaders, bool success = false; int tex = 0; for (int n = 0; shaders[n]; n++) { - const char *body = gl_sc_loadfile(p->sc, shaders[n]); + const char *body = load_cached_file(p, shaders[n]); if (!body) continue; finish_pass_fbo(p, &textures[tex], w, h, tex_num, 0); @@ -1067,7 +1105,7 @@ static void pass_sample(struct gl_video *p, int src_tex, struct scaler *scaler, } else if (strcmp(name, "oversample") == 0) { pass_sample_oversample(p->sc, scaler, w, h); } else if (strcmp(name, "custom") == 0) { - const char *body = gl_sc_loadfile(p->sc, p->opts.scale_shader); + const char *body = load_cached_file(p, p->opts.scale_shader); if (body) { load_shader(p, body); GLSLF("// custom scale-shader\n"); @@ -2390,7 +2428,7 @@ struct gl_video *gl_video_init(GL *gl, struct mp_log *log, struct mpv_global *g) .gl_target = GL_TEXTURE_2D, .texture_16bit_depth = 16, .scaler = {{.index = 0}, {.index = 1}, {.index = 2}, {.index = 3}}, - .sc = gl_sc_create(gl, log, g), + .sc = gl_sc_create(gl, log), }; gl_video_set_debug(p, true); init_gl(p); |