• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/window_finder_x11.h"
26 #include "modules/desktop_capture/linux/x11/x_atom_cache.h"
27 #include "modules/desktop_capture/linux/x11/x_server_pixel_buffer.h"
28 
29 namespace webrtc {
30 
31 class WindowCapturerX11 : public DesktopCapturer,
32                           public SharedXDisplay::XEventHandler {
33  public:
34   explicit WindowCapturerX11(const DesktopCaptureOptions& options);
35   ~WindowCapturerX11() override;
36 
37   WindowCapturerX11(const WindowCapturerX11&) = delete;
38   WindowCapturerX11& operator=(const WindowCapturerX11&) = delete;
39 
40   static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
41       const DesktopCaptureOptions& options);
42 
43   // DesktopCapturer interface.
44   void Start(Callback* callback) override;
45   void CaptureFrame() override;
46   bool GetSourceList(SourceList* sources) override;
47   bool SelectSource(SourceId id) override;
48   bool FocusOnSelectedSource() override;
49   bool IsOccluded(const DesktopVector& pos) override;
50 
51   // SharedXDisplay::XEventHandler interface.
52   bool HandleXEvent(const XEvent& event) override;
53 
54  private:
display()55   Display* display() { return x_display_->display(); }
56 
57   // Returns window title for the specified X `window`.
58   bool GetWindowTitle(::Window window, std::string* title);
59 
60   Callback* callback_ = nullptr;
61 
62   rtc::scoped_refptr<SharedXDisplay> x_display_;
63 
64   bool has_composite_extension_ = false;
65 
66   ::Window selected_window_ = 0;
67   XServerPixelBuffer x_server_pixel_buffer_;
68   XAtomCache atom_cache_;
69   WindowFinderX11 window_finder_;
70 };
71 
72 }  // namespace webrtc
73 
74 #endif  // MODULES_DESKTOP_CAPTURE_LINUX_X11_WINDOW_CAPTURER_X11_H_
75