mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00

This reverts commit3f87250a4f
. Reason for revert: Downstream is fixed Original change's description: > Revert "Remove RTC_DISALLOW_COPY_AND_ASSIGN usages completely" > > This reverts commit5f0eb93d2a
. > > Reason for revert: Breaks downstream project. I'm going to fix that one and create a reland of this CL after. > > Original change's description: > > Remove RTC_DISALLOW_COPY_AND_ASSIGN usages completely > > > > Bug: webrtc:13555, webrtc:13082 > > Change-Id: Iff2cda6f516739419e97e975e03f77a98f74be03 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249260 > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Reviewed-by: Artem Titov <titovartem@webrtc.org> > > Commit-Queue: (Daniel.L) Byoungchan Lee <daniel.l@hpcnt.com> > > Cr-Commit-Position: refs/heads/main@{#35805} > > TBR=hta@webrtc.org,titovartem@webrtc.org,daniel.l@hpcnt.com,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com > > Change-Id: I33d497f1132adfe6d151023195a388d9b7d548f9 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:13555, webrtc:13082 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249364 > Reviewed-by: Artem Titov <titovartem@webrtc.org> > Owners-Override: Artem Titov <titovartem@webrtc.org> > Reviewed-by: Andrey Logvin <landrey@webrtc.org> > Reviewed-by: Björn Terelius <terelius@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#35807} # Not skipping CQ checks because this is a reland. Bug: webrtc:13555, webrtc:13082 Change-Id: I7ef1ef3b6e3c41b1a96014aa75f003c0fcf33949 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249365 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35814}
147 lines
5.2 KiB
C++
147 lines
5.2 KiB
C++
/*
|
|
* Copyright 2018 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.
|
|
*/
|
|
|
|
#ifndef MODULES_DESKTOP_CAPTURE_LINUX_X11_SCREEN_CAPTURER_X11_H_
|
|
#define MODULES_DESKTOP_CAPTURE_LINUX_X11_SCREEN_CAPTURER_X11_H_
|
|
|
|
#include <X11/X.h>
|
|
#include <X11/Xlib.h>
|
|
#include <X11/extensions/Xdamage.h>
|
|
#include <X11/extensions/Xfixes.h>
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
#include <memory>
|
|
|
|
#include "modules/desktop_capture/desktop_capture_options.h"
|
|
#include "modules/desktop_capture/desktop_capturer.h"
|
|
#include "modules/desktop_capture/desktop_frame.h"
|
|
#include "modules/desktop_capture/desktop_region.h"
|
|
#include "modules/desktop_capture/linux/x11/shared_x_display.h"
|
|
#include "modules/desktop_capture/linux/x11/x_atom_cache.h"
|
|
#include "modules/desktop_capture/linux/x11/x_server_pixel_buffer.h"
|
|
#include "modules/desktop_capture/screen_capture_frame_queue.h"
|
|
#include "modules/desktop_capture/screen_capturer_helper.h"
|
|
#include "modules/desktop_capture/shared_desktop_frame.h"
|
|
|
|
namespace webrtc {
|
|
|
|
// A class to perform video frame capturing for Linux on X11.
|
|
//
|
|
// If XDamage is used, this class sets DesktopFrame::updated_region() according
|
|
// to the areas reported by XDamage. Otherwise this class does not detect
|
|
// DesktopFrame::updated_region(), the field is always set to the entire frame
|
|
// rectangle. ScreenCapturerDifferWrapper should be used if that functionality
|
|
// is necessary.
|
|
class ScreenCapturerX11 : public DesktopCapturer,
|
|
public SharedXDisplay::XEventHandler {
|
|
public:
|
|
ScreenCapturerX11();
|
|
~ScreenCapturerX11() override;
|
|
|
|
ScreenCapturerX11(const ScreenCapturerX11&) = delete;
|
|
ScreenCapturerX11& operator=(const ScreenCapturerX11&) = delete;
|
|
|
|
static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
|
|
const DesktopCaptureOptions& options);
|
|
|
|
// TODO(ajwong): Do we really want this to be synchronous?
|
|
bool Init(const DesktopCaptureOptions& options);
|
|
|
|
// DesktopCapturer interface.
|
|
void Start(Callback* delegate) override;
|
|
void CaptureFrame() override;
|
|
bool GetSourceList(SourceList* sources) override;
|
|
bool SelectSource(SourceId id) override;
|
|
|
|
private:
|
|
Display* display() { return options_.x_display()->display(); }
|
|
|
|
// SharedXDisplay::XEventHandler interface.
|
|
bool HandleXEvent(const XEvent& event) override;
|
|
|
|
void InitXDamage();
|
|
void InitXrandr();
|
|
void UpdateMonitors();
|
|
|
|
// Capture screen pixels to the current buffer in the queue. In the DAMAGE
|
|
// case, the ScreenCapturerHelper already holds the list of invalid rectangles
|
|
// from HandleXEvent(). In the non-DAMAGE case, this captures the
|
|
// whole screen, then calculates some invalid rectangles that include any
|
|
// differences between this and the previous capture.
|
|
std::unique_ptr<DesktopFrame> CaptureScreen();
|
|
|
|
// Called when the screen configuration is changed.
|
|
void ScreenConfigurationChanged();
|
|
|
|
// Synchronize the current buffer with `last_buffer_`, by copying pixels from
|
|
// the area of `last_invalid_rects`.
|
|
// Note this only works on the assumption that kNumBuffers == 2, as
|
|
// `last_invalid_rects` holds the differences from the previous buffer and
|
|
// the one prior to that (which will then be the current buffer).
|
|
void SynchronizeFrame();
|
|
|
|
void DeinitXlib();
|
|
|
|
DesktopCaptureOptions options_;
|
|
|
|
Callback* callback_ = nullptr;
|
|
|
|
// X11 graphics context.
|
|
GC gc_ = nullptr;
|
|
Window root_window_ = BadValue;
|
|
|
|
// XRandR 1.5 monitors.
|
|
bool use_randr_ = false;
|
|
int randr_event_base_ = 0;
|
|
XRRMonitorInfo* monitors_ = nullptr;
|
|
int num_monitors_ = 0;
|
|
DesktopRect selected_monitor_rect_;
|
|
// selected_monitor_name_ will be changed to kFullDesktopScreenId
|
|
// by a call to SelectSource() at the end of Init() because
|
|
// selected_monitor_rect_ should be updated as well.
|
|
// Setting it to kFullDesktopScreenId here might be misleading.
|
|
Atom selected_monitor_name_ = 0;
|
|
typedef XRRMonitorInfo* (*get_monitors_func)(Display*, Window, Bool, int*);
|
|
typedef void (*free_monitors_func)(XRRMonitorInfo*);
|
|
get_monitors_func get_monitors_ = nullptr;
|
|
free_monitors_func free_monitors_ = nullptr;
|
|
|
|
// XFixes.
|
|
bool has_xfixes_ = false;
|
|
int xfixes_event_base_ = -1;
|
|
int xfixes_error_base_ = -1;
|
|
|
|
// XDamage information.
|
|
bool use_damage_ = false;
|
|
Damage damage_handle_ = 0;
|
|
int damage_event_base_ = -1;
|
|
int damage_error_base_ = -1;
|
|
XserverRegion damage_region_ = 0;
|
|
|
|
// Access to the X Server's pixel buffer.
|
|
XServerPixelBuffer x_server_pixel_buffer_;
|
|
|
|
// A thread-safe list of invalid rectangles, and the size of the most
|
|
// recently captured screen.
|
|
ScreenCapturerHelper helper_;
|
|
|
|
// Queue of the frames buffers.
|
|
ScreenCaptureFrameQueue<SharedDesktopFrame> queue_;
|
|
|
|
// Invalid region from the previous capture. This is used to synchronize the
|
|
// current with the last buffer used.
|
|
DesktopRegion last_invalid_region_;
|
|
|
|
std::unique_ptr<XAtomCache> atom_cache_;
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // MODULES_DESKTOP_CAPTURE_LINUX_X11_SCREEN_CAPTURER_X11_H_
|