d3d11converter: Set alpha-mode using config

... and disallow runtime alpha-mode update for now

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5457>
This commit is contained in:
Seungha Yang 2023-10-09 01:05:34 +09:00 committed by GStreamer Marge Bot
parent 8fe26c8a10
commit bfdea297d2
6 changed files with 86 additions and 84 deletions

View file

@ -669,8 +669,6 @@ enum
PROP_DEST_MASTERING_DISPLAY_INFO, PROP_DEST_MASTERING_DISPLAY_INFO,
PROP_DEST_CONTENT_LIGHT_LEVEL, PROP_DEST_CONTENT_LIGHT_LEVEL,
PROP_VIDEO_DIRECTION, PROP_VIDEO_DIRECTION,
PROP_SRC_ALPHA_MODE,
PROP_DEST_ALPHA_MODE,
}; };
struct _GstD3D11ConverterPrivate struct _GstD3D11ConverterPrivate
@ -890,14 +888,6 @@ gst_d3d11_converter_class_init (GstD3D11ConverterClass * klass)
g_param_spec_enum ("video-direction", "Video Direction", g_param_spec_enum ("video-direction", "Video Direction",
"Video direction", GST_TYPE_VIDEO_ORIENTATION_METHOD, "Video direction", GST_TYPE_VIDEO_ORIENTATION_METHOD,
GST_VIDEO_ORIENTATION_IDENTITY, param_flags)); GST_VIDEO_ORIENTATION_IDENTITY, param_flags));
g_object_class_install_property (object_class, PROP_SRC_ALPHA_MODE,
g_param_spec_enum ("src-alpha-mode", "Src Alpha Mode",
"Src alpha mode to use", GST_TYPE_D3D11_CONVERTER_ALPHA_MODE,
GST_D3D11_CONVERTER_ALPHA_MODE_UNSPECIFIED, param_flags));
g_object_class_install_property (object_class, PROP_DEST_ALPHA_MODE,
g_param_spec_enum ("dest-alpha-mode", "Dest Alpha Mode",
"Dest alpha mode to use", GST_TYPE_D3D11_CONVERTER_ALPHA_MODE,
GST_D3D11_CONVERTER_ALPHA_MODE_UNSPECIFIED, param_flags));
GST_DEBUG_CATEGORY_INIT (gst_d3d11_converter_debug, GST_DEBUG_CATEGORY_INIT (gst_d3d11_converter_debug,
"d3d11converter", 0, "d3d11converter"); "d3d11converter", 0, "d3d11converter");
@ -1119,38 +1109,6 @@ gst_d3d11_converter_set_property (GObject * object, guint prop_id,
} }
break; break;
} }
case PROP_SRC_ALPHA_MODE:
{
DWORD prev_premul = priv->const_data.in_premul_alpha;
priv->src_alpha_mode = (GstD3D11ConverterAlphaMode)
g_value_get_enum (value);
if (priv->src_alpha_mode == GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED) {
priv->const_data.in_premul_alpha = TRUE;
} else {
priv->const_data.in_premul_alpha = FALSE;
}
if (prev_premul != priv->const_data.in_premul_alpha) {
priv->update_alpha = TRUE;
}
break;
}
case PROP_DEST_ALPHA_MODE:
{
DWORD prev_premul = priv->const_data.out_premul_alpha;
priv->dst_alpha_mode = (GstD3D11ConverterAlphaMode)
g_value_get_enum (value);
if (priv->dst_alpha_mode == GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED) {
priv->const_data.out_premul_alpha = TRUE;
} else {
priv->const_data.out_premul_alpha = FALSE;
}
if (prev_premul != priv->const_data.out_premul_alpha) {
priv->update_alpha = TRUE;
}
break;
}
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -1232,12 +1190,6 @@ gst_d3d11_converter_get_property (GObject * object, guint prop_id,
case PROP_VIDEO_DIRECTION: case PROP_VIDEO_DIRECTION:
g_value_set_enum (value, priv->video_direction); g_value_set_enum (value, priv->video_direction);
break; break;
case PROP_SRC_ALPHA_MODE:
g_value_set_enum (value, priv->src_alpha_mode);
break;
case PROP_DEST_ALPHA_MODE:
g_value_set_enum (value, priv->dst_alpha_mode);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -3265,9 +3217,21 @@ gst_d3d11_converter_new (GstD3D11Device * device, const GstVideoInfo * in_info,
gst_structure_get_enum (config, GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER, gst_structure_get_enum (config, GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER,
GST_TYPE_D3D11_CONVERTER_SAMPLER_FILTER, (int *) &sampler_filter); GST_TYPE_D3D11_CONVERTER_SAMPLER_FILTER, (int *) &sampler_filter);
gst_structure_get_enum (config, GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE, (int *) &priv->src_alpha_mode);
gst_structure_get_enum (config, GST_D3D11_CONVERTER_OPT_DEST_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE, (int *) &priv->dst_alpha_mode);
gst_structure_free (config); gst_structure_free (config);
} }
if (priv->src_alpha_mode == GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED)
priv->const_data.in_premul_alpha = TRUE;
if (priv->dst_alpha_mode == GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED)
priv->const_data.out_premul_alpha = TRUE;
if (!wanted_backend) { if (!wanted_backend) {
wanted_backend = wanted_backend =
GST_D3D11_CONVERTER_BACKEND_SHADER | GST_D3D11_CONVERTER_BACKEND_SHADER |

View file

@ -122,6 +122,26 @@ GST_D3D11_API
GType gst_d3d11_converter_alpha_mode_get_type (void); GType gst_d3d11_converter_alpha_mode_get_type (void);
#define GST_TYPE_D3D11_CONVERTER_ALPHA_MODE (gst_d3d11_converter_alpha_mode_get_type()) #define GST_TYPE_D3D11_CONVERTER_ALPHA_MODE (gst_d3d11_converter_alpha_mode_get_type())
/**
* GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE:
*
* Set the source alpha mode.
* Default is #GST_D3D11_CONVERTER_ALPHA_MODE_UNSPECIFIED.
*
* Since: 1.24
*/
#define GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE "GstD3D11Converter.src-alpha-mode"
/**
* GST_D3D11_CONVERTER_OPT_DEST_ALPHA_MODE:
*
* Set the source alpha mode.
* Default is #GST_D3D11_CONVERTER_ALPHA_MODE_UNSPECIFIED.
*
* Since: 1.24
*/
#define GST_D3D11_CONVERTER_OPT_DEST_ALPHA_MODE "GstD3D11Converter.dest-alpha-mode"
/** /**
* GstD3D11Converter: * GstD3D11Converter:
* *

View file

@ -1724,7 +1724,12 @@ gst_d3d11_base_convert_set_info (GstD3D11BaseFilter * filter,
GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER, GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER,
GST_TYPE_D3D11_CONVERTER_SAMPLER_FILTER, GST_TYPE_D3D11_CONVERTER_SAMPLER_FILTER,
gst_d3d11_base_convert_sampling_method_to_filter gst_d3d11_base_convert_sampling_method_to_filter
(self->active_sampling_method), nullptr); (self->active_sampling_method),
GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE,
self->src_alpha_mode,
GST_D3D11_CONVERTER_OPT_DEST_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE, self->dst_alpha_mode, nullptr);
self->converter = gst_d3d11_converter_new (filter->device, in_info, out_info, self->converter = gst_d3d11_converter_new (filter->device, in_info, out_info,
config); config);
@ -1769,9 +1774,7 @@ gst_d3d11_base_convert_set_info (GstD3D11BaseFilter * filter,
"dest-y", (gint) self->out_rect.top, "dest-y", (gint) self->out_rect.top,
"dest-width", (gint) (self->out_rect.right - self->out_rect.left), "dest-width", (gint) (self->out_rect.right - self->out_rect.left),
"dest-height", (gint) (self->out_rect.bottom - self->out_rect.top), "dest-height", (gint) (self->out_rect.bottom - self->out_rect.top),
"video-direction", self->active_method, "video-direction", self->active_method, nullptr);
"src-alpha-mode", self->src_alpha_mode,
"dest-alpha-mode", self->dst_alpha_mode, nullptr);
if (self->borders_w > 0 || self->borders_h > 0) { if (self->borders_w > 0 || self->borders_h > 0) {
g_object_set (self->converter, "fill-border", TRUE, "border-color", g_object_set (self->converter, "fill-border", TRUE, "border-color",
@ -2245,9 +2248,10 @@ gst_d3d11_base_convert_set_src_alpha_mode (GstD3D11BaseConvert * self,
{ {
GstD3D11SRWLockGuard lk (&self->lock); GstD3D11SRWLockGuard lk (&self->lock);
self->src_alpha_mode = mode; if (self->src_alpha_mode != mode) {
if (self->converter) self->src_alpha_mode = mode;
g_object_set (self->converter, "src-alpha-mode", mode, nullptr); gst_base_transform_reconfigure_src (GST_BASE_TRANSFORM_CAST (self));
}
} }
static void static void
@ -2256,9 +2260,10 @@ gst_d3d11_base_convert_set_dst_alpha_mode (GstD3D11BaseConvert * self,
{ {
GstD3D11SRWLockGuard lk (&self->lock); GstD3D11SRWLockGuard lk (&self->lock);
self->dst_alpha_mode = mode; if (self->dst_alpha_mode != mode) {
if (self->converter) self->dst_alpha_mode = mode;
g_object_set (self->converter, "dest-alpha-mode", mode, nullptr); gst_base_transform_reconfigure_src (GST_BASE_TRANSFORM_CAST (self));
}
} }
/** /**

View file

@ -1299,7 +1299,17 @@ gst_d3d11_test_src_setup_resource (GstD3D11TestSrc * self, GstCaps * caps)
config = gst_structure_new ("converter-config", config = gst_structure_new ("converter-config",
GST_D3D11_CONVERTER_OPT_BACKEND, GST_TYPE_D3D11_CONVERTER_BACKEND, GST_D3D11_CONVERTER_OPT_BACKEND, GST_TYPE_D3D11_CONVERTER_BACKEND,
GST_D3D11_CONVERTER_BACKEND_SHADER, nullptr); GST_D3D11_CONVERTER_BACKEND_SHADER,
GST_D3D11_CONVERTER_OPT_DEST_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE, self->alpha_mode, nullptr);
/* D2D uses premultiplied alpha */
if (self->pattern == GST_D3D11_TEST_SRC_CIRCULAR ||
self->pattern == GST_D3D11_TEST_SRC_BALL) {
gst_structure_set (config, GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE,
GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED, nullptr);
}
gst_video_info_set_format (&draw_info, GST_VIDEO_FORMAT_BGRA, gst_video_info_set_format (&draw_info, GST_VIDEO_FORMAT_BGRA,
self->info.width, self->info.height); self->info.width, self->info.height);
@ -1311,15 +1321,6 @@ gst_d3d11_test_src_setup_resource (GstD3D11TestSrc * self, GstCaps * caps)
goto error; goto error;
} }
/* D2D uses premultiplied alpha */
if (self->pattern == GST_D3D11_TEST_SRC_CIRCULAR ||
self->pattern == GST_D3D11_TEST_SRC_BALL) {
g_object_set (self->converter, "src-alpha-mode",
GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED, nullptr);
}
g_object_set (self->converter, "dest-alpha-mode", self->alpha_mode, nullptr);
draw_caps = gst_video_info_to_caps (&draw_info); draw_caps = gst_video_info_to_caps (&draw_info);
params = gst_d3d11_allocation_params_new (self->device, &draw_info, params = gst_d3d11_allocation_params_new (self->device, &draw_info,
GST_D3D11_ALLOCATION_FLAG_DEFAULT, GST_D3D11_ALLOCATION_FLAG_DEFAULT,

View file

@ -755,6 +755,19 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width,
gst_video_info_apply_dxgi_color_space (swapchain_colorspace, gst_video_info_apply_dxgi_color_space (swapchain_colorspace,
&window->render_info); &window->render_info);
if (GST_VIDEO_INFO_HAS_ALPHA (&window->info)) {
if (config) {
gst_structure_set (config, GST_D3D11_CONVERTER_OPT_DEST_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE,
GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED, nullptr);
} else {
config = gst_structure_new ("convert-config",
GST_D3D11_CONVERTER_OPT_DEST_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE,
GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED, nullptr);
}
}
window->converter = gst_d3d11_converter_new (device, window->converter = gst_d3d11_converter_new (device,
&window->info, &window->render_info, config); &window->info, &window->render_info, config);
@ -765,11 +778,6 @@ 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);

View file

@ -234,7 +234,8 @@ is_subsampled_yuv (const GstVideoInfo * info)
static GstD3D11Converter * static GstD3D11Converter *
gst_dwrite_overlay_object_create_converter (GstDWriteOverlayObject * self, gst_dwrite_overlay_object_create_converter (GstDWriteOverlayObject * self,
const GstVideoInfo * in_info, const GstVideoInfo * out_info) const GstVideoInfo * in_info, const GstVideoInfo * out_info,
gboolean is_blend)
{ {
GstD3D11Converter *ret; GstD3D11Converter *ret;
GstDWriteOverlayObjectPrivate *priv = self->priv; GstDWriteOverlayObjectPrivate *priv = self->priv;
@ -249,6 +250,11 @@ gst_dwrite_overlay_object_create_converter (GstDWriteOverlayObject * self,
GST_D3D11_CONVERTER_BACKEND_SHADER, GST_D3D11_CONVERTER_BACKEND_SHADER,
GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER, GST_D3D11_CONVERTER_OPT_SAMPLER_FILTER,
GST_TYPE_D3D11_CONVERTER_SAMPLER_FILTER, filter, nullptr); GST_TYPE_D3D11_CONVERTER_SAMPLER_FILTER, filter, nullptr);
if (is_blend) {
gst_structure_set (config, GST_D3D11_CONVERTER_OPT_SRC_ALPHA_MODE,
GST_TYPE_D3D11_CONVERTER_ALPHA_MODE,
GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED, nullptr);
}
ret = gst_d3d11_converter_new (priv->device, in_info, out_info, config); ret = gst_d3d11_converter_new (priv->device, in_info, out_info, config);
if (!ret) if (!ret)
@ -352,7 +358,7 @@ gst_dwrite_overlay_object_prepare_resource (GstDWriteOverlayObject * self)
break; break;
case GstDWriteBlendMode::BLEND: case GstDWriteBlendMode::BLEND:
priv->blend_conv = gst_dwrite_overlay_object_create_converter (self, priv->blend_conv = gst_dwrite_overlay_object_create_converter (self,
&priv->bgra_info, &priv->info); &priv->bgra_info, &priv->info, TRUE);
if (!priv->blend_conv) if (!priv->blend_conv)
return FALSE; return FALSE;
break; break;
@ -363,17 +369,17 @@ gst_dwrite_overlay_object_prepare_resource (GstDWriteOverlayObject * self)
return FALSE; return FALSE;
priv->pre_conv = gst_dwrite_overlay_object_create_converter (self, priv->pre_conv = gst_dwrite_overlay_object_create_converter (self,
&priv->info, &priv->bgra_info); &priv->info, &priv->bgra_info, FALSE);
if (!priv->pre_conv) if (!priv->pre_conv)
return FALSE; return FALSE;
priv->blend_conv = gst_dwrite_overlay_object_create_converter (self, priv->blend_conv = gst_dwrite_overlay_object_create_converter (self,
&priv->bgra_info, &priv->bgra_info); &priv->bgra_info, &priv->bgra_info, TRUE);
if (!priv->blend_conv) if (!priv->blend_conv)
return FALSE; return FALSE;
priv->post_conv = gst_dwrite_overlay_object_create_converter (self, priv->post_conv = gst_dwrite_overlay_object_create_converter (self,
&priv->bgra_info, &priv->info); &priv->bgra_info, &priv->info, FALSE);
if (!priv->blend_conv) if (!priv->blend_conv)
return FALSE; return FALSE;
break; break;
@ -389,17 +395,17 @@ gst_dwrite_overlay_object_prepare_resource (GstDWriteOverlayObject * self)
return FALSE; return FALSE;
priv->pre_conv = gst_dwrite_overlay_object_create_converter (self, priv->pre_conv = gst_dwrite_overlay_object_create_converter (self,
&priv->info, &blend_info); &priv->info, &blend_info, FALSE);
if (!priv->pre_conv) if (!priv->pre_conv)
return FALSE; return FALSE;
priv->blend_conv = gst_dwrite_overlay_object_create_converter (self, priv->blend_conv = gst_dwrite_overlay_object_create_converter (self,
&priv->bgra_info, &blend_info); &priv->bgra_info, &blend_info, TRUE);
if (!priv->pre_conv) if (!priv->pre_conv)
return FALSE; return FALSE;
priv->post_conv = gst_dwrite_overlay_object_create_converter (self, priv->post_conv = gst_dwrite_overlay_object_create_converter (self,
&blend_info, &priv->info); &blend_info, &priv->info, FALSE);
if (!priv->post_conv) if (!priv->post_conv)
return FALSE; return FALSE;
@ -433,9 +439,7 @@ gst_dwrite_overlay_object_prepare_resource (GstDWriteOverlayObject * self)
return FALSE; return FALSE;
} }
g_object_set (priv->blend_conv, "blend-state", blend.Get (), g_object_set (priv->blend_conv, "blend-state", blend.Get (), nullptr);
"src-alpha-mode", GST_D3D11_CONVERTER_ALPHA_MODE_PREMULTIPLIED,
nullptr);
} }
return TRUE; return TRUE;