Don't assume output dir + "../.." == src/ in ui/gl/generate_bindings.py
[chromium-blink-merge.git] / ui / gl / BUILD.gn
blob98c03963022edb642fe04f9ebd8bf11f2ffdcd7a
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("//build/config/ui.gni")
6 if (is_android) {
7   import("//build/config/android/rules.gni")
10 gl_binding_output_dir = target_gen_dir
12 config("gl_config") {
13   if (use_x11) {
14     defines = [ "GL_GLEXT_PROTOTYPES" ]
15   }
17   # TODO(brettw) this should be removed and the the files using the generated
18   # GL bindings should use the path inside the gen directory.
19   include_dirs = [ gl_binding_output_dir ]
22 component("gl") {
23   output_name = "gl_wrapper"  # Avoid colliding with OS X"s libGL.dylib.
25   sources = [
26     "android/gl_jni_registrar.cc",
27     "android/gl_jni_registrar.h",
28     "android/scoped_java_surface.cc",
29     "android/scoped_java_surface.h",
30     "android/surface_texture.cc",
31     "android/surface_texture.h",
32     "android/surface_texture_listener.cc",
33     "android/surface_texture_listener.h",
34     "android/surface_texture_tracker.cc",
35     "android/surface_texture_tracker.h",
36     "gl_bindings.h",
37     "gl_bindings_skia_in_process.cc",
38     "gl_bindings_skia_in_process.h",
39     "gl_context.cc",
40     "gl_context.h",
41     "gl_context_android.cc",
42     "gl_context_mac.mm",
43     "gl_context_osmesa.cc",
44     "gl_context_osmesa.h",
45     "gl_context_stub.cc",
46     "gl_context_stub.h",
47     "gl_context_stub_with_extensions.cc",
48     "gl_context_stub_with_extensions.h",
49     "gl_context_win.cc",
50     "gl_export.h",
51     "gl_fence.cc",
52     "gl_fence.h",
53     "gl_gl_api_implementation.cc",
54     "gl_gl_api_implementation.h",
55     "gl_image.cc",
56     "gl_image.h",
57     "gl_image_android.cc",
58     "gl_image_mac.cc",
59     "gl_image_shm.cc",
60     "gl_image_shm.h",
61     "gl_image_stub.cc",
62     "gl_image_stub.h",
63     "gl_image_win.cc",
64     "gl_implementation.cc",
65     "gl_implementation.h",
66     "gl_implementation_android.cc",
67     "gl_implementation_mac.cc",
68     "gl_implementation_win.cc",
69     "gl_osmesa_api_implementation.cc",
70     "gl_osmesa_api_implementation.h",
71     "gl_share_group.cc",
72     "gl_share_group.h",
73     "gl_state_restorer.cc",
74     "gl_state_restorer.h",
75     "gl_surface.cc",
76     "gl_surface.h",
77     "gl_surface_android.cc",
78     "gl_surface_mac.cc",
79     "gl_surface_stub.cc",
80     "gl_surface_stub.h",
81     "gl_surface_win.cc",
82     "gl_surface_osmesa.cc",
83     "gl_surface_osmesa.h",
84     "gl_switches.cc",
85     "gl_switches.h",
86     "gl_version_info.cc",
87     "gl_version_info.h",
88     "gpu_switching_manager.cc",
89     "gpu_switching_manager.h",
90     "scoped_binders.cc",
91     "scoped_binders.h",
92     "scoped_make_current.cc",
93     "scoped_make_current.h",
94     "sync_control_vsync_provider.cc",
95     "sync_control_vsync_provider.h",
96     "$gl_binding_output_dir/gl_bindings_autogen_gl.cc",
97     "$gl_binding_output_dir/gl_bindings_autogen_gl.h",
98     "$gl_binding_output_dir/gl_bindings_autogen_osmesa.cc",
99     "$gl_binding_output_dir/gl_bindings_autogen_osmesa.h",
100   ]
102   defines = [ "GL_IMPLEMENTATION" ]
104   include_dirs = [
105     "//third_party/switfshader/include",
106     "//third_party/khronos",
107     "//third_party/mesa/src/include",
108     gl_binding_output_dir,
109   ]
111   all_dependent_configs = [ ":gl_config" ]
113   deps = [
114     ":generate_gl_bindings",
115     "//base",
116     "//base/third_party/dynamic_annotations",
117     "//gpu/command_buffer/common",
118     "//third_party/mesa:mesa_headers",
119     "//skia",
120     "//ui/events/platform",
121     "//ui/gfx",
122     "//ui/gfx/geometry",
123   ]
125   # TODO(GYP) hook up once this is converted.
126   forward_dependent_configs_from = [ "//third_party/mesa:mesa_headers" ]
128   if (is_win || is_android || is_linux) {
129     sources += [
130       "egl_util.cc",
131       "egl_util.h",
132       "gl_context_egl.cc",
133       "gl_context_egl.h",
134       "gl_image_egl.cc",
135       "gl_image_egl.h",
136       "gl_surface_egl.cc",
137       "gl_surface_egl.h",
138       "$gl_binding_output_dir/gl_bindings_autogen_egl.cc",
139       "$gl_binding_output_dir/gl_bindings_autogen_egl.h",
140     ]
141   }
142   if (is_android || is_linux) {
143     sources += [
144       "gl_implementation_osmesa.cc",
145       "gl_implementation_osmesa.h",
146     ]
147   }
148   if (use_x11) {
149     sources += [
150       "gl_context_glx.cc",
151       "gl_context_glx.h",
152       "gl_context_x11.cc",
153       "gl_glx_api_implementation.cc",
154       "gl_glx_api_implementation.h",
155       "gl_image_glx.cc",
156       "gl_image_glx.h",
157       "gl_image_x11.cc",
158       "gl_implementation_x11.cc",
159       "gl_surface_glx.cc",
160       "gl_surface_glx.h",
161       "gl_surface_x11.cc",
162       "gl_egl_api_implementation.cc",
163       "gl_egl_api_implementation.h",
164       "$gl_binding_output_dir/gl_bindings_autogen_glx.cc",
165       "$gl_binding_output_dir/gl_bindings_autogen_glx.h",
166     ]
168     configs += [
169       "//build/config/linux:x11",
170       "//build/config/linux:xcomposite",
171       "//build/config/linux:xext",
172     ]
174     deps += [
175       "//ui/gfx:gfx_x11",
176     ]
177   }
178   if (is_win) {
179     sources += [
180       "gl_context_wgl.cc",
181       "gl_context_wgl.h",
182       "gl_egl_api_implementation.cc",
183       "gl_egl_api_implementation.h",
184       "gl_surface_wgl.cc",
185       "gl_surface_wgl.h",
186       "gl_wgl_api_implementation.cc",
187       "gl_wgl_api_implementation.h",
188       "$gl_binding_output_dir/gl_bindings_autogen_wgl.cc",
189       "$gl_binding_output_dir/gl_bindings_autogen_wgl.h",
190     ]
192     libs = [ "dwmapi.lib" ]
193     ldflags = [ "/DELAYLOAD:dwmapi.dll" ]
194   }
195   if (is_mac) {
196     sources += [
197       "gl_context_cgl.cc",
198       "gl_context_cgl.h",
199       "gl_image_io_surface.cc",
200       "gl_image_io_surface.h",
201       "gl_surface_cgl.cc",
202       "gl_surface_cgl.h",
203       "scoped_cgl.cc",
204       "scoped_cgl.h",
205     ]
207     libs = [ "OpenGL.framework" ]
208   }
209   if (is_android) {
210     sources += [
211       "gl_egl_api_implementation.cc",
212       "gl_egl_api_implementation.h",
213       "gl_image_android_native_buffer.cc",
214       "gl_image_android_native_buffer.h",
215       "gl_image_surface_texture.cc",
216       "gl_image_surface_texture.h",
217     ]
219     defines += [
220       "GL_GLEXT_PROTOTYPES",
221       "EGL_EGLEXT_PROTOTYPES",
222     ]
224     libs = [ "android" ]
226     deps += [
227       ":gl_jni_headers",
228     ]
229   }
230   if (use_ozone) {
231     sources += [
232       "gl_context_ozone.cc",
233       "gl_image_ozone.cc",
234       "gl_implementation_ozone.cc",
235       "gl_surface_ozone.cc",
236     ]
237     deps += [
238       "//ui/gfx/ozone",
239       "//ui/ozone",
240     ]
241   }
243   # TODO(GYP) enable this dependency once its written.
244   #if (is_android && !android_webview_build) {
245   #  deps += [ "//ui/android:ui_java" ]
246   #}
249 action("generate_gl_bindings") {
250   visibility = ":*"  # Only targets in this file can see this.
252   script = "generate_bindings.py"
254   # TODO(brettw) make this dynamic. The GYP version calls "generate_bindings.py
255   # --inputs" to get the list here. What should happen is that the script
256   # should generate a .d file, which we should declare here. That will
257   # eliminate the need bot both hardcoding the list here or calling the script
258   # during GN-time.
259   source_prereqs = [
260     "EGL/eglextchromium.h",
261     "GL/glextchromium.h",
262     "//third_party/mesa/src/include/GL/glext.h",
263     "//third_party/khronos/GLES2/gl2ext.h",
264     "//gpu/GLES2/gl2chromium.h",
265     "//gpu/GLES2/gl2extchromium.h",
266     "//third_party/khronos/EGL/eglext.h",
267     "//third_party/mesa/src/include/GL/wglext.h",
268     "//third_party/mesa/src/include/GL/glx.h",
269     "//third_party/mesa/src/include/GL/glxext.h",
270   ]
272   outputs = [
273     "$gl_binding_output_dir/gl_bindings_autogen_egl.cc",
274     "$gl_binding_output_dir/gl_bindings_autogen_egl.h",
275     "$gl_binding_output_dir/gl_bindings_api_autogen_egl.h",
276     "$gl_binding_output_dir/gl_bindings_autogen_gl.cc",
277     "$gl_binding_output_dir/gl_bindings_autogen_gl.h",
278     "$gl_binding_output_dir/gl_bindings_api_autogen_gl.h",
279     "$gl_binding_output_dir/gl_bindings_autogen_glx.cc",
280     "$gl_binding_output_dir/gl_bindings_autogen_glx.h",
281     "$gl_binding_output_dir/gl_bindings_api_autogen_glx.h",
282     "$gl_binding_output_dir/gl_bindings_autogen_mock.cc",
283     "$gl_binding_output_dir/gl_bindings_autogen_mock.h",
284     "$gl_binding_output_dir/gl_bindings_autogen_osmesa.cc",
285     "$gl_binding_output_dir/gl_bindings_autogen_osmesa.h",
286     "$gl_binding_output_dir/gl_bindings_api_autogen_osmesa.h",
287     "$gl_binding_output_dir/gl_bindings_autogen_wgl.cc",
288     "$gl_binding_output_dir/gl_bindings_autogen_wgl.h",
289     "$gl_binding_output_dir/gl_bindings_api_autogen_wgl.h",
290     "$gl_binding_output_dir/gl_mock_autogen_gl.h",
291   ]
293   args = [
294     "--header-paths=" +
295         rebase_path("//third_party/khronos", root_build_dir) + ":" +
296         rebase_path("//third_party/mesa/src/include", root_build_dir) + ":" +
297         rebase_path("//ui/gl", root_build_dir) + ":" +
298         rebase_path("//gpu", root_build_dir),
299     rebase_path(gl_binding_output_dir, root_build_dir),
300   ]
303 config("gl_unittest_utils_config") {
304   include_dirs = [ gl_binding_output_dir ]
307 source_set("gl_unittest_utils") {
308   sources = [
309     "gl_mock.h",
310     "gl_mock.cc",
311     "$gl_binding_output_dir/gl_bindings_autogen_mock.cc",
312     "$gl_binding_output_dir/gl_bindings_autogen_mock.h",
313     "$gl_binding_output_dir/gl_mock_autogen_gl.h",
314   ]
316   configs += [ "//third_party/khronos:khronos_headers" ]
317   direct_dependent_configs = [ ":gl_unittest_utils_config" ]
319   deps = [
320     ":gl",
321     "//testing/gmock",
322   ]
325 if (is_android) {
326   generate_jar_jni("surface_jni_headers") {
327     jni_package = "ui/gl"
328     classes = [ "android/view/Surface.class" ]
329   }
331   generate_jni("gl_jni_headers") {
332     deps = [ ":surface_jni_headers" ]
333     forward_dependent_configs_from = [ ":surface_jni_headers" ]
334     sources = [
335       "../android/java/src/org/chromium/ui/gl/SurfaceTextureListener.java",
336       "../android/java/src/org/chromium/ui/gl/SurfaceTexturePlatformWrapper.java",
337     ]
338     jni_package = "ui/gl"
339   }