d3d11window: Misc code cleanup

* Remove unnecessary upcasting. We are now dealing with C++ class objects
  and don't need explicit C-style casting in C++ world
* Use helper macro IID_PPV_ARGS() everywhere. It will make code
  a little short.
* Use ComPtr smart pointer instead of calling manual IUnknown::Release()

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2461>
This commit is contained in:
Seungha Yang 2021-08-10 02:48:01 +09:00 committed by GStreamer Marge Bot
parent a1048ce110
commit 1f6fd7550c
5 changed files with 25 additions and 41 deletions

View file

@ -311,7 +311,7 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * window, guint width,
goto done;
}
hr = swap_chain->GetBuffer (0, IID_ID3D11Texture2D, (void **) &backbuffer);
hr = swap_chain->GetBuffer (0, IID_PPV_ARGS (&backbuffer));
if (!gst_d3d11_result (hr, window->device)) {
GST_ERROR_OBJECT (window,
"Cannot get backbuffer from swapchain, hr: 0x%x", (guint) hr);
@ -349,8 +349,7 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * window, guint width,
"New client area %dx%d, render rect x: %d, y: %d, %dx%d",
desc.Width, desc.Height, rst_rect.x, rst_rect.y, rst_rect.w, rst_rect.h);
hr = device_handle->CreateRenderTargetView ((ID3D11Resource *) backbuffer,
NULL, &window->rtv);
hr = device_handle->CreateRenderTargetView (backbuffer, NULL, &window->rtv);
if (!gst_d3d11_result (hr, window->device)) {
GST_ERROR_OBJECT (window, "Cannot create render target view, hr: 0x%x",
(guint) hr);
@ -365,7 +364,7 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * window, guint width,
pov_desc.Texture2D.MipSlice = 0;
if (!gst_d3d11_video_processor_create_output_view (window->processor,
&pov_desc, (ID3D11Resource *) backbuffer, &window->pov))
&pov_desc, backbuffer, &window->pov))
goto done;
}
@ -586,11 +585,10 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
if (gst_video_mastering_display_info_from_caps (&minfo, caps) &&
gst_video_content_light_level_from_caps (&cll, caps)) {
IDXGISwapChain4 *swapchain4 = NULL;
ComPtr < IDXGISwapChain4 > swapchain4;
HRESULT hr;
hr = window->swap_chain->QueryInterface (IID_IDXGISwapChain4,
(void **) &swapchain4);
hr = window->swap_chain->QueryInterface (IID_PPV_ARGS (&swapchain4));
if (gst_d3d11_result (hr, window->device)) {
GST_DEBUG_OBJECT (window, "Have HDR metadata, set to DXGI swapchain");
@ -604,8 +602,6 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
} else {
have_hdr10 = TRUE;
}
swapchain4->Release ();
}
}
}
@ -626,16 +622,15 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
#if (GST_D3D11_DXGI_HEADER_VERSION >= 4)
{
IDXGISwapChain3 *swapchain3 = NULL;
ComPtr < IDXGISwapChain3 > swapchain3;
HRESULT hr;
hr = window->swap_chain->QueryInterface (IID_IDXGISwapChain3,
(void **) &swapchain3);
hr = window->swap_chain->QueryInterface (IID_PPV_ARGS (&swapchain3));
if (gst_d3d11_result (hr, window->device)) {
chosen_colorspace =
gst_d3d11_find_swap_chain_color_space (&window->render_info,
swapchain3, have_hdr10);
swapchain3.Get (), have_hdr10);
if (chosen_colorspace) {
native_colorspace_type =
(DXGI_COLOR_SPACE_TYPE) chosen_colorspace->dxgi_color_space_type;
@ -658,8 +653,6 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
window->render_info.colorimetry.matrix = chosen_colorspace->matrix;
}
}
swapchain3->Release ();
}
}
#endif

View file

@ -385,7 +385,7 @@ create_swap_chain_for_core_window (GstD3D11WindowCoreWindow * self,
IDXGISwapChain1 *swap_chain = NULL;
ID3D11Device *device_handle = gst_d3d11_device_get_device_handle (device);
IDXGIFactory1 *factory = gst_d3d11_device_get_dxgi_factory_handle (device);
IDXGIFactory2 *factory2 = NULL;
ComPtr < IDXGIFactory2 > factory2;
hr = factory->QueryInterface (IID_PPV_ARGS (&factory2));
if (!gst_d3d11_result (hr, device)) {
@ -394,7 +394,7 @@ create_swap_chain_for_core_window (GstD3D11WindowCoreWindow * self,
}
gst_d3d11_device_lock (device);
hr = factory2->CreateSwapChainForCoreWindow ((IUnknown *) device_handle,
hr = factory2->CreateSwapChainForCoreWindow (device_handle,
(IUnknown *) core_window, desc, output, &swap_chain);
gst_d3d11_device_unlock (device);
@ -404,8 +404,6 @@ create_swap_chain_for_core_window (GstD3D11WindowCoreWindow * self,
swap_chain = NULL;
}
factory2->Release ();
return swap_chain;
}

View file

@ -319,8 +319,7 @@ gst_d3d11_window_dummy_setup_fallback_texture (GstD3D11Window * window,
pov_desc.Texture2D.MipSlice = 0;
if (!gst_d3d11_video_processor_create_output_view (window->processor,
&pov_desc, (ID3D11Resource *) self->fallback_texture,
&self->fallback_pov)) {
&pov_desc, self->fallback_texture, &self->fallback_pov)) {
GST_ERROR_OBJECT (window,
"ID3D11VideoProcessorOutputView is unavailable");
gst_d3d11_window_dummy_clear_resources (self);
@ -386,7 +385,7 @@ gst_d3d11_window_dummy_open_shared_handle (GstD3D11Window * window,
pov_desc.Texture2D.MipSlice = 0;
if (!gst_d3d11_video_processor_create_output_view (window->processor,
&pov_desc, (ID3D11Resource *) texture, &pov)) {
&pov_desc, texture, &pov)) {
GST_WARNING_OBJECT (window,
"ID3D11VideoProcessorOutputView is unavailable");
}

View file

@ -359,7 +359,7 @@ create_swap_chain_for_composition (GstD3D11WindowSwapChainPanel * self,
IDXGISwapChain1 *swap_chain = NULL;
ID3D11Device *device_handle = gst_d3d11_device_get_device_handle (device);
IDXGIFactory1 *factory = gst_d3d11_device_get_dxgi_factory_handle (device);
IDXGIFactory2 *factory2 = NULL;
ComPtr < IDXGIFactory2 > factory2;
hr = factory->QueryInterface (IID_PPV_ARGS (&factory2));
if (!gst_d3d11_result (hr, device)) {
@ -368,7 +368,7 @@ create_swap_chain_for_composition (GstD3D11WindowSwapChainPanel * self,
}
gst_d3d11_device_lock (device);
hr = factory2->CreateSwapChainForComposition ((IUnknown *) device_handle,
hr = factory2->CreateSwapChainForComposition (device_handle,
desc, output, &swap_chain);
gst_d3d11_device_unlock (device);
@ -378,8 +378,6 @@ create_swap_chain_for_composition (GstD3D11WindowSwapChainPanel * self,
swap_chain = NULL;
}
factory2->Release ();
return swap_chain;
}

View file

@ -25,8 +25,11 @@
#endif
#include "gstd3d11window_win32.h"
#include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_window_debug);
@ -533,7 +536,7 @@ gst_d3d11_window_win32_change_fullscreen_mode_internal (GstD3D11WindowWin32 *
ShowWindow (hwnd, SW_NORMAL);
} else {
IDXGIOutput *output;
ComPtr < IDXGIOutput > output;
DXGI_OUTPUT_DESC output_desc;
IDXGISwapChain *swap_chain = window->swap_chain;
@ -553,7 +556,6 @@ gst_d3d11_window_win32_change_fullscreen_mode_internal (GstD3D11WindowWin32 *
swap_chain->GetContainingOutput (&output);
output->GetDesc (&output_desc);
output->Release ();
SetWindowPos (hwnd, HWND_TOPMOST,
output_desc.DesktopCoordinates.left,
@ -839,10 +841,10 @@ static void
gst_d3d11_window_win32_disable_alt_enter (GstD3D11WindowWin32 * self,
GstD3D11Device * device, IDXGISwapChain * swap_chain, HWND hwnd)
{
IDXGIFactory1 *factory = NULL;
ComPtr < IDXGIFactory1 > factory;
HRESULT hr;
hr = swap_chain->GetParent (IID_IDXGIFactory1, (void **) &factory);
hr = swap_chain->GetParent (IID_PPV_ARGS (&factory));
if (!gst_d3d11_result (hr, device) || !factory) {
GST_WARNING_OBJECT (self,
"Cannot get parent dxgi factory for swapchain %p, hr: 0x%x",
@ -855,8 +857,6 @@ gst_d3d11_window_win32_disable_alt_enter (GstD3D11WindowWin32 * self,
GST_WARNING_OBJECT (self,
"MakeWindowAssociation failure, hr: 0x%x", (guint) hr);
}
factory->Release ();
}
static IDXGISwapChain *
@ -869,7 +869,7 @@ create_swap_chain (GstD3D11WindowWin32 * self, GstD3D11Device * device,
IDXGIFactory1 *factory = gst_d3d11_device_get_dxgi_factory_handle (device);
gst_d3d11_device_lock (device);
hr = factory->CreateSwapChain ((IUnknown *) device_handle, desc, &swap_chain);
hr = factory->CreateSwapChain (device_handle, desc, &swap_chain);
gst_d3d11_device_unlock (device);
if (!gst_d3d11_result (hr, device)) {
@ -891,7 +891,7 @@ create_swap_chain_for_hwnd (GstD3D11WindowWin32 * self, GstD3D11Device * device,
IDXGISwapChain1 *swap_chain = NULL;
ID3D11Device *device_handle = gst_d3d11_device_get_device_handle (device);
IDXGIFactory1 *factory = gst_d3d11_device_get_dxgi_factory_handle (device);
IDXGIFactory2 *factory2 = NULL;
ComPtr < IDXGIFactory2 > factory2;
hr = factory->QueryInterface (IID_PPV_ARGS (&factory2));
if (!gst_d3d11_result (hr, device)) {
@ -900,9 +900,8 @@ create_swap_chain_for_hwnd (GstD3D11WindowWin32 * self, GstD3D11Device * device,
}
gst_d3d11_device_lock (device);
hr = factory2->CreateSwapChainForHwnd (
(IUnknown *) device_handle, hwnd, desc, fullscreen_desc,
output, &swap_chain);
hr = factory2->CreateSwapChainForHwnd (device_handle, hwnd, desc,
fullscreen_desc, output, &swap_chain);
gst_d3d11_device_unlock (device);
if (!gst_d3d11_result (hr, device)) {
@ -911,8 +910,6 @@ create_swap_chain_for_hwnd (GstD3D11WindowWin32 * self, GstD3D11Device * device,
swap_chain = NULL;
}
factory2->Release ();
return swap_chain;
}
#endif
@ -951,8 +948,7 @@ gst_d3d11_window_win32_create_swap_chain (GstD3D11Window * window,
desc1.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
desc1.Flags = swapchain_flags;
new_swapchain = (IDXGISwapChain *)
create_swap_chain_for_hwnd (self, device,
new_swapchain = create_swap_chain_for_hwnd (self, device,
self->internal_hwnd, &desc1, NULL, NULL);
if (!new_swapchain) {