fix: add capability to use ScreenCaptureKit for thumbnail generation (#41329)

This aligns us with Chromiums flags / capabilities in regards to using SCK for
everything. Currently on 14.4 Electron apps will pop warnings for usage of
deprecated APIs.  With this change and a few "enable-features" toggles.

`--enable-features="ScreenCaptureKitMac,ScreenCaptureKitStreamPickerSonoma,ThumbnailCapturerMac:capture_mode/sc_screenshot_manager"`

As Chromium enables these by default Electron will inherit those changes, apps wishing to skip ahead can apply these flags early.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
This commit is contained in:
trop[bot]
2024-02-14 01:11:29 -08:00
committed by GitHub
parent 85db55516b
commit 5c71377f40
4 changed files with 84 additions and 12 deletions

View File

@@ -14,6 +14,7 @@
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/media/webrtc/desktop_capturer_wrapper.h"
#include "chrome/browser/media/webrtc/desktop_media_list.h"
#include "chrome/browser/media/webrtc/thumbnail_capturer_mac.h"
#include "chrome/browser/media/webrtc/window_icon_util.h"
#include "content/public/browser/desktop_capture.h"
#include "gin/object_template_builder.h"
@@ -136,6 +137,38 @@ std::map<int32_t, uint32_t> MonitorAtomIdToDisplayId() {
}
#endif
namespace {
std::unique_ptr<ThumbnailCapturer> MakeWindowCapturer() {
#if BUILDFLAG(IS_MAC)
if (ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kWindow)) {
return CreateThumbnailCapturerMac(DesktopMediaList::Type::kWindow);
}
#endif // BUILDFLAG(IS_MAC)
std::unique_ptr<webrtc::DesktopCapturer> window_capturer =
content::desktop_capture::CreateWindowCapturer();
return window_capturer ? std::make_unique<DesktopCapturerWrapper>(
std::move(window_capturer))
: nullptr;
}
std::unique_ptr<ThumbnailCapturer> MakeScreenCapturer() {
#if BUILDFLAG(IS_MAC)
if (ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kScreen)) {
return CreateThumbnailCapturerMac(DesktopMediaList::Type::kScreen);
}
#endif // BUILDFLAG(IS_MAC)
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer =
content::desktop_capture::CreateScreenCapturer();
return screen_capturer ? std::make_unique<DesktopCapturerWrapper>(
std::move(screen_capturer))
: nullptr;
}
} // namespace
namespace gin {
template <>
@@ -265,16 +298,15 @@ void DesktopCapturer::StartHandling(bool capture_window,
// Initialize the source list.
// Apply the new thumbnail size and restart capture.
if (capture_window) {
std::unique_ptr<webrtc::DesktopCapturer> window_capturer =
content::desktop_capture::CreateWindowCapturer();
auto capturer = window_capturer
? std::make_unique<DesktopCapturerWrapper>(
std::move(window_capturer))
: nullptr;
auto capturer = MakeWindowCapturer();
if (capturer) {
window_capturer_ = std::make_unique<NativeDesktopMediaList>(
DesktopMediaList::Type::kWindow, std::move(capturer));
window_capturer_->SetThumbnailSize(thumbnail_size);
#if BUILDFLAG(IS_MAC)
window_capturer_->skip_next_refresh_ =
ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kWindow);
#endif
OnceCallback update_callback = base::BindOnce(
&DesktopCapturer::UpdateSourcesList, weak_ptr_factory_.GetWeakPtr(),
@@ -295,16 +327,15 @@ void DesktopCapturer::StartHandling(bool capture_window,
}
if (capture_screen) {
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer =
content::desktop_capture::CreateScreenCapturer();
auto capturer = screen_capturer
? std::make_unique<DesktopCapturerWrapper>(
std::move(screen_capturer))
: nullptr;
auto capturer = MakeScreenCapturer();
if (capturer) {
screen_capturer_ = std::make_unique<NativeDesktopMediaList>(
DesktopMediaList::Type::kScreen, std::move(capturer));
screen_capturer_->SetThumbnailSize(thumbnail_size);
#if BUILDFLAG(IS_MAC)
screen_capturer_->skip_next_refresh_ =
ShouldUseThumbnailCapturerMac(DesktopMediaList::Type::kScreen);
#endif
OnceCallback update_callback = base::BindOnce(
&DesktopCapturer::UpdateSourcesList, weak_ptr_factory_.GetWeakPtr(),