1 /* 2 * Copyright 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_DESKTOP_CAPTURE_LINUX_WINDOW_CAPTURER_X11_H_ 12 #define MODULES_DESKTOP_CAPTURE_LINUX_WINDOW_CAPTURER_X11_H_ 13 14 #include <X11/X.h> 15 #include <X11/Xlib.h> 16 17 #include <memory> 18 #include <string> 19 20 #include "api/scoped_refptr.h" 21 #include "modules/desktop_capture/desktop_capture_options.h" 22 #include "modules/desktop_capture/desktop_capturer.h" 23 #include "modules/desktop_capture/desktop_geometry.h" 24 #include "modules/desktop_capture/linux/shared_x_display.h" 25 #include "modules/desktop_capture/linux/window_finder_x11.h" 26 #include "modules/desktop_capture/linux/x_atom_cache.h" 27 #include "modules/desktop_capture/linux/x_server_pixel_buffer.h" 28 #include "rtc_base/constructor_magic.h" 29 30 namespace webrtc { 31 32 class WindowCapturerX11 : public DesktopCapturer, 33 public SharedXDisplay::XEventHandler { 34 public: 35 explicit WindowCapturerX11(const DesktopCaptureOptions& options); 36 ~WindowCapturerX11() override; 37 38 static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer( 39 const DesktopCaptureOptions& options); 40 41 // DesktopCapturer interface. 42 void Start(Callback* callback) override; 43 void CaptureFrame() override; 44 bool GetSourceList(SourceList* sources) override; 45 bool SelectSource(SourceId id) override; 46 bool FocusOnSelectedSource() override; 47 bool IsOccluded(const DesktopVector& pos) override; 48 49 // SharedXDisplay::XEventHandler interface. 50 bool HandleXEvent(const XEvent& event) override; 51 52 private: display()53 Display* display() { return x_display_->display(); } 54 55 // Returns window title for the specified X |window|. 56 bool GetWindowTitle(::Window window, std::string* title); 57 58 Callback* callback_ = nullptr; 59 60 rtc::scoped_refptr<SharedXDisplay> x_display_; 61 62 bool has_composite_extension_ = false; 63 64 ::Window selected_window_ = 0; 65 XServerPixelBuffer x_server_pixel_buffer_; 66 XAtomCache atom_cache_; 67 WindowFinderX11 window_finder_; 68 69 RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerX11); 70 }; 71 72 } // namespace webrtc 73 74 #endif // MODULES_DESKTOP_CAPTURE_LINUX_WINDOW_CAPTURER_X11_H_ 75