glwindow: handle gst_video_overlay_set_render_rectangle
authorMatthew Waters <matthew@centricular.com>
Fri, 29 May 2015 08:03:52 +0000 (18:03 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:32:03 +0000 (19:32 +0000)
ext/gl/gstglimagesink.c
ext/gl/gstglimagesink.h
gst-libs/gst/gl/gstglwindow.c
gst-libs/gst/gl/gstglwindow.h

index 648b8da..30ff74f 100644 (file)
@@ -351,9 +351,9 @@ static void gst_glimage_sink_video_overlay_init (GstVideoOverlayInterface *
 static void gst_glimage_sink_set_window_handle (GstVideoOverlay * overlay,
     guintptr id);
 static void gst_glimage_sink_expose (GstVideoOverlay * overlay);
-
-static void
-gst_glimage_sink_handle_events (GstVideoOverlay * overlay,
+static void gst_glimage_sink_set_render_rectangle (GstVideoOverlay * overlay,
+    gint x, gint y, gint width, gint height);
+static void gst_glimage_sink_handle_events (GstVideoOverlay * overlay,
     gboolean handle_events);
 
 static GstStaticPadTemplate gst_glimage_sink_template =
@@ -761,6 +761,12 @@ _ensure_gl_setup (GstGLImageSink * gl_sink)
           g_signal_connect (window, "mouse-event",
           G_CALLBACK (gst_glimage_sink_mouse_event_cb), gl_sink);
 
+      if (gl_sink->x >= 0 && gl_sink->y >= 0 && gl_sink->width > 0 &&
+          gl_sink->height > 0) {
+        gst_gl_window_set_render_rectangle (window, gl_sink->x, gl_sink->y,
+            gl_sink->width, gl_sink->height);
+      }
+
       if (other_context)
         gst_object_unref (other_context);
       gst_object_unref (window);
@@ -1234,6 +1240,7 @@ static void
 gst_glimage_sink_video_overlay_init (GstVideoOverlayInterface * iface)
 {
   iface->set_window_handle = gst_glimage_sink_set_window_handle;
+  iface->set_render_rectangle = gst_glimage_sink_set_render_rectangle;
   iface->handle_events = gst_glimage_sink_handle_events;
   iface->expose = gst_glimage_sink_expose;
 }
@@ -1288,6 +1295,25 @@ gst_glimage_sink_handle_events (GstVideoOverlay * overlay,
   }
 }
 
+static void
+gst_glimage_sink_set_render_rectangle (GstVideoOverlay * overlay,
+    gint x, gint y, gint width, gint height)
+{
+  GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);
+
+  if (G_LIKELY (glimage_sink->context)) {
+    GstGLWindow *window;
+    window = gst_gl_context_get_window (glimage_sink->context);
+    gst_gl_window_set_render_rectangle (window, x, y, width, height);
+    gst_object_unref (window);
+  }
+
+  glimage_sink->x = x;
+  glimage_sink->y = y;
+  glimage_sink->width = width;
+  glimage_sink->height = height;
+}
+
 static gboolean
 gst_glimage_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
 {
index 52db017..03e8136 100644 (file)
@@ -56,6 +56,12 @@ struct _GstGLImageSink
     gulong mouse_sig_id;
     gulong key_sig_id;
 
+    /* GstVideoOverlay::set_render_rectangle() cache */
+    gint x;
+    gint y;
+    gint width;
+    gint height;
+
     //caps
     GstVideoInfo info;
     GstCaps *caps;
index 347781f..8682b1c 100644 (file)
@@ -1094,3 +1094,35 @@ gst_gl_window_handle_events (GstGLWindow * window, gboolean handle_events)
   if (window_class->handle_events)
     window_class->handle_events (window, handle_events);
 }
+
+/**
+ * gst_gl_window_set_render_rectangle:
+ * @window: a #GstGLWindow
+ * @x: x position
+ * @y: y position
+ * @width: width
+ * @height: height
+ *
+ * Tell a @window that it should render into a specific region of the window
+ * according to the #GstVideoOverlay interface.
+ *
+ * Returns: whether the specified region could be set
+ */
+gboolean
+gst_gl_window_set_render_rectangle (GstGLWindow * window, gint x, gint y,
+    gint width, gint height)
+{
+  GstGLWindowClass *window_class;
+  gboolean ret = FALSE;
+
+  g_return_if_fail (GST_GL_IS_WINDOW (window));
+  window_class = GST_GL_WINDOW_GET_CLASS (window);
+
+  if (x < 0 || y < 0 || width <= 0 || height <= 0)
+    return FALSE;
+
+  if (window_class->set_render_rectangle)
+    ret = window_class->set_render_rectangle (window, x, y, width, height);
+
+  return ret;
+}
index f12a317..b7c5a76 100644 (file)
@@ -142,6 +142,7 @@ struct _GstGLWindowClass {
   void     (*handle_events)      (GstGLWindow *window, gboolean handle_events);
   void     (*set_preferred_size) (GstGLWindow *window, gint width, gint height);
   void     (*show)               (GstGLWindow *window);
+  gboolean (*set_render_rectangle)(GstGLWindow *window, gint x, gint y, gint width, gint height);
 
   /*< private >*/
   gpointer _reserved[GST_PADDING];
@@ -221,6 +222,11 @@ void     gst_gl_window_set_preferred_size   (GstGLWindow * window,
 void     gst_gl_window_get_surface_dimensions (GstGLWindow * window,
                                                guint * width,
                                                guint * height);
+gboolean gst_gl_window_set_render_rectangle   (GstGLWindow * window,
+                                               gint x,
+                                               gint y,
+                                               gint width,
+                                               gint height);
 
 GstGLContext * gst_gl_window_get_context    (GstGLWindow *window);
 guintptr       gst_gl_window_get_display    (GstGLWindow *window);