[vlc-commits] [Git][videolan/vlc][3.0.x] 3 commits: direct3d9: renaming and cleaning

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Sat May 21 14:34:01 UTC 2022



Hugo Beauzée-Luyssen pushed to branch 3.0.x at VideoLAN / VLC


Commits:
b6f79ee6 by Steve Lhomme at 2022-05-21T14:15:54+00:00
direct3d9: renaming and cleaning

(cherry picked from commit d7e9562be34d10cf0f91e363b423d0447ff49f36) (edited)
edited:
- 3.0 is based on the rectangles computed in the common code

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
20e6ea23 by Steve Lhomme at 2022-05-21T14:15:54+00:00
direct3d9: create the scene texture with the visible size

We will never copy more than the visible area (plus one if the source is an
odd dimension).

(cherry picked from commit 70a2dab831b9e40d3612c16b206b11f98eedaf00) (edited)
- 3.0 is based on the rectangles computed in the common code

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
90284275 by Steve Lhomme at 2022-05-21T14:15:54+00:00
direct3d9: fix the texture stretching

The destination texture (sys->sceneTexture) has the visible dimensions, not the
decoder dimensions.

Factorize the size processing for the stretching and the vertex computing..

Ref. https://forum.videolan.org/viewtopic.php?f=14&t=159861

(cherry picked from commit 86846565053ae759cf0215d0670d5e603aee2de5) (edited)
- 3.0 is based on the rectangles computed in the common code

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -


1 changed file:

- modules/video_output/win32/direct3d9.c


Changes:

=====================================
modules/video_output/win32/direct3d9.c
=====================================
@@ -253,6 +253,16 @@ static HINSTANCE Direct3D9LoadShaderLibrary(void)
     return instance;
 }
 
+static unsigned int GetPictureWidth(const vout_display_t *vd)
+{
+    return vd->source.i_visible_width;
+}
+
+static unsigned int GetPictureHeight(const vout_display_t *vd)
+{
+    return vd->source.i_visible_height;
+}
+
 /**
  * It creates a Direct3D vout display.
  */
@@ -310,6 +320,9 @@ static int Open(vlc_object_t *object)
     if (CommonInit(vd))
         goto error;
 
+    sys->sys.pf_GetPictureWidth  = GetPictureWidth;
+    sys->sys.pf_GetPictureHeight = GetPictureHeight;
+
     /* */
     video_format_t fmt;
     if (Direct3D9Open(vd, &fmt)) {
@@ -996,7 +1009,7 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt)
     else if (!vd->source.b_color_range_full && d3dbuffer->rmask && !d3dfmt->rmask)
     {
         D3DADAPTER_IDENTIFIER9 d3dai;
-        if (sys->hd3d.use_ex && SUCCEEDED(IDirect3D9Ex_GetAdapterIdentifier(sys->hd3d.objex, sys->d3d_dev.adapterId, 0, &d3dai)) && 
+        if (sys->hd3d.use_ex && SUCCEEDED(IDirect3D9Ex_GetAdapterIdentifier(sys->hd3d.objex, sys->d3d_dev.adapterId, 0, &d3dai)) &&
             d3dai.VendorId == GPU_MANUFACTURER_NVIDIA) {
 
             // NVIDIA bug, YUV to RGB internal conversion in StretchRect always converts from limited to limited range
@@ -1246,6 +1259,14 @@ static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
     LPDIRECT3DDEVICE9       d3ddev = p_d3d9_dev->dev;
     HRESULT hr;
 
+    // On nVidia & AMD, StretchRect will fail if the visible size isn't even.
+    // When copying the entire buffer, the margin end up being blended in the actual picture
+    // on nVidia (regardless of even/odd dimensions)
+    UINT texture_width  = fmt->i_visible_width;
+    UINT texture_height = fmt->i_visible_height;
+    if (texture_width  & 1) texture_width++;
+    if (texture_height & 1) texture_height++;
+
     /*
      * Create a texture for use when rendering a scene
      * for performance reason, texture format is identical to backbuffer
@@ -1253,8 +1274,8 @@ static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
      */
     LPDIRECT3DTEXTURE9 d3dtex;
     hr = IDirect3DDevice9_CreateTexture(d3ddev,
-                                        fmt->i_width,
-                                        fmt->i_height,
+                                        texture_width,
+                                        texture_height,
                                         1,
                                         D3DUSAGE_RENDERTARGET,
                                         p_d3d9_dev->pp.BackBufferFormat,
@@ -1267,8 +1288,7 @@ static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
     }
 
 #ifndef NDEBUG
-    msg_Dbg(vd, "Direct3D created texture: %ix%i",
-                fmt->i_width, fmt->i_height);
+    msg_Dbg(vd, "Direct3D created texture: %ix%i", texture_width, texture_height);
 #endif
 
     /*
@@ -1601,17 +1621,17 @@ static void orientationVertexOrder(video_orientation_t orientation, int vertex_o
 }
 
 static void  Direct3D9SetupVertices(CUSTOMVERTEX *vertices,
-                                  const RECT *src, const RECT *src_clipped,
-                                  const RECT *dst,
+                                  const RECT *full_texture, const RECT *visible_texture,
+                                  const RECT *rect_in_display,
                                   int alpha,
                                   video_orientation_t orientation)
 {
     /* Vertices of the dst rectangle in the unrotated (clockwise) order. */
     const int vertices_coords[4][2] = {
-        { dst->left,  dst->top    },
-        { dst->right, dst->top    },
-        { dst->right, dst->bottom },
-        { dst->left,  dst->bottom },
+        { rect_in_display->left,  rect_in_display->top    },
+        { rect_in_display->right, rect_in_display->top    },
+        { rect_in_display->right, rect_in_display->bottom },
+        { rect_in_display->left,  rect_in_display->bottom },
     };
 
     /* Compute index remapping necessary to implement the rotation. */
@@ -1623,22 +1643,22 @@ static void  Direct3D9SetupVertices(CUSTOMVERTEX *vertices,
         vertices[i].y  = vertices_coords[vertex_order[i]][1];
     }
 
-    float right = (float)src_clipped->right / (float)src->right;
-    float left = (float)src_clipped->left / (float)src->right;
-    float top = (float)src_clipped->top / (float)src->bottom;
-    float bottom = (float)src_clipped->bottom / (float)src->bottom;
+    float texture_right  = (float)visible_texture->right / (float)full_texture->right;
+    float texture_left   = (float)visible_texture->left  / (float)full_texture->right;
+    float texture_top    = (float)visible_texture->top    / (float)full_texture->bottom;
+    float texture_bottom = (float)visible_texture->bottom / (float)full_texture->bottom;
 
-    vertices[0].tu = left;
-    vertices[0].tv = top;
+    vertices[0].tu = texture_left;
+    vertices[0].tv = texture_top;
 
-    vertices[1].tu = right;
-    vertices[1].tv = top;
+    vertices[1].tu = texture_right;
+    vertices[1].tv = texture_top;
 
-    vertices[2].tu = right;
-    vertices[2].tv = bottom;
+    vertices[2].tu = texture_right;
+    vertices[2].tv = texture_bottom;
 
-    vertices[3].tu = left;
-    vertices[3].tv = bottom;
+    vertices[3].tu = texture_left;
+    vertices[3].tv = texture_bottom;
 
     for (int i = 0; i < 4; i++) {
         /* -0.5f is a "feature" of DirectX and it seems to apply to Direct3d also */
@@ -1686,17 +1706,17 @@ static int Direct3D9ImportPicture(vout_display_t *vd,
     {
         /* Copy picture surface into texture surface
         * color space conversion happen here */
-        RECT copy_rect = sys->sys.rect_src_clipped;
+        RECT texture_visible_rect = sys->sys.rect_src_clipped;
         // On nVidia & AMD, StretchRect will fail if the visible size isn't even.
         // When copying the entire buffer, the margin end up being blended in the actual picture
         // on nVidia (regardless of even/odd dimensions)
-        if ( copy_rect.right & 1 ) copy_rect.right++;
-        if ( copy_rect.left & 1 ) copy_rect.left--;
-        if ( copy_rect.bottom & 1 ) copy_rect.bottom++;
-        if ( copy_rect.top & 1 ) copy_rect.top--;
-        hr = IDirect3DDevice9_StretchRect(sys->d3d_dev.dev, source, &copy_rect, destination,
-                                        &copy_rect, D3DTEXF_NONE);
-    }  
+        if ( texture_visible_rect.right & 1 ) texture_visible_rect.right++;
+        if ( texture_visible_rect.left & 1 ) texture_visible_rect.left--;
+        if ( texture_visible_rect.bottom & 1 ) texture_visible_rect.bottom++;
+        if ( texture_visible_rect.top & 1 ) texture_visible_rect.top--;
+        hr = IDirect3DDevice9_StretchRect(sys->d3d_dev.dev, source, &texture_visible_rect, destination,
+                                        &texture_visible_rect, D3DTEXF_NONE);
+    }
     IDirect3DSurface9_Release(destination);
     if (FAILED(hr)) {
         msg_Dbg(vd, "Failed IDirect3DDevice9_StretchRect: source 0x%p 0x%0lx",
@@ -1818,26 +1838,26 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd,
         const float scale_w = (float)(video.right  - video.left) / subpicture->i_original_picture_width;
         const float scale_h = (float)(video.bottom - video.top)  / subpicture->i_original_picture_height;
 
-        RECT dst;
-        dst.left   = video.left + scale_w * r->i_x,
-        dst.right  = dst.left + scale_w * r->fmt.i_visible_width,
-        dst.top    = video.top  + scale_h * r->i_y,
-        dst.bottom = dst.top  + scale_h * r->fmt.i_visible_height;
-
-        RECT src;
-        src.left = 0;
-        src.right = r->fmt.i_width;
-        src.top = 0;
-        src.bottom = r->fmt.i_height;
-
-        RECT src_clipped;
-        src_clipped.left = r->fmt.i_x_offset;
-        src_clipped.right = r->fmt.i_x_offset + r->fmt.i_visible_width;
-        src_clipped.top = r->fmt.i_y_offset;
-        src_clipped.bottom = r->fmt.i_y_offset + r->fmt.i_visible_height;
-
-        Direct3D9SetupVertices(d3dr->vertex, &src, &src_clipped,
-                              &dst, subpicture->i_alpha * r->i_alpha / 255, ORIENT_NORMAL);
+        RECT rect_in_display;
+        rect_in_display.left   = video.left + scale_w * r->i_x,
+        rect_in_display.right  = rect_in_display.left + scale_w * r->fmt.i_visible_width,
+        rect_in_display.top    = video.top  + scale_h * r->i_y,
+        rect_in_display.bottom = rect_in_display.top  + scale_h * r->fmt.i_visible_height;
+
+        RECT texture_rect;
+        texture_rect.left   = 0;
+        texture_rect.right  = r->fmt.i_width;
+        texture_rect.top    = 0;
+        texture_rect.bottom = r->fmt.i_height;
+
+        RECT texture_visible_rect;
+        texture_visible_rect.left   = r->fmt.i_x_offset;
+        texture_visible_rect.right  = r->fmt.i_x_offset + r->fmt.i_visible_width;
+        texture_visible_rect.top    = r->fmt.i_y_offset;
+        texture_visible_rect.bottom = r->fmt.i_y_offset + r->fmt.i_visible_height;
+
+        Direct3D9SetupVertices(d3dr->vertex, &texture_rect, &texture_visible_rect,
+                              &rect_in_display, subpicture->i_alpha * r->i_alpha / 255, ORIENT_NORMAL);
     }
 }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6c5ed18a6bb06cc55afe0eaa7e2134fb090bf5d5...902842750b287847ba7b675d10176dd48de2bf35

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6c5ed18a6bb06cc55afe0eaa7e2134fb090bf5d5...902842750b287847ba7b675d10176dd48de2bf35
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list