[vlc-commits] [Git][videolan/vlc][master] 5 commits: direct3d11: always initialize the subpicture region d3d11_quad_t video format

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Mar 28 16:47:44 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
8269f9ea by Steve Lhomme at 2024-03-28T15:41:25+00:00
direct3d11: always initialize the subpicture region d3d11_quad_t video format

It's cleaned in the destructor.

- - - - -
ac18e4fa by Steve Lhomme at 2024-03-28T15:41:25+00:00
direct3d11: factorize the code to get the area to display of a quad

- - - - -
ab7eeb6c by Steve Lhomme at 2024-03-28T15:41:25+00:00
direct3d11: pass the picture placement to UpdateViewport()

Rather than create a local variant of it.

- - - - -
75bac835 by Steve Lhomme at 2024-03-28T15:41:25+00:00
direct3d9 pass the picture placement to Direct3D9SetupVertices()

Rather than create a local variant of it.

- - - - -
81869518 by Steve Lhomme at 2024-03-28T15:41:25+00:00
direct3d9: pass the video_format with picture crop information to Direct3D9SetupVertices()

- - - - -


5 changed files:

- modules/video_output/win32/d3d11_quad.cpp
- modules/video_output/win32/d3d11_quad.h
- modules/video_output/win32/d3d11_shaders.h
- modules/video_output/win32/direct3d11.cpp
- modules/video_output/win32/direct3d9.c


Changes:

=====================================
modules/video_output/win32/d3d11_quad.cpp
=====================================
@@ -140,7 +140,7 @@ void d3d11_quad_t::Reset()
 
 #undef D3D11_UpdateQuadPosition
 bool D3D11_UpdateQuadPosition( vlc_object_t *o, d3d11_device_t *d3d_dev, d3d11_quad_t *quad,
-                                const RECT *output, video_transform_t orientation )
+                               video_transform_t orientation )
 {
     bool result = true;
     HRESULT hr;
@@ -166,7 +166,13 @@ bool D3D11_UpdateQuadPosition( vlc_object_t *o, d3d11_device_t *d3d_dev, d3d11_q
         return false;
     }
 
-    result = D3D_SetupQuadData(o, &quad->generic, output, dst_data, mappedResource.pData, orientation);
+    RECT output;
+    output.left   = quad->quad_fmt.i_x_offset;
+    output.right  = quad->quad_fmt.i_x_offset + quad->quad_fmt.i_visible_width;
+    output.top    = quad->quad_fmt.i_y_offset;
+    output.bottom = quad->quad_fmt.i_y_offset + quad->quad_fmt.i_visible_height;
+
+    result = D3D_SetupQuadData(o, &quad->generic, &output, dst_data, mappedResource.pData, orientation);
 
     d3d_dev->d3dcontext->Unmap(quad->indexBuffer.Get(), 0);
     d3d_dev->d3dcontext->Unmap(quad->vertexBuffer.Get(), 0);
@@ -298,26 +304,21 @@ int D3D11_SetupQuad(vlc_object_t *o, d3d11_device_t *d3d_dev, const video_format
     return VLC_SUCCESS;
 }
 
-void d3d11_quad_t::UpdateViewport(const RECT *rect, const d3d_format_t *display)
+void d3d11_quad_t::UpdateViewport(const vout_display_place_t *place, const d3d_format_t *display)
 {
-    LONG srcAreaWidth, srcAreaHeight;
-
-    srcAreaWidth  = RECTWidth(*rect);
-    srcAreaHeight = RECTHeight(*rect);
-
-    cropViewport[0].TopLeftX = rect->left;
-    cropViewport[0].TopLeftY = rect->top;
-    cropViewport[0].Width    = srcAreaWidth;
-    cropViewport[0].Height   = srcAreaHeight;
+    cropViewport[0].TopLeftX = place->x;
+    cropViewport[0].TopLeftY = place->y;
+    cropViewport[0].Width    = place->width;
+    cropViewport[0].Height   = place->height;
 
     switch ( generic.textureFormat->formatTexture )
     {
     case DXGI_FORMAT_NV12:
     case DXGI_FORMAT_P010:
-        cropViewport[1].TopLeftX = rect->left / 2;
-        cropViewport[1].TopLeftY = rect->top / 2;
-        cropViewport[1].Width    = srcAreaWidth / 2;
-        cropViewport[1].Height   = srcAreaHeight / 2;
+        cropViewport[1].TopLeftX = place->x / 2;
+        cropViewport[1].TopLeftY = place->y / 2;
+        cropViewport[1].Width    = place->width  / 2;
+        cropViewport[1].Height   = place->height / 2;
         break;
     case DXGI_FORMAT_R8G8B8A8_UNORM:
     case DXGI_FORMAT_B8G8R8A8_UNORM:
@@ -332,10 +333,10 @@ void d3d11_quad_t::UpdateViewport(const RECT *rect, const d3d_format_t *display)
         if ( display->formatTexture == DXGI_FORMAT_NV12 ||
              display->formatTexture == DXGI_FORMAT_P010 )
         {
-            cropViewport[1].TopLeftX = rect->left / 2;
-            cropViewport[1].TopLeftY = rect->top / 2;
-            cropViewport[1].Width    = srcAreaWidth / 2;
-            cropViewport[1].Height   = srcAreaHeight / 2;
+            cropViewport[1].TopLeftX = place->x / 2;
+            cropViewport[1].TopLeftY = place->y / 2;
+            cropViewport[1].Width    = place->width  / 2;
+            cropViewport[1].Height   = place->height / 2;
         }
         break;
     case DXGI_FORMAT_UNKNOWN:
@@ -363,10 +364,10 @@ void d3d11_quad_t::UpdateViewport(const RECT *rect, const d3d_format_t *display)
         case VLC_CODEC_I420_10L:
         case VLC_CODEC_I420:
         case VLC_CODEC_YUV420A:
-            cropViewport[1].TopLeftX = cropViewport[0].TopLeftX / 2;
-            cropViewport[1].TopLeftY = cropViewport[0].TopLeftY / 2;
-            cropViewport[1].Width    = cropViewport[0].Width / 2;
-            cropViewport[1].Height   = cropViewport[0].Height / 2;
+            cropViewport[1].TopLeftX = place->x / 2;
+            cropViewport[1].TopLeftY = place->y / 2;
+            cropViewport[1].Width    = place->width  / 2;
+            cropViewport[1].Height   = place->height / 2;
             break;
         }
         break;


=====================================
modules/video_output/win32/d3d11_quad.h
=====================================
@@ -61,8 +61,8 @@ int D3D11_SetupQuad(vlc_object_t *, d3d11_device_t *, const video_format_t *, d3
 #define D3D11_SetupQuad(a,b,c,d,e)  D3D11_SetupQuad(VLC_OBJECT(a),b,c,d,e)
 
 bool D3D11_UpdateQuadPosition( vlc_object_t *, d3d11_device_t *, d3d11_quad_t *,
-                               const RECT *output, video_transform_t );
-#define D3D11_UpdateQuadPosition(a,b,c,d,e)  D3D11_UpdateQuadPosition(VLC_OBJECT(a),b,c,d,e)
+                               video_transform_t );
+#define D3D11_UpdateQuadPosition(a,b,c,d)  D3D11_UpdateQuadPosition(VLC_OBJECT(a),b,c,d)
 
 void D3D11_UpdateQuadOpacity(vlc_object_t *, d3d11_device_t *, d3d11_quad_t *, float opacity);
 #define D3D11_UpdateQuadOpacity(a,b,c,d)  D3D11_UpdateQuadOpacity(VLC_OBJECT(a),b,c,d)


=====================================
modules/video_output/win32/d3d11_shaders.h
=====================================
@@ -51,7 +51,7 @@ struct d3d11_quad_t
     }
 
     void Reset();
-    void UpdateViewport(const RECT *, const d3d_format_t *display);
+    void UpdateViewport(const vout_display_place_t *, const d3d_format_t *display);
 
     picture_sys_d3d11_t       picSys = {};
     d3d_quad_t                generic = {};


=====================================
modules/video_output/win32/direct3d11.cpp
=====================================
@@ -338,22 +338,11 @@ static void UpdateSize(vout_display_t *vd)
 
     UpdateDisplayFormat(vd, vd->fmt);
 
-    RECT rect_dst;
-    rect_dst.left   = sys->area.place.x;
-    rect_dst.right  = sys->area.place.x + sys->area.place.width;
-    rect_dst.top    = sys->area.place.y;
-    rect_dst.bottom = sys->area.place.y + sys->area.place.height;
-
-    sys->picQuad.UpdateViewport( &rect_dst, sys->display.pixelFormat );
-
-    RECT source_rect;
-    source_rect.left   = sys->picQuad.quad_fmt.i_x_offset;
-    source_rect.right  = sys->picQuad.quad_fmt.i_x_offset + sys->picQuad.quad_fmt.i_visible_width;
-    source_rect.top    = sys->picQuad.quad_fmt.i_y_offset;
-    source_rect.bottom = sys->picQuad.quad_fmt.i_y_offset + sys->picQuad.quad_fmt.i_visible_height;
+    sys->picQuad.UpdateViewport( &sys->area.place, sys->display.pixelFormat );
+
     d3d11_device_lock( sys->d3d_dev );
 
-    D3D11_UpdateQuadPosition(vd, sys->d3d_dev, &sys->picQuad, &source_rect,
+    D3D11_UpdateQuadPosition(vd, sys->d3d_dev, &sys->picQuad,
                              video_format_GetTransform(vd->source->orientation, sys->display.orientation));
 
     D3D11_UpdateViewpoint( vd, sys->d3d_dev, &sys->picQuad, &vd->cfg->viewpoint,
@@ -1309,12 +1298,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
         return VLC_EGENERIC;
     }
 
-    RECT source_rect;
-    source_rect.left   = sys->picQuad.quad_fmt.i_x_offset;
-    source_rect.right  = sys->picQuad.quad_fmt.i_x_offset + sys->picQuad.quad_fmt.i_visible_width;
-    source_rect.top    = sys->picQuad.quad_fmt.i_y_offset;
-    source_rect.bottom = sys->picQuad.quad_fmt.i_y_offset + sys->picQuad.quad_fmt.i_visible_height;
-    if (!D3D11_UpdateQuadPosition(vd, sys->d3d_dev, &sys->picQuad, &source_rect,
+    if (!D3D11_UpdateQuadPosition(vd, sys->d3d_dev, &sys->picQuad,
                                   video_format_GetTransform(sys->picQuad.quad_fmt.orientation, sys->display.orientation)))
     {
         msg_Err(vd, "Could not set quad picture position.");
@@ -1424,13 +1408,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
       return VLC_EGENERIC;
     }
 
-    RECT rect_dst;
-    rect_dst.left   = sys->area.place.x;
-    rect_dst.right  = sys->area.place.x + sys->area.place.width;
-    rect_dst.top    = sys->area.place.y;
-    rect_dst.bottom = sys->area.place.y + sys->area.place.height;
-
-    sys->picQuad.UpdateViewport( &rect_dst, sys->display.pixelFormat );
+    sys->picQuad.UpdateViewport( &sys->area.place, sys->display.pixelFormat );
 
 #ifndef NDEBUG
     msg_Dbg( vd, "picQuad position (%.02f,%.02f) %.02fx%.02f",
@@ -1569,6 +1547,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
                 i++;
                 continue;
             }
+            video_format_Copy(&d3dquad->quad_fmt, &r->p_picture->format);
             d3dquad->generic.i_width  = r->p_picture->format.i_width;
             d3dquad->generic.i_height = r->p_picture->format.i_height;
 
@@ -1636,22 +1615,10 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
             continue;
         }
 
-        RECT output;
-        output.left   = r->p_picture->format.i_x_offset;
-        output.right  = r->p_picture->format.i_x_offset + r->p_picture->format.i_visible_width;
-        output.top    = r->p_picture->format.i_y_offset;
-        output.bottom = r->p_picture->format.i_y_offset + r->p_picture->format.i_visible_height;
-
-        D3D11_UpdateQuadPosition(vd, sys->d3d_dev, quad, &output,
+        D3D11_UpdateQuadPosition(vd, sys->d3d_dev, quad,
             video_format_GetTransform(ORIENT_NORMAL, sys->display.orientation));
 
-        RECT spuViewport;
-        spuViewport.left   = r->place.x;
-        spuViewport.top    = r->place.y;
-        spuViewport.right  = r->place.x + r->place.width;
-        spuViewport.bottom = r->place.y + r->place.height;
-
-        quad->UpdateViewport( &spuViewport, sys->display.pixelFormat );
+        quad->UpdateViewport( &r->place, sys->display.pixelFormat );
 
         D3D11_UpdateQuadOpacity(vd, sys->d3d_dev, quad, r->i_alpha / 255.0f );
         i++;


=====================================
modules/video_output/win32/direct3d9.c
=====================================
@@ -266,17 +266,31 @@ static void orientationVertexOrder(video_orientation_t orientation, int vertex_o
 }
 
 static void  Direct3D9SetupVertices(CUSTOMVERTEX *vertices,
-                                  const RECT *full_texture, const RECT *visible_texture,
-                                  const RECT *rect_in_display,
+                                  const RECT *full_texture, const video_format_t *src_fmt,
+                                  const vout_display_place_t *place_in_display,
                                   int alpha,
                                   video_orientation_t orientation)
 {
+    RECT rect_in_display = {
+        .left   = place_in_display->x,
+        .right  = place_in_display->x + place_in_display->width,
+        .top    = place_in_display->y,
+        .bottom = place_in_display->y + place_in_display->height,
+    };
+
+    RECT visible_texture = {
+        .left   = src_fmt->i_x_offset,
+        .right  = src_fmt->i_x_offset + src_fmt->i_visible_width,
+        .top    = src_fmt->i_y_offset,
+        .bottom = src_fmt->i_y_offset + src_fmt->i_visible_height,
+    };
+
     /* Vertices of the dst rectangle in the unrotated (clockwise) order. */
     const int vertices_coords[4][2] = {
-        { 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 },
+        { 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. */
@@ -288,10 +302,10 @@ static void  Direct3D9SetupVertices(CUSTOMVERTEX *vertices,
         vertices[i].y  = vertices_coords[vertex_order[i]][1];
     }
 
-    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;
+    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 = texture_left;
     vertices[0].tv = texture_top;
@@ -398,14 +412,8 @@ static int Direct3D9ImportPicture(vout_display_t *vd,
 
     /* */
     region->texture = sys->sceneTexture;
-    RECT rect_in_display = {
-        .left   = sys->area.place.x,
-        .right  = sys->area.place.x + sys->area.place.width,
-        .top    = sys->area.place.y,
-        .bottom = sys->area.place.y + sys->area.place.height,
-    };
-    Direct3D9SetupVertices(region->vertex, &texture_visible_rect, &source_visible_rect,
-                           &rect_in_display, 255, vd->source->orientation);
+    Direct3D9SetupVertices(region->vertex, &texture_visible_rect, vd->source,
+                           &sys->area.place, 255, vd->source->orientation);
     return VLC_SUCCESS;
 }
 
@@ -955,26 +963,14 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd,
         }
 
         /* Map the subpicture to sys->sys.sys.place */
-        RECT rect_in_display;
-        rect_in_display.left   = r->place.x;
-        rect_in_display.right  = r->place.x + r->place.width;
-        rect_in_display.top    = r->place.y;
-        rect_in_display.bottom = r->place.y + r->place.height;
-
         RECT texture_rect;
         texture_rect.left   = 0;
         texture_rect.right  = r->p_picture->format.i_width;
         texture_rect.top    = 0;
         texture_rect.bottom = r->p_picture->format.i_height;
 
-        RECT texture_visible_rect;
-        texture_visible_rect.left   = r->p_picture->format.i_x_offset;
-        texture_visible_rect.right  = r->p_picture->format.i_x_offset + r->p_picture->format.i_visible_width;
-        texture_visible_rect.top    = r->p_picture->format.i_y_offset;
-        texture_visible_rect.bottom = r->p_picture->format.i_y_offset + r->p_picture->format.i_visible_height;
-
-        Direct3D9SetupVertices(d3dr->vertex, &texture_rect, &texture_visible_rect,
-                              &rect_in_display, r->i_alpha, ORIENT_NORMAL);
+        Direct3D9SetupVertices(d3dr->vertex, &texture_rect, &r->p_picture->format,
+                              &r->place, r->i_alpha, ORIENT_NORMAL);
         i++;
     }
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/349e7c09eeea8e947eb560d4890a784e1772aa22...818695182e3ff5ef5d13902461a55a97b94e94a2

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/349e7c09eeea8e947eb560d4890a784e1772aa22...818695182e3ff5ef5d13902461a55a97b94e94a2
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