libs: display: delay getting screen resolution
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Fri, 29 Sep 2017 13:07:47 +0000 (15:07 +0200)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Tue, 3 Oct 2017 11:14:55 +0000 (13:14 +0200)
Instead of extracting the screen resolution at GstVaapiDisplay
creation, this patch delay it until the screen size is requested for
first time.

https://bugzilla.gnome.org/show_bug.cgi?id=782212

gst-libs/gst/vaapi/gstvaapidisplay.c
gst-libs/gst/vaapi/gstvaapidisplay_priv.h

index 30abf91..0e80f9c 100644 (file)
@@ -783,6 +783,25 @@ gst_vaapi_display_calculate_pixel_aspect_ratio (GstVaapiDisplay * display)
 }
 
 static void
+gst_vaapi_display_ensure_screen_resolution (GstVaapiDisplay * display)
+{
+  GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
+  const GstVaapiDisplayClass *const klass =
+      GST_VAAPI_DISPLAY_GET_CLASS (display);
+
+  if (priv->got_scrres)
+    return;
+
+  if (klass->get_size)
+    klass->get_size (display, &priv->width, &priv->height);
+  if (klass->get_size_mm)
+    klass->get_size_mm (display, &priv->width_mm, &priv->height_mm);
+
+  gst_vaapi_display_calculate_pixel_aspect_ratio (display);
+  priv->got_scrres = TRUE;
+}
+
+static void
 gst_vaapi_display_destroy (GstVaapiDisplay * display)
 {
   GstVaapiDisplayPrivate *const priv = GST_VAAPI_DISPLAY_GET_PRIVATE (display);
@@ -869,11 +888,6 @@ gst_vaapi_display_create_unlocked (GstVaapiDisplay * display,
         return FALSE;
       priv->display = info.va_display;
       priv->native_display = info.native_display;
-      if (klass->get_size)
-        klass->get_size (display, &priv->width, &priv->height);
-      if (klass->get_size_mm)
-        klass->get_size_mm (display, &priv->width_mm, &priv->height_mm);
-      gst_vaapi_display_calculate_pixel_aspect_ratio (display);
       break;
   }
   if (!priv->display)
@@ -1379,6 +1393,8 @@ gst_vaapi_display_get_width (GstVaapiDisplay * display)
 {
   g_return_val_if_fail (display != NULL, 0);
 
+  gst_vaapi_display_ensure_screen_resolution (display);
+
   return GST_VAAPI_DISPLAY_GET_PRIVATE (display)->width;
 }
 
@@ -1395,6 +1411,8 @@ gst_vaapi_display_get_height (GstVaapiDisplay * display)
 {
   g_return_val_if_fail (display != NULL, 0);
 
+  gst_vaapi_display_ensure_screen_resolution (display);
+
   return GST_VAAPI_DISPLAY_GET_PRIVATE (display)->height;
 }
 
@@ -1412,6 +1430,8 @@ gst_vaapi_display_get_size (GstVaapiDisplay * display, guint * pwidth,
 {
   g_return_if_fail (GST_VAAPI_DISPLAY (display));
 
+  gst_vaapi_display_ensure_screen_resolution (display);
+
   if (pwidth)
     *pwidth = GST_VAAPI_DISPLAY_GET_PRIVATE (display)->width;
 
@@ -1433,6 +1453,8 @@ gst_vaapi_display_get_pixel_aspect_ratio (GstVaapiDisplay * display,
 {
   g_return_if_fail (display != NULL);
 
+  gst_vaapi_display_ensure_screen_resolution (display);
+
   if (par_n)
     *par_n = GST_VAAPI_DISPLAY_GET_PRIVATE (display)->par_n;
 
index 20b2bce..7f96208 100644 (file)
@@ -128,6 +128,7 @@ struct _GstVaapiDisplayPrivate
   guint use_foreign_display:1;
   guint has_vpp:1;
   guint has_profiles:1;
+  guint got_scrres:1;
 };
 
 /**