Skip to content

Commit 8576aee

Browse files
committed
fix windows runner
1 parent 4392dba commit 8576aee

File tree

1 file changed

+62
-65
lines changed

1 file changed

+62
-65
lines changed

src/windows/ThreadRunner.cpp

+62-65
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,86 @@
1-
#include "ScreenCapture.h"
21
#include "DXFrameProcessor.h"
32
#include "GDIFrameProcessor.h"
43
#include "GDIMouseProcessor.h"
54
#include "GDIWindowProcessor.h"
5+
#include "ScreenCapture.h"
66
#include "ThreadManager.h"
77

88
#define NOMINMAX
99
#define WIN32_LEAN_AND_MEAN
1010
#include <windows.h>
1111

12+
#include <iostream>
1213
#include <memory>
1314
#include <string>
14-
#include <iostream>
1515

1616
namespace SL {
17-
namespace Screen_Capture {
18-
17+
namespace Screen_Capture {
1918

20-
template<class T>void ProcessExit(DUPL_RETURN Ret, T* TData) {
21-
if (Ret != DUPL_RETURN_SUCCESS)
22-
{
23-
if (Ret == DUPL_RETURN_ERROR_EXPECTED)
24-
{
25-
// The system is in a transition state so request the duplication be restarted
26-
TData->CommonData_.ExpectedErrorEvent = true;
27-
}
28-
else
29-
{
30-
// Unexpected error so exit the application
31-
TData->CommonData_.UnexpectedErrorEvent = true;
32-
}
19+
template <class T> void ProcessExit(DUPL_RETURN Ret, T *TData)
20+
{
21+
if (Ret != DUPL_RETURN_SUCCESS) {
22+
if (Ret == DUPL_RETURN_ERROR_EXPECTED) {
23+
// The system is in a transition state so request the duplication be restarted
24+
TData->CommonData_.ExpectedErrorEvent = true;
3325
}
34-
}
35-
template<class T>bool SwitchToInputDesktop(const std::shared_ptr<T> data) {
36-
HDESK CurrentDesktop = nullptr;
37-
CurrentDesktop = OpenInputDesktop(0, FALSE, GENERIC_ALL);
38-
if (!CurrentDesktop)
39-
{
40-
// We do not have access to the desktop so request a retry
41-
data->CommonData_.ExpectedErrorEvent = true;
42-
ProcessExit(DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED, data.get());
43-
return false;
26+
else {
27+
// Unexpected error so exit the application
28+
TData->CommonData_.UnexpectedErrorEvent = true;
4429
}
30+
}
31+
}
32+
template <class T> bool SwitchToInputDesktop(const std::shared_ptr<T> data)
33+
{
34+
HDESK CurrentDesktop = nullptr;
35+
CurrentDesktop = OpenInputDesktop(0, FALSE, GENERIC_ALL);
36+
if (!CurrentDesktop) {
37+
// We do not have access to the desktop so request a retry
38+
data->CommonData_.ExpectedErrorEvent = true;
39+
ProcessExit(DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED, data.get());
40+
return false;
41+
}
4542

46-
// Attach desktop to this thread
47-
bool DesktopAttached = SetThreadDesktop(CurrentDesktop) != 0;
48-
CloseDesktop(CurrentDesktop);
49-
CurrentDesktop = nullptr;
50-
if (!DesktopAttached)
51-
{
52-
// We do not have access to the desktop so request a retry
53-
data->CommonData_.ExpectedErrorEvent = true;
54-
ProcessExit(DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED, data.get());
55-
return false;
56-
}
57-
return true;
43+
// Attach desktop to this thread
44+
bool DesktopAttached = SetThreadDesktop(CurrentDesktop) != 0;
45+
CloseDesktop(CurrentDesktop);
46+
CurrentDesktop = nullptr;
47+
if (!DesktopAttached) {
48+
// We do not have access to the desktop so request a retry
49+
data->CommonData_.ExpectedErrorEvent = true;
50+
ProcessExit(DUPL_RETURN::DUPL_RETURN_ERROR_EXPECTED, data.get());
51+
return false;
5852
}
59-
void RunCaptureMouse(std::shared_ptr<Thread_Data> data) {
60-
if (!SwitchToInputDesktop(data)) return;
61-
TryCaptureMouse<GDIMouseProcessor>(data);
62-
}
63-
void RunCaptureMonitor(std::shared_ptr<Thread_Data> data, Monitor monitor) {
64-
//need to switch to the input desktop for capturing...
65-
if (!SwitchToInputDesktop(data)) return;
53+
return true;
54+
}
55+
void RunCaptureMouse(std::shared_ptr<Thread_Data> data)
56+
{
57+
if (!SwitchToInputDesktop(data))
58+
return;
59+
TryCaptureMouse<GDIMouseProcessor>(data);
60+
}
61+
void RunCaptureMonitor(std::shared_ptr<Thread_Data> data, Monitor monitor)
62+
{
63+
// need to switch to the input desktop for capturing...
64+
if (!SwitchToInputDesktop(data))
65+
return;
6666
#if defined _DEBUG || !defined NDEBUG
67-
std::cout << "Starting to Capture on Monitor " << Name(monitor) << std::endl;
68-
std::cout << "Trying DirectX Desktop Duplication " << std::endl;
67+
std::cout << "Starting to Capture on Monitor " << Name(monitor) << std::endl;
68+
std::cout << "Trying DirectX Desktop Duplication " << std::endl;
6969
#endif
70-
if (monitor.Adapter == -1)
71-
{
72-
TryCaptureMonitor<GDIFrameProcessor>(data, monitor);
73-
}
74-
else
75-
{
76-
TryCaptureMonitor<DXFrameProcessor>(data, monitor);
77-
}
78-
}
79-
80-
void RunCaptureWindow(std::shared_ptr<Thread_Data> data, Window wnd) {
81-
//need to switch to the input desktop for capturing...
82-
if (!SwitchToInputDesktop(data)) return;
83-
TryCaptureWindow<GDIFrameProcessor>(data, wnd);
70+
if (!TryCaptureMonitor<DXFrameProcessor>(data, monitor)) { // if DX is not supported, fallback to GDI capture
71+
#if defined _DEBUG || !defined NDEBUG
72+
std::cout << "DirectX Desktop Duplication not supported, falling back to GDI Capturing . . ." << std::endl;
73+
#endif
74+
TryCaptureMonitor<GDIFrameProcessor>(data, monitor);
8475
}
8576
}
86-
}
87-
88-
8977

78+
void RunCaptureWindow(std::shared_ptr<Thread_Data> data, Window wnd)
79+
{
80+
// need to switch to the input desktop for capturing...
81+
if (!SwitchToInputDesktop(data))
82+
return;
83+
TryCaptureWindow<GDIFrameProcessor>(data, wnd);
84+
}
85+
} // namespace Screen_Capture
86+
} // namespace SL

0 commit comments

Comments
 (0)