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_MAC_DESKTOP_CONFIGURATION_MONITOR_H_
12#define WEBRTC_MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_CONFIGURATION_MONITOR_H_
13
14#include <ApplicationServices/ApplicationServices.h>
15
16#include <set>
17
18#include "webrtc/modules/desktop_capture/mac/desktop_configuration.h"
19#include "webrtc/system_wrappers/interface/atomic32.h"
20#include "webrtc/system_wrappers/interface/scoped_ptr.h"
21
22namespace webrtc {
23
24class EventWrapper;
25
26// The class provides functions to synchronize capturing and display
27// reconfiguring across threads, and the up-to-date MacDesktopConfiguration.
28class DesktopConfigurationMonitor {
29 public:
30  DesktopConfigurationMonitor();
31  // Acquires a lock on the current configuration.
32  void Lock();
33  // Releases the lock previously acquired.
34  void Unlock();
35  // Returns the current desktop configuration. Should only be called when the
36  // lock has been acquired.
37  const MacDesktopConfiguration& desktop_configuration() {
38    return desktop_configuration_;
39  }
40
41  void AddRef() { ++ref_count_; }
42  void Release() {
43    if (--ref_count_ == 0)
44      delete this;
45  }
46
47 private:
48  static void DisplaysReconfiguredCallback(CGDirectDisplayID display,
49                                           CGDisplayChangeSummaryFlags flags,
50                                           void *user_parameter);
51  ~DesktopConfigurationMonitor();
52
53  void DisplaysReconfigured(CGDirectDisplayID display,
54                            CGDisplayChangeSummaryFlags flags);
55
56  Atomic32 ref_count_;
57  std::set<CGDirectDisplayID> reconfiguring_displays_;
58  MacDesktopConfiguration desktop_configuration_;
59  scoped_ptr<EventWrapper> display_configuration_capture_event_;
60
61  DISALLOW_COPY_AND_ASSIGN(DesktopConfigurationMonitor);
62};
63
64}  // namespace webrtc
65
66#endif  // WEBRTC_MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_CONFIGURATION_MONITOR_H_
67