1 /*
2  *  Copyright (c) 2016 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_DESKTOP_CAPTURER_DIFFER_WRAPPER_H_
12 #define MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_DIFFER_WRAPPER_H_
13 
14 #include <memory>
15 
16 #include "modules/desktop_capture/desktop_capture_types.h"
17 #include "modules/desktop_capture/desktop_capturer.h"
18 #include "modules/desktop_capture/desktop_frame.h"
19 #include "modules/desktop_capture/desktop_geometry.h"
20 #include "modules/desktop_capture/shared_desktop_frame.h"
21 #include "modules/desktop_capture/shared_memory.h"
22 #include "rtc_base/system/rtc_export.h"
23 
24 namespace webrtc {
25 
26 // DesktopCapturer wrapper that calculates updated_region() by comparing frames
27 // content. This class always expects the underlying DesktopCapturer
28 // implementation returns a superset of updated regions in DestkopFrame. If a
29 // DesktopCapturer implementation does not know the updated region, it should
30 // set updated_region() to full frame.
31 //
32 // This class marks entire frame as updated if the frame size or frame stride
33 // has been changed.
34 class RTC_EXPORT DesktopCapturerDifferWrapper
35     : public DesktopCapturer,
36       public DesktopCapturer::Callback {
37  public:
38   // Creates a DesktopCapturerDifferWrapper with a DesktopCapturer
39   // implementation, and takes its ownership.
40   explicit DesktopCapturerDifferWrapper(
41       std::unique_ptr<DesktopCapturer> base_capturer);
42 
43   ~DesktopCapturerDifferWrapper() override;
44 
45   // DesktopCapturer interface.
46   void Start(DesktopCapturer::Callback* callback) override;
47   void SetSharedMemoryFactory(
48       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
49   void CaptureFrame() override;
50   void SetExcludedWindow(WindowId window) override;
51   bool GetSourceList(SourceList* screens) override;
52   bool SelectSource(SourceId id) override;
53   bool FocusOnSelectedSource() override;
54   bool IsOccluded(const DesktopVector& pos) override;
55 
56  private:
57   // DesktopCapturer::Callback interface.
58   void OnCaptureResult(Result result,
59                        std::unique_ptr<DesktopFrame> frame) override;
60 
61   const std::unique_ptr<DesktopCapturer> base_capturer_;
62   DesktopCapturer::Callback* callback_;
63   std::unique_ptr<SharedDesktopFrame> last_frame_;
64 };
65 
66 }  // namespace webrtc
67 
68 #endif  // MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_DIFFER_WRAPPER_H_
69