This reverts commit 913b34e5891823007c5adc7580a4d59126d51cac. Reason for revert: Suspected for breaking chromium tests. The WebRTC import was reverted, see: https://chromium-review.googlesource.com/c/chromium/src/+/3322494 Due to for example failures like: https://ci.chromium.org/ui/p/chromium/builders/ci/Linux%20CFI/21522/overview Example tests: WebRtcScreenCaptureBrowserTestWithPicker Original change's description: > Reland "Linux capturers: organize X11 and Wayland implementations into separate folders" > > Bug: webrtc:13429 > Change-Id: Ib5e429fe248f058387e23b77339558ca7d064466 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/240184 > Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> > Reviewed-by: Mark Foltz <mfoltz@chromium.org> > Commit-Queue: Mark Foltz <mfoltz@chromium.org> > Cr-Commit-Position: refs/heads/main@{#35493} TBR=mbonadei@webrtc.org,grulja@gmail.com,mfoltz@chromium.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com Change-Id: I6d05062c9bc947d5bc6f9db5f6861cbf37d4b9bc No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:13429 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/240380 Reviewed-by: Henrik Boström <hbos@webrtc.org> Auto-Submit: Henrik Boström <hbos@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Owners-Override: Henrik Boström <hbos@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35501}
102 lines
2.9 KiB
C++
102 lines
2.9 KiB
C++
/*
|
|
* Copyright (c) 2013 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/linux/shared_x_display.h"
|
|
|
|
#include <X11/Xlib.h>
|
|
#include <X11/extensions/XTest.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "rtc_base/checks.h"
|
|
#include "rtc_base/logging.h"
|
|
|
|
namespace webrtc {
|
|
|
|
SharedXDisplay::SharedXDisplay(Display* display) : display_(display) {
|
|
RTC_DCHECK(display_);
|
|
}
|
|
|
|
SharedXDisplay::~SharedXDisplay() {
|
|
RTC_DCHECK(event_handlers_.empty());
|
|
XCloseDisplay(display_);
|
|
}
|
|
|
|
// static
|
|
rtc::scoped_refptr<SharedXDisplay> SharedXDisplay::Create(
|
|
const std::string& display_name) {
|
|
Display* display =
|
|
XOpenDisplay(display_name.empty() ? NULL : display_name.c_str());
|
|
if (!display) {
|
|
RTC_LOG(LS_ERROR) << "Unable to open display";
|
|
return NULL;
|
|
}
|
|
return new SharedXDisplay(display);
|
|
}
|
|
|
|
// static
|
|
rtc::scoped_refptr<SharedXDisplay> SharedXDisplay::CreateDefault() {
|
|
return Create(std::string());
|
|
}
|
|
|
|
void SharedXDisplay::AddEventHandler(int type, XEventHandler* handler) {
|
|
event_handlers_[type].push_back(handler);
|
|
}
|
|
|
|
void SharedXDisplay::RemoveEventHandler(int type, XEventHandler* handler) {
|
|
EventHandlersMap::iterator handlers = event_handlers_.find(type);
|
|
if (handlers == event_handlers_.end())
|
|
return;
|
|
|
|
std::vector<XEventHandler*>::iterator new_end =
|
|
std::remove(handlers->second.begin(), handlers->second.end(), handler);
|
|
handlers->second.erase(new_end, handlers->second.end());
|
|
|
|
// Check if no handlers left for this event.
|
|
if (handlers->second.empty())
|
|
event_handlers_.erase(handlers);
|
|
}
|
|
|
|
void SharedXDisplay::ProcessPendingXEvents() {
|
|
// Hold reference to `this` to prevent it from being destroyed while
|
|
// processing events.
|
|
rtc::scoped_refptr<SharedXDisplay> self(this);
|
|
|
|
// Find the number of events that are outstanding "now." We don't just loop
|
|
// on XPending because we want to guarantee this terminates.
|
|
int events_to_process = XPending(display());
|
|
XEvent e;
|
|
|
|
for (int i = 0; i < events_to_process; i++) {
|
|
XNextEvent(display(), &e);
|
|
EventHandlersMap::iterator handlers = event_handlers_.find(e.type);
|
|
if (handlers == event_handlers_.end())
|
|
continue;
|
|
for (std::vector<XEventHandler*>::iterator it = handlers->second.begin();
|
|
it != handlers->second.end(); ++it) {
|
|
if ((*it)->HandleXEvent(e))
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SharedXDisplay::IgnoreXServerGrabs() {
|
|
int test_event_base = 0;
|
|
int test_error_base = 0;
|
|
int major = 0;
|
|
int minor = 0;
|
|
if (XTestQueryExtension(display(), &test_event_base, &test_error_base, &major,
|
|
&minor)) {
|
|
XTestGrabControl(display(), true);
|
|
}
|
|
}
|
|
|
|
} // namespace webrtc
|