[feat] add Windows screen capture method setting

This commit is contained in:
dijunkun
2026-09-11 16:41:16 +08:00
parent ceb0a1654a
commit 9af7417c46
11 changed files with 116 additions and 13 deletions
@@ -439,9 +439,12 @@ int ScreenCapturerWin::Init(const int fps, cb_desktop_data cb) {
return true;
};
// Short-circuiting also keeps the unused WGC plugin unloaded.
if (try_init(std::make_unique<ScreenCapturerDxgi>()) ||
try_init(WgcPluginCapturer::Create()) ||
try_init(std::make_unique<ScreenCapturerGdi>())) {
if ((IsBackendEnabled(ScreenCaptureMethod::Dxgi) &&
try_init(std::make_unique<ScreenCapturerDxgi>())) ||
(IsBackendEnabled(ScreenCaptureMethod::Wgc) &&
try_init(WgcPluginCapturer::Create())) ||
(IsBackendEnabled(ScreenCaptureMethod::Gdi) &&
try_init(std::make_unique<ScreenCapturerGdi>()))) {
LOG_INFO("Windows capturer: using {}", CaptureBackendName(impl_.get()));
BuildCanonicalFromImpl();
monitor_index_.store(0, std::memory_order_relaxed);
@@ -449,7 +452,8 @@ int ScreenCapturerWin::Init(const int fps, cb_desktop_data cb) {
return 0;
}
LOG_ERROR("Windows capturer: all implementations failed, ret={}", ret);
LOG_ERROR("Windows capturer: selected capture method {} failed, ret={}",
static_cast<int>(capture_method_), ret);
return -1;
}
@@ -576,6 +580,11 @@ int ScreenCapturerWin::Start(bool show_cursor) {
}
}
if (ret != 0) {
if (capture_method_ != ScreenCaptureMethod::Auto) {
LOG_ERROR("Windows capturer: selected backend {} failed to start (ret={})",
CaptureBackendName(impl_.get()), ret);
return ret;
}
LOG_WARN("Windows capturer: refresh/start failed (ret={}), trying fallback",
ret);
@@ -799,10 +808,12 @@ bool ScreenCapturerWin::RestartCaptureBackendAfterSecureDesktop() {
return true;
}
if (TryStartBackend(std::make_unique<ScreenCapturerDxgi>(),
current_monitor) ||
TryStartBackend(WgcPluginCapturer::Create(), current_monitor) ||
TryStartBackend(std::make_unique<ScreenCapturerGdi>(), current_monitor)) {
if ((IsBackendEnabled(ScreenCaptureMethod::Dxgi) &&
TryStartBackend(std::make_unique<ScreenCapturerDxgi>(), current_monitor)) ||
(IsBackendEnabled(ScreenCaptureMethod::Wgc) &&
TryStartBackend(WgcPluginCapturer::Create(), current_monitor)) ||
(IsBackendEnabled(ScreenCaptureMethod::Gdi) &&
TryStartBackend(std::make_unique<ScreenCapturerGdi>(), current_monitor))) {
return true;
}
@@ -20,6 +20,7 @@
#include <vector>
#include "screen_capturer.h"
#include "screen_capture_method.h"
#include "privacy_controller.h"
namespace crossdesk {
@@ -45,9 +46,16 @@ class ScreenCapturerWin : public ScreenCapturer {
std::vector<DisplayInfo> GetDisplayInfoList() override;
void SetPrivacyController(PrivacyController* privacy) { privacy_ = privacy; }
// Set before Init(), while capture is stopped.
void SetCaptureMethod(ScreenCaptureMethod method) { capture_method_ = method; }
private:
std::unique_ptr<ScreenCapturer> impl_;
ScreenCaptureMethod capture_method_ = ScreenCaptureMethod::Auto;
bool IsBackendEnabled(ScreenCaptureMethod method) const {
return capture_method_ == ScreenCaptureMethod::Auto ||
capture_method_ == method;
}
PrivacyController* privacy_ = nullptr;
void NotifyPrivacyCapture(bool running);
int fps_ = 60;