From df8cc84f4782334015393b2dee669830d1cca516 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 14 Aug 2017 19:57:44 +0200 Subject: vo_opengl: remove DR image layouting code to renderer No reason to have it in a higher level. --- video/out/opengl/video.c | 30 +++++++++++++++++++++++++++--- video/out/opengl/video.h | 5 +++-- video/out/vo_opengl.c | 22 +--------------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 7f467397a1..791d1895a1 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -3757,7 +3757,7 @@ void gl_video_set_hwdec(struct gl_video *p, struct ra_hwdec *hwdec) p->hwdec = hwdec; } -void *gl_video_dr_alloc_buffer(struct gl_video *p, size_t size) +static void *gl_video_dr_alloc_buffer(struct gl_video *p, size_t size) { struct ra_buf_params params = { .type = RA_BUF_TYPE_TEX_UPLOAD, @@ -3775,11 +3775,13 @@ void *gl_video_dr_alloc_buffer(struct gl_video *p, size_t size) return buf->data; }; -void gl_video_dr_free_buffer(struct gl_video *p, void *ptr) +static void gl_video_dr_free_buffer(void *opaque, uint8_t *data) { + struct gl_video *p = opaque; + for (int n = 0; n < p->num_dr_buffers; n++) { struct dr_buffer *buffer = &p->dr_buffers[n]; - if (buffer->buf->data == ptr) { + if (buffer->buf->data == data) { assert(!buffer->mpi); // can't be freed while it has a ref ra_buf_free(p->ra, &buffer->buf); MP_TARRAY_REMOVE_AT(p->dr_buffers, p->num_dr_buffers, n); @@ -3789,3 +3791,25 @@ void gl_video_dr_free_buffer(struct gl_video *p, void *ptr) // not found - must not happen assert(0); } + +struct mp_image *gl_video_get_image(struct gl_video *p, int imgfmt, int w, int h, + int stride_align) +{ + int size = mp_image_get_alloc_size(imgfmt, w, h, stride_align); + if (size < 0) + return NULL; + + int alloc_size = size + stride_align; + void *ptr = gl_video_dr_alloc_buffer(p, alloc_size); + if (!ptr) + return NULL; + + // (we expect vo.c to proxy the free callback, so it happens in the same + // thread it was allocated in, removing the need for synchronization) + struct mp_image *res = mp_image_from_buffer(imgfmt, w, h, stride_align, + ptr, alloc_size, p, + gl_video_dr_free_buffer); + if (!res) + gl_video_dr_free_buffer(p, ptr); + return res; +} diff --git a/video/out/opengl/video.h b/video/out/opengl/video.h index 915994f435..fd27c7a1bc 100644 --- a/video/out/opengl/video.h +++ b/video/out/opengl/video.h @@ -189,7 +189,8 @@ void gl_video_set_hwdec(struct gl_video *p, struct ra_hwdec *hwdec); struct vo; void gl_video_configure_queue(struct gl_video *p, struct vo *vo); -void *gl_video_dr_alloc_buffer(struct gl_video *p, size_t size); -void gl_video_dr_free_buffer(struct gl_video *p, void *ptr); +struct mp_image *gl_video_get_image(struct gl_video *p, int imgfmt, int w, int h, + int stride_align); + #endif diff --git a/video/out/vo_opengl.c b/video/out/vo_opengl.c index 5e8a3c7110..02a7318970 100644 --- a/video/out/vo_opengl.c +++ b/video/out/vo_opengl.c @@ -350,32 +350,12 @@ static void wait_events(struct vo *vo, int64_t until_time_us) } } -static void vo_opengl_free_dr(void *opaque, uint8_t *data) -{ - struct gl_priv *p = opaque; - gl_video_dr_free_buffer(p->renderer, data); -} - static struct mp_image *get_image(struct vo *vo, int imgfmt, int w, int h, int stride_align) { struct gl_priv *p = vo->priv; - int size = mp_image_get_alloc_size(imgfmt, w, h, stride_align); - if (size < 0) - return NULL; - - int alloc_size = size + stride_align; - void *ptr = gl_video_dr_alloc_buffer(p->renderer, alloc_size); - if (!ptr) - return NULL; - - struct mp_image *res = mp_image_from_buffer(imgfmt, w, h, stride_align, - ptr, alloc_size, p, - vo_opengl_free_dr); - if (!res) - gl_video_dr_free_buffer(p->renderer, ptr); - return res; + return gl_video_get_image(p->renderer, imgfmt, w, h, stride_align); } static void uninit(struct vo *vo) -- cgit v1.2.3