scoped_thread_desktop.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #ifndef MODULES_DESKTOP_CAPTURE_WIN_SCOPED_THREAD_DESKTOP_H_
  11. #define MODULES_DESKTOP_CAPTURE_WIN_SCOPED_THREAD_DESKTOP_H_
  12. #include <windows.h>
  13. #include <memory>
  14. #include "rtc_base/constructor_magic.h"
  15. #include "rtc_base/system/rtc_export.h"
  16. namespace webrtc {
  17. class Desktop;
  18. class RTC_EXPORT ScopedThreadDesktop {
  19. public:
  20. ScopedThreadDesktop();
  21. ~ScopedThreadDesktop();
  22. // Returns true if |desktop| has the same desktop name as the currently
  23. // assigned desktop (if assigned) or as the initial desktop (if not assigned).
  24. // Returns false in any other case including failing Win32 APIs and
  25. // uninitialized desktop handles.
  26. bool IsSame(const Desktop& desktop);
  27. // Reverts the calling thread to use the initial desktop.
  28. void Revert();
  29. // Assigns |desktop| to be the calling thread. Returns true if the thread has
  30. // been switched to |desktop| successfully. Takes ownership of |desktop|.
  31. bool SetThreadDesktop(Desktop* desktop);
  32. private:
  33. // The desktop handle assigned to the calling thread by Set
  34. std::unique_ptr<Desktop> assigned_;
  35. // The desktop handle assigned to the calling thread at creation.
  36. std::unique_ptr<Desktop> initial_;
  37. RTC_DISALLOW_COPY_AND_ASSIGN(ScopedThreadDesktop);
  38. };
  39. } // namespace webrtc
  40. #endif // MODULES_DESKTOP_CAPTURE_WIN_SCOPED_THREAD_DESKTOP_H_