Skip to content

Commit 1d35338

Browse files
DirectX9 Grabber (#1039)
1 parent 65a036d commit 1d35338

File tree

15 files changed

+474
-16
lines changed

15 files changed

+474
-16
lines changed

.github/workflows/pull-request.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ jobs:
124124
runs-on: windows-latest
125125
env:
126126
VCINSTALLDIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC'
127+
QT_VERSION: 5.15.0
127128
steps:
128129
- name: Checkout
129130
uses: actions/checkout@v1
@@ -137,20 +138,37 @@ jobs:
137138
tr -d '\n' < version > temp && mv temp version
138139
echo -n "-PR#${{ github.event.pull_request.number }}" >> version
139140
141+
- name: Cache Qt
142+
uses: actions/cache@v2
143+
id: cache-qt-windows
144+
with:
145+
path: ${{ runner.workspace }}/Qt
146+
key: ${{ runner.os }}-Qt.${{ env.QT_VERSION }}
147+
140148
- name: Install Qt
141149
uses: jurplel/install-qt-action@v2
142150
with:
143-
version: '5.15.0'
151+
version: ${{env.QT_VERSION}}
144152
target: 'desktop'
145153
arch: 'win64_msvc2019_64'
154+
cached: ${{ steps.cache-qt-windows.outputs.cache-hit }}
146155

147-
- name: Install Python
148-
uses: actions/setup-python@v1
156+
- name: Cache Chocolatey downloads
157+
uses: actions/cache@v2
149158
with:
150-
python-version: '3.x'
159+
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
160+
key: ${{ runner.os }}-chocolatey
161+
162+
- name: "Remove Redistributable"
163+
shell: cmd
164+
run: |
165+
MsiExec.exe /passive /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}
166+
MsiExec.exe /passive /X{1D8E6291-B0D5-35EC-8441-6616F567A0F7}
151167
152-
- name: Install OpenSSL & NSIS
153-
run: choco install --no-progress openssl nsis -y
168+
- name: Install Python, NSIS, OpenSSL, DirectX SDK
169+
shell: powershell
170+
run: |
171+
choco install --no-progress python nsis openssl directx-sdk -y
154172
155173
- name: Set up x64 build architecture environment
156174
shell: cmd

.github/workflows/push-master.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,44 @@ jobs:
9595
runs-on: windows-latest
9696
env:
9797
VCINSTALLDIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC'
98+
QT_VERSION: 5.15.0
9899
steps:
99100
- name: Checkout
100101
uses: actions/checkout@v1
101102
with:
102103
submodules: true
103104

105+
- name: Cache Qt
106+
uses: actions/cache@v2
107+
id: cache-qt-windows
108+
with:
109+
path: ${{ runner.workspace }}/Qt
110+
key: ${{ runner.os }}-Qt.${{ env.QT_VERSION }}
111+
104112
- name: Install Qt
105113
uses: jurplel/install-qt-action@v2
106114
with:
107-
version: '5.15.0'
115+
version: ${{ env.QT_VERSION }}
108116
target: 'desktop'
109117
arch: 'win64_msvc2019_64'
118+
cached: ${{ steps.cache-qt-windows.outputs.cache-hit }}
110119

111-
- name: Install Python
112-
uses: actions/setup-python@v1
120+
- name: Cache Chocolatey downloads
121+
uses: actions/cache@v2
113122
with:
114-
python-version: '3.x'
123+
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
124+
key: ${{ runner.os }}-chocolatey
125+
126+
- name: "Remove Redistributable"
127+
shell: cmd
128+
run: |
129+
MsiExec.exe /passive /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}
130+
MsiExec.exe /passive /X{1D8E6291-B0D5-35EC-8441-6616F567A0F7}
115131
116-
- name: Install OpenSSL & NSIS
117-
run: choco install --no-progress openssl nsis -y
132+
- name: Install Python, NSIS, OpenSSL, DirectX SDK
133+
shell: powershell
134+
run: |
135+
choco install --no-progress python nsis openssl directx-sdk -y
118136
119137
- name: Set up x64 build architecture environment
120138
shell: cmd

CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ endif()
3939
SET ( DEFAULT_AMLOGIC OFF )
4040
SET ( DEFAULT_DISPMANX OFF )
4141
SET ( DEFAULT_OSX OFF )
42+
SET ( DEFAULT_QT ON )
4243
SET ( DEFAULT_X11 OFF )
4344
SET ( DEFAULT_XCB OFF )
44-
SET ( DEFAULT_QT ON )
4545
SET ( DEFAULT_WS281XPWM OFF )
4646
SET ( DEFAULT_AVAHI ON )
4747
SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON )
@@ -58,6 +58,8 @@ IF ( ${CMAKE_SYSTEM} MATCHES "Linux" )
5858
SET ( DEFAULT_FB ON )
5959
SET ( DEFAULT_USB_HID ON )
6060
SET ( DEFAULT_CEC ON )
61+
ELSEIF ( WIN32 )
62+
SET ( DEFAULT_DX ON )
6163
ELSE()
6264
SET ( DEFAULT_V4L2 OFF )
6365
SET ( DEFAULT_FB OFF )
@@ -190,6 +192,9 @@ message(STATUS "ENABLE_XCB = ${ENABLE_XCB}")
190192
option(ENABLE_QT "Enable the qt grabber" ${DEFAULT_QT})
191193
message(STATUS "ENABLE_QT = ${ENABLE_QT}")
192194

195+
option(ENABLE_DX "Enable the DirectX grabber" ${DEFAULT_DX})
196+
message(STATUS "ENABLE_DX = ${ENABLE_DX}")
197+
193198
option(ENABLE_TESTS "Compile additional test applications" ${DEFAULT_TESTS})
194199
message(STATUS "ENABLE_TESTS = ${ENABLE_TESTS}")
195200

@@ -303,6 +308,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
303308
message(STATUS "Set Qt5 module path: ${SUBDIRQT}")
304309
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${SUBDIRQT}/msvc2019_64/lib/cmake/Qt5")
305310
endif()
311+
312+
# Search for DirectX9
313+
if (ENABLE_DX)
314+
find_package(DirectX9 REQUIRED)
315+
endif()
316+
306317
endif()
307318

308319
# Use GNU gold linker if available

HyperionConfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
// Define to enable the qt grabber
2525
#cmakedefine ENABLE_QT
2626

27+
// Define to enable the DirectX grabber
28+
#cmakedefine ENABLE_DX
29+
2730
// Define to enable the spi-device
2831
#cmakedefine ENABLE_SPIDEV
2932

cmake/FindDirectX9.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Find the DirectX 9 includes and library
2+
# This module defines:
3+
# DIRECTX9_INCLUDE_DIRS, where to find d3d9.h, etc.
4+
# DIRECTX9_LIBRARIES, libraries to link against to use DirectX.
5+
# DIRECTX9_FOUND, If false, do not try to use DirectX.
6+
# DIRECTX9_ROOT_DIR, directory where DirectX was installed.
7+
8+
set(DIRECTX9_INCLUDE_PATHS
9+
"$ENV{DXSDK_DIR}/Include"
10+
"$ENV{DIRECTX_ROOT}/Include"
11+
"C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Include"
12+
"C:/Program Files/Microsoft DirectX SDK (June 2010)/Include"
13+
)
14+
find_path(DIRECTX9_INCLUDE_DIRS d3dx9.h ${DIRECTX9_INCLUDE_PATHS} NO_DEFAULT_PATH)
15+
16+
get_filename_component(DIRECTX9_ROOT_DIR "${DIRECTX9_INCLUDE_DIRS}/.." ABSOLUTE)
17+
18+
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
19+
set(DIRECTX9_LIBRARY_PATHS "${DIRECTX9_ROOT_DIR}/Lib/x64")
20+
else ()
21+
set(DIRECTX9_LIBRARY_PATHS "${DIRECTX9_ROOT_DIR}/Lib/x86" "${DIRECTX9_ROOT_DIR}/Lib")
22+
endif ()
23+
24+
find_library(DIRECTX9_D3D9_LIBRARY d3d9 ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH)
25+
find_library(DIRECTX9_D3DX9_LIBRARY d3dx9 ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH)
26+
find_library(DIRECTX9_DXERR_LIBRARY DxErr ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH)
27+
set(DIRECTX9_LIBRARIES ${DIRECTX9_D3D9_LIBRARY} ${DIRECTX9_D3DX9_LIBRARY} ${DIRECTX9_DXERR_LIBRARY})
28+
29+
# handle the QUIETLY and REQUIRED arguments and set DIRECTX9_FOUND to TRUE if all listed variables are TRUE
30+
include(FindPackageHandleStandardArgs)
31+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(DirectX9 DEFAULT_MSG DIRECTX9_ROOT_DIR DIRECTX9_LIBRARIES DIRECTX9_INCLUDE_DIRS)
32+
mark_as_advanced(DIRECTX9_INCLUDE_DIRS DIRECTX9_D3D9_LIBRARY DIRECTX9_D3DX9_LIBRARY DIRECTX9_DXERR_LIBRARY)

include/grabber/DirectXGrabber.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#pragma once
2+
3+
#include <QObject>
4+
5+
// DirectX 9 header
6+
#include <d3d9.h>
7+
#include <d3dx9.h>
8+
9+
// Hyperion-utils includes
10+
#include <utils/ColorRgb.h>
11+
#include <hyperion/Grabber.h>
12+
13+
///
14+
/// @brief The DirectX9 capture implementation
15+
///
16+
class DirectXGrabber : public Grabber
17+
{
18+
public:
19+
20+
DirectXGrabber(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation, int display);
21+
22+
virtual ~DirectXGrabber();
23+
24+
///
25+
/// Captures a single snapshot of the display and writes the data to the given image. The
26+
/// provided image should have the same dimensions as the configured values (_width and
27+
/// _height)
28+
///
29+
/// @param[out] image The snapped screenshot
30+
///
31+
virtual int grabFrame(Image<ColorRgb> & image);
32+
33+
///
34+
/// @brief Set a new video mode
35+
///
36+
virtual void setVideoMode(VideoMode mode);
37+
38+
///
39+
/// @brief Apply new width/height values, overwrite Grabber.h implementation
40+
///
41+
virtual bool setWidthHeight(int width, int height) { return true; };
42+
43+
///
44+
/// @brief Apply new pixelDecimation
45+
///
46+
virtual void setPixelDecimation(int pixelDecimation);
47+
48+
///
49+
/// Set the crop values
50+
/// @param cropLeft Left pixel crop
51+
/// @param cropRight Right pixel crop
52+
/// @param cropTop Top pixel crop
53+
/// @param cropBottom Bottom pixel crop
54+
///
55+
virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);
56+
57+
private:
58+
///
59+
/// @brief Setup a new capture display, will free the previous one
60+
/// @return True on success, false if no display is found
61+
///
62+
bool setupDisplay();
63+
64+
///
65+
/// @brief free the _screen pointer
66+
///
67+
void freeResources();
68+
69+
private:
70+
int _pixelDecimation;
71+
unsigned _displayWidth;
72+
unsigned _displayHeight;
73+
RECT* _srcRect;
74+
75+
IDirect3D9* _d3d9;
76+
IDirect3DDevice9* _device;
77+
IDirect3DSurface9* _surface;
78+
IDirect3DSurface9* _surfaceDest;
79+
};

include/grabber/DirectXWrapper.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <hyperion/GrabberWrapper.h>
4+
#include <grabber/DirectXGrabber.h>
5+
6+
class DirectXWrapper: public GrabberWrapper
7+
{
8+
public:
9+
///
10+
/// Constructs the DirectX grabber with a specified grab size and update rate.
11+
///
12+
/// @param[in] cropLeft Remove from left [pixels]
13+
/// @param[in] cropRight Remove from right [pixels]
14+
/// @param[in] cropTop Remove from top [pixels]
15+
/// @param[in] cropBottom Remove from bottom [pixels]
16+
/// @param[in] pixelDecimation Decimation factor for image [pixels]
17+
/// @param[in] display The display used[index]
18+
/// @param[in] updateRate_Hz The image grab rate [Hz]
19+
///
20+
DirectXWrapper(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation, int display, const unsigned updateRate_Hz);
21+
22+
///
23+
/// Destructor of this DirectX grabber. Releases any claimed resources.
24+
///
25+
virtual ~DirectXWrapper() {};
26+
27+
public slots:
28+
///
29+
/// Performs a single frame grab and computes the led-colors
30+
///
31+
virtual void action();
32+
33+
private:
34+
/// The actual grabber
35+
DirectXGrabber _grabber;
36+
};

libsrc/grabber/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ endif()
2929
if (ENABLE_QT)
3030
add_subdirectory(qt)
3131
endif()
32+
33+
if (ENABLE_DX)
34+
add_subdirectory(directx)
35+
endif()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Define the current source locations
2+
SET( CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/grabber )
3+
SET( CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/directx )
4+
5+
include_directories(${DIRECTX9_INCLUDE_DIRS})
6+
7+
FILE ( GLOB DIRECTX_GRAB_SOURCES "${CURRENT_HEADER_DIR}/DirectX*.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.cpp" )
8+
9+
add_library( directx-grabber ${DIRECTX_GRAB_SOURCES} )
10+
11+
target_link_libraries(directx-grabber
12+
hyperion
13+
${DIRECTX9_LIBRARIES}
14+
)

0 commit comments

Comments
 (0)