webrtc_m130/modules/desktop_capture/mac/screen_capturer_mac.h
Julien Isorce 1c4bbba491 Can use the given IOSurfaceRef to reach higher capture framerate on Mac
The given IOSurfaceRef was ignored until now. Wrap it into the new
DesktopFrameIOSurface. The new DesktopFrameProvider object is there
to manage them as it has to be done per display id.

From initial measurement this speed-up the frame capture by 2.

Disabled by default for now but it can be enabled by calling
options.set_use_iosurface. This CL will allow to do some advanced
tests.

Bug: webrtc:8652
Change-Id: Ia9ac0b69b30098774941cb378804b45cb1710119
Reviewed-on: https://webrtc-review.googlesource.com/33014
Commit-Queue: Zijie He <zijiehe@chromium.org>
Reviewed-by: Zijie He <zijiehe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#22801}
2018-04-10 00:37:59 +00:00

117 lines
3.9 KiB
C++

/*
* Copyright (c) 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_MAC_SCREEN_CAPTURER_MAC_H_
#define MODULES_DESKTOP_CAPTURE_MAC_SCREEN_CAPTURER_MAC_H_
#include <CoreGraphics/CoreGraphics.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_geometry.h"
#include "modules/desktop_capture/desktop_region.h"
#include "modules/desktop_capture/mac/desktop_configuration.h"
#include "modules/desktop_capture/mac/desktop_configuration_monitor.h"
#include "modules/desktop_capture/mac/desktop_frame_provider.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 {
class DisplayStreamManager;
// A class to perform video frame capturing for mac.
class ScreenCapturerMac final : public DesktopCapturer {
public:
ScreenCapturerMac(
rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor,
bool detect_updated_region,
bool allow_iosurface);
~ScreenCapturerMac() override;
// TODO(julien.isorce): Remove Init() or make it private.
bool Init();
// DesktopCapturer interface.
void Start(Callback* callback) override;
void CaptureFrame() override;
void SetExcludedWindow(WindowId window) override;
bool GetSourceList(SourceList* screens) override;
bool SelectSource(SourceId id) override;
private:
// Returns false if the selected screen is no longer valid.
bool CgBlit(const DesktopFrame& frame, const DesktopRegion& region);
// Called when the screen configuration is changed.
void ScreenConfigurationChanged();
bool RegisterRefreshAndMoveHandlers();
void UnregisterRefreshAndMoveHandlers();
void ScreenRefresh(CGDirectDisplayID display_id,
CGRectCount count,
const CGRect* rect_array,
DesktopVector display_origin,
IOSurfaceRef io_surface);
void ReleaseBuffers();
std::unique_ptr<DesktopFrame> CreateFrame();
const bool detect_updated_region_;
Callback* callback_ = nullptr;
// Queue of the frames buffers.
ScreenCaptureFrameQueue<SharedDesktopFrame> queue_;
// Current display configuration.
MacDesktopConfiguration desktop_config_;
// Currently selected display, or 0 if the full desktop is selected. On OS X
// 10.6 and before, this is always 0.
CGDirectDisplayID current_display_ = 0;
// The physical pixel bounds of the current screen.
DesktopRect screen_pixel_bounds_;
// The dip to physical pixel scale of the current screen.
float dip_to_pixel_scale_ = 1.0f;
// A thread-safe list of invalid rectangles, and the size of the most
// recently captured screen.
ScreenCapturerHelper helper_;
// Contains an invalid region from the previous capture.
DesktopRegion last_invalid_region_;
// Monitoring display reconfiguration.
rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor_;
CGWindowID excluded_window_ = 0;
// A self-owned object that will destroy itself after ScreenCapturerMac and
// all display streams have been destroyed..
DisplayStreamManager* display_stream_manager_;
// Container holding latest state of the snapshot per displays.
DesktopFrameProvider desktop_frame_provider_;
RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerMac);
};
} // namespace webrtc
#endif // MODULES_DESKTOP_CAPTURE_MAC_SCREEN_CAPTURER_MAC_H_