mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 16:02:00 +02:00
Sink: keep track of widget allocation size
Instead of obtaining allocation size on each frame draw, keep track of its current size and update value on its change.
This commit is contained in:
@@ -91,6 +91,23 @@ gtk_gst_base_widget_measure (GtkWidget * widget, GtkOrientation orientation,
|
|||||||
*minimum_baseline = -1;
|
*minimum_baseline = -1;
|
||||||
*natural_baseline = -1;
|
*natural_baseline = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_gst_base_widget_size_allocate (GtkWidget * widget,
|
||||||
|
gint width, gint height, gint baseline)
|
||||||
|
{
|
||||||
|
GtkGstBaseWidget *base_widget = GTK_GST_BASE_WIDGET (widget);
|
||||||
|
gint scale_factor = gtk_widget_get_scale_factor (widget);
|
||||||
|
|
||||||
|
GTK_GST_BASE_WIDGET_LOCK (base_widget);
|
||||||
|
|
||||||
|
base_widget->scaled_width = width * scale_factor;
|
||||||
|
base_widget->scaled_height = height * scale_factor;
|
||||||
|
|
||||||
|
GTK_GST_BASE_WIDGET_UNLOCK (base_widget);
|
||||||
|
|
||||||
|
gtk_gl_area_queue_render (GTK_GL_AREA (widget));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -170,7 +187,6 @@ _calculate_par (GtkGstBaseWidget * widget, GstVideoInfo * info)
|
|||||||
display_par_d = 1;
|
display_par_d = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ok = gst_video_calculate_display_ratio (&widget->display_ratio_num,
|
ok = gst_video_calculate_display_ratio (&widget->display_ratio_num,
|
||||||
&widget->display_ratio_den, width, height, par_n, par_d, display_par_n,
|
&widget->display_ratio_den, width, height, par_n, par_d, display_par_n,
|
||||||
display_par_d);
|
display_par_d);
|
||||||
@@ -234,7 +250,7 @@ _queue_draw (GtkGstBaseWidget * widget)
|
|||||||
|
|
||||||
gtk_widget_queue_resize (GTK_WIDGET (widget));
|
gtk_widget_queue_resize (GTK_WIDGET (widget));
|
||||||
} else {
|
} else {
|
||||||
gtk_widget_queue_draw (GTK_WIDGET (widget));
|
gtk_gl_area_queue_render (GTK_GL_AREA (widget));
|
||||||
}
|
}
|
||||||
|
|
||||||
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
GTK_GST_BASE_WIDGET_UNLOCK (widget);
|
||||||
@@ -308,8 +324,7 @@ gtk_gst_base_widget_key_event (GtkEventControllerKey * key_controller,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_fit_stream_to_allocated_size (GtkGstBaseWidget * base_widget,
|
_fit_stream_to_allocated_size (GtkGstBaseWidget * base_widget, GstVideoRectangle * result)
|
||||||
GtkAllocation * allocation, GstVideoRectangle * result)
|
|
||||||
{
|
{
|
||||||
if (base_widget->force_aspect_ratio) {
|
if (base_widget->force_aspect_ratio) {
|
||||||
GstVideoRectangle src, dst;
|
GstVideoRectangle src, dst;
|
||||||
@@ -321,15 +336,15 @@ _fit_stream_to_allocated_size (GtkGstBaseWidget * base_widget,
|
|||||||
|
|
||||||
dst.x = 0;
|
dst.x = 0;
|
||||||
dst.y = 0;
|
dst.y = 0;
|
||||||
dst.w = allocation->width;
|
dst.w = base_widget->scaled_width;
|
||||||
dst.h = allocation->height;
|
dst.h = base_widget->scaled_height;
|
||||||
|
|
||||||
gst_video_sink_center_rect (src, dst, result, TRUE);
|
gst_video_sink_center_rect (src, dst, result, TRUE);
|
||||||
} else {
|
} else {
|
||||||
result->x = 0;
|
result->x = 0;
|
||||||
result->y = 0;
|
result->y = 0;
|
||||||
result->w = allocation->width;
|
result->w = base_widget->scaled_width;
|
||||||
result->h = allocation->height;
|
result->h = base_widget->scaled_height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,11 +353,9 @@ _display_size_to_stream_size (GtkGstBaseWidget * base_widget, gdouble x,
|
|||||||
gdouble y, gdouble * stream_x, gdouble * stream_y)
|
gdouble y, gdouble * stream_x, gdouble * stream_y)
|
||||||
{
|
{
|
||||||
gdouble stream_width, stream_height;
|
gdouble stream_width, stream_height;
|
||||||
GtkAllocation allocation;
|
|
||||||
GstVideoRectangle result;
|
GstVideoRectangle result;
|
||||||
|
|
||||||
gtk_widget_get_allocation (GTK_WIDGET (base_widget), &allocation);
|
_fit_stream_to_allocated_size (base_widget, &result);
|
||||||
_fit_stream_to_allocated_size (base_widget, &allocation, &result);
|
|
||||||
|
|
||||||
stream_width = (gdouble) GST_VIDEO_INFO_WIDTH (&base_widget->v_info);
|
stream_width = (gdouble) GST_VIDEO_INFO_WIDTH (&base_widget->v_info);
|
||||||
stream_height = (gdouble) GST_VIDEO_INFO_HEIGHT (&base_widget->v_info);
|
stream_height = (gdouble) GST_VIDEO_INFO_HEIGHT (&base_widget->v_info);
|
||||||
@@ -475,6 +488,7 @@ gtk_gst_base_widget_class_init (GtkGstBaseWidgetClass * klass)
|
|||||||
|
|
||||||
#if defined(BUILD_FOR_GTK4)
|
#if defined(BUILD_FOR_GTK4)
|
||||||
widget_klass->measure = gtk_gst_base_widget_measure;
|
widget_klass->measure = gtk_gst_base_widget_measure;
|
||||||
|
widget_klass->size_allocate = gtk_gst_base_widget_size_allocate;
|
||||||
#else
|
#else
|
||||||
widget_klass->get_preferred_width = gtk_gst_base_widget_get_preferred_width;
|
widget_klass->get_preferred_width = gtk_gst_base_widget_get_preferred_width;
|
||||||
widget_klass->get_preferred_height = gtk_gst_base_widget_get_preferred_height;
|
widget_klass->get_preferred_height = gtk_gst_base_widget_get_preferred_height;
|
||||||
|
@@ -55,6 +55,10 @@ struct _GtkGstBaseWidget
|
|||||||
gint display_width;
|
gint display_width;
|
||||||
gint display_height;
|
gint display_height;
|
||||||
|
|
||||||
|
/* Widget dimensions */
|
||||||
|
gint scaled_width;
|
||||||
|
gint scaled_height;
|
||||||
|
|
||||||
gboolean negotiated;
|
gboolean negotiated;
|
||||||
GstBuffer *pending_buffer;
|
GstBuffer *pending_buffer;
|
||||||
GstBuffer *buffer;
|
GstBuffer *buffer;
|
||||||
|
@@ -253,15 +253,10 @@ gtk_gst_gl_widget_render (GtkGLArea * widget, GdkGLContext * context)
|
|||||||
|
|
||||||
if (base_widget->force_aspect_ratio) {
|
if (base_widget->force_aspect_ratio) {
|
||||||
GstVideoRectangle src, dst, result;
|
GstVideoRectangle src, dst, result;
|
||||||
gint widget_width, widget_height, widget_scale;
|
|
||||||
|
|
||||||
gl->ClearColor (0.0, 0.0, 0.0, 1.0);
|
gl->ClearColor (0.0, 0.0, 0.0, 1.0);
|
||||||
gl->Clear (GL_COLOR_BUFFER_BIT);
|
gl->Clear (GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
widget_scale = gtk_widget_get_scale_factor (GTK_WIDGET (widget));
|
|
||||||
widget_width = gtk_widget_get_allocated_width (GTK_WIDGET (widget));
|
|
||||||
widget_height = gtk_widget_get_allocated_height (GTK_WIDGET (widget));
|
|
||||||
|
|
||||||
src.x = 0;
|
src.x = 0;
|
||||||
src.y = 0;
|
src.y = 0;
|
||||||
src.w = base_widget->display_width;
|
src.w = base_widget->display_width;
|
||||||
@@ -269,8 +264,8 @@ gtk_gst_gl_widget_render (GtkGLArea * widget, GdkGLContext * context)
|
|||||||
|
|
||||||
dst.x = 0;
|
dst.x = 0;
|
||||||
dst.y = 0;
|
dst.y = 0;
|
||||||
dst.w = widget_width * widget_scale;
|
dst.w = base_widget->scaled_width;
|
||||||
dst.h = widget_height * widget_scale;
|
dst.h = base_widget->scaled_height;
|
||||||
|
|
||||||
gst_video_sink_center_rect (src, dst, &result, TRUE);
|
gst_video_sink_center_rect (src, dst, &result, TRUE);
|
||||||
|
|
||||||
@@ -429,6 +424,8 @@ gtk_gst_gl_widget_init (GtkGstGLWidget * gst_widget)
|
|||||||
gtk_gl_area_set_has_alpha (GTK_GL_AREA (gst_widget),
|
gtk_gl_area_set_has_alpha (GTK_GL_AREA (gst_widget),
|
||||||
!base_widget->ignore_alpha);
|
!base_widget->ignore_alpha);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
gtk_gl_area_set_auto_render (GTK_GL_AREA (gst_widget), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Reference in New Issue
Block a user