9e8d3863025a3320ddd48d25b5ef183c6f21525a
[platform/upstream/gstreamer.git] / gst-libs / gst / gl / winrt / gstglwindow_winrt_egl.c
1 /*
2  * GStreamer
3  * Copyright (C) 2019 Nirbheek Chauhan <nirbheek@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <gst/gl/gstglcontext.h>
25 #include <gst/gl/egl/gstglcontext_egl.h>
26
27 #include "gstglwindow_winrt_egl.h"
28 #include "../gstglwindow_private.h"
29
30 #define GST_CAT_DEFAULT gst_gl_window_debug
31
32 #define GST_GL_WINDOW_WINRT_EGL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
33     GST_TYPE_GL_WINDOW_WINRT_EGL, GstGLWindowWinRTEGLPrivate))
34
35
36 G_DEFINE_TYPE (GstGLWindowWinRTEGL, gst_gl_window_winrt_egl,
37     GST_TYPE_GL_WINDOW);
38
39 static guintptr gst_gl_window_winrt_egl_get_display (GstGLWindow * window);
40 static guintptr gst_gl_window_winrt_egl_get_window_handle (GstGLWindow *
41     window);
42 static void gst_gl_window_winrt_egl_set_window_handle (GstGLWindow * window,
43     guintptr handle);
44
45 static void
46 gst_gl_window_winrt_egl_class_init (GstGLWindowWinRTEGLClass * klass)
47 {
48   GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
49
50   window_class->get_display =
51       GST_DEBUG_FUNCPTR (gst_gl_window_winrt_egl_get_display);
52   window_class->get_window_handle =
53       GST_DEBUG_FUNCPTR (gst_gl_window_winrt_egl_get_window_handle);
54   window_class->set_window_handle =
55       GST_DEBUG_FUNCPTR (gst_gl_window_winrt_egl_set_window_handle);
56 }
57
58 static void
59 gst_gl_window_winrt_egl_init (GstGLWindowWinRTEGL * window_winrt)
60 {
61 }
62
63 static void
64 gst_gl_window_winrt_egl_set_window_handle (GstGLWindow * window,
65     guintptr handle)
66 {
67   GstGLWindowWinRTEGL *window_egl = GST_GL_WINDOW_WINRT_EGL (window);
68
69   GST_INFO_OBJECT (window, "Setting WinRT EGL window handle: %p", handle);
70
71   window_egl->window = (EGLNativeWindowType) handle;
72 }
73
74 static guintptr
75 gst_gl_window_winrt_egl_get_window_handle (GstGLWindow * window)
76 {
77   GstGLWindowWinRTEGL *window_egl = GST_GL_WINDOW_WINRT_EGL (window);
78
79   GST_INFO_OBJECT (window, "Getting WinRT EGL window handle");
80
81   return (guintptr) window_egl->window;
82 }
83
84 /* Must be called in the gl thread */
85 GstGLWindowWinRTEGL *
86 gst_gl_window_winrt_egl_new (GstGLDisplay * display)
87 {
88   GstGLWindowWinRTEGL *window_egl;
89
90   GST_INFO_OBJECT (display, "Trying to create WinRT EGL window");
91
92   if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_EGL) == 0)
93     /* we require an EGL display to create windows */
94     return NULL;
95
96   GST_INFO_OBJECT (display, "Creating WinRT EGL window");
97
98   window_egl = g_object_new (GST_TYPE_GL_WINDOW_WINRT_EGL, NULL);
99
100   return window_egl;
101 }
102
103 static guintptr
104 gst_gl_window_winrt_egl_get_display (GstGLWindow * window)
105 {
106   /* EGL_DEFAULT_DISPLAY */
107   return 0;
108 }