[vlc-commits] direct3d9: Always process full buffers & crop using texture mapping
Hugo Beauzée-Luyssen
git at videolan.org
Thu Apr 6 16:38:06 CEST 2017
vlc/vlc-2.2 | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Apr 6 11:15:11 2017 +0200| [3477dba3d506de8d95bccef2c6b67861188f6c29] | committer: Hugo Beauzée-Luyssen
direct3d9: Always process full buffers & crop using texture mapping
Manually cherry-picked from 52799c39e166b249df73b376bd3a18bb486367e1
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=3477dba3d506de8d95bccef2c6b67861188f6c29
---
modules/video_output/msw/direct3d.c | 47 +++++++++++++++++++------------------
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git a/modules/video_output/msw/direct3d.c b/modules/video_output/msw/direct3d.c
index abdfaec..f395fad 100644
--- a/modules/video_output/msw/direct3d.c
+++ b/modules/video_output/msw/direct3d.c
@@ -315,8 +315,8 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
d3d_region_t picture_region;
if (!Direct3DImportPicture(vd, &picture_region, surface)) {
- picture_region.width = picture->format.i_visible_width;
- picture_region.height = picture->format.i_visible_height;
+ picture_region.width = picture->format.i_width;
+ picture_region.height = picture->format.i_height;
int subpicture_region_count = 0;
d3d_region_t *subpicture_region = NULL;
if (subpicture)
@@ -1055,8 +1055,8 @@ static int Direct3DCreateScene(vout_display_t *vd, const video_format_t *fmt)
*/
LPDIRECT3DTEXTURE9 d3dtex;
hr = IDirect3DDevice9_CreateTexture(d3ddev,
- fmt->i_visible_width,
- fmt->i_visible_height,
+ fmt->i_width,
+ fmt->i_height,
1,
D3DUSAGE_RENDERTARGET,
sys->d3dpp.BackBufferFormat,
@@ -1387,6 +1387,7 @@ static void orientationVertexOrder(video_orientation_t orientation, int vertex_o
}
static void Direct3DSetupVertices(CUSTOMVERTEX *vertices,
+ const RECT *src, const RECT *src_clipped,
const RECT dst,
int alpha,
video_orientation_t orientation)
@@ -1398,6 +1399,7 @@ static void Direct3DSetupVertices(CUSTOMVERTEX *vertices,
{ dst.right, dst.bottom },
{ dst.left, dst.bottom },
};
+ bool has_src = src != NULL && src_clipped != NULL;
/* Compute index remapping necessary to implement the rotation. */
int vertex_order[4];
@@ -1411,14 +1413,14 @@ static void Direct3DSetupVertices(CUSTOMVERTEX *vertices,
vertices[0].tu = .0f;
vertices[0].tv = .0f;
- vertices[1].tu = 1.f;
+ vertices[1].tu = has_src ? (float)src_clipped->right / (float)src->right : 1.0f;
vertices[1].tv = .0f;
- vertices[2].tu = 1.f;
- vertices[2].tv = 1.f;
+ vertices[2].tu = has_src ? (float)src_clipped->right / (float)src->right : 1.0f;
+ vertices[2].tv = has_src ? ((float)src_clipped->bottom) / (float)src->bottom : 1.0f;
vertices[3].tu = .0f;
- vertices[3].tv = 1.f;
+ vertices[3].tv = has_src ? ((float)src_clipped->bottom) / (float)src->bottom : 1.0f;
for (int i = 0; i < 4; i++) {
/* -0.5f is a "feature" of DirectX and it seems to apply to Direct3d also */
@@ -1457,7 +1459,7 @@ static int Direct3DImportPicture(vout_display_t *vd,
/* Copy picture surface into texture surface
* color space conversion happen here */
- hr = IDirect3DDevice9_StretchRect(sys->d3ddev, source, &vd->sys->rect_src_clipped, destination, NULL, D3DTEXF_NONE );
+ hr = IDirect3DDevice9_StretchRect(sys->d3ddev, source, &vd->sys->rect_src, destination, NULL, D3DTEXF_NONE );
IDirect3DSurface9_Release(destination);
if (FAILED(hr)) {
msg_Dbg(vd, "%s:%d (hr=0x%0lX)", __FUNCTION__, __LINE__, hr);
@@ -1466,7 +1468,8 @@ static int Direct3DImportPicture(vout_display_t *vd,
/* */
region->texture = sys->d3dtex;
- Direct3DSetupVertices(region->vertex, vd->sys->rect_dest_clipped, 255, vd->fmt.orientation);
+ Direct3DSetupVertices(region->vertex, &vd->sys->rect_src, &vd->sys->rect_src_clipped,
+ vd->sys->rect_dest_clipped, 255, vd->fmt.orientation);
return VLC_SUCCESS;
}
@@ -1506,8 +1509,8 @@ static void Direct3DImportSubpicture(vout_display_t *vd,
d3d_region_t *cache = &sys->d3dregion[j];
if (cache->texture &&
cache->format == sys->d3dregion_format &&
- cache->width == r->fmt.i_visible_width &&
- cache->height == r->fmt.i_visible_height) {
+ cache->width == r->fmt.i_width &&
+ cache->height == r->fmt.i_height) {
#ifndef NDEBUG
msg_Dbg(vd, "Reusing %dx%d texture for OSD",
cache->width, cache->height);
@@ -1519,8 +1522,8 @@ static void Direct3DImportSubpicture(vout_display_t *vd,
}
if (!d3dr->texture) {
d3dr->format = sys->d3dregion_format;
- d3dr->width = r->fmt.i_visible_width;
- d3dr->height = r->fmt.i_visible_height;
+ d3dr->width = r->fmt.i_width;
+ d3dr->height = r->fmt.i_height;
hr = IDirect3DDevice9_CreateTexture(sys->d3ddev,
d3dr->width, d3dr->height,
1,
@@ -1537,7 +1540,7 @@ static void Direct3DImportSubpicture(vout_display_t *vd,
}
#ifndef NDEBUG
msg_Dbg(vd, "Created %dx%d texture for OSD",
- r->fmt.i_visible_width, r->fmt.i_visible_height);
+ r->fmt.i_width, r->fmt.i_height);
#endif
}
@@ -1546,12 +1549,10 @@ static void Direct3DImportSubpicture(vout_display_t *vd,
if (SUCCEEDED(hr)) {
uint8_t *dst_data = lock.pBits;
int dst_pitch = lock.Pitch;
- const int src_offset = r->fmt.i_y_offset * r->p_picture->p->i_pitch +
- r->fmt.i_x_offset * r->p_picture->p->i_pixel_pitch;
- uint8_t *src_data = &r->p_picture->p->p_pixels[src_offset];
+ uint8_t *src_data = r->p_picture->p->p_pixels;
int src_pitch = r->p_picture->p->i_pitch;
- for (unsigned y = 0; y < r->fmt.i_visible_height; y++) {
- int copy_pitch = __MIN(dst_pitch, r->p_picture->p->i_visible_pitch);
+ for (unsigned y = 0; y < r->fmt.i_height; y++) {
+ int copy_pitch = __MIN(dst_pitch, r->p_picture->p->i_pitch);
if (d3dr->format == D3DFMT_A8B8G8R8) {
memcpy(&dst_data[y * dst_pitch], &src_data[y * src_pitch],
copy_pitch);
@@ -1578,10 +1579,10 @@ static void Direct3DImportSubpicture(vout_display_t *vd,
RECT dst;
dst.left = video.left + scale_w * r->i_x,
- dst.right = dst.left + scale_w * r->fmt.i_visible_width,
+ dst.right = dst.left + scale_w * r->fmt.i_width,
dst.top = video.top + scale_h * r->i_y,
- dst.bottom = dst.top + scale_h * r->fmt.i_visible_height,
- Direct3DSetupVertices(d3dr->vertex,
+ dst.bottom = dst.top + scale_h * r->fmt.i_height,
+ Direct3DSetupVertices(d3dr->vertex, NULL, NULL,
dst,
subpicture->i_alpha * r->i_alpha / 255, ORIENT_NORMAL);
}
More information about the vlc-commits
mailing list