xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/BUILD.gn (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
2#
3# Use of this source code is governed by a BSD-style license
4# that can be found in the LICENSE file in the root of the source
5# tree. An additional intellectual property rights grant can be found
6# in the file PATENTS.  All contributing project authors may
7# be found in the AUTHORS file in the root of the source tree.
8
9import("//build/config/linux/gtk/gtk.gni")
10import("//build/config/ui.gni")
11import("../../webrtc.gni")
12
13use_desktop_capture_differ_sse2 = current_cpu == "x86" || current_cpu == "x64"
14
15config("x11_config") {
16  if (rtc_use_x11_extensions) {
17    defines = [ "WEBRTC_USE_X11" ]
18  }
19}
20
21rtc_library("primitives") {
22  visibility = [ "*" ]
23  sources = [
24    "desktop_capture_types.h",
25    "desktop_frame.cc",
26    "desktop_frame.h",
27    "desktop_geometry.cc",
28    "desktop_geometry.h",
29    "desktop_region.cc",
30    "desktop_region.h",
31    "shared_desktop_frame.cc",
32    "shared_desktop_frame.h",
33    "shared_memory.cc",
34    "shared_memory.h",
35  ]
36
37  deps = [
38    "../../api:scoped_refptr",
39    "../../rtc_base:checks",
40    "../../rtc_base:refcount",
41    "../../rtc_base/system:rtc_export",
42    "//third_party/libyuv",
43  ]
44
45  if (!build_with_mozilla) {
46    deps += [ "../../rtc_base" ]  # TODO(kjellander): Cleanup in
47                                  # bugs.webrtc.org/3806.
48  }
49}
50
51if (rtc_include_tests) {
52  rtc_library("desktop_capture_modules_tests") {
53    testonly = true
54
55    defines = []
56    sources = []
57    deps = [
58      ":desktop_capture",
59      "../../api:function_view",
60      "../../api:scoped_refptr",
61      "../../rtc_base:checks",
62      "../../rtc_base:logging",
63      "../../rtc_base:platform_thread",
64      "../../rtc_base:random",
65      "../../rtc_base:timeutils",
66    ]
67    if (rtc_desktop_capture_supported) {
68      deps += [
69        ":desktop_capture_mock",
70        ":primitives",
71        ":screen_drawer",
72        "../../rtc_base",
73        "../../rtc_base/third_party/base64",
74        "../../system_wrappers",
75        "../../test:test_support",
76        "../../test:video_test_support",
77      ]
78      sources += [
79        "screen_capturer_integration_test.cc",
80        "screen_drawer_unittest.cc",
81        "window_finder_unittest.cc",
82      ]
83
84      if ((is_linux || is_chromeos) && rtc_use_pipewire) {
85        configs += [ "../portal:gio" ]
86      }
87
88      public_configs = [ ":x11_config" ]
89
90      if (is_win) {
91        deps += [ "../../rtc_base/win:windows_version" ]
92      }
93    }
94  }
95
96  if ((is_linux || is_chromeos) && rtc_use_pipewire) {
97    rtc_test("shared_screencast_stream_test") {
98      testonly = true
99
100      sources = [
101        "linux/wayland/shared_screencast_stream_unittest.cc",
102        "linux/wayland/test/test_screencast_stream_provider.cc",
103        "linux/wayland/test/test_screencast_stream_provider.h",
104      ]
105
106      configs += [ "../portal:pipewire_all" ]
107
108      deps = [
109        ":desktop_capture",
110        ":desktop_capture_mock",
111        ":primitives",
112        "../../rtc_base:checks",
113        "../../rtc_base:logging",
114        "../../rtc_base:random",
115        "../../rtc_base:timeutils",
116        "../portal",
117
118        # TODO(bugs.webrtc.org/9987): Remove this dep on rtc_base:rtc_base once
119        # rtc_base:threading is fully defined.
120        "../../rtc_base:rtc_base",
121        "../../rtc_base:task_queue_for_test",
122        "../../rtc_base:threading",
123        "../../system_wrappers",
124        "../../test:test_main",
125        "../../test:test_support",
126        "//api/units:time_delta",
127        "//rtc_base:rtc_event",
128      ]
129
130      data = [ "../../third_party/pipewire" ]
131      public_configs = [ "../portal:pipewire_config" ]
132    }
133  }
134
135  rtc_library("desktop_capture_unittests") {
136    testonly = true
137
138    defines = []
139    sources = [
140      "blank_detector_desktop_capturer_wrapper_unittest.cc",
141      "cropped_desktop_frame_unittest.cc",
142      "desktop_and_cursor_composer_unittest.cc",
143      "desktop_capturer_differ_wrapper_unittest.cc",
144      "desktop_frame_rotation_unittest.cc",
145      "desktop_frame_unittest.cc",
146      "desktop_geometry_unittest.cc",
147      "desktop_region_unittest.cc",
148      "differ_block_unittest.cc",
149      "fallback_desktop_capturer_wrapper_unittest.cc",
150      "mouse_cursor_monitor_unittest.cc",
151      "rgba_color_unittest.cc",
152      "test_utils.cc",
153      "test_utils.h",
154      "test_utils_unittest.cc",
155    ]
156
157    if ((is_linux || is_chromeos) && rtc_use_pipewire) {
158      configs += [ "../portal:gio" ]
159    }
160
161    deps = [
162      ":desktop_capture",
163      ":desktop_capture_mock",
164      ":primitives",
165      "../../rtc_base:checks",
166      "../../rtc_base:logging",
167      "../../rtc_base:macromagic",
168      "../../rtc_base:random",
169      "../../rtc_base:timeutils",
170
171      # TODO(bugs.webrtc.org/9987): Remove this dep on rtc_base:rtc_base once
172      # rtc_base:threading is fully defined.
173      "../../rtc_base:rtc_base",
174      "../../rtc_base:task_queue_for_test",
175      "../../rtc_base:threading",
176      "../../system_wrappers",
177      "../../test:test_support",
178    ]
179
180    if (is_win) {
181      sources += [
182        "win/cursor_unittest.cc",
183        "win/cursor_unittest_resources.h",
184        "win/cursor_unittest_resources.rc",
185        "win/screen_capture_utils_unittest.cc",
186        "win/screen_capturer_win_directx_unittest.cc",
187        "win/test_support/test_window.cc",
188        "win/test_support/test_window.h",
189        "win/window_capture_utils_unittest.cc",
190      ]
191      deps += [
192        "../../rtc_base/win:scoped_com_initializer",
193        "../../rtc_base/win:windows_version",
194      ]
195    }
196
197    if (rtc_desktop_capture_supported) {
198      sources += [
199        "screen_capturer_helper_unittest.cc",
200        "screen_capturer_unittest.cc",
201        "window_capturer_unittest.cc",
202      ]
203      if (is_mac) {
204        sources += [ "screen_capturer_mac_unittest.cc" ]
205      }
206      if (rtc_enable_win_wgc) {
207        sources += [
208          "win/wgc_capture_source_unittest.cc",
209          "win/wgc_capturer_win_unittest.cc",
210        ]
211      }
212      deps += [
213        ":desktop_capture_mock",
214        "../../system_wrappers:metrics",
215      ]
216      public_configs = [ ":x11_config" ]
217    }
218  }
219
220  rtc_library("screen_drawer") {
221    testonly = true
222
223    sources = [
224      "screen_drawer.cc",
225      "screen_drawer.h",
226    ]
227
228    if (is_linux || is_chromeos) {
229      sources += [ "screen_drawer_linux.cc" ]
230      libs = [ "X11" ]
231    }
232
233    if (is_mac) {
234      sources += [ "screen_drawer_mac.cc" ]
235    }
236
237    if (is_win) {
238      sources += [ "screen_drawer_win.cc" ]
239    }
240
241    deps = [
242      ":desktop_capture",
243      ":primitives",
244      "../../api:scoped_refptr",
245      "../../rtc_base:checks",
246      "../../rtc_base:logging",
247      "../../system_wrappers",
248    ]
249    absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
250
251    if (is_posix || is_fuchsia) {
252      sources += [
253        "screen_drawer_lock_posix.cc",
254        "screen_drawer_lock_posix.h",
255      ]
256    }
257  }
258
259  rtc_library("desktop_capture_mock") {
260    testonly = true
261
262    sources = [
263      "mock_desktop_capturer_callback.cc",
264      "mock_desktop_capturer_callback.h",
265    ]
266
267    if ((is_linux || is_chromeos) && rtc_use_pipewire) {
268      configs += [ "../portal:gio" ]
269    }
270
271    deps = [
272      ":desktop_capture",
273      ":primitives",
274      "../../test:test_support",
275    ]
276  }
277}
278
279# TODO(bugs.webrtc.org/14187): remove when all users are gone
280if ((is_linux || is_chromeos) && rtc_use_pipewire) {
281  config("pipewire_config") {
282    configs = [ "../portal:pipewire_config" ]
283  }
284}
285
286rtc_library("desktop_capture") {
287  visibility = [ "*" ]
288  defines = []
289  deps = []
290  public_configs = [ ":x11_config" ]
291  sources = [
292    "blank_detector_desktop_capturer_wrapper.cc",
293    "blank_detector_desktop_capturer_wrapper.h",
294    "cropped_desktop_frame.cc",
295    "cropped_desktop_frame.h",
296    "cropping_window_capturer.cc",
297    "cropping_window_capturer.h",
298    "delegated_source_list_controller.h",
299    "desktop_and_cursor_composer.cc",
300    "desktop_and_cursor_composer.h",
301    "desktop_capture_metrics_helper.cc",
302    "desktop_capture_metrics_helper.h",
303    "desktop_capture_options.cc",
304    "desktop_capture_options.h",
305    "desktop_capturer.cc",
306    "desktop_capturer.h",
307    "desktop_capturer_differ_wrapper.cc",
308    "desktop_capturer_differ_wrapper.h",
309    "desktop_capturer_wrapper.cc",
310    "desktop_capturer_wrapper.h",
311    "desktop_frame_generator.cc",
312    "desktop_frame_generator.h",
313    "desktop_frame_rotation.cc",
314    "desktop_frame_rotation.h",
315    "differ_block.cc",
316    "differ_block.h",
317    "fake_desktop_capturer.cc",
318    "fake_desktop_capturer.h",
319    "fallback_desktop_capturer_wrapper.cc",
320    "fallback_desktop_capturer_wrapper.h",
321    "full_screen_application_handler.cc",
322    "full_screen_application_handler.h",
323    "full_screen_window_detector.cc",
324    "full_screen_window_detector.h",
325    "mouse_cursor.cc",
326    "mouse_cursor.h",
327    "mouse_cursor_monitor.h",
328    "resolution_tracker.cc",
329    "resolution_tracker.h",
330    "rgba_color.cc",
331    "rgba_color.h",
332    "screen_capture_frame_queue.h",
333    "screen_capturer_helper.cc",
334    "screen_capturer_helper.h",
335    "window_finder.cc",
336    "window_finder.h",
337  ]
338  if (is_linux && !is_castos && rtc_use_pipewire) {
339    sources += [ "desktop_capture_metadata.h" ]
340  }
341  if (is_mac) {
342    sources += [
343      "mac/desktop_configuration.h",
344      "mac/desktop_configuration_monitor.cc",
345      "mac/desktop_configuration_monitor.h",
346      "mac/full_screen_mac_application_handler.cc",
347      "mac/full_screen_mac_application_handler.h",
348      "mac/window_list_utils.cc",
349      "mac/window_list_utils.h",
350    ]
351    deps += [ ":desktop_capture_objc" ]
352  }
353
354  if (build_with_mozilla) {
355    sources += [
356      "desktop_device_info.cc",
357      "desktop_device_info.h",
358    ]
359    if (is_win) {
360      sources += [
361        "app_capturer_win.cc",
362        "win/desktop_device_info_win.cc",
363        "win/win_shared.cc",
364      ]
365    }
366  }
367  if (rtc_use_x11_extensions || rtc_use_pipewire) {
368    sources += [
369      "mouse_cursor_monitor_linux.cc",
370      "screen_capturer_linux.cc",
371      "window_capturer_linux.cc",
372    ]
373
374    if (build_with_mozilla && (is_linux || is_chromeos)) {
375      sources += [
376        "app_capturer_linux.cc",
377        "linux/x11/app_capturer_x11.cc",
378        "linux/x11/desktop_device_info_linux.cc",
379        "linux/x11/desktop_device_info_linux.h",
380        "linux/x11/shared_x_util.cc",
381        "linux/x11/shared_x_util.h",
382      ]
383    }
384  }
385
386  if (rtc_use_x11_extensions) {
387    sources += [
388      "linux/x11/mouse_cursor_monitor_x11.cc",
389      "linux/x11/mouse_cursor_monitor_x11.h",
390      "linux/x11/screen_capturer_x11.cc",
391      "linux/x11/screen_capturer_x11.h",
392      "linux/x11/shared_x_display.cc",
393      "linux/x11/shared_x_display.h",
394      "linux/x11/window_capturer_x11.cc",
395      "linux/x11/window_capturer_x11.h",
396      "linux/x11/window_finder_x11.cc",
397      "linux/x11/window_finder_x11.h",
398      "linux/x11/window_list_utils.cc",
399      "linux/x11/window_list_utils.h",
400      "linux/x11/x_atom_cache.cc",
401      "linux/x11/x_atom_cache.h",
402      "linux/x11/x_error_trap.cc",
403      "linux/x11/x_error_trap.h",
404      "linux/x11/x_server_pixel_buffer.cc",
405      "linux/x11/x_server_pixel_buffer.h",
406      "linux/x11/x_window_property.cc",
407      "linux/x11/x_window_property.h",
408    ]
409    libs = [
410      "X11",
411      "Xcomposite",
412      "Xdamage",
413      "Xext",
414      "Xfixes",
415      "Xrender",
416      "Xrandr",
417      "Xtst",
418    ]
419  }
420
421  if (!is_win && !is_mac && !rtc_use_x11_extensions && !rtc_use_pipewire &&
422      !is_fuchsia) {
423    sources += [
424      "mouse_cursor_monitor_null.cc",
425      "screen_capturer_null.cc",
426      "window_capturer_null.cc",
427    ]
428  }
429
430  deps += [
431    ":primitives",
432    "../../api:function_view",
433    "../../api:make_ref_counted",
434    "../../api:refcountedbase",
435    "../../api:scoped_refptr",
436    "../../api:sequence_checker",
437    "../../rtc_base:checks",
438    "../../rtc_base:event_tracer",
439    "../../rtc_base:logging",
440    "../../rtc_base:macromagic",
441    "../../rtc_base:random",
442    "../../rtc_base:stringutils",
443    "../../rtc_base:timeutils",
444    "../../rtc_base/synchronization:mutex",
445    "../../rtc_base/system:arch",
446    "../../rtc_base/system:no_unique_address",
447    "../../rtc_base/system:rtc_export",
448    "../../system_wrappers",
449    "../../system_wrappers:metrics",
450  ]
451
452  if (is_fuchsia) {
453    sources += [
454      "mouse_cursor_monitor_null.cc",
455      "screen_capturer_fuchsia.cc",
456      "screen_capturer_fuchsia.h",
457      "window_capturer_null.cc",
458    ]
459    deps += [
460      "../../rtc_base:divide_round",
461      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem",
462      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.composition",
463      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.scenic",
464      "//third_party/fuchsia-sdk/sdk/pkg/scenic_cpp",
465      "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
466    ]
467  }
468
469  if (is_win) {
470    sources += [
471      "cropping_window_capturer_win.cc",
472      "desktop_frame_win.cc",
473      "desktop_frame_win.h",
474      "mouse_cursor_monitor_win.cc",
475      "screen_capturer_win.cc",
476      "win/cursor.cc",
477      "win/cursor.h",
478      "win/d3d_device.cc",
479      "win/d3d_device.h",
480      "win/desktop.cc",
481      "win/desktop.h",
482      "win/desktop_capture_utils.cc",
483      "win/desktop_capture_utils.h",
484      "win/display_configuration_monitor.cc",
485      "win/display_configuration_monitor.h",
486      "win/dxgi_adapter_duplicator.cc",
487      "win/dxgi_adapter_duplicator.h",
488      "win/dxgi_context.cc",
489      "win/dxgi_context.h",
490      "win/dxgi_duplicator_controller.cc",
491      "win/dxgi_duplicator_controller.h",
492      "win/dxgi_frame.cc",
493      "win/dxgi_frame.h",
494      "win/dxgi_output_duplicator.cc",
495      "win/dxgi_output_duplicator.h",
496      "win/dxgi_texture.cc",
497      "win/dxgi_texture.h",
498      "win/dxgi_texture_mapping.cc",
499      "win/dxgi_texture_mapping.h",
500      "win/dxgi_texture_staging.cc",
501      "win/dxgi_texture_staging.h",
502      "win/full_screen_win_application_handler.cc",
503      "win/full_screen_win_application_handler.h",
504      "win/scoped_gdi_object.h",
505      "win/scoped_thread_desktop.cc",
506      "win/scoped_thread_desktop.h",
507      "win/screen_capture_utils.cc",
508      "win/screen_capture_utils.h",
509      "win/screen_capturer_win_directx.cc",
510      "win/screen_capturer_win_directx.h",
511      "win/screen_capturer_win_gdi.cc",
512      "win/screen_capturer_win_gdi.h",
513      "win/screen_capturer_win_magnifier.cc",
514      "win/screen_capturer_win_magnifier.h",
515      "win/selected_window_context.cc",
516      "win/selected_window_context.h",
517      "win/window_capture_utils.cc",
518      "win/window_capture_utils.h",
519      "win/window_capturer_win_gdi.cc",
520      "win/window_capturer_win_gdi.h",
521      "window_capturer_win.cc",
522      "window_finder_win.cc",
523      "window_finder_win.h",
524    ]
525    libs = [
526      "d3d11.lib",
527      "dxgi.lib",
528    ]
529    deps += [
530      "../../rtc_base:win32",
531      "../../rtc_base/win:create_direct3d_device",
532      "../../rtc_base/win:get_activation_factory",
533      "../../rtc_base/win:windows_version",
534    ]
535  }
536
537  absl_deps = [
538    "//third_party/abseil-cpp/absl/memory",
539    "//third_party/abseil-cpp/absl/strings",
540    "//third_party/abseil-cpp/absl/types:optional",
541  ]
542
543  if (rtc_use_x11_extensions) {
544    deps += [ "../../rtc_base:sanitizer" ]
545  }
546
547  if (!build_with_mozilla) {
548    deps += [ "//third_party/libyuv" ]
549  }
550
551  if (use_desktop_capture_differ_sse2) {
552    deps += [ ":desktop_capture_differ_sse2" ]
553  }
554
555  if (rtc_use_pipewire) {
556    sources += [
557      "linux/wayland/base_capturer_pipewire.cc",
558      "linux/wayland/base_capturer_pipewire.h",
559      "linux/wayland/egl_dmabuf.cc",
560      "linux/wayland/egl_dmabuf.h",
561      "linux/wayland/mouse_cursor_monitor_pipewire.cc",
562      "linux/wayland/mouse_cursor_monitor_pipewire.h",
563      "linux/wayland/portal_request_response.h",
564      "linux/wayland/restore_token_manager.cc",
565      "linux/wayland/restore_token_manager.h",
566      "linux/wayland/scoped_glib.h",
567      "linux/wayland/screen_capture_portal_interface.cc",
568      "linux/wayland/screen_capture_portal_interface.h",
569      "linux/wayland/screencast_portal.cc",
570      "linux/wayland/screencast_portal.h",
571      "linux/wayland/screencast_stream_utils.cc",
572      "linux/wayland/screencast_stream_utils.h",
573      "linux/wayland/shared_screencast_stream.cc",
574      "linux/wayland/shared_screencast_stream.h",
575      "linux/wayland/xdg_desktop_portal_utils.h",
576      "linux/wayland/xdg_session_details.h",
577    ]
578
579    configs += [ "../portal:pipewire_all" ]
580
581    public_configs += [ "../portal:pipewire_config" ]
582
583    deps += [
584      "../../rtc_base:sanitizer",
585      "../portal",
586    ]
587  }
588
589  if (rtc_enable_win_wgc) {
590    sources += [
591      "win/wgc_capture_session.cc",
592      "win/wgc_capture_session.h",
593      "win/wgc_capture_source.cc",
594      "win/wgc_capture_source.h",
595      "win/wgc_capturer_win.cc",
596      "win/wgc_capturer_win.h",
597      "win/wgc_desktop_frame.cc",
598      "win/wgc_desktop_frame.h",
599    ]
600    libs += [ "dwmapi.lib" ]
601    deps += [
602      "../../rtc_base:rtc_event",
603      "../../rtc_base/win:hstring",
604    ]
605  }
606}
607
608if (is_mac) {
609  rtc_library("desktop_capture_objc") {
610    # This target, needs to be separated from ":desktop_capture" because
611    # that is the C++ part of the target while this one is the Obj-C++ part.
612    # Aside from this, both represent a "desktop_capture" target.
613    # This target separation based on programming languages introduces a
614    # dependency cycle between ":desktop_capture" and
615    # ":desktop_capture_objc".
616    # To break this, ":desktop_capture_objc" shares some .h files with
617    # ":desktop_capture" but when external targets need one of these
618    # headers, they should depend on ":desktop_capture" and consider
619    # this target as private.
620    visibility = [ ":desktop_capture" ]
621    sources = [
622      "delegated_source_list_controller.h",
623      "desktop_capture_options.h",
624      "desktop_capturer.h",
625      "full_screen_application_handler.h",
626      "full_screen_window_detector.h",
627      "mac/desktop_configuration.h",
628      "mac/desktop_configuration.mm",
629      "mac/desktop_configuration_monitor.h",
630      "mac/desktop_frame_cgimage.h",
631      "mac/desktop_frame_cgimage.mm",
632      "mac/desktop_frame_iosurface.h",
633      "mac/desktop_frame_iosurface.mm",
634      "mac/desktop_frame_provider.h",
635      "mac/desktop_frame_provider.mm",
636      "mac/screen_capturer_mac.h",
637      "mac/screen_capturer_mac.mm",
638      "mac/window_list_utils.h",
639      "mouse_cursor.h",
640      "mouse_cursor_monitor.h",
641      "mouse_cursor_monitor_mac.mm",
642      "screen_capture_frame_queue.h",
643      "screen_capturer_darwin.mm",
644      "screen_capturer_helper.h",
645      "window_capturer_mac.mm",
646      "window_finder.h",
647      "window_finder_mac.h",
648      "window_finder_mac.mm",
649    ]
650    deps = [
651      ":primitives",
652      "../../api:function_view",
653      "../../api:refcountedbase",
654      "../../api:scoped_refptr",
655      "../../api:sequence_checker",
656      "../../rtc_base",
657      "../../rtc_base:checks",
658      "../../rtc_base:event_tracer",
659      "../../rtc_base:logging",
660      "../../rtc_base:macromagic",
661      "../../rtc_base:timeutils",
662      "../../rtc_base/synchronization:mutex",
663      "../../rtc_base/system:rtc_export",
664      "../../sdk:helpers_objc",
665    ]
666    frameworks = [
667      "AppKit.framework",
668      "IOKit.framework",
669      "IOSurface.framework",
670    ]
671  }
672}
673
674if (use_desktop_capture_differ_sse2) {
675  # Have to be compiled as a separate target because it needs to be compiled
676  # with SSE2 enabled.
677  rtc_library("desktop_capture_differ_sse2") {
678    visibility = [ ":*" ]
679    sources = [
680      "differ_vector_sse2.cc",
681      "differ_vector_sse2.h",
682    ]
683
684    if (is_posix || is_fuchsia) {
685      cflags = [ "-msse2" ]
686    }
687  }
688}
689