gl: Decouple win32 window and wgl context
[platform/upstream/gstreamer.git] / gst-libs / gst / gl / meson.build
1 if get_option('gl').disabled()
2   message('GStreamer OpenGL integration disabled via options.')
3   gstgl_dep = dependency('', required: false)
4   build_gstgl = false
5   subdir_done()
6 endif
7
8 gl_sources = [
9   'gstglapi.c',
10   'gstglbasefilter.c',
11   'gstglbasememory.c',
12   'gstglbasesrc.c',
13   'gstglcolorconvert.c',
14   'gstglbuffer.c',
15   'gstglbufferpool.c',
16   'gstglcontext.c',
17   'gstgldebug.c',
18   'gstgldisplay.c',
19   'gstglfeature.c',
20   'gstglfilter.c',
21   'gstglformat.c',
22   'gstglframebuffer.c',
23   'gstglmemory.c',
24   'gstglmemorypbo.c',
25   'gstgloverlaycompositor.c',
26   'gstglquery.c',
27   'gstglrenderbuffer.c',
28   'gstglshader.c',
29   'gstglshaderstrings.c',
30   'gstglsl.c',
31   'gstglslstage.c',
32   'gstglsyncmeta.c',
33   'gstglupload.c',
34   'gstglutils.c',
35   'gstglviewconvert.c',
36   'gstglwindow.c',
37 ]
38
39 gl_priv_sources = []
40
41 gir_gl_headers = [
42   'gl.h',
43   'gl-prelude.h',
44   'gstgl_enums.h',
45   'gstgl_fwd.h',
46   'gstglapi.h',
47   'gstglbasefilter.h',
48   'gstglbasememory.h',
49   'gstglbasesrc.h',
50   'gstglbuffer.h',
51   'gstglbufferpool.h',
52   'gstglcolorconvert.h',
53   'gstglcontext.h',
54   'gstgldebug.h',
55   'gstgldisplay.h',
56   'gstglfeature.h',
57   'gstglfilter.h',
58   'gstglformat.h',
59   'gstglframebuffer.h',
60   'gstglmemory.h',
61   'gstglmemorypbo.h',
62   'gstgloverlaycompositor.h',
63   'gstglquery.h',
64   'gstglrenderbuffer.h',
65   'gstglshader.h',
66   'gstglshaderstrings.h',
67   'gstglsl.h',
68   'gstglslstage.h',
69   'gstglsyncmeta.h',
70   'gstglupload.h',
71   'gstglutils.h',
72   'gstglviewconvert.h',
73   'gstglwindow.h',
74 ]
75
76 gl_headers = gir_gl_headers + [
77   'gstglfuncs.h',
78 ]
79
80 gl_prototype_headers = [
81   'glprototypes/all_functions.h',
82   'glprototypes/base.h',
83   'glprototypes/blending.h',
84   'glprototypes/buffers.h',
85   'glprototypes/debug.h',
86   'glprototypes/eglimage.h',
87   'glprototypes/fbo.h',
88   'glprototypes/fixedfunction.h',
89   'glprototypes/gles.h',
90   'glprototypes/gstgl_compat.h',
91   'glprototypes/gstgl_gles2compat.h',
92   'glprototypes/opengl.h',
93   'glprototypes/query.h',
94   'glprototypes/shaders.h',
95   'glprototypes/sync.h',
96   'glprototypes/vao.h',
97 ]
98
99 gl_x11_headers = []
100 gl_wayland_headers = []
101 gl_win32_headers = []
102 gl_cocoa_headers = []
103 gl_egl_headers = []
104
105 glconf = configuration_data()
106 glconf_options = [
107     'GST_GL_HAVE_OPENGL',
108     'GST_GL_HAVE_GLES2',
109     'GST_GL_HAVE_GLES3',
110     'GST_GL_HAVE_GLES3EXT3_H',
111
112     'GST_GL_HAVE_WINDOW_X11',
113     'GST_GL_HAVE_WINDOW_COCOA',
114     'GST_GL_HAVE_WINDOW_WIN32',
115     'GST_GL_HAVE_WINDOW_WINRT',
116     'GST_GL_HAVE_WINDOW_WAYLAND',
117     'GST_GL_HAVE_WINDOW_ANDROID',
118     'GST_GL_HAVE_WINDOW_DISPMANX',
119     'GST_GL_HAVE_WINDOW_EAGL',
120     'GST_GL_HAVE_WINDOW_VIV_FB',
121     'GST_GL_HAVE_WINDOW_GBM',
122
123     'GST_GL_HAVE_PLATFORM_EGL',
124     'GST_GL_HAVE_PLATFORM_GLX',
125     'GST_GL_HAVE_PLATFORM_WGL',
126     'GST_GL_HAVE_PLATFORM_CGL',
127     'GST_GL_HAVE_PLATFORM_EAGL',
128
129     'GST_GL_HAVE_DMABUF',
130     'GST_GL_HAVE_VIV_DIRECTVIV',
131
132     'GST_GL_HAVE_GLEGLIMAGEOES',
133     'GST_GL_HAVE_GLCHAR',
134     'GST_GL_HAVE_GLSIZEIPTR',
135     'GST_GL_HAVE_GLINTPTR',
136     'GST_GL_HAVE_GLSYNC',
137     'GST_GL_HAVE_GLUINT64',
138     'GST_GL_HAVE_GLINT64',
139     'GST_GL_HAVE_EGLATTRIB',
140     'GST_GL_HAVE_EGLUINT64KHR',
141 ]
142
143 foreach option : glconf_options
144   glconf.set10(option, false)
145 endforeach
146
147 unneeded_dep = dependency('', required : false)
148 if unneeded_dep.found()
149   error ('Found unfindable dependency')
150 endif
151
152 # OpenGL/GLES2 libraries
153 gl_lib_deps = []
154 # GL platform - EGL, GLX, CGL, WGL, etc
155 gl_platform_deps = []
156 # GL winsys - wayland, X11, Cocoa, win32, etc
157 gl_winsys_deps = []
158 # other things we need.
159 gl_misc_deps = []
160 # Other preprocessor arguments
161 gl_cpp_args = []
162 gl_includes = []
163 gl_objc_args = []
164
165 enabled_gl_apis = []
166 enabled_gl_platforms = []
167 enabled_gl_winsys = []
168
169 # parse provided options
170 libegl_module_name = get_option('egl_module_name')
171 if libegl_module_name != ''
172   gl_cpp_args += ['-DGST_GL_LIBEGL_MODULE_NAME="@0@"'.format(libegl_module_name)]
173 endif
174 libgles2_module_name = get_option('gles2_module_name')
175 if libgles2_module_name != ''
176   gl_cpp_args += ['-DGST_GL_LIBGLESV2_MODULE_NAME="@0@"'.format(libgles2_module_name)]
177 endif
178 libgl_module_name = get_option('opengl_module_name')
179 if libgl_module_name != ''
180   gl_cpp_args += ['-DGST_GL_LIBGL_MODULE_NAME="@0@"'.format(libgl_module_name)]
181 endif
182
183 gl_apis = get_option('gl_api')
184 if gl_apis.contains('auto')
185   need_api_opengl = 'auto'
186   need_api_gles2 = 'auto'
187 else
188   need_api_opengl = 'no'
189   need_api_gles2 = 'no'
190   foreach api : gl_apis
191     if api == 'opengl'
192       need_api_opengl = 'yes'
193     elif api == 'gles2'
194       need_api_gles2 = 'yes'
195     else
196       error('Unsupported GL api provided ' + api)
197     endif
198   endforeach
199 endif
200
201 gl_platforms = get_option('gl_platform')
202 if gl_platforms.contains('auto')
203   need_platform_egl = 'auto'
204   need_platform_glx = 'auto'
205   need_platform_cgl = 'auto'
206   need_platform_wgl = 'auto'
207   need_platform_eagl = 'auto'
208 else
209   need_platform_egl = 'no'
210   need_platform_glx = 'no'
211   need_platform_cgl = 'no'
212   need_platform_wgl = 'no'
213   need_platform_eagl = 'no'
214   foreach platform : gl_platforms
215     if platform == 'egl'
216       need_platform_egl = 'yes'
217     elif platform == 'glx'
218       need_platform_glx = 'yes'
219     elif platform == 'cgl'
220       need_platform_cgl = 'yes'
221     elif platform == 'wgl'
222       need_platform_wgl = 'yes'
223     elif platform == 'eagl'
224       need_platform_eagl = 'yes'
225     else
226       error('Unsupported GL platform provided ' + platform)
227     endif
228   endforeach
229 endif
230
231 gl_winsys = get_option('gl_winsys')
232 if gl_winsys.contains('auto')
233   need_win_x11 = 'auto'
234   need_win_wayland = 'auto'
235   need_win_win32 = 'auto'
236   need_win_winrt = 'auto'
237   need_win_cocoa = 'auto'
238   need_win_eagl = 'auto'
239   need_win_dispmanx = 'auto'
240   need_win_viv_fb = 'auto'
241   need_win_gbm = 'auto'
242   need_win_android = 'auto'
243 else
244   need_win_x11 = 'no'
245   need_win_wayland = 'no'
246   need_win_win32 = 'no'
247   need_win_winrt = 'no'
248   need_win_cocoa = 'no'
249   need_win_eagl = 'no'
250   need_win_dispmanx = 'no'
251   need_win_viv_fb = 'no'
252   need_win_gbm = 'no'
253   need_win_android = 'no'
254   foreach winsys : gl_winsys
255     if winsys == 'x11'
256       need_win_x11 = 'yes'
257     elif winsys == 'wayland'
258       need_win_wayland = 'yes'
259     elif winsys == 'win32'
260       need_win_win32 = 'yes'
261     elif winsys == 'winrt'
262       need_win_winrt = 'yes'
263     elif winsys == 'cocoa'
264       need_win_cocoa = 'yes'
265     elif winsys == 'eagl'
266       need_win_eagl = 'yes'
267     elif winsys == 'dispmanx'
268       need_win_dispmanx = 'yes'
269     elif winsys == 'viv-fb'
270       need_win_viv_fb = 'yes'
271     elif winsys == 'gbm'
272       need_win_gbm = 'yes'
273     elif winsys == 'android'
274       need_win_android = 'yes'
275     else
276       error('Unsupported GL winsys provided ' + winsys)
277     endif
278   endforeach
279 endif
280
281 gl_include_header = '''
282 #ifdef __GNUC__
283 #  pragma GCC diagnostic push
284 #  pragma GCC diagnostic ignored "-Wredundant-decls"
285 #endif
286 #ifndef GL_GLEXT_PROTOTYPES
287 #define GL_GLEXT_PROTOTYPES 1
288 #endif
289 '''
290
291 # convoluted way of getting at the subproject taking into account the wrap-mode
292 # so we don't download a subproject unless allowed
293 gl_header_dep = dependency('', fallback : ['gl-headers', 'gl_headers_dummy_dep'],
294     required : false)
295 if gl_header_dep.type_name() == 'internal'
296   # this will only contain the includes of headers that are not found
297   compat_includes = subproject('gl-headers').get_variable('compatibility_includes')
298 else
299   compat_includes = []
300 endif
301
302 # Desktop OpenGL checks
303 gl_dep = unneeded_dep
304 glx_dep = unneeded_dep
305 if need_api_opengl != 'no' or need_platform_glx != 'no'
306   if host_system == 'darwin'
307     gl_dep = dependency('appleframeworks', modules : ['OpenGL'], required : false)
308   else
309     # override meson's braindead gl detection on osx/windows/etc by forcing pkg-config
310     gl_dep = dependency('gl', method: 'pkg-config', required : false)
311   endif
312
313   if not gl_dep.found()
314     if host_system == 'windows'
315       gl_dep = cc.find_library('opengl32', required : false)
316     else
317       gl_dep = cc.find_library('GL', required : false)
318     endif
319
320     if not cc.has_header('GL/gl.h', include_directories : compat_includes)
321       gl_dep = unneeded_dep
322     endif
323
324     if not gl_dep.found() and need_api_opengl == 'yes'
325       error ('Could not find requested OpenGL library')
326     endif
327
328     if gl_dep.found()
329       gl_includes += [compat_includes]
330     endif
331   endif
332
333   if host_system == 'darwin'
334     glx_dep = cc.find_library('GL', required : false)
335   else
336     glx_dep = gl_dep
337   endif
338
339   if need_api_opengl == 'no'
340     gl_dep = unneeded_dep
341   endif
342   if need_platform_glx == 'no'
343     glx_dep = unneeded_dep
344   endif
345
346   opengl_includes = ''
347   if host_system == 'darwin'
348     opengl_includes += '''
349 #include <OpenGL/OpenGL.h>
350 #include <OpenGL/gl.h>
351 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
352 # define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED
353 # include <OpenGL/gl3.h>
354 #endif
355 '''
356   else
357     opengl_includes += '''
358 #if _MSC_VER
359 # include <windows.h>
360 #endif
361 #include <GL/gl.h>
362 #if __WIN32__ || _WIN32
363 # include <GL/glext.h>
364 #endif
365 '''
366   endif
367 endif
368
369 # GLES2 checks
370 gles2_dep = unneeded_dep
371 gles3_h = false
372 gles3ext3_h = false
373 if need_api_gles2 != 'no'
374   if host_system == 'ios'
375     gles2_dep = dependency('appleframeworks', modules : ['OpenGLES'], required : false)
376   else
377     gles2_dep = dependency('glesv2', required : false)
378   endif
379
380   if not gles2_dep.found()
381 #    if host_system == 'windows'
382 #    elif host_system == ios
383 #      gles2_dep = cc.find_library('GLESv2', required : false)
384 #    else
385       gles2_dep = cc.find_library('GLESv2', required : false)
386 #    endif
387
388     if not cc.has_header('GLES2/gl2.h', include_directories : compat_includes)
389       gles2_dep = unneeded_dep
390     endif
391
392     if not gles2_dep.found() and need_api_gles2 == 'yes'
393       error ('Could not find requested OpenGL ES library')
394     endif
395
396     if gles2_dep.found()
397       gl_includes += [compat_includes]
398     endif
399   endif
400
401   gles3_h = gles2_dep.found() and cc.has_header('GLES3/gl3.h', dependencies : gles2_dep, include_directories : compat_includes)
402
403   gles_includes = ''
404   if host_system == 'ios'
405     gles_includes += '''
406 # include <OpenGLES/ES2/gl.h>
407 # include <OpenGLES/ES2/glext.h>
408 '''
409   else
410     if gles3_h
411       gl_includes += [compat_includes]
412       gles3ext3_h = gles3_h and cc.has_header('GLES3/gl3ext.h', dependencies : gles2_dep, include_directories : compat_includes)
413       gles_includes += '''
414 # include <GLES3/gl3.h>
415 # include <GLES2/gl2ext.h>'''
416       if gles3ext3_h
417         gles_includes += '''
418 # include <GLES3/gl3ext.h>'''
419       endif
420     else
421       gles_includes += '''
422 # include <GLES2/gl2.h>
423 # include <GLES2/gl2ext.h>'''
424     endif
425   endif
426 endif
427
428 # can we include both gles2 and opengl headers?
429 if gles2_dep.found() and gl_dep.found()
430   gl_include_block = gl_include_header + gles_includes + opengl_includes
431   # TODO: Revert to passing gl_include_block via prefix: once
432   # https://github.com/mesonbuild/meson/issues/2364 is fixed
433   if not cc.compiles(gl_include_block + '\n' + 'void f (void) {}',dependencies : [gles2_dep, gl_dep], include_directories : compat_includes)
434     message ('Cannot include both OpenGL and OpenGL ES headers')
435     if need_api_gles2 != 'yes'
436       gles2_dep = unneeded_dep
437     elif need_api_opengl != 'yes'
438       gl_dep = unneeded_dep
439     else
440       error('Both OpenGL and OpenGL ES were requested but cannot be included together')
441     endif
442   endif
443 endif
444 gl_include_block = gl_include_header
445 if gles2_dep.found()
446   gl_include_block += gles_includes
447 endif
448 if gl_dep.found()
449   gl_include_block += opengl_includes
450 endif
451
452 if gles2_dep.found()
453   gl_lib_deps += gles2_dep
454   glconf.set10('GST_GL_HAVE_GLES2', 1)
455   if gles3_h
456     glconf.set10('GST_GL_HAVE_GLES3', 1)
457     if gles3ext3_h
458       glconf.set10('GST_GL_HAVE_GLES3EXT3_H', 1)
459     endif
460   endif
461   enabled_gl_apis += 'gles2'
462 endif
463
464 if gl_dep.found()
465   gl_lib_deps += gl_dep
466   glconf.set10('GST_GL_HAVE_OPENGL', 1)
467   enabled_gl_apis += 'gl'
468 endif
469
470 # EGL checks
471 egl_dep = unneeded_dep
472 if need_platform_egl != 'no'
473   egl_dep = dependency('egl', required : false)
474   if not egl_dep.found()
475     egl_dep = cc.find_library('EGL', required : false)
476   endif
477
478   if egl_dep.found() and not cc.has_header('EGL/egl.h',
479                                            dependencies : egl_dep,
480                                            include_directories : compat_includes)
481     egl_dep = unneeded_dep
482   endif
483   if egl_dep.found() and not cc.has_header('EGL/eglext.h',
484                                            dependencies : egl_dep,
485                                            include_directories : compat_includes)
486     egl_dep = unneeded_dep
487   endif
488
489   if egl_dep.found()
490     gl_sources += [
491       'egl/gstegl.c',
492       'egl/gsteglimage.c',
493       'egl/gstglcontext_egl.c',
494       'egl/gstgldisplay_egl.c',
495       'egl/gstglmemoryegl.c',
496       'egl/gstgldisplay_egl_device.c',
497     ]
498     gl_egl_headers += [
499       'egl/gstegl.h',
500       'egl/gsteglimage.h',
501       'egl/gstgldisplay_egl.h',
502       'egl/gstglmemoryegl.h',
503       'egl/gstgldisplay_egl_device.h',
504     ]
505     gl_platform_deps += egl_dep
506     glconf.set10('GST_GL_HAVE_PLATFORM_EGL', 1)
507
508     if cc.has_header('libdrm/drm_fourcc.h')
509       gl_misc_deps += allocators_dep
510       glconf.set10('GST_GL_HAVE_DMABUF', 1)
511     endif
512
513     egl_includes = '''
514 #include <EGL/egl.h>
515 #include <EGL/eglext.h>
516 '''
517     enabled_gl_platforms += 'egl'
518   elif need_platform_egl == 'yes'
519     error ('Could not find requested EGL library')
520   endif
521 endif
522
523 # wayland checks
524 wayland_client_dep = unneeded_dep
525 wayland_cursor_dep = unneeded_dep
526 wayland_egl_dep = unneeded_dep
527 if need_win_wayland != 'no'
528   if need_win_wayland == 'yes'
529     if need_platform_egl == 'no'
530       error('Impossible situation requested: Cannot use Wayland without EGL support')
531     endif
532   endif
533   if not egl_dep.found()
534     if need_win_wayland == 'yes'
535       error ('Could not find EGL libraries for wayland')
536     else
537       message ('Could not find EGL libraries for wayland')
538     endif
539   else
540     wayland_client_dep = dependency('wayland-client', version : '>= 1.0', required : false)
541     wayland_cursor_dep = dependency('wayland-cursor', version : '>= 1.0', required : false)
542     wayland_egl_dep = dependency('wayland-egl', version : '>= 1.0', required : false)
543     wayland_protocols_dep = dependency('wayland-protocols', version : '>= 1.15', required : false)
544     wayland_scanner = find_program('wayland-scanner', required: false)
545
546     if wayland_client_dep.found() and wayland_cursor_dep.found() and wayland_egl_dep.found() and wayland_protocols_dep.found() and wayland_scanner.found()
547       # Generate the XDG shell interface
548       wayland_protocols_basedir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
549       xdg_shell_xml_spec = join_paths(wayland_protocols_basedir, 'stable', 'xdg-shell', 'xdg-shell.xml')
550       xdg_shell_header = custom_target('xdg-shell-client-header',
551         command: [ wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@' ],
552         input: xdg_shell_xml_spec,
553         output: 'xdg-shell-client-protocol.h',
554       )
555       xdg_shell_code = custom_target('xdg-shell-client-code',
556         command: [ wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@' ],
557         input: xdg_shell_xml_spec,
558         output: 'xdg-shell-client-protocol.c',
559       )
560
561       gl_sources += [
562         'wayland/gstgldisplay_wayland.c',
563         'wayland/gstglwindow_wayland_egl.c',
564         'wayland/wayland_event_source.c',
565       ]
566       gl_priv_sources += [
567         xdg_shell_header,
568         xdg_shell_code,
569       ]
570       gl_wayland_headers += [
571         'wayland/gstgldisplay_wayland.h'
572       ]
573       glconf.set('GST_GL_HAVE_WINDOW_WAYLAND', 1)
574       gl_winsys_deps += [wayland_client_dep, wayland_cursor_dep, wayland_egl_dep]
575       enabled_gl_winsys += 'wayland'
576     else
577       if need_win_wayland == 'yes'
578         error ('Could not find requested Wayland libraries')
579       endif
580       wayland_client_dep = unneeded_dep
581       wayland_cursor_dep = unneeded_dep
582       wayland_egl_dep = unneeded_dep
583       wayland_protocols_dep = unneeded_dep
584     endif
585   endif
586 endif
587
588 # X11 checks
589 if need_platform_glx == 'yes'
590   if need_win_x11 == 'no'
591     error('Impossible situation requested: Cannot use GLX without X11 support')
592   elif need_api_opengl == 'no'
593     error('Impossible situation requested: Cannot use GLX without the OpenGL library')
594   endif
595 endif
596
597 if need_win_x11 != 'no'
598   xcb_dep = dependency('x11-xcb', required : false)
599   if x11_dep.found() and xcb_dep.found()
600     gl_sources += [
601       'x11/gstgldisplay_x11.c',
602       'x11/gstglwindow_x11.c',
603       'x11/xcb_event_source.c',
604     ]
605     gl_x11_headers += [
606       'x11/gstgldisplay_x11.h',
607     ]
608     glconf.set('GST_GL_HAVE_WINDOW_X11', 1)
609     gl_winsys_deps += [x11_dep, xcb_dep]
610     enabled_gl_winsys += 'x11'
611
612     if need_platform_glx != 'no' and glx_dep.found() and cc.has_function ('glXMakeCurrent', dependencies : glx_dep)
613       glconf.set('GST_GL_HAVE_PLATFORM_GLX', 1)
614       gl_sources += [
615         'x11/gstglcontext_glx.c',
616       ]
617       # GLX is in the opengl library on linux
618       gl_platform_deps += glx_dep
619       enabled_gl_platforms += 'glx'
620     endif
621   elif need_win_x11 == 'yes'
622     error ('Could not find requested X11 libraries')
623   endif
624 endif
625
626 bcm_host_dep = unneeded_dep
627 if need_win_dispmanx != 'no'
628
629   # Try pkg-config for bcm_host then fallback to find_library to also
630   # support older distribution
631   bcm_host_dep = dependency('bcm_host', required : false)
632   if not bcm_host_dep.found()
633     bcm_host_dep = cc.find_library('bcm_host', required : false)
634   endif
635
636   if bcm_host_dep.found()
637     if not egl_dep.found()
638       error('dispmanx requires the use of egl')
639     endif
640
641     gl_sources += [
642       'dispmanx/gstglwindow_dispmanx_egl.c'
643     ]
644
645     glconf.set('GST_GL_HAVE_WINDOW_DISPMANX', 1)
646     gl_winsys_deps += bcm_host_dep
647     enabled_gl_winsys += 'dispmanx'
648     gl_cpp_args += ['-DUSE_EGL_RPI']
649   elif need_win_dispmanx == 'yes'
650     error('Could not find dispmanx libraries')
651   endif
652 endif
653
654 # win32 checks
655 if need_platform_wgl == 'yes'
656   if need_win_win32 == 'no'
657     error('Impossible situation requested: Cannot use WGL without the win32 window system')
658   endif
659 endif
660
661 if need_platform_wgl != 'no' and need_win_win32 != 'no'
662   gdi_dep = cc.find_library('gdi32', required : false)
663   wglext_h = cc.has_header('GL/wglext.h',
664                            prefix : '''#include <windows.h>
665                                        #include <GL/gl.h>''',
666                            include_directories : compat_includes)
667
668   if wglext_h and gdi_dep.found() and gl_dep.found()
669     gl_includes += [compat_includes]
670     gl_platform_deps += gdi_dep
671     gl_sources += [
672       'win32/gstglwindow_win32.c',
673       'win32/gstglwindow_win32.c',
674       'wgl/gstglcontext_wgl.c',
675     ]
676     enabled_gl_winsys += 'win32'
677     gl_winsys_deps += gdi_dep
678     enabled_gl_platforms += 'wgl'
679     glconf.set('GST_GL_HAVE_WINDOW_WIN32', 1)
680     glconf.set('GST_GL_HAVE_PLATFORM_WGL', 1)
681   endif
682 endif
683
684 # WinRT ANGLE checks
685 if need_win_winrt != 'no' and host_system == 'windows'
686   if need_win_winrt == 'yes' and not enabled_gl_platforms.contains('egl')
687     error('Impossible situation requested: Cannot use WinRT ANGLE without EGL support')
688   endif
689
690   if egl_dep.found()
691     windows_graphics_h = cc.has_header('windows.graphics.h')
692     windows_app_dep = cc.find_library('WindowsApp', required: false)
693
694     if windows_graphics_h and windows_app_dep.found()
695       enabled_gl_winsys += 'winrt'
696       glconf.set10('GST_GL_HAVE_WINDOW_WINRT', 1)
697       gl_sources += [
698         'winrt/gstglwindow_winrt_egl.c'
699       ]
700     elif need_win_winrt == 'yes'
701       error('WinRT is enabled, but headers/libraries were not found')
702     endif
703   elif need_win_winrt == 'yes'
704     error('WinRT ANGLE is enabled, but EGL was not found')
705   else
706     message('WinRT ANGLE disabled because EGL was not found')
707   endif
708 endif
709
710 if ['darwin', 'ios'].contains(host_system)
711   if not have_objc
712     error('No ObjC compiler found')
713   endif
714
715   objc = meson.get_compiler('objc')
716   if not objc.has_argument('-fobjc-arc')
717     error('ARC is required for building')
718   endif
719
720   gl_objc_args += ['-fobjc-arc']
721 endif
722
723 # OSX check
724 if need_platform_cgl == 'yes'
725   if need_win_cocoa == 'no'
726     error('Impossible situation requested: Cannot use CGL without Cocoa support')
727   elif need_api_opengl == 'no'
728     error('Impossible situation requested: Cannot use CGL without the OpenGL library')
729   endif
730 elif need_platform_cgl == 'no' and need_win_cocoa == 'yes'
731   error('Impossible situation requested: Cannot use Cocoa without CGL support')
732 endif
733
734 if host_system == 'darwin'
735   foundation_dep = dependency('appleframeworks', modules : ['Foundation'], required : false)
736   quartzcore_dep = dependency('appleframeworks', modules : ['QuartzCore'], required : false)
737   corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required : false)
738
739   if need_platform_cgl != 'no'
740     if foundation_dep.found() and quartzcore_dep.found() and corefoundation_dep.found()
741       gl_platform_deps += [quartzcore_dep, corefoundation_dep, foundation_dep]
742       enabled_gl_platforms += 'cgl'
743       glconf.set10('GST_GL_HAVE_PLATFORM_CGL', 1)
744
745       if need_win_cocoa != 'no'
746         cocoa_dep = dependency('appleframeworks', modules : ['Cocoa'], required : false)
747         if cocoa_dep.found()
748           gl_sources += [
749             'cocoa/gstglcaopengllayer.m',
750             'cocoa/gstglcontext_cocoa.m',
751             'cocoa/gstgldisplay_cocoa.m',
752             'cocoa/gstglwindow_cocoa.m'
753           ]
754           gl_winsys_deps += cocoa_dep
755           enabled_gl_winsys += 'cocoa'
756           glconf.set10('GST_GL_HAVE_WINDOW_COCOA', 1)
757         elif need_win_cocoa == 'yes'
758           error('Could not find Cocoa')
759         endif
760       endif
761     elif need_platform_cgl == 'yes'
762       error('Could not find CGL dependencies')
763     endif
764   endif
765 endif
766
767 if need_platform_eagl == 'yes'
768   if host_system != 'ios'
769     error('Can only use EAGL on iOS')
770   endif
771   if need_win_eagl == 'no'
772     error('Impossible situation requested: Cannot use EAGL platform without the EAGL window system')
773   elif need_api_gles == 'no'
774     error('Impossible situation requested: Cannot use EAGL platform without the GLES library')
775   endif
776 elif need_platform_eagl == 'no' and need_win_eagl == 'yes'
777   error('Impossible situation requested: Cannot use EAGL window system without the EAGL platform')
778 endif
779
780 if host_system == 'ios' and need_platform_eagl != 'no' and need_win_eagl != 'no'
781   foundation_dep = dependency('appleframeworks', modules : ['Foundation'], required : false)
782   corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required : false)
783   coregraphics_dep = dependency('appleframeworks', modules : ['CoreGraphics'], required : false)
784   uikit_dep = dependency('appleframeworks', modules : ['UIkit'], required : false)
785
786   if foundation_dep.found() and corefoundation_dep.found() and coregraphics_dep.found() and uikit_dep.found()
787     gl_platform_deps += [
788       corefoundation_dep,
789       foundation_dep,
790       coregraphics_dep,
791       uikit_dep,
792     ]
793     gl_sources += [
794       'eagl/gstglcontext_eagl.m',
795       'eagl/gstglwindow_eagl.m',
796     ]
797     enabled_gl_winsys += 'eagl'
798     enabled_gl_platforms += 'eagl'
799     glconf.set('GST_GL_HAVE_WINDOW_EAGL', 1)
800     glconf.set('GST_GL_HAVE_PLATFORM_EAGL', 1)
801   elif need_platform_eagl == 'yes' or need_win_eagl == 'yes'
802     error('Could not find dependencies for EAGL')
803   endif
804 endif
805
806 # GBM Checks
807 gbm_gudev_dep = unneeded_dep
808 gbm_libdrm_dep = unneeded_dep
809 gbm_dep = unneeded_dep
810 if need_win_gbm != 'no'
811   if need_win_gbm == 'yes'
812     if need_platform_egl == 'no'
813       error('Impossible situation requested: Cannot use GBM without EGL support')
814     endif
815   endif
816
817   gbm_gudev_dep = dependency('gudev-1.0', version : '>=147', required : false)
818   gbm_libdrm_dep = dependency('libdrm', version : '>= 2.4.55', required : false)
819   gbm_dep = dependency('gbm', required : false)
820   if egl_dep.found() and gbm_gudev_dep.found() and gbm_libdrm_dep.found() and gbm_dep.found()
821     gl_sources += [
822       'gbm/gstgldisplay_gbm.c',
823       'gbm/gstgl_gbm_utils.c',
824       'gbm/gstglwindow_gbm_egl.c',
825     ]
826     enabled_gl_winsys += 'gbm'
827     gl_winsys_deps += [gbm_gudev_dep, gbm_libdrm_dep, gbm_dep]
828     glconf.set('GST_GL_HAVE_WINDOW_GBM', 1)
829   else
830     if need_win_gbm == 'yes'
831       error ('Could not find requested GBM libraries')
832     endif
833     gbm_gudev_dep = unneeded_dep
834     gbm_libdrm_dep = unneeded_dep
835     gbm_dep = unneeded_dep
836   endif
837 endif
838
839 if need_platform_egl != 'no' and need_win_viv_fb != 'no'
840   if egl_dep.found() and cc.has_function ('fbGetDisplay', dependencies : egl_dep)
841     if cc.has_function ('glTexDirectVIV', dependencies : gles2_dep)
842       enabled_gl_winsys += 'viv-fb'
843       glconf.set10('GST_GL_HAVE_WINDOW_VIV_FB', 1)
844       glconf.set10('GST_GL_HAVE_VIV_DIRECTVIV', 1)
845       gl_sources += [
846         'viv-fb/gstgldisplay_viv_fb.c',
847         'viv-fb/gstglwindow_viv_fb_egl.c',
848       ]
849       gl_cpp_args += ['-DEGL_API_FB']
850     endif
851   endif
852 endif
853
854 if need_win_android == 'yes'
855   if need_platform_egl == 'no'
856     error('Impossible situation requested: Cannot build for Android without EGL')
857   elif need_api_gles2 == 'no'
858     error('Impossible situation requested: Cannot build for Android without GLES2 support')
859   elif host_system != 'android'
860     error('Impossible situation requested: Cannot build for Android without an android system')
861   endif
862 endif
863
864 if host_system == 'android' and need_win_android != 'no' and need_platform_egl != 'no'
865   if gles2_dep.found() and egl_dep.found()
866     enabled_gl_winsys += ['android']
867     glconf.set10('GST_GL_HAVE_WINDOW_ANDROID', 1)
868     gl_sources += [
869       'android/gstglwindow_android_egl.c'
870     ]
871   endif
872 endif
873
874 # TODO: Add rest of gl config here.
875 # iOS, specific support
876
877 build_gstgl = true
878 if enabled_gl_apis.length() == 0
879   message('No OpenGL API libraries found or requested')
880   build_gstgl = false
881 endif
882 if enabled_gl_platforms.length() == 0
883   message('No OpenGL Platforms found or requested')
884   build_gstgl = false
885 endif
886 if enabled_gl_winsys.length() == 0
887   message('No OpenGL Window systems found or requested')
888   build_gstgl = false
889 endif
890
891 if build_gstgl
892   # find some types that may or may not be defined
893   if cc.has_type('GLeglImageOES', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
894     glconf.set('GST_GL_HAVE_GLEGLIMAGEOES', 1)
895   endif
896   if cc.has_type('GLchar', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
897     glconf.set('GST_GL_HAVE_GLCHAR', 1)
898   endif
899   if cc.has_type('GLsizeiptr', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
900     glconf.set('GST_GL_HAVE_GLSIZEIPTR', 1)
901   endif
902   if cc.has_type('GLintptr', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
903     glconf.set('GST_GL_HAVE_GLINTPTR', 1)
904   endif
905   if cc.has_type('GLsync', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
906     glconf.set('GST_GL_HAVE_GLSYNC', 1)
907   endif
908   if cc.has_type('GLuint64', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
909     glconf.set('GST_GL_HAVE_GLUINT64', 1)
910   endif
911   if cc.has_type('GLint64', prefix : gl_include_block, dependencies : gl_lib_deps, include_directories : gl_includes)
912     glconf.set('GST_GL_HAVE_GLINT64', 1)
913   endif
914   if egl_dep.found() and cc.has_type('EGLAttrib', prefix : gl_include_block + egl_includes, dependencies : gl_lib_deps + [egl_dep], include_directories : gl_includes)
915     glconf.set('GST_GL_HAVE_EGLATTRIB', 1)
916   endif
917   if egl_dep.found() and cc.has_type('EGLuint64KHR', prefix : gl_include_block + egl_includes, dependencies : gl_lib_deps + [egl_dep], include_directories : gl_includes)
918     glconf.set('GST_GL_HAVE_EGLUINT64KHR', 1)
919   endif
920
921   message('Building libgstgl with GL api:      ' + ' '.join(enabled_gl_apis))
922   message('Building libgstgl with GL platform: ' + ' '.join(enabled_gl_platforms))
923   message('Building libgstgl with GL winsys:   ' + ' '.join(enabled_gl_winsys))
924
925   install_headers(gl_headers, subdir : 'gstreamer-1.0/gst/gl')
926   install_headers(gl_cocoa_headers, subdir : 'gstreamer-1.0/gst/gl/cocoa')
927   install_headers(gl_egl_headers, subdir : 'gstreamer-1.0/gst/gl/egl')
928   install_headers(gl_prototype_headers, subdir : 'gstreamer-1.0/gst/gl/glprototypes')
929   install_headers(gl_x11_headers, subdir : 'gstreamer-1.0/gst/gl/x11')
930   install_headers(gl_wayland_headers, subdir : 'gstreamer-1.0/gst/gl/wayland')
931
932   configure_file(input : 'gstglconfig.h.meson',
933     output : 'gstglconfig.h',
934     install_dir : get_option('libdir') + '/gstreamer-1.0/include/gst/gl',
935     configuration : glconf)
936
937   gl_enums = gnome.mkenums_simple('gl-enumtypes',
938     sources : gir_gl_headers,
939     body_prefix : '#ifdef HAVE_CONFIG_H\n#include "config.h"\n#endif',
940     header_prefix : '#include <gst/gl/gl-prelude.h>',
941     decorator : 'GST_GL_API',
942     install_header: true,
943     install_dir : join_paths(get_option('includedir'), 'gstreamer-1.0/gst/gl'))
944   gl_enumtypes_c = gl_enums[0]
945   gl_enumtypes_h = gl_enums[1]
946   gen_sources = [gl_enumtypes_h]
947
948   gstgl = library('gstgl-' + api_version,
949     gl_sources, gl_priv_sources, gl_enumtypes_c, gl_enumtypes_h,
950     c_args : gst_plugins_base_args + gl_cpp_args + ['-DBUILDING_GST_GL'],
951     objc_args : gst_plugins_base_args + gl_cpp_args + gl_objc_args + ['-DBUILDING_GST_GL'],
952     include_directories : [configinc, libsinc, gl_includes],
953     version : libversion,
954     soversion : soversion,
955   darwin_versions : osxversion,
956     install : true,
957     dependencies : [gst_base_dep, video_dep, allocators_dep, gmodule_dep,
958                     gl_lib_deps, gl_platform_deps, gl_winsys_deps, gl_misc_deps])
959   if build_gir
960     gl_gir = gnome.generate_gir(gstgl,
961       sources : gl_sources + [gl_enumtypes_h] + [gl_enumtypes_c] + gir_gl_headers + gl_x11_headers + gl_wayland_headers + gl_win32_headers + gl_cocoa_headers + gl_egl_headers,
962       namespace : 'GstGL',
963       nsversion : api_version,
964       identifier_prefix : 'Gst',
965       symbol_prefix : 'gst',
966       export_packages : 'gstreamer-gl-1.0',
967       includes : ['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0'],
968       install : true,
969       extra_args : gir_init_section + ['--c-include=gst/gl/gl.h'],
970       dependencies : [video_dep, gst_dep, gst_base_dep]
971     )
972     gen_sources += gl_gir
973   endif
974
975
976   gstgl_dep = declare_dependency(link_with : gstgl,
977     include_directories : [libsinc, compat_includes],
978     sources: gen_sources,
979     dependencies : [video_dep, gst_base_dep] + gl_winsys_deps)
980
981 elif get_option('gl').enabled()
982   error('GStreamer OpenGL integration required via options, but needed dependencies not found.')
983 else
984   gstgl_dep = dependency('', required : false)
985 endif