d3d11window: Invoke initial resize method from baseclass

... instead of calling from subclass in order for baseclass to handle
more things between swapchain creation and resource creation.
This commit is contained in:
Seungha Yang 2020-01-10 21:45:43 +09:00 committed by GStreamer Merge Bot
parent 7aad9187e4
commit c1d2d9171d
5 changed files with 91 additions and 64 deletions

View file

@ -103,6 +103,8 @@ static void gst_d3d11_window_get_property (GObject * object, guint prop_id,
static void gst_d3d11_window_dispose (GObject * object); static void gst_d3d11_window_dispose (GObject * object);
static GstFlowReturn gst_d3d111_window_present (GstD3D11Window * self, static GstFlowReturn gst_d3d111_window_present (GstD3D11Window * self,
GstBuffer * buffer); GstBuffer * buffer);
static void gst_d3d11_window_on_resize_default (GstD3D11Window * window,
guint width, guint height);
static void static void
gst_d3d11_window_class_init (GstD3D11WindowClass * klass) gst_d3d11_window_class_init (GstD3D11WindowClass * klass)
@ -113,6 +115,8 @@ gst_d3d11_window_class_init (GstD3D11WindowClass * klass)
gobject_class->get_property = gst_d3d11_window_get_property; gobject_class->get_property = gst_d3d11_window_get_property;
gobject_class->dispose = gst_d3d11_window_dispose; gobject_class->dispose = gst_d3d11_window_dispose;
klass->on_resize = GST_DEBUG_FUNCPTR (gst_d3d11_window_on_resize_default);
g_object_class_install_property (gobject_class, PROP_D3D11_DEVICE, g_object_class_install_property (gobject_class, PROP_D3D11_DEVICE,
g_param_spec_object ("d3d11device", "D3D11 Device", g_param_spec_object ("d3d11device", "D3D11 Device",
"GstD3D11Device object for creating swapchain", "GstD3D11Device object for creating swapchain",
@ -283,8 +287,9 @@ gst_d3d11_window_dispose (GObject * object)
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
} }
void static void
gst_d3d11_window_on_resize (GstD3D11Window * window, guint width, guint height) gst_d3d11_window_on_resize_default (GstD3D11Window * window, guint width,
guint height)
{ {
HRESULT hr; HRESULT hr;
ID3D11Device *device_handle; ID3D11Device *device_handle;
@ -690,6 +695,9 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint width, guint height,
} }
#endif #endif
/* call resize to allocated resources */
klass->on_resize (window, width, height);
if (window->requested_fullscreen != window->fullscreen) { if (window->requested_fullscreen != window->fullscreen) {
klass->change_fullscreen_mode (window); klass->change_fullscreen_mode (window);
} }

View file

@ -134,6 +134,10 @@ struct _GstD3D11WindowClass
gboolean (*unlock) (GstD3D11Window * window); gboolean (*unlock) (GstD3D11Window * window);
gboolean (*unlock_stop) (GstD3D11Window * window); gboolean (*unlock_stop) (GstD3D11Window * window);
void (*on_resize) (GstD3D11Window * window,
guint width,
guint height);
}; };
GType gst_d3d11_window_get_type (void); GType gst_d3d11_window_get_type (void);
@ -161,10 +165,6 @@ gboolean gst_d3d11_window_unlock (GstD3D11Window * window);
gboolean gst_d3d11_window_unlock_stop (GstD3D11Window * window); gboolean gst_d3d11_window_unlock_stop (GstD3D11Window * window);
void gst_d3d11_window_on_resize (GstD3D11Window * window,
guint width,
guint height);
void gst_d3d11_window_on_key_event (GstD3D11Window * window, void gst_d3d11_window_on_key_event (GstD3D11Window * window,
const gchar * event, const gchar * event,
const gchar * key); const gchar * key);

View file

@ -94,8 +94,10 @@ gst_d3d11_window_core_window_unlock (GstD3D11Window * window);
static gboolean static gboolean
gst_d3d11_window_core_window_unlock_stop (GstD3D11Window * window); gst_d3d11_window_core_window_unlock_stop (GstD3D11Window * window);
static void static void
gst_d3d11_window_core_window_on_resize (GstD3D11WindowCoreWindow * self, gst_d3d11_window_core_window_on_resize (GstD3D11Window * window,
guint width, guint height); guint width, guint height);
static void
gst_d3d11_window_core_window_on_resize_sync (GstD3D11Window * window);
static float static float
get_logical_dpi (void) get_logical_dpi (void)
@ -130,7 +132,7 @@ class CoreResizeHandler
{ {
public: public:
CoreResizeHandler () {} CoreResizeHandler () {}
HRESULT RuntimeClassInitialize (GstD3D11WindowCoreWindow * listener) HRESULT RuntimeClassInitialize (GstD3D11Window * listener)
{ {
if (!listener) if (!listener)
return E_INVALIDARG; return E_INVALIDARG;
@ -151,7 +153,9 @@ public:
width = (guint) dip_to_pixel (new_size.Width); width = (guint) dip_to_pixel (new_size.Width);
height = (guint) dip_to_pixel (new_size.Height); height = (guint) dip_to_pixel (new_size.Height);
gst_d3d11_window_core_window_on_resize (window, width, height); window->surface_width = width;
window->surface_height = height;
gst_d3d11_window_core_window_on_resize_sync (window);
} }
} }
@ -159,7 +163,7 @@ public:
} }
private: private:
GstD3D11WindowCoreWindow * window; GstD3D11Window * window;
}; };
template <typename CB> template <typename CB>
@ -253,6 +257,8 @@ gst_d3d11_window_core_window_class_init (GstD3D11WindowCoreWindowClass * klass)
GST_DEBUG_FUNCPTR (gst_d3d11_window_core_window_unlock); GST_DEBUG_FUNCPTR (gst_d3d11_window_core_window_unlock);
window_class->unlock_stop = window_class->unlock_stop =
GST_DEBUG_FUNCPTR (gst_d3d11_window_core_window_unlock_stop); GST_DEBUG_FUNCPTR (gst_d3d11_window_core_window_unlock_stop);
window_class->on_resize =
GST_DEBUG_FUNCPTR (gst_d3d11_window_core_window_on_resize);
} }
static void static void
@ -299,7 +305,7 @@ gst_d3d11_window_core_window_constructed (GObject * object)
window->surface_width = size.Width; window->surface_width = size.Width;
window->surface_height = size.Height; window->surface_height = size.Height;
hr = MakeAndInitialize<CoreResizeHandler>(&resize_handler, self); hr = MakeAndInitialize<CoreResizeHandler>(&resize_handler, window);
if (!gst_d3d11_result (hr, NULL)) if (!gst_d3d11_result (hr, NULL))
goto error; goto error;
@ -389,13 +395,6 @@ gst_d3d11_window_core_window_create_swap_chain (GstD3D11Window * window,
new_swapchain.CopyTo (swap_chain); new_swapchain.CopyTo (swap_chain);
run_async (storage->dispatcher, storage->cancellable, DEFAULT_ASYNC_TIMEOUT,
[window] {
gst_d3d11_window_on_resize (window,
window->surface_width, window->surface_height);
return S_OK;
});
return TRUE; return TRUE;
} }
@ -450,14 +449,9 @@ static void
gst_d3d11_window_core_window_update_swap_chain (GstD3D11Window * window) gst_d3d11_window_core_window_update_swap_chain (GstD3D11Window * window)
{ {
GstD3D11WindowCoreWindow *self = GST_D3D11_WINDOW_CORE_WINDOW (window); GstD3D11WindowCoreWindow *self = GST_D3D11_WINDOW_CORE_WINDOW (window);
CoreWindowWinRTStorage *storage = self->storage;
run_async (storage->dispatcher, storage->cancellable, DEFAULT_ASYNC_TIMEOUT, gst_d3d11_window_core_window_on_resize (window,
[window] {
gst_d3d11_window_on_resize (window,
window->surface_width, window->surface_height); window->surface_width, window->surface_height);
return S_OK;
});
return; return;
} }
@ -471,17 +465,27 @@ gst_d3d11_window_core_window_change_fullscreen_mode (GstD3D11Window * window)
} }
static void static void
gst_d3d11_window_core_window_on_resize (GstD3D11WindowCoreWindow * self, gst_d3d11_window_core_window_on_resize (GstD3D11Window * window,
guint width, guint height) guint width, guint height)
{ {
GstD3D11Window *window = GST_D3D11_WINDOW (self); GstD3D11WindowCoreWindow *self = GST_D3D11_WINDOW_CORE_WINDOW (window);
CoreWindowWinRTStorage *storage = self->storage;
window->surface_width = width; run_async (storage->dispatcher, storage->cancellable, DEFAULT_ASYNC_TIMEOUT,
window->surface_height = height; [window] {
gst_d3d11_window_core_window_on_resize_sync (window);
return S_OK;
});
}
GST_LOG_OBJECT (self, "New size %dx%d", width, height); static void
gst_d3d11_window_core_window_on_resize_sync (GstD3D11Window * window)
{
GST_LOG_OBJECT (window,
"New size %dx%d", window->surface_width, window->surface_height);
gst_d3d11_window_on_resize (GST_D3D11_WINDOW (self), width, height); GST_D3D11_WINDOW_CLASS (parent_class)->on_resize (window,
window->surface_width, window->surface_height);
} }
GstD3D11Window * GstD3D11Window *

View file

@ -91,16 +91,18 @@ gst_d3d11_window_swap_chain_panel_unlock (GstD3D11Window * window);
static gboolean static gboolean
gst_d3d11_window_swap_chain_panel_unlock_stop (GstD3D11Window * window); gst_d3d11_window_swap_chain_panel_unlock_stop (GstD3D11Window * window);
static void static void
gst_d3d11_window_swap_chain_panel_on_resize (GstD3D11WindowSwapChainPanel * gst_d3d11_window_swap_chain_panel_on_resize (GstD3D11Window * window,
self, guint width, guint height); guint width, guint height);
static void
gst_d3d11_window_swap_chain_panel_on_resize_sync (GstD3D11Window *
window);
class PanelResizeHandler class PanelResizeHandler
: public RuntimeClass<RuntimeClassFlags<ClassicCom>, : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
Xaml::ISizeChangedEventHandler> Xaml::ISizeChangedEventHandler>
{ {
public: public:
PanelResizeHandler () {} PanelResizeHandler () {}
HRESULT RuntimeClassInitialize (GstD3D11WindowSwapChainPanel * listener) HRESULT RuntimeClassInitialize (GstD3D11Window * listener)
{ {
if (!listener) if (!listener)
return E_INVALIDARG; return E_INVALIDARG;
@ -116,8 +118,9 @@ public:
Size new_size; Size new_size;
HRESULT hr = args->get_NewSize(&new_size); HRESULT hr = args->get_NewSize(&new_size);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
gst_d3d11_window_swap_chain_panel_on_resize (window, window->surface_width = new_size.Width;
new_size.Width, new_size.Height); window->surface_height = new_size.Height;
gst_d3d11_window_swap_chain_panel_on_resize_sync (window);
} }
} }
@ -125,7 +128,7 @@ public:
} }
private: private:
GstD3D11WindowSwapChainPanel * window; GstD3D11Window * window;
}; };
template <typename CB> template <typename CB>
@ -219,6 +222,8 @@ gst_d3d11_window_swap_chain_panel_class_init (GstD3D11WindowSwapChainPanelClass
GST_DEBUG_FUNCPTR (gst_d3d11_window_swap_chain_panel_unlock); GST_DEBUG_FUNCPTR (gst_d3d11_window_swap_chain_panel_unlock);
window_class->unlock_stop = window_class->unlock_stop =
GST_DEBUG_FUNCPTR (gst_d3d11_window_swap_chain_panel_unlock_stop); GST_DEBUG_FUNCPTR (gst_d3d11_window_swap_chain_panel_unlock_stop);
window_class->on_resize =
GST_DEBUG_FUNCPTR (gst_d3d11_window_swap_chain_panel_on_resize);
} }
static void static void
@ -270,7 +275,7 @@ gst_d3d11_window_swap_chain_panel_constructed (GObject * object)
window->surface_width = size.Width; window->surface_width = size.Width;
window->surface_height = size.Height; window->surface_height = size.Height;
hr = MakeAndInitialize<PanelResizeHandler>(&resize_handler, self); hr = MakeAndInitialize<PanelResizeHandler>(&resize_handler, window);
if (!gst_d3d11_result (hr, NULL)) if (!gst_d3d11_result (hr, NULL))
goto error; goto error;
@ -378,13 +383,6 @@ gst_d3d11_window_swap_chain_panel_create_swap_chain (GstD3D11Window * window,
new_swapchain.CopyTo (swap_chain); new_swapchain.CopyTo (swap_chain);
run_async (storage->dispatcher, storage->cancellable, DEFAULT_ASYNC_TIMEOUT,
[window] {
gst_d3d11_window_on_resize (window,
window->surface_width, window->surface_height);
return S_OK;
});
return TRUE; return TRUE;
} }
@ -443,14 +441,9 @@ gst_d3d11_window_swap_chain_panel_update_swap_chain (GstD3D11Window * window)
{ {
GstD3D11WindowSwapChainPanel *self = GstD3D11WindowSwapChainPanel *self =
GST_D3D11_WINDOW_SWAP_CHAIN_PANEL (window); GST_D3D11_WINDOW_SWAP_CHAIN_PANEL (window);
SwapChainPanelWinRTStorage *storage = self->storage;
run_async (storage->dispatcher, storage->cancellable, DEFAULT_ASYNC_TIMEOUT, gst_d3d11_window_swap_chain_panel_on_resize (window, window->surface_width,
[window] { window->surface_height);
gst_d3d11_window_on_resize (window,
window->surface_width, window->surface_height);
return S_OK;
});
return; return;
} }
@ -465,16 +458,28 @@ gst_d3d11_window_swap_chain_panel_change_fullscreen_mode (GstD3D11Window *
} }
static void static void
gst_d3d11_window_swap_chain_panel_on_resize (GstD3D11WindowSwapChainPanel * gst_d3d11_window_swap_chain_panel_on_resize (GstD3D11Window * window,
self, guint width, guint height) guint width, guint height)
{ {
GstD3D11Window *window = GST_D3D11_WINDOW (self); GstD3D11WindowSwapChainPanel *self =
window->surface_width = width; GST_D3D11_WINDOW_SWAP_CHAIN_PANEL (window);
window->surface_height = height; SwapChainPanelWinRTStorage *storage = self->storage;
GST_LOG_OBJECT (self, "New size %dx%d", width, height); run_async (storage->dispatcher, storage->cancellable, DEFAULT_ASYNC_TIMEOUT,
[window] {
gst_d3d11_window_swap_chain_panel_on_resize_sync (window);
return S_OK;
});
}
gst_d3d11_window_on_resize (GST_D3D11_WINDOW (self), width, height); static void
gst_d3d11_window_swap_chain_panel_on_resize_sync (GstD3D11Window * window)
{
GST_LOG_OBJECT (window,
"New size %dx%d", window->surface_width, window->surface_height);
GST_D3D11_WINDOW_CLASS (parent_class)->on_resize (window,
window->surface_width, window->surface_height);
} }
GstD3D11Window * GstD3D11Window *

View file

@ -115,6 +115,9 @@ static void gst_d3d11_window_win32_release_external_handle (GstD3D11WindowWin32
static void static void
gst_d3d11_window_win32_set_window_handle (GstD3D11WindowWin32 * self, gst_d3d11_window_win32_set_window_handle (GstD3D11WindowWin32 * self,
guintptr handle); guintptr handle);
static void
gst_d3d11_window_win32_on_resize (GstD3D11Window * window,
guint width, guint height);
static void static void
gst_d3d11_window_win32_class_init (GstD3D11WindowWin32Class * klass) gst_d3d11_window_win32_class_init (GstD3D11WindowWin32Class * klass)
@ -134,6 +137,8 @@ gst_d3d11_window_win32_class_init (GstD3D11WindowWin32Class * klass)
window_class->create_swap_chain = window_class->create_swap_chain =
GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_create_swap_chain); GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_create_swap_chain);
window_class->present = GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_present); window_class->present = GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_present);
window_class->on_resize =
GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_on_resize);
} }
static void static void
@ -573,7 +578,7 @@ gst_d3d11_window_win32_handle_window_proc (GstD3D11WindowWin32 * self,
switch (uMsg) { switch (uMsg) {
case WM_SIZE: case WM_SIZE:
gst_d3d11_window_on_resize (window, 0, 0); gst_d3d11_window_win32_on_resize (window, 0, 0);
break; break;
case WM_CLOSE: case WM_CLOSE:
if (self->internal_hwnd) { if (self->internal_hwnd) {
@ -790,9 +795,6 @@ gst_d3d11_window_win32_create_swap_chain (GstD3D11Window * window,
*swap_chain = new_swapchain; *swap_chain = new_swapchain;
/* Set zero width and height here. dxgi will decide client area by itself */
gst_d3d11_window_on_resize (window, 0, 0);
return TRUE; return TRUE;
} }
@ -883,6 +885,14 @@ gst_d3d11_window_win32_present (GstD3D11Window * window, guint present_flags)
return GST_FLOW_OK; return GST_FLOW_OK;
} }
static void
gst_d3d11_window_win32_on_resize (GstD3D11Window * window,
guint width, guint height)
{
/* Set zero width and height here. dxgi will decide client area by itself */
GST_D3D11_WINDOW_CLASS (parent_class)->on_resize (window, 0, 0);
}
static void static void
gst_d3d11_window_win32_update_swap_chain (GstD3D11Window * window) gst_d3d11_window_win32_update_swap_chain (GstD3D11Window * window)
{ {