1 /*
2  *  Copyright (c) 2014 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 WEBRTC_MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_
13 
14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
16 #include "webrtc/modules/desktop_capture/screen_capturer.h"
17 #include "webrtc/modules/desktop_capture/window_capturer.h"
18 
19 namespace webrtc {
20 
21 // WindowCapturer implementation that uses a screen capturer to capture the
22 // whole screen and crops the video frame to the window area when the captured
23 // window is on top.
24 class CroppingWindowCapturer : public WindowCapturer,
25                                public DesktopCapturer::Callback {
26  public:
27   static WindowCapturer* Create(const DesktopCaptureOptions& options);
28   virtual ~CroppingWindowCapturer();
29 
30   // DesktopCapturer implementation.
31   void Start(DesktopCapturer::Callback* callback) override;
32   void Capture(const DesktopRegion& region) override;
33   void SetExcludedWindow(WindowId window) override;
34 
35   // WindowCapturer implementation.
36   bool GetWindowList(WindowList* windows) override;
37   bool SelectWindow(WindowId id) override;
38   bool BringSelectedWindowToFront() override;
39 
40   // DesktopCapturer::Callback implementation, passed to |screen_capturer_| to
41   // intercept the capture result.
42   SharedMemory* CreateSharedMemory(size_t size) override;
43   void OnCaptureCompleted(DesktopFrame* frame) override;
44 
45  protected:
46   explicit CroppingWindowCapturer(const DesktopCaptureOptions& options);
47 
48   // The platform implementation should override these methods.
49 
50   // Returns true if it is OK to capture the whole screen and crop to the
51   // selected window, i.e. the selected window is opaque, rectangular, and not
52   // occluded.
53   virtual bool ShouldUseScreenCapturer() = 0;
54 
55   // Returns the window area relative to the top left of the virtual screen
56   // within the bounds of the virtual screen.
57   virtual DesktopRect GetWindowRectInVirtualScreen() = 0;
58 
selected_window()59   WindowId selected_window() const { return selected_window_; }
excluded_window()60   WindowId excluded_window() const { return excluded_window_; }
61 
62  private:
63   DesktopCaptureOptions options_;
64   DesktopCapturer::Callback* callback_;
65   rtc::scoped_ptr<WindowCapturer> window_capturer_;
66   rtc::scoped_ptr<ScreenCapturer> screen_capturer_;
67   WindowId selected_window_;
68   WindowId excluded_window_;
69 };
70 
71 }  // namespace webrtc
72 
73 #endif  // WEBRTC_MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_
74 
75