window_capturer_x11.h (2648B)
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_X11_WINDOW_CAPTURER_X11_H_ 12 #define MODULES_DESKTOP_CAPTURE_LINUX_X11_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/x11/shared_x_display.h" 25 #include "modules/desktop_capture/linux/x11/x_window_property.h" 26 #include "modules/desktop_capture/linux/x11/window_finder_x11.h" 27 #include "modules/desktop_capture/linux/x11/x_atom_cache.h" 28 #include "modules/desktop_capture/linux/x11/x_server_pixel_buffer.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 WindowCapturerX11(const WindowCapturerX11&) = delete; 39 WindowCapturerX11& operator=(const WindowCapturerX11&) = delete; 40 41 static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer( 42 const DesktopCaptureOptions& options); 43 44 // DesktopCapturer interface. 45 void Start(Callback* callback) override; 46 void CaptureFrame() override; 47 bool GetSourceList(SourceList* sources) override; 48 bool SelectSource(SourceId id) override; 49 bool FocusOnSelectedSource() override; 50 bool IsOccluded(const DesktopVector& pos) override; 51 52 // SharedXDisplay::XEventHandler interface. 53 bool HandleXEvent(const XEvent& event) override; 54 55 private: 56 Display* display() { return x_display_->display(); } 57 58 // Returns window title for the specified X `window`. 59 bool GetWindowTitle(::Window window, std::string* title); 60 61 // Returns the id of the owning process. 62 int GetWindowProcessID(::Window window); 63 64 Callback* callback_ = nullptr; 65 66 scoped_refptr<SharedXDisplay> x_display_; 67 68 bool has_composite_extension_ = false; 69 70 ::Window selected_window_ = 0; 71 XServerPixelBuffer x_server_pixel_buffer_; 72 XAtomCache atom_cache_; 73 WindowFinderX11 window_finder_; 74 }; 75 76 } // namespace webrtc 77 78 #endif // MODULES_DESKTOP_CAPTURE_LINUX_X11_WINDOW_CAPTURER_X11_H_