初始化完毕 并添加debug

This commit is contained in:
zhangyazhou 2023-12-19 20:34:17 +08:00
commit a1912a6302
7 changed files with 264 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
cmake*/
output/
build/
.vs/
.idea/

86
CMakeLists.txt Normal file
View File

@ -0,0 +1,86 @@
cmake_minimum_required(VERSION 3.26)
project(WinMedia)
set(CMAKE_CXX_STANDARD 14)
file(GLOB_RECURSE SOURCE_FILES "./src/*")
add_library(WinMedia SHARED
${SOURCE_FILES}
)
target_precompile_headers(WinMedia PRIVATE "stdafx.h" "Export.h")
set(Windows_Kits_DIR "C:\\Program Files (x86)\\Windows Kits\\10")
set(Windows_Kits_Version "10.0.19041.0")
set(DirectX_SDK_INCLUDE_DIR "${Windows_Kits_DIR}\\Include\\${Windows_Kits_Version}\\um")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64-bit
set(CMAKE_LIBRARY_ARCHITECTURE x64)
set(DirectX_SDK_LIB_DIR "${Windows_Kits_DIR}\\Lib\\${Windows_Kits_Version}\\um\\x64")
else()
# 32-bit
set(CMAKE_LIBRARY_ARCHITECTURE x86)
set(DirectX_SDK_LIB_DIR "${Windows_Kits_DIR}\\Lib\\${Windows_Kits_Version}\\um\\x86")
endif()
# DirectX
file(GLOB DirectX_LIBS
"${DirectX_SDK_LIB_DIR}/d3d9.lib"
"${DirectX_SDK_LIB_DIR}/d3d10.lib"
"${DirectX_SDK_LIB_DIR}/d3d11.lib"
"${DirectX_SDK_LIB_DIR}/d3d12.lib"
"${DirectX_SDK_LIB_DIR}/ddraw.lib"
)
#
target_include_directories(WinMedia
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
PRIVATE
${DirectX_SDK_INCLUDE_DIR}
)
# d3d lib
target_link_libraries(WinMedia PRIVATE ${DirectX_LIBS})
# output
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/output/)
#
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/output)
#
message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") #
# CMakeLists.txt
message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}") #
# include
file(GLOB_RECURSE EXPORTED_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h)
foreach(HEADER ${EXPORTED_HEADERS})
get_filename_component(HEADER_DIR ${HEADER} DIRECTORY)
get_filename_component(HEADER_NAME ${HEADER} NAME)
string(REPLACE "${CMAKE_SOURCE_DIR}/src" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
file(COPY ${HEADER} DESTINATION ${BUILD_DIR}/include/${HEADER_RELATIVE_PATH})
endforeach()
# DLL output
add_custom_command(TARGET WinMedia POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:WinMedia>
${BUILD_DIR})
# Debug
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_executable(WinMediaTest "src/main.cpp" ${SOURCE_FILES})
target_precompile_headers(WinMediaTest PRIVATE "stdafx.h" "Export.h")
# d3d lib
target_link_libraries(WinMediaTest PRIVATE ${DirectX_LIBS})
# DLL output
add_custom_command(TARGET WinMediaTest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:WinMedia>
${BUILD_DIR})
endif ()

7
Export.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#ifdef WINDEVICE_EXPORTS
#define WINDEVICE_API __declspec(dllexport)
#else
#define WINDEVICE_API __declspec(dllimport)
#endif

View File

@ -0,0 +1,101 @@
#include "WinDeviceManager.h"
namespace WinMedia
{
WinDeviceManager::WinDeviceManager()
{
}
WinDeviceManager::~WinDeviceManager()
{
}
bool WinDeviceManager::IsDirectDrawAccelerationAvailable()
{
IDirectDraw* pDirectDraw = nullptr;
HRESULT hr = DirectDrawCreate(nullptr, &pDirectDraw, nullptr);
if (FAILED(hr))
{
// DirectDraw 创建失败,可能是不支持或没有安装 DirectX
return false;
}
// 获取 DirectDraw 加速信息
DDCAPS ddcaps;
ZeroMemory(&ddcaps, sizeof(ddcaps));
ddcaps.dwSize = sizeof(ddcaps);
hr = pDirectDraw->GetCaps(&ddcaps, nullptr);
pDirectDraw->Release();
if (FAILED(hr))
{
// 获取 DirectDraw 加速信息失败
return false;
}
// 检查是否支持硬件加速
return (ddcaps.dwCaps & DDCAPS_NOHARDWARE) == 0;
}
bool WinDeviceManager::IsDirect3DAccelerationAvailable()
{
D3D_FEATURE_LEVEL featureLevel;
// 尝试创建硬件设备,如果失败,尝试创建支持较低特性级别的设备
HRESULT hr = D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
0,
nullptr,
0,
D3D11_SDK_VERSION,
nullptr,
&featureLevel,
nullptr
);
if (SUCCEEDED(hr))
{
return true;
}
// 依次尝试创建支持较低特性级别的设备
hr = D3D10CreateDevice(
nullptr,
D3D10_DRIVER_TYPE_HARDWARE,
nullptr,
0,
D3D10_SDK_VERSION,
nullptr
);
if (SUCCEEDED(hr))
{
return true;
}
IDirect3D9* pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (pD3D == nullptr)
{
// DirectX is not installed or not available
return false;
}
D3DCAPS9 caps;
if (FAILED(pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps)))
{
// Failed to get device capabilities
pD3D->Release();
return false;
}
// Check if Direct3D acceleration is supported
const bool accelerationAvailable = (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0;
pD3D->Release();
return accelerationAvailable;
}
}

View File

@ -0,0 +1,13 @@
#pragma once
namespace WinMedia
{
class WinDeviceManager {
public:
WinDeviceManager();
~WinDeviceManager();
static bool IsDirectDrawAccelerationAvailable();
static bool IsDirect3DAccelerationAvailable();
};
}

13
src/main.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <iostream>
// Your library header(s)
#include "Device/WinDeviceManager.h"
int main() {
// Your test code here
bool draw = WinMedia::WinDeviceManager::IsDirectDrawAccelerationAvailable();
std::cout << "direct draw available:" << draw << std::endl;
bool d3d = WinMedia::WinDeviceManager::IsDirect3DAccelerationAvailable();
std::cout << "d3d available:" << d3d << std::endl;
return 0;
}

38
stdafx.h Normal file
View File

@ -0,0 +1,38 @@
// 防止多次包含此头文件
#pragma once
// 自定义导出定义
#include "Export.h"
// Windows API 头文件
#include <Windows.h>
#include <winerror.h>
#include "winuser.h"
// 附加的 Windows API 头文件
#include <Shlwapi.h>
#include <Psapi.h>
#include <shellapi.h>
// 内置函数和系统信息 API 头文件
#include <intrin.h>
#include "sysinfoapi.h"
// DXGIDirectX 图形基础设施)头文件
#include "dxgi.h"
#include <dxgi1_4.h>
// DirectDraw 头文件,提供 DirectDraw 和相关功能的支持
#include <ddraw.h>
// DirectXMath 头文件,提供高性能的数学运算库,适用于图形和游戏开发
#include <DirectXMath.h>
// DirectWrite 头文件,用于文本渲染,特别是在 Direct2D 中使用
#include <dwrite.h>
// Direct3D 9、10、11、12以及 DirectWrite 头文件
#include <d3d9.h>
#include <d3d9caps.h>
#include <d3d11.h>
#include <d3d10_1.h>
#include <d3d12.h>