xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/full_screen_window_detector.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_
12 #define MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_
13 
14 #include <memory>
15 
16 #include "api/function_view.h"
17 #include "api/ref_counted_base.h"
18 #include "api/scoped_refptr.h"
19 #include "modules/desktop_capture/desktop_capturer.h"
20 #include "modules/desktop_capture/full_screen_application_handler.h"
21 
22 namespace webrtc {
23 
24 // This is a way to handle switch to full-screen mode for application in some
25 // specific cases:
26 // - Chrome on MacOS creates a new window in full-screen mode to
27 //   show a tab full-screen and minimizes the old window.
28 // - PowerPoint creates new windows in full-screen mode when user goes to
29 //   presentation mode (Slide Show Window, Presentation Window).
30 //
31 // To continue capturing in these cases, we try to find the new full-screen
32 // window using criteria provided by application specific
33 // FullScreenApplicationHandler.
34 
35 class FullScreenWindowDetector
36     : public rtc::RefCountedNonVirtual<FullScreenWindowDetector> {
37  public:
38   using ApplicationHandlerFactory =
39       std::function<std::unique_ptr<FullScreenApplicationHandler>(
40           DesktopCapturer::SourceId sourceId)>;
41 
42   FullScreenWindowDetector(
43       ApplicationHandlerFactory application_handler_factory);
44 
45   FullScreenWindowDetector(const FullScreenWindowDetector&) = delete;
46   FullScreenWindowDetector& operator=(const FullScreenWindowDetector&) = delete;
47 
48   // Returns the full-screen window in place of the original window if all the
49   // criteria provided by FullScreenApplicationHandler are met, or 0 if no such
50   // window found.
51   DesktopCapturer::SourceId FindFullScreenWindow(
52       DesktopCapturer::SourceId original_source_id);
53 
54   // The caller should call this function periodically, implementation will
55   // update internal state no often than twice per second
56   void UpdateWindowListIfNeeded(
57       DesktopCapturer::SourceId original_source_id,
58       rtc::FunctionView<bool(DesktopCapturer::SourceList*)> get_sources);
59 
60   static rtc::scoped_refptr<FullScreenWindowDetector>
61   CreateFullScreenWindowDetector();
62 
63  protected:
64   std::unique_ptr<FullScreenApplicationHandler> app_handler_;
65 
66  private:
67   void CreateApplicationHandlerIfNeeded(DesktopCapturer::SourceId source_id);
68 
69   ApplicationHandlerFactory application_handler_factory_;
70 
71   int64_t last_update_time_ms_;
72   DesktopCapturer::SourceId previous_source_id_;
73 
74   // Save the source id when we fail to create an instance of
75   // CreateApplicationHandlerIfNeeded to avoid redundant attempt to do it again.
76   DesktopCapturer::SourceId no_handler_source_id_;
77 
78   DesktopCapturer::SourceList window_list_;
79 };
80 
81 }  // namespace webrtc
82 
83 #endif  // MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_
84