From ca87289e56b9a7273822231efd17aec738e31663 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Wed, 3 Jun 2020 01:20:41 +0900 Subject: [PATCH] d3d11colorconverter: Add support conversion with blending This is pre-work for d3d11compositor support Part-of: --- sys/d3d11/gstd3d11colorconvert.c | 2 +- sys/d3d11/gstd3d11colorconverter.c | 13 ++++++++----- sys/d3d11/gstd3d11colorconverter.h | 8 ++++++-- sys/d3d11/gstd3d11decoder.c | 5 +++-- sys/d3d11/gstd3d11overlaycompositor.c | 2 +- sys/d3d11/gstd3d11shader.c | 13 +++++++++---- sys/d3d11/gstd3d11shader.h | 8 ++++++-- sys/d3d11/gstd3d11window.cpp | 2 +- 8 files changed, 35 insertions(+), 18 deletions(-) diff --git a/sys/d3d11/gstd3d11colorconvert.c b/sys/d3d11/gstd3d11colorconvert.c index e4439fbe27..e32083f3d5 100644 --- a/sys/d3d11/gstd3d11colorconvert.c +++ b/sys/d3d11/gstd3d11colorconvert.c @@ -1566,7 +1566,7 @@ gst_d3d11_color_convert_transform (GstBaseTransform * trans, if (!gst_d3d11_color_converter_convert (self->converter, copy_input ? self->shader_resource_view : resource_view, - copy_output ? self->render_target_view : render_view)) { + copy_output ? self->render_target_view : render_view, NULL, NULL)) { GST_ERROR_OBJECT (self, "Failed to convert"); return GST_FLOW_ERROR; diff --git a/sys/d3d11/gstd3d11colorconverter.c b/sys/d3d11/gstd3d11colorconverter.c index 72d28d9f15..279d0c53f9 100644 --- a/sys/d3d11/gstd3d11colorconverter.c +++ b/sys/d3d11/gstd3d11colorconverter.c @@ -1506,7 +1506,8 @@ gst_d3d11_color_converter_update_vertex_buffer (GstD3D11ColorConverter * self) gboolean gst_d3d11_color_converter_convert (GstD3D11ColorConverter * converter, ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES], - ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES]) + ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES], + ID3D11BlendState * blend, gfloat blend_factor[4]) { gboolean ret; @@ -1515,7 +1516,8 @@ gst_d3d11_color_converter_convert (GstD3D11ColorConverter * converter, g_return_val_if_fail (rtv != NULL, FALSE); gst_d3d11_device_lock (converter->device); - ret = gst_d3d11_color_converter_convert_unlocked (converter, srv, rtv); + ret = gst_d3d11_color_converter_convert_unlocked (converter, + srv, rtv, blend, blend_factor); gst_d3d11_device_unlock (converter->device); return ret; @@ -1524,7 +1526,8 @@ gst_d3d11_color_converter_convert (GstD3D11ColorConverter * converter, gboolean gst_d3d11_color_converter_convert_unlocked (GstD3D11ColorConverter * converter, ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES], - ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES]) + ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES], + ID3D11BlendState * blend, gfloat blend_factor[4]) { gboolean ret; ID3D11Resource *resource; @@ -1555,7 +1558,7 @@ gst_d3d11_color_converter_convert_unlocked (GstD3D11ColorConverter * converter, } ret = gst_d3d11_draw_quad_unlocked (converter->quad[0], converter->viewport, - 1, srv, converter->num_input_view, rtv, 1, NULL); + 1, srv, converter->num_input_view, rtv, 1, NULL, blend, blend_factor); if (!ret) return FALSE; @@ -1564,7 +1567,7 @@ gst_d3d11_color_converter_convert_unlocked (GstD3D11ColorConverter * converter, ret = gst_d3d11_draw_quad_unlocked (converter->quad[1], &converter->viewport[1], converter->num_output_view - 1, srv, converter->num_input_view, &rtv[1], converter->num_output_view - 1, - NULL); + NULL, blend, blend_factor); if (!ret) return FALSE; diff --git a/sys/d3d11/gstd3d11colorconverter.h b/sys/d3d11/gstd3d11colorconverter.h index b14eb9a302..36b678961e 100644 --- a/sys/d3d11/gstd3d11colorconverter.h +++ b/sys/d3d11/gstd3d11colorconverter.h @@ -36,11 +36,15 @@ void gst_d3d11_color_converter_free (GstD3D11ColorConverter gboolean gst_d3d11_color_converter_convert (GstD3D11ColorConverter * converter, ID3D11ShaderResourceView *srv[GST_VIDEO_MAX_PLANES], - ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES]); + ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES], + ID3D11BlendState *blend, + gfloat blend_factor[4]); gboolean gst_d3d11_color_converter_convert_unlocked (GstD3D11ColorConverter * converter, ID3D11ShaderResourceView *srv[GST_VIDEO_MAX_PLANES], - ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES]); + ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES], + ID3D11BlendState *blend, + gfloat blend_factor[4]); gboolean gst_d3d11_color_converter_update_viewport (GstD3D11ColorConverter * converter, D3D11_VIEWPORT * viewport); diff --git a/sys/d3d11/gstd3d11decoder.c b/sys/d3d11/gstd3d11decoder.c index a502ca7526..ddb62cf69a 100644 --- a/sys/d3d11/gstd3d11decoder.c +++ b/sys/d3d11/gstd3d11decoder.c @@ -1250,7 +1250,7 @@ copy_to_system (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width, gst_d3d11_color_converter_update_src_rect (priv->converter, &rect); if (!gst_d3d11_color_converter_convert_unlocked (priv->converter, - srv, priv->fallback_render_target_view)) { + srv, priv->fallback_render_target_view, NULL, NULL)) { GST_ERROR_OBJECT (self, "Failed to convert"); goto error; } @@ -1386,7 +1386,8 @@ copy_to_d3d11 (GstD3D11Decoder * self, GstVideoInfo * info, gint display_width, gst_d3d11_color_converter_update_src_rect (priv->converter, &rect); - if (!gst_d3d11_color_converter_convert_unlocked (priv->converter, srv, rtv)) { + if (!gst_d3d11_color_converter_convert_unlocked (priv->converter, + srv, rtv, NULL, NULL)) { GST_ERROR_OBJECT (self, "Failed to convert"); goto error; } diff --git a/sys/d3d11/gstd3d11overlaycompositor.c b/sys/d3d11/gstd3d11overlaycompositor.c index 75d4383348..bda4865f9d 100644 --- a/sys/d3d11/gstd3d11overlaycompositor.c +++ b/sys/d3d11/gstd3d11overlaycompositor.c @@ -667,7 +667,7 @@ gst_d3d11_overlay_compositor_draw_unlocked (GstD3D11OverlayCompositor * (GstD3D11CompositionOverlay *) iter->data; ret = gst_d3d11_draw_quad_unlocked (overlay->quad, - &compositor->viewport, 1, &overlay->srv, 1, rtv, 1, NULL); + &compositor->viewport, 1, &overlay->srv, 1, rtv, 1, NULL, NULL, NULL); if (!ret) break; diff --git a/sys/d3d11/gstd3d11shader.c b/sys/d3d11/gstd3d11shader.c index f3fc0d9715..2e887be1b4 100644 --- a/sys/d3d11/gstd3d11shader.c +++ b/sys/d3d11/gstd3d11shader.c @@ -349,7 +349,8 @@ gst_d3d11_draw_quad (GstD3D11Quad * quad, D3D11_VIEWPORT viewport[GST_VIDEO_MAX_PLANES], guint num_viewport, ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES], guint num_srv, ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES], guint num_rtv, - ID3D11DepthStencilView * dsv) + ID3D11DepthStencilView * dsv, ID3D11BlendState * blend, + gfloat blend_factor[4]) { gboolean ret; @@ -357,7 +358,7 @@ gst_d3d11_draw_quad (GstD3D11Quad * quad, gst_d3d11_device_lock (quad->device); ret = gst_d3d11_draw_quad_unlocked (quad, viewport, num_viewport, - srv, num_srv, rtv, num_viewport, dsv); + srv, num_srv, rtv, num_viewport, dsv, blend, blend_factor); gst_d3d11_device_unlock (quad->device); return ret; @@ -368,11 +369,13 @@ gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad, D3D11_VIEWPORT viewport[GST_VIDEO_MAX_PLANES], guint num_viewport, ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES], guint num_srv, ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES], guint num_rtv, - ID3D11DepthStencilView * dsv) + ID3D11DepthStencilView * dsv, ID3D11BlendState * blend, + gfloat blend_factor[4]) { ID3D11DeviceContext *context_handle; UINT offsets = 0; ID3D11ShaderResourceView *clear_view[GST_VIDEO_MAX_PLANES] = { NULL, }; + ID3D11BlendState *blend_state = blend; g_return_val_if_fail (quad != NULL, FALSE); g_return_val_if_fail (viewport != NULL, FALSE); @@ -403,8 +406,10 @@ gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad, ID3D11DeviceContext_PSSetShaderResources (context_handle, 0, num_srv, srv); ID3D11DeviceContext_OMSetRenderTargets (context_handle, num_rtv, rtv, dsv); + if (!blend_state) + blend_state = quad->blend; ID3D11DeviceContext_OMSetBlendState (context_handle, - quad->blend, NULL, 0xffffffff); + blend_state, blend_factor, 0xffffffff); ID3D11DeviceContext_OMSetDepthStencilState (context_handle, quad->depth_stencil, 1); diff --git a/sys/d3d11/gstd3d11shader.h b/sys/d3d11/gstd3d11shader.h index 4c1e062f78..0c1a441a84 100644 --- a/sys/d3d11/gstd3d11shader.h +++ b/sys/d3d11/gstd3d11shader.h @@ -66,7 +66,9 @@ gboolean gst_d3d11_draw_quad (GstD3D11Quad * quad, guint num_srv, ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES], guint num_rtv, - ID3D11DepthStencilView *dsv); + ID3D11DepthStencilView *dsv, + ID3D11BlendState *blend, + gfloat blend_factor[4]); gboolean gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad, D3D11_VIEWPORT viewport[GST_VIDEO_MAX_PLANES], @@ -75,7 +77,9 @@ gboolean gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad, guint num_srv, ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES], guint num_rtv, - ID3D11DepthStencilView *dsv); + ID3D11DepthStencilView *dsv, + ID3D11BlendState *blend, + gfloat blend_factor[4]); G_END_DECLS diff --git a/sys/d3d11/gstd3d11window.cpp b/sys/d3d11/gstd3d11window.cpp index a40e2e624e..fb46233b5a 100644 --- a/sys/d3d11/gstd3d11window.cpp +++ b/sys/d3d11/gstd3d11window.cpp @@ -937,7 +937,7 @@ gst_d3d111_window_present (GstD3D11Window * self, GstBuffer * buffer) } } else { if (!gst_d3d11_color_converter_convert_unlocked (self->converter, - srv, &self->rtv)) { + srv, &self->rtv, NULL, NULL)) { GST_ERROR_OBJECT (self, "Couldn't render to backbuffer using converter"); return GST_FLOW_ERROR; } else {