xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/win/desktop.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2013 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_WIN_DESKTOP_H_
12 #define MODULES_DESKTOP_CAPTURE_WIN_DESKTOP_H_
13 
14 #include <windows.h>
15 
16 #include <string>
17 
18 #include "rtc_base/system/rtc_export.h"
19 
20 namespace webrtc {
21 
22 class RTC_EXPORT Desktop {
23  public:
24   ~Desktop();
25 
26   Desktop(const Desktop&) = delete;
27   Desktop& operator=(const Desktop&) = delete;
28 
29   // Returns the name of the desktop represented by the object. Return false if
30   // quering the name failed for any reason.
31   bool GetName(std::wstring* desktop_name_out) const;
32 
33   // Returns true if `other` has the same name as this desktop. Returns false
34   // in any other case including failing Win32 APIs and uninitialized desktop
35   // handles.
36   bool IsSame(const Desktop& other) const;
37 
38   // Assigns the desktop to the current thread. Returns false is the operation
39   // failed for any reason.
40   bool SetThreadDesktop() const;
41 
42   // Returns the desktop by its name or NULL if an error occurs.
43   static Desktop* GetDesktop(const wchar_t* desktop_name);
44 
45   // Returns the desktop currently receiving user input or NULL if an error
46   // occurs.
47   static Desktop* GetInputDesktop();
48 
49   // Returns the desktop currently assigned to the calling thread or NULL if
50   // an error occurs.
51   static Desktop* GetThreadDesktop();
52 
53  private:
54   Desktop(HDESK desktop, bool own);
55 
56   // The desktop handle.
57   HDESK desktop_;
58 
59   // True if `desktop_` must be closed on teardown.
60   bool own_;
61 };
62 
63 }  // namespace webrtc
64 
65 #endif  // MODULES_DESKTOP_CAPTURE_WIN_DESKTOP_H_
66