This reverts commit 0a3593c25dbc96b7d66d17ab77fc9984ab2bf245. Reason for revert: breaks WebRTC roll to Chromium. https://chromium-review.googlesource.com/c/chromium/src/+/894164 [19742:771:0130/150628.286256:FATAL:thread_restrictions.cc(67)] Check failed: !g_blocking_disallowed.Get().Get(). To allow //base sync primitives in a scope where blocking is disallowed use ScopedAllowBaseSyncPrimitivesOutsideBlockingScope. 0 browser_tests 0x0000000108d3682c base::debug::StackTrace::StackTrace(unsigned long) + 28 1 browser_tests 0x0000000108d5b210 logging::LogMessage::~LogMessage() + 224 2 browser_tests 0x0000000108e04366 base::ScopedAllowBaseSyncPrimitives::ScopedAllowBaseSyncPrimitives() + 150 3 browser_tests 0x000000010be59c48 webrtc::DesktopConfigurationMonitor::Lock() + 24 4 browser_tests 0x0000000106dbf229 webrtc::DesktopCapturer::CreateRawScreenCapturer(webrtc::DesktopCaptureOptions const&) + 313 5 browser_tests 0x000000010be58725 webrtc::DesktopCapturer::CreateScreenCapturer(webrtc::DesktopCaptureOptions const&) + 21 6 browser_tests 0x00000001074dc209 content::DesktopCaptureDevice::Create(content::DesktopMediaID const&) + 169 (...) Original change's description: > Add ScopedAllowBaseSyncPrimitives for DesktopConfigurationMonitor. > This is a temporary measure until the synchronization method > used in the class, gets fixed. > > Bug: chromium:796889, chromium:795340 > Change-Id: Ie3d394ae42f005e8e0f353d04ea9c1d053ea9fd2 > Reviewed-on: https://webrtc-review.googlesource.com/40460 > Reviewed-by: Erik Språng <sprang@webrtc.org> > Commit-Queue: Tommi <tommi@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#21812} TBR=tommi@webrtc.org,sprang@webrtc.org Change-Id: I6237c3df7e33918d9fe2e46bad0f6f96cda77cd1 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: chromium:796889, chromium:795340 Reviewed-on: https://webrtc-review.googlesource.com/46540 Reviewed-by: Henrik Grunell <henrikg@webrtc.org> Commit-Queue: Henrik Grunell <henrikg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#21817}
91 lines
3.2 KiB
C++
91 lines
3.2 KiB
C++
/*
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/desktop_capture/mac/desktop_configuration_monitor.h"
|
|
|
|
#include "modules/desktop_capture/mac/desktop_configuration.h"
|
|
#include "rtc_base/logging.h"
|
|
#include "system_wrappers/include/event_wrapper.h"
|
|
|
|
namespace webrtc {
|
|
|
|
// The amount of time allowed for displays to reconfigure.
|
|
static const int64_t kDisplayConfigurationEventTimeoutMs = 10 * 1000;
|
|
|
|
DesktopConfigurationMonitor::DesktopConfigurationMonitor()
|
|
: display_configuration_capture_event_(EventWrapper::Create()) {
|
|
CGError err = CGDisplayRegisterReconfigurationCallback(
|
|
DesktopConfigurationMonitor::DisplaysReconfiguredCallback, this);
|
|
if (err != kCGErrorSuccess) {
|
|
RTC_LOG(LS_ERROR) << "CGDisplayRegisterReconfigurationCallback " << err;
|
|
abort();
|
|
}
|
|
display_configuration_capture_event_->Set();
|
|
|
|
desktop_configuration_ = MacDesktopConfiguration::GetCurrent(
|
|
MacDesktopConfiguration::TopLeftOrigin);
|
|
}
|
|
|
|
DesktopConfigurationMonitor::~DesktopConfigurationMonitor() {
|
|
CGError err = CGDisplayRemoveReconfigurationCallback(
|
|
DesktopConfigurationMonitor::DisplaysReconfiguredCallback, this);
|
|
if (err != kCGErrorSuccess)
|
|
RTC_LOG(LS_ERROR) << "CGDisplayRemoveReconfigurationCallback " << err;
|
|
}
|
|
|
|
void DesktopConfigurationMonitor::Lock() {
|
|
if (!display_configuration_capture_event_->Wait(
|
|
kDisplayConfigurationEventTimeoutMs)) {
|
|
RTC_LOG_F(LS_ERROR) << "Event wait timed out.";
|
|
abort();
|
|
}
|
|
}
|
|
|
|
void DesktopConfigurationMonitor::Unlock() {
|
|
display_configuration_capture_event_->Set();
|
|
}
|
|
|
|
// static
|
|
void DesktopConfigurationMonitor::DisplaysReconfiguredCallback(
|
|
CGDirectDisplayID display,
|
|
CGDisplayChangeSummaryFlags flags,
|
|
void *user_parameter) {
|
|
DesktopConfigurationMonitor* monitor =
|
|
reinterpret_cast<DesktopConfigurationMonitor*>(user_parameter);
|
|
monitor->DisplaysReconfigured(display, flags);
|
|
}
|
|
|
|
void DesktopConfigurationMonitor::DisplaysReconfigured(
|
|
CGDirectDisplayID display,
|
|
CGDisplayChangeSummaryFlags flags) {
|
|
if (flags & kCGDisplayBeginConfigurationFlag) {
|
|
if (reconfiguring_displays_.empty()) {
|
|
// If this is the first display to start reconfiguring then wait on
|
|
// |display_configuration_capture_event_| to block the capture thread
|
|
// from accessing display memory until the reconfiguration completes.
|
|
if (!display_configuration_capture_event_->Wait(
|
|
kDisplayConfigurationEventTimeoutMs)) {
|
|
RTC_LOG_F(LS_ERROR) << "Event wait timed out.";
|
|
abort();
|
|
}
|
|
}
|
|
reconfiguring_displays_.insert(display);
|
|
} else {
|
|
reconfiguring_displays_.erase(display);
|
|
if (reconfiguring_displays_.empty()) {
|
|
desktop_configuration_ = MacDesktopConfiguration::GetCurrent(
|
|
MacDesktopConfiguration::TopLeftOrigin);
|
|
display_configuration_capture_event_->Set();
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace webrtc
|