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