Commit f4da1404 authored by Steve Lhomme's avatar Steve Lhomme Committed by Jean-Baptiste Kempf

vout: win32: move the GPU to CPU picture buffer mapping in copy

It may be used by other modules, even though it seems Windows is the only one
to provide a pitch for the main plane.
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent fd97bea7
...@@ -723,3 +723,58 @@ void CopyFromYv12ToYv12(picture_t *dst, uint8_t *src[3], size_t src_pitch[3], ...@@ -723,3 +723,58 @@ void CopyFromYv12ToYv12(picture_t *dst, uint8_t *src[3], size_t src_pitch[3],
CopyPlane(dst->p[2].p_pixels, dst->p[2].i_pitch, CopyPlane(dst->p[2].p_pixels, dst->p[2].i_pitch,
src[2], src_pitch[2], height / 2); src[2], src_pitch[2], height / 2);
} }
int picture_UpdatePlanes(picture_t *picture, uint8_t *data, unsigned pitch)
{
/* fill in buffer info in first plane */
picture->p->p_pixels = data;
picture->p->i_pitch = pitch;
picture->p->i_lines = picture->format.i_height;
assert(picture->p->i_visible_pitch <= picture->p->i_pitch);
assert(picture->p->i_visible_lines <= picture->p->i_lines);
/* Fill chroma planes for biplanar YUV */
if (picture->format.i_chroma == VLC_CODEC_NV12 ||
picture->format.i_chroma == VLC_CODEC_NV21 ||
picture->format.i_chroma == VLC_CODEC_P010) {
for (int n = 1; n < picture->i_planes; n++) {
const plane_t *o = &picture->p[n-1];
plane_t *p = &picture->p[n];
p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
p->i_pitch = pitch;
p->i_lines = picture->format.i_height;
assert(p->i_visible_pitch <= p->i_pitch);
assert(p->i_visible_lines <= p->i_lines);
}
/* The dx/d3d buffer is always allocated as NV12 */
if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_NV12)) {
/* TODO : Swap NV21 UV planes to match NV12 */
return VLC_EGENERIC;
}
}
/* Fill chroma planes for planar YUV */
else
if (picture->format.i_chroma == VLC_CODEC_I420 ||
picture->format.i_chroma == VLC_CODEC_J420 ||
picture->format.i_chroma == VLC_CODEC_YV12) {
for (int n = 1; n < picture->i_planes; n++) {
const plane_t *o = &picture->p[n-1];
plane_t *p = &picture->p[n];
p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
p->i_pitch = pitch / 2;
p->i_lines = picture->format.i_height / 2;
}
/* The dx/d3d buffer is always allocated as YV12 */
if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
uint8_t *p_tmp = picture->p[1].p_pixels;
picture->p[1].p_pixels = picture->p[2].p_pixels;
picture->p[2].p_pixels = p_tmp;
}
}
return VLC_SUCCESS;
}
...@@ -53,4 +53,15 @@ void CopyFromI420ToNv12(picture_t *dst, uint8_t *src[3], size_t src_pitch[3], ...@@ -53,4 +53,15 @@ void CopyFromI420ToNv12(picture_t *dst, uint8_t *src[3], size_t src_pitch[3],
void CopyFromI420_10ToP010(picture_t *dst, uint8_t *src[3], size_t src_pitch[3], void CopyFromI420_10ToP010(picture_t *dst, uint8_t *src[3], size_t src_pitch[3],
unsigned height, copy_cache_t *cache); unsigned height, copy_cache_t *cache);
/**
* This functions sets the internal plane pointers/dimensions for the given
* buffer.
* This is useful when mapping opaque surfaces into CPU planes.
*
* picture is the picture to update
* data is the buffer pointer to use as the start of data for all the planes
* pitch is the internal line pitch for the buffer
*/
int picture_UpdatePlanes(picture_t *picture, uint8_t *data, unsigned pitch);
#endif #endif
...@@ -207,6 +207,7 @@ endif ...@@ -207,6 +207,7 @@ endif
### Win32 ### ### Win32 ###
libdirect3d9_plugin_la_SOURCES = video_output/win32/direct3d9.c \ libdirect3d9_plugin_la_SOURCES = video_output/win32/direct3d9.c \
video_chroma/copy.c video_chroma/copy.h \
video_output/win32/common.c video_output/win32/common.h \ video_output/win32/common.c video_output/win32/common.h \
video_output/win32/events.c video_output/win32/events.h \ video_output/win32/events.c video_output/win32/events.h \
video_output/win32/builtin_shaders.h \ video_output/win32/builtin_shaders.h \
...@@ -228,7 +229,8 @@ endif ...@@ -228,7 +229,8 @@ endif
libdirect3d11_plugin_la_SOURCES = video_output/win32/direct3d11.c \ libdirect3d11_plugin_la_SOURCES = video_output/win32/direct3d11.c \
video_chroma/d3d11_fmt.h video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h \ video_chroma/d3d11_fmt.h video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h \
video_output/win32/common.c video_output/win32/common.h video_output/win32/common.c video_output/win32/common.h \
video_chroma/copy.c video_chroma/copy.h
libdirect3d11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \ libdirect3d11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DMODULE_NAME_IS_direct3d11 -DMODULE_NAME_IS_direct3d11
if !HAVE_WINSTORE if !HAVE_WINSTORE
...@@ -251,6 +253,7 @@ EXTRA_LTLIBRARIES += libdirect3d11_deinterlace_plugin.la ...@@ -251,6 +253,7 @@ EXTRA_LTLIBRARIES += libdirect3d11_deinterlace_plugin.la
libdirectdraw_plugin_la_SOURCES = video_output/win32/directdraw.c \ libdirectdraw_plugin_la_SOURCES = video_output/win32/directdraw.c \
video_output/win32/common.c video_output/win32/common.h \ video_output/win32/common.c video_output/win32/common.h \
video_chroma/copy.c video_chroma/copy.h \
video_output/win32/events.c video_output/win32/events.h \ video_output/win32/events.c video_output/win32/events.h \
video_output/win32/win32touch.c video_output/win32/win32touch.h video_output/win32/win32touch.c video_output/win32/win32touch.h
libdirectdraw_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \ libdirectdraw_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
...@@ -265,6 +268,7 @@ endif ...@@ -265,6 +268,7 @@ endif
libglwin32_plugin_la_SOURCES = $(OPENGL_COMMONSOURCES) \ libglwin32_plugin_la_SOURCES = $(OPENGL_COMMONSOURCES) \
video_output/win32/glwin32.c \ video_output/win32/glwin32.c \
video_output/win32/common.c video_output/win32/common.h \ video_output/win32/common.c video_output/win32/common.h \
video_chroma/copy.c video_chroma/copy.h \
video_output/win32/events.c video_output/win32/events.h \ video_output/win32/events.c video_output/win32/events.h \
video_output/win32/win32touch.c video_output/win32/win32touch.h video_output/win32/win32touch.c video_output/win32/win32touch.h
libwgl_plugin_la_SOURCES = video_output/win32/wgl.c $(OPENGL_COMMONSOURCES) libwgl_plugin_la_SOURCES = video_output/win32/wgl.c $(OPENGL_COMMONSOURCES)
...@@ -289,6 +293,7 @@ endif ...@@ -289,6 +293,7 @@ endif
libwingdi_plugin_la_SOURCES = video_output/win32/wingdi.c \ libwingdi_plugin_la_SOURCES = video_output/win32/wingdi.c \
video_output/win32/common.c video_output/win32/common.h \ video_output/win32/common.c video_output/win32/common.h \
video_chroma/copy.c video_chroma/copy.h \
video_output/win32/events.c video_output/win32/events.h \ video_output/win32/events.c video_output/win32/events.h \
video_output/win32/win32touch.c video_output/win32/win32touch.h video_output/win32/win32touch.c video_output/win32/win32touch.h
libwingdi_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \ libwingdi_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#define vout_display_sys_win32_t vout_display_sys_t #define vout_display_sys_win32_t vout_display_sys_t
#include "common.h" #include "common.h"
#include "../video_chroma/copy.h"
#if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H) #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
# include <initguid.h> # include <initguid.h>
...@@ -459,57 +460,7 @@ int CommonUpdatePicture(picture_t *picture, picture_t **fallback, ...@@ -459,57 +460,7 @@ int CommonUpdatePicture(picture_t *picture, picture_t **fallback,
} }
return VLC_SUCCESS; return VLC_SUCCESS;
} }
/* fill in buffer info in first plane */ return picture_UpdatePlanes(picture, data, pitch);
picture->p->p_pixels = data;
picture->p->i_pitch = pitch;
picture->p->i_lines = picture->format.i_height;
assert(picture->p->i_visible_pitch <= picture->p->i_pitch);
assert(picture->p->i_visible_lines <= picture->p->i_lines);
/* Fill chroma planes for biplanar YUV */
if (picture->format.i_chroma == VLC_CODEC_NV12 ||
picture->format.i_chroma == VLC_CODEC_NV21 ||
picture->format.i_chroma == VLC_CODEC_P010) {
for (int n = 1; n < picture->i_planes; n++) {
const plane_t *o = &picture->p[n-1];
plane_t *p = &picture->p[n];
p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
p->i_pitch = pitch;
p->i_lines = picture->format.i_height;
assert(p->i_visible_pitch <= p->i_pitch);
assert(p->i_visible_lines <= p->i_lines);
}
/* The dx/d3d buffer is always allocated as NV12 */
if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_NV12)) {
/* TODO : Swap NV21 UV planes to match NV12 */
return VLC_EGENERIC;
}
}
/* Fill chroma planes for planar YUV */
else
if (picture->format.i_chroma == VLC_CODEC_I420 ||
picture->format.i_chroma == VLC_CODEC_J420 ||
picture->format.i_chroma == VLC_CODEC_YV12) {
for (int n = 1; n < picture->i_planes; n++) {
const plane_t *o = &picture->p[n-1];
plane_t *p = &picture->p[n];
p->p_pixels = o->p_pixels + o->i_lines * o->i_pitch;
p->i_pitch = pitch / 2;
p->i_lines = picture->format.i_height / 2;
}
/* The dx/d3d buffer is always allocated as YV12 */
if (vlc_fourcc_AreUVPlanesSwapped(picture->format.i_chroma, VLC_CODEC_YV12)) {
uint8_t *p_tmp = picture->p[1].p_pixels;
picture->p[1].p_pixels = picture->p[2].p_pixels;
picture->p[2].p_pixels = p_tmp;
}
}
return VLC_SUCCESS;
} }
void AlignRect(RECT *r, int align_boundary, int align_size) void AlignRect(RECT *r, int align_boundary, int align_size)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment