Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectX9 Grabber #1039

Merged
merged 8 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ jobs:
runs-on: windows-latest
env:
VCINSTALLDIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC'
QT_VERSION: 5.15.0
steps:
- name: Checkout
uses: actions/checkout@v1
Expand All @@ -137,20 +138,37 @@ jobs:
tr -d '\n' < version > temp && mv temp version
echo -n "-PR#${{ github.event.pull_request.number }}" >> version

- name: Cache Qt
uses: actions/cache@v2
id: cache-qt-windows
with:
path: ${{ runner.workspace }}/Qt
key: ${{ runner.os }}-Qt.${{ env.QT_VERSION }}

- name: Install Qt
uses: jurplel/install-qt-action@v2
with:
version: '5.15.0'
version: ${{env.QT_VERSION}}
target: 'desktop'
arch: 'win64_msvc2019_64'
cached: ${{ steps.cache-qt-windows.outputs.cache-hit }}

- name: Install Python
uses: actions/setup-python@v1
- name: Cache Chocolatey downloads
uses: actions/cache@v2
with:
python-version: '3.x'
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
key: ${{ runner.os }}-chocolatey

- name: "Remove Redistributable"
shell: cmd
run: |
MsiExec.exe /passive /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}
MsiExec.exe /passive /X{1D8E6291-B0D5-35EC-8441-6616F567A0F7}

- name: Install OpenSSL & NSIS
run: choco install --no-progress openssl nsis -y
- name: Install Python, NSIS, OpenSSL, DirectX SDK
shell: powershell
run: |
choco install --no-progress python nsis openssl directx-sdk -y

- name: Set up x64 build architecture environment
shell: cmd
Expand Down
30 changes: 24 additions & 6 deletions .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,44 @@ jobs:
runs-on: windows-latest
env:
VCINSTALLDIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC'
QT_VERSION: 5.15.0
steps:
- name: Checkout
uses: actions/checkout@v1
with:
submodules: true

- name: Cache Qt
uses: actions/cache@v2
id: cache-qt-windows
with:
path: ${{ runner.workspace }}/Qt
key: ${{ runner.os }}-Qt.${{ env.QT_VERSION }}

- name: Install Qt
uses: jurplel/install-qt-action@v2
with:
version: '5.15.0'
version: ${{ env.QT_VERSION }}
target: 'desktop'
arch: 'win64_msvc2019_64'
cached: ${{ steps.cache-qt-windows.outputs.cache-hit }}

- name: Install Python
uses: actions/setup-python@v1
- name: Cache Chocolatey downloads
uses: actions/cache@v2
with:
python-version: '3.x'
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
key: ${{ runner.os }}-chocolatey

- name: "Remove Redistributable"
shell: cmd
run: |
MsiExec.exe /passive /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}
MsiExec.exe /passive /X{1D8E6291-B0D5-35EC-8441-6616F567A0F7}

- name: Install OpenSSL & NSIS
run: choco install --no-progress openssl nsis -y
- name: Install Python, NSIS, OpenSSL, DirectX SDK
shell: powershell
run: |
choco install --no-progress python nsis openssl directx-sdk -y

- name: Set up x64 build architecture environment
shell: cmd
Expand Down
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ endif()
SET ( DEFAULT_AMLOGIC OFF )
SET ( DEFAULT_DISPMANX OFF )
SET ( DEFAULT_OSX OFF )
SET ( DEFAULT_QT ON )
Paulchen-Panther marked this conversation as resolved.
Show resolved Hide resolved
SET ( DEFAULT_X11 OFF )
SET ( DEFAULT_XCB OFF )
SET ( DEFAULT_QT ON )
SET ( DEFAULT_WS281XPWM OFF )
SET ( DEFAULT_AVAHI ON )
SET ( DEFAULT_USE_SHARED_AVAHI_LIBS ON )
Expand All @@ -58,6 +58,8 @@ IF ( ${CMAKE_SYSTEM} MATCHES "Linux" )
SET ( DEFAULT_FB ON )
SET ( DEFAULT_USB_HID ON )
SET ( DEFAULT_CEC ON )
ELSEIF ( WIN32 )
SET ( DEFAULT_DX ON )
ELSE()
SET ( DEFAULT_V4L2 OFF )
SET ( DEFAULT_FB OFF )
Expand Down Expand Up @@ -190,6 +192,9 @@ message(STATUS "ENABLE_XCB = ${ENABLE_XCB}")
option(ENABLE_QT "Enable the qt grabber" ${DEFAULT_QT})
message(STATUS "ENABLE_QT = ${ENABLE_QT}")

option(ENABLE_DX "Enable the DirectX grabber" ${DEFAULT_DX})
message(STATUS "ENABLE_DX = ${ENABLE_DX}")

option(ENABLE_TESTS "Compile additional test applications" ${DEFAULT_TESTS})
message(STATUS "ENABLE_TESTS = ${ENABLE_TESTS}")

Expand Down Expand Up @@ -303,6 +308,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message(STATUS "Set Qt5 module path: ${SUBDIRQT}")
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${SUBDIRQT}/msvc2019_64/lib/cmake/Qt5")
endif()

# Search for DirectX9
if (ENABLE_DX)
find_package(DirectX9 REQUIRED)
endif()

endif()

# Use GNU gold linker if available
Expand Down
3 changes: 3 additions & 0 deletions HyperionConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
// Define to enable the qt grabber
#cmakedefine ENABLE_QT

// Define to enable the DirectX grabber
#cmakedefine ENABLE_DX

// Define to enable the spi-device
#cmakedefine ENABLE_SPIDEV

Expand Down
32 changes: 32 additions & 0 deletions cmake/FindDirectX9.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Find the DirectX 9 includes and library
# This module defines:
# DIRECTX9_INCLUDE_DIRS, where to find d3d9.h, etc.
# DIRECTX9_LIBRARIES, libraries to link against to use DirectX.
# DIRECTX9_FOUND, If false, do not try to use DirectX.
# DIRECTX9_ROOT_DIR, directory where DirectX was installed.

set(DIRECTX9_INCLUDE_PATHS
"$ENV{DXSDK_DIR}/Include"
"$ENV{DIRECTX_ROOT}/Include"
"C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Include"
"C:/Program Files/Microsoft DirectX SDK (June 2010)/Include"
)
find_path(DIRECTX9_INCLUDE_DIRS d3dx9.h ${DIRECTX9_INCLUDE_PATHS} NO_DEFAULT_PATH)

get_filename_component(DIRECTX9_ROOT_DIR "${DIRECTX9_INCLUDE_DIRS}/.." ABSOLUTE)

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(DIRECTX9_LIBRARY_PATHS "${DIRECTX9_ROOT_DIR}/Lib/x64")
else ()
set(DIRECTX9_LIBRARY_PATHS "${DIRECTX9_ROOT_DIR}/Lib/x86" "${DIRECTX9_ROOT_DIR}/Lib")
endif ()

find_library(DIRECTX9_D3D9_LIBRARY d3d9 ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH)
find_library(DIRECTX9_D3DX9_LIBRARY d3dx9 ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH)
find_library(DIRECTX9_DXERR_LIBRARY DxErr ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH)
set(DIRECTX9_LIBRARIES ${DIRECTX9_D3D9_LIBRARY} ${DIRECTX9_D3DX9_LIBRARY} ${DIRECTX9_DXERR_LIBRARY})

# handle the QUIETLY and REQUIRED arguments and set DIRECTX9_FOUND to TRUE if all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(DirectX9 DEFAULT_MSG DIRECTX9_ROOT_DIR DIRECTX9_LIBRARIES DIRECTX9_INCLUDE_DIRS)
mark_as_advanced(DIRECTX9_INCLUDE_DIRS DIRECTX9_D3D9_LIBRARY DIRECTX9_D3DX9_LIBRARY DIRECTX9_DXERR_LIBRARY)
79 changes: 79 additions & 0 deletions include/grabber/DirectXGrabber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once

#include <QObject>

// DirectX 9 header
#include <d3d9.h>
#include <d3dx9.h>

// Hyperion-utils includes
#include <utils/ColorRgb.h>
#include <hyperion/Grabber.h>

///
/// @brief The DirectX9 capture implementation
///
class DirectXGrabber : public Grabber
{
public:

DirectXGrabber(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation, int display);

virtual ~DirectXGrabber();

///
/// Captures a single snapshot of the display and writes the data to the given image. The
/// provided image should have the same dimensions as the configured values (_width and
/// _height)
///
/// @param[out] image The snapped screenshot
///
virtual int grabFrame(Image<ColorRgb> & image);

///
/// @brief Set a new video mode
///
virtual void setVideoMode(VideoMode mode);

///
/// @brief Apply new width/height values, overwrite Grabber.h implementation
///
virtual bool setWidthHeight(int width, int height) { return true; };

///
/// @brief Apply new pixelDecimation
///
virtual void setPixelDecimation(int pixelDecimation);

///
/// Set the crop values
/// @param cropLeft Left pixel crop
/// @param cropRight Right pixel crop
/// @param cropTop Top pixel crop
/// @param cropBottom Bottom pixel crop
///
virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);

private:
///
/// @brief Setup a new capture display, will free the previous one
/// @return True on success, false if no display is found
///
bool setupDisplay();

///
/// @brief free the _screen pointer
///
void freeResources();

private:
int _pixelDecimation;
unsigned _displayWidth;
unsigned _displayHeight;
RECT* _srcRect;

IDirect3D9* _d3d9;
IDirect3DDevice9* _device;
IDirect3DSurface9* _surface;
IDirect3DSurface9* _surfaceDest;
};
36 changes: 36 additions & 0 deletions include/grabber/DirectXWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <hyperion/GrabberWrapper.h>
#include <grabber/DirectXGrabber.h>

class DirectXWrapper: public GrabberWrapper
{
public:
///
/// Constructs the DirectX grabber with a specified grab size and update rate.
///
/// @param[in] cropLeft Remove from left [pixels]
/// @param[in] cropRight Remove from right [pixels]
/// @param[in] cropTop Remove from top [pixels]
/// @param[in] cropBottom Remove from bottom [pixels]
/// @param[in] pixelDecimation Decimation factor for image [pixels]
/// @param[in] display The display used[index]
/// @param[in] updateRate_Hz The image grab rate [Hz]
///
DirectXWrapper(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation, int display, const unsigned updateRate_Hz);

///
/// Destructor of this DirectX grabber. Releases any claimed resources.
///
virtual ~DirectXWrapper() {};

public slots:
///
/// Performs a single frame grab and computes the led-colors
///
virtual void action();

private:
/// The actual grabber
DirectXGrabber _grabber;
};
4 changes: 4 additions & 0 deletions libsrc/grabber/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ endif()
if (ENABLE_QT)
add_subdirectory(qt)
endif()

if (ENABLE_DX)
add_subdirectory(directx)
endif()
14 changes: 14 additions & 0 deletions libsrc/grabber/directx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Define the current source locations
SET( CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/grabber )
SET( CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/directx )

include_directories(${DIRECTX9_INCLUDE_DIRS})

FILE ( GLOB DIRECTX_GRAB_SOURCES "${CURRENT_HEADER_DIR}/DirectX*.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*.cpp" )

add_library( directx-grabber ${DIRECTX_GRAB_SOURCES} )

target_link_libraries(directx-grabber
hyperion
${DIRECTX9_LIBRARIES}
)
Loading