[vlc-devel] [PATCH 13/39] vout: win32: move the GPU to CPU picture buffer mapping in a separate file
Steve Lhomme
robux4 at videolabs.io
Fri Jun 2 16:46:16 CEST 2017
It can be used for CPU to GPU mapping as well
---
modules/video_output/Makefile.am | 7 ++-
modules/video_output/win32/common.c | 54 +-----------------
modules/video_output/win32/picture_helper.c | 87 +++++++++++++++++++++++++++++
modules/video_output/win32/picture_helper.h | 37 ++++++++++++
4 files changed, 133 insertions(+), 52 deletions(-)
create mode 100644 modules/video_output/win32/picture_helper.c
create mode 100644 modules/video_output/win32/picture_helper.h
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 783c047932..4ea159ded6 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_output/win32/common.c video_output/win32/common.h \
+ video_output/win32/picture_helper.c video_output/win32/picture_helper.h \
video_output/win32/events.c video_output/win32/events.h \
video_output/win32/builtin_shaders.h \
video_output/win32/win32touch.c video_output/win32/win32touch.h \
@@ -227,7 +228,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_output/win32/picture_helper.c video_output/win32/picture_helper.h
libdirect3d11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DMODULE_NAME_IS_direct3d11
if !HAVE_WINSTORE
@@ -250,6 +252,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_output/win32/picture_helper.c video_output/win32/picture_helper.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) \
@@ -264,6 +267,7 @@ endif
libglwin32_plugin_la_SOURCES = $(OPENGL_COMMONSOURCES) \
video_output/win32/glwin32.c \
video_output/win32/common.c video_output/win32/common.h \
+ video_output/win32/picture_helper.c video_output/win32/picture_helper.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)
@@ -288,6 +292,7 @@ endif
libwingdi_plugin_la_SOURCES = video_output/win32/wingdi.c \
video_output/win32/common.c video_output/win32/common.h \
+ video_output/win32/picture_helper.c video_output/win32/picture_helper.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..bd08d9d620 100644
--- a/modules/video_output/win32/common.c
+++ b/modules/video_output/win32/common.c
@@ -50,6 +50,8 @@
# include <dxgidebug.h>
#endif
+#include "picture_helper.h"
+
static void CommonChangeThumbnailClip(vout_display_t *, bool show);
#if !VLC_WINSTORE_APP
static int CommonControlSetFullscreen(vout_display_t *, bool is_fullscreen);
@@ -459,57 +461,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)
diff --git a/modules/video_output/win32/picture_helper.c b/modules/video_output/win32/picture_helper.c
new file mode 100644
index 0000000000..b9252a3149
--- /dev/null
+++ b/modules/video_output/win32/picture_helper.c
@@ -0,0 +1,87 @@
+/*****************************************************************************
+ * picture_helper.c: Helper functions to map picture memory to/from GPU textures
+ *****************************************************************************
+ * Copyright (C) 2001-2017 VLC authors and VideoLAN
+ *
+ * Authors: Gildas Bazin <gbazin at videolan.org>
+ * Martell Malone <martellmalone at gmail.com>
+ * Steve Lhomme <robux4 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_picture.h>
+#include <assert.h>
+
+#include "picture_helper.h"
+
+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_output/win32/picture_helper.h b/modules/video_output/win32/picture_helper.h
new file mode 100644
index 0000000000..6decfa5a03
--- /dev/null
+++ b/modules/video_output/win32/picture_helper.h
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * picture_helper.h: Helper functions to map picture memory to/from GPU textures
+ *****************************************************************************
+ * Copyright (C) 2001-2017 VLC authors and VideoLAN
+ *
+ * Authors: Steve Lhomme <robux4 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_PICTURE_HELPER_H
+#define VLC_PICTURE_HELPER_H
+
+/**
+ * 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 /* VLC_PICTURE_HELPER_H */
--
2.12.1
More information about the vlc-devel
mailing list