vlc | branch: master | Steve Lhomme <[email protected]> | Tue Jun 6 17:15:24 2017 +0200| [f4da1404ce59730561d7fc63cc58f2085c450c92] | committer: 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 <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f4da1404ce59730561d7fc63cc58f2085c450c92 --- modules/video_chroma/copy.c | 55 +++++++++++++++++++++++++++++++++++++ modules/video_chroma/copy.h | 11 ++++++++ modules/video_output/Makefile.am | 7 ++++- modules/video_output/win32/common.c | 53 ++--------------------------------- 4 files changed, 74 insertions(+), 52 deletions(-) diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c index defbafb6c0..6238ffb1ab 100644 --- a/modules/video_chroma/copy.c +++ b/modules/video_chroma/copy.c @@ -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, 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; +} diff --git a/modules/video_chroma/copy.h b/modules/video_chroma/copy.h index f32bd24c60..9b9dbd1f66 100644 --- a/modules/video_chroma/copy.h +++ b/modules/video_chroma/copy.h @@ -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], 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 diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am index dae0183d96..121797c64f 100644 --- a/modules/video_output/Makefile.am +++ b/modules/video_output/Makefile.am @@ -207,6 +207,7 @@ endif ### Win32 ### 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/events.c video_output/win32/events.h \ video_output/win32/builtin_shaders.h \ @@ -228,7 +229,8 @@ endif 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_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) \ -DMODULE_NAME_IS_direct3d11 if !HAVE_WINSTORE @@ -251,6 +253,7 @@ EXTRA_LTLIBRARIES += libdirect3d11_deinterlace_plugin.la libdirectdraw_plugin_la_SOURCES = video_output/win32/directdraw.c \ 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/win32touch.c video_output/win32/win32touch.h libdirectdraw_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \ @@ -265,6 +268,7 @@ endif libglwin32_plugin_la_SOURCES = $(OPENGL_COMMONSOURCES) \ video_output/win32/glwin32.c \ 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/win32touch.c video_output/win32/win32touch.h libwgl_plugin_la_SOURCES = video_output/win32/wgl.c $(OPENGL_COMMONSOURCES) @@ -289,6 +293,7 @@ endif libwingdi_plugin_la_SOURCES = video_output/win32/wingdi.c \ 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/win32touch.c video_output/win32/win32touch.h libwingdi_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \ diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c index 328139bee4..c7bc1d9b1b 100644 --- a/modules/video_output/win32/common.c +++ b/modules/video_output/win32/common.c @@ -44,6 +44,7 @@ #define vout_display_sys_win32_t vout_display_sys_t #include "common.h" +#include "../video_chroma/copy.h" #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H) # include <initguid.h> @@ -459,57 +460,7 @@ int CommonUpdatePicture(picture_t *picture, picture_t **fallback, } return VLC_SUCCESS; } - /* 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; + return picture_UpdatePlanes(picture, data, pitch); } void AlignRect(RECT *r, int align_boundary, int align_size) _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
