summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/video.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-08-14 19:57:44 +0200
committerwm4 <wm4@nowhere>2017-08-14 19:57:44 +0200
commitdf8cc84f4782334015393b2dee669830d1cca516 (patch)
treeba0889281df8e29619a5c5ed86c79cd2a6f4789e /video/out/opengl/video.c
parent68201f4591bd07c7d7027d50fdb6cc5500c7382c (diff)
downloadmpv-df8cc84f4782334015393b2dee669830d1cca516.tar.bz2
mpv-df8cc84f4782334015393b2dee669830d1cca516.tar.xz
vo_opengl: remove DR image layouting code to renderer
No reason to have it in a higher level.
Diffstat (limited to 'video/out/opengl/video.c')
-rw-r--r--video/out/opengl/video.c30
1 files changed, 27 insertions, 3 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;
+}