mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 02:01:12 +00:00
d3d11videosink: Use premultiplied-alpha swapchain
Don't ignore alpha component if it's present Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5242>
This commit is contained in:
parent
de07c44183
commit
ff435c80a2
3 changed files with 15 additions and 12 deletions
|
@ -71,14 +71,12 @@ static const gchar templ_premul_pixel_shader[] =
|
||||||
"float4 main(PS_INPUT input): SV_TARGET\n"
|
"float4 main(PS_INPUT input): SV_TARGET\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" float4 sample = shaderTexture.Sample(samplerState, input.Texture);\n"
|
" float4 sample = shaderTexture.Sample(samplerState, input.Texture);\n"
|
||||||
" float4 unpremul_sample;\n"
|
" float4 premul_sample;\n"
|
||||||
" if (sample.a == 0 || sample.a == 1)\n"
|
" premul_sample.r = saturate (sample.r * sample.a);\n"
|
||||||
" return sample;\n"
|
" premul_sample.g = saturate (sample.g * sample.a);\n"
|
||||||
" unpremul_sample.r = saturate (sample.r / sample.a);\n"
|
" premul_sample.b = saturate (sample.b * sample.a);\n"
|
||||||
" unpremul_sample.g = saturate (sample.g / sample.a);\n"
|
" premul_sample.a = sample.a;\n"
|
||||||
" unpremul_sample.b = saturate (sample.b / sample.a);\n"
|
" return premul_sample;\n"
|
||||||
" unpremul_sample.a = sample.a;\n"
|
|
||||||
" return unpremul_sample;\n"
|
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
static const gchar templ_vertex_shader[] =
|
static const gchar templ_vertex_shader[] =
|
||||||
|
@ -459,11 +457,11 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self)
|
||||||
blend_desc.AlphaToCoverageEnable = FALSE;
|
blend_desc.AlphaToCoverageEnable = FALSE;
|
||||||
blend_desc.IndependentBlendEnable = FALSE;
|
blend_desc.IndependentBlendEnable = FALSE;
|
||||||
blend_desc.RenderTarget[0].BlendEnable = TRUE;
|
blend_desc.RenderTarget[0].BlendEnable = TRUE;
|
||||||
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
|
||||||
blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||||
blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
|
blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
|
||||||
blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
|
||||||
blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
|
blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||||
blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
||||||
blend_desc.RenderTarget[0].RenderTargetWriteMask =
|
blend_desc.RenderTarget[0].RenderTargetWriteMask =
|
||||||
D3D11_COLOR_WRITE_ENABLE_ALL;
|
D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||||
|
@ -710,7 +708,7 @@ gst_d3d11_overlay_compositor_draw_unlocked (GstD3D11OverlayCompositor *
|
||||||
gst_memory_map (mem, &info, (GstMapFlags) (GST_MAP_D3D11 | GST_MAP_READ));
|
gst_memory_map (mem, &info, (GstMapFlags) (GST_MAP_D3D11 | GST_MAP_READ));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overlay->premul_alpha)
|
if (!overlay->premul_alpha)
|
||||||
context->PSSetShader (priv->premul_ps.Get (), nullptr, 0);
|
context->PSSetShader (priv->premul_ps.Get (), nullptr, 0);
|
||||||
else
|
else
|
||||||
context->PSSetShader (priv->ps.Get (), nullptr, 0);
|
context->PSSetShader (priv->ps.Get (), nullptr, 0);
|
||||||
|
|
|
@ -765,6 +765,11 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GST_VIDEO_INFO_HAS_ALPHA (&window->info)) {
|
||||||
|
g_object_set (window->converter, "dest-alpha-mode",
|
||||||
|
GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
if (have_hdr10_meta) {
|
if (have_hdr10_meta) {
|
||||||
g_object_set (window->converter, "src-mastering-display-info", mdcv_str,
|
g_object_set (window->converter, "src-mastering-display-info", mdcv_str,
|
||||||
"src-content-light-level", cll_str, nullptr);
|
"src-content-light-level", cll_str, nullptr);
|
||||||
|
|
|
@ -1104,7 +1104,7 @@ gst_d3d11_window_win32_create_swap_chain (GstD3D11Window * window,
|
||||||
if (gst_d3d11_is_windows_8_or_greater ())
|
if (gst_d3d11_is_windows_8_or_greater ())
|
||||||
desc1.Scaling = DXGI_SCALING_NONE;
|
desc1.Scaling = DXGI_SCALING_NONE;
|
||||||
desc1.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
desc1.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||||
desc1.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
|
desc1.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED;
|
||||||
desc1.Flags = swapchain_flags;
|
desc1.Flags = swapchain_flags;
|
||||||
|
|
||||||
new_swapchain = create_swap_chain_for_hwnd (self, device,
|
new_swapchain = create_swap_chain_for_hwnd (self, device,
|
||||||
|
|
Loading…
Reference in a new issue