OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" | 11 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" |
12 | 12 |
13 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" | 13 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" |
14 #include "webrtc/system_wrappers/include/event_wrapper.h" | 14 #include "webrtc/system_wrappers/include/event_wrapper.h" |
15 #include "webrtc/system_wrappers/include/logging.h" | |
16 | 15 |
17 namespace webrtc { | 16 namespace webrtc { |
18 | 17 |
19 // The amount of time allowed for displays to reconfigure. | 18 // The amount of time allowed for displays to reconfigure. |
20 static const int64_t kDisplayConfigurationEventTimeoutMs = 10 * 1000; | 19 static const int64_t kDisplayConfigurationEventTimeoutMs = 10 * 1000; |
21 | 20 |
22 DesktopConfigurationMonitor::DesktopConfigurationMonitor() | 21 DesktopConfigurationMonitor::DesktopConfigurationMonitor() |
23 : ref_count_(0), | 22 : ref_count_(0), |
24 display_configuration_capture_event_(EventWrapper::Create()) { | 23 display_configuration_capture_event_(EventWrapper::Create()) { |
25 CGError err = CGDisplayRegisterReconfigurationCallback( | 24 CGError err = CGDisplayRegisterReconfigurationCallback( |
26 DesktopConfigurationMonitor::DisplaysReconfiguredCallback, this); | 25 DesktopConfigurationMonitor::DisplaysReconfiguredCallback, this); |
27 if (err != kCGErrorSuccess) { | 26 if (err != kCGErrorSuccess) { |
28 LOG(LS_ERROR) << "CGDisplayRegisterReconfigurationCallback " << err; | |
29 abort(); | 27 abort(); |
30 } | 28 } |
31 display_configuration_capture_event_->Set(); | 29 display_configuration_capture_event_->Set(); |
32 | 30 |
33 desktop_configuration_ = MacDesktopConfiguration::GetCurrent( | 31 desktop_configuration_ = MacDesktopConfiguration::GetCurrent( |
34 MacDesktopConfiguration::TopLeftOrigin); | 32 MacDesktopConfiguration::TopLeftOrigin); |
35 } | 33 } |
36 | 34 |
37 DesktopConfigurationMonitor::~DesktopConfigurationMonitor() { | 35 DesktopConfigurationMonitor::~DesktopConfigurationMonitor() { |
38 CGError err = CGDisplayRemoveReconfigurationCallback( | 36 CGError err = CGDisplayRemoveReconfigurationCallback( |
39 DesktopConfigurationMonitor::DisplaysReconfiguredCallback, this); | 37 DesktopConfigurationMonitor::DisplaysReconfiguredCallback, this); |
40 if (err != kCGErrorSuccess) | 38 if (err != kCGErrorSuccess) |
41 LOG(LS_ERROR) << "CGDisplayRemoveReconfigurationCallback " << err; | 39 ; |
42 } | 40 } |
43 | 41 |
44 void DesktopConfigurationMonitor::Lock() { | 42 void DesktopConfigurationMonitor::Lock() { |
45 if (!display_configuration_capture_event_->Wait( | 43 if (!display_configuration_capture_event_->Wait( |
46 kDisplayConfigurationEventTimeoutMs)) { | 44 kDisplayConfigurationEventTimeoutMs)) { |
47 LOG_F(LS_ERROR) << "Event wait timed out."; | |
48 abort(); | 45 abort(); |
49 } | 46 } |
50 } | 47 } |
51 | 48 |
52 void DesktopConfigurationMonitor::Unlock() { | 49 void DesktopConfigurationMonitor::Unlock() { |
53 display_configuration_capture_event_->Set(); | 50 display_configuration_capture_event_->Set(); |
54 } | 51 } |
55 | 52 |
56 // static | 53 // static |
57 void DesktopConfigurationMonitor::DisplaysReconfiguredCallback( | 54 void DesktopConfigurationMonitor::DisplaysReconfiguredCallback( |
58 CGDirectDisplayID display, | 55 CGDirectDisplayID display, |
59 CGDisplayChangeSummaryFlags flags, | 56 CGDisplayChangeSummaryFlags flags, |
60 void *user_parameter) { | 57 void *user_parameter) { |
61 DesktopConfigurationMonitor* monitor = | 58 DesktopConfigurationMonitor* monitor = |
62 reinterpret_cast<DesktopConfigurationMonitor*>(user_parameter); | 59 reinterpret_cast<DesktopConfigurationMonitor*>(user_parameter); |
63 monitor->DisplaysReconfigured(display, flags); | 60 monitor->DisplaysReconfigured(display, flags); |
64 } | 61 } |
65 | 62 |
66 void DesktopConfigurationMonitor::DisplaysReconfigured( | 63 void DesktopConfigurationMonitor::DisplaysReconfigured( |
67 CGDirectDisplayID display, | 64 CGDirectDisplayID display, |
68 CGDisplayChangeSummaryFlags flags) { | 65 CGDisplayChangeSummaryFlags flags) { |
69 if (flags & kCGDisplayBeginConfigurationFlag) { | 66 if (flags & kCGDisplayBeginConfigurationFlag) { |
70 if (reconfiguring_displays_.empty()) { | 67 if (reconfiguring_displays_.empty()) { |
71 // If this is the first display to start reconfiguring then wait on | 68 // If this is the first display to start reconfiguring then wait on |
72 // |display_configuration_capture_event_| to block the capture thread | 69 // |display_configuration_capture_event_| to block the capture thread |
73 // from accessing display memory until the reconfiguration completes. | 70 // from accessing display memory until the reconfiguration completes. |
74 if (!display_configuration_capture_event_->Wait( | 71 if (!display_configuration_capture_event_->Wait( |
75 kDisplayConfigurationEventTimeoutMs)) { | 72 kDisplayConfigurationEventTimeoutMs)) { |
76 LOG_F(LS_ERROR) << "Event wait timed out."; | |
77 abort(); | 73 abort(); |
78 } | 74 } |
79 } | 75 } |
80 reconfiguring_displays_.insert(display); | 76 reconfiguring_displays_.insert(display); |
81 } else { | 77 } else { |
82 reconfiguring_displays_.erase(display); | 78 reconfiguring_displays_.erase(display); |
83 if (reconfiguring_displays_.empty()) { | 79 if (reconfiguring_displays_.empty()) { |
84 desktop_configuration_ = MacDesktopConfiguration::GetCurrent( | 80 desktop_configuration_ = MacDesktopConfiguration::GetCurrent( |
85 MacDesktopConfiguration::TopLeftOrigin); | 81 MacDesktopConfiguration::TopLeftOrigin); |
86 display_configuration_capture_event_->Set(); | 82 display_configuration_capture_event_->Set(); |
87 } | 83 } |
88 } | 84 } |
89 } | 85 } |
90 | 86 |
91 } // namespace webrtc | 87 } // namespace webrtc |
OLD | NEW |