debug test正常运行

This commit is contained in:
DevWiki 2023-12-22 19:05:40 +08:00
parent 5cce100311
commit 94c19cf117
9 changed files with 103 additions and 95 deletions

2
DeviceManager/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/cmake-*
/output

View File

@ -49,26 +49,41 @@ endif()
target_link_libraries(DeviceManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
set(WinDevice_INCLUDE_DIR "../WinDevice/output/include/")
set(WinDevice_THIRD_INCLUDE_DIR "../WinDevice/output/third_lib/")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Debug WinDevice
add_subdirectory(../WinDevice WinDevice)
# WinDevice
target_include_directories(DeviceManager PRIVATE
../WinDevice/src
include/third_lib
)
target_link_libraries(DeviceManager PRIVATE WinDevice)
set(WinDevice_LIB_DIR "../WinDevice/output/debug/")
else()
# Release WinDevice
target_link_libraries(DeviceManager PRIVATE WinDevice)
# Release WinDevice
target_include_directories(DeviceManager PRIVATE
../WinDevice/lib
)
set(WinDevice_LIB_DIR "../WinDevice/output/release/")
endif()
# 使 find_library
find_library(WinDevice_LIB
NAMES WinDevice
HINTS ${WinDevice_LIB_DIR}
)
#
include_directories(${WinDevice_INCLUDE_DIR} ${WinDevice_THIRD_INCLUDE_DIR})
#
target_link_libraries(DeviceManager PRIVATE ${WinDevice_LIB})
# if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# # Debug WinDevice
# add_subdirectory(../WinDevice WinDevice)
# # WinDevice
# target_include_directories(DeviceManager PRIVATE
# ../WinDevice/src
# include/third_lib
# )
# target_link_libraries(DeviceManager PRIVATE WinDevice)
# else()
# # Release WinDevice
# target_link_libraries(DeviceManager PRIVATE WinDevice)
# # Release WinDevice
# target_include_directories(DeviceManager PRIVATE
# ../WinDevice/lib
# )
# endif()
## target_link_libraries(DeviceManager PRIVATE dxgi)
set_target_properties(DeviceManager PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com

View File

@ -27,13 +27,6 @@ if (ENABLE_UTF8_SOURCE)
endif()
endif()
# 使
file(GLOB_RECURSE SOURCE_FILES "./src/*")
#
add_library(WinDevice SHARED
${SOURCE_FILES}
)
# DirectX
set(Windows_Kits_DIR "C:\\Program Files (x86)\\Windows Kits\\10")
set(Windows_Kits_Version "10.0.19041.0")
@ -48,24 +41,33 @@ else()
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}/dxgi.lib"
"${DirectX_SDK_LIB_DIR}/ddraw.lib"
)
# 使
file(GLOB_RECURSE SOURCE_FILES "./src/*")
set(Third_Include_DIR "include/third_lib/")
#
add_library(WinDevice SHARED
${SOURCE_FILES}
)
# WinDevice
target_include_directories(WinDevice
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
PRIVATE
${DirectX_SDK_INCLUDE_DIR}
include/third_lib
${Third_Include_DIR}
)
# d3d lib
target_link_libraries(WinDevice PRIVATE
"${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"
"${DirectX_SDK_LIB_DIR}\\dxgi.lib")
target_link_libraries(WinDevice PRIVATE ${DirectX_LIBS})
# output
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/output)
@ -75,6 +77,12 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Debug
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG")
set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/debug")
#
add_executable(WinDeviceTest "src/main.cpp" ${SOURCE_FILES})
target_include_directories(WinDeviceTest
PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
PRIVATE ${Third_Include_DIR} ${DirectX_SDK_INCLUDE_DIR})
target_link_libraries(WinDeviceTest PRIVATE ${DirectX_LIBS})
else()
# Release
set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/release")

View File

@ -1,15 +0,0 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
}
]
}

View File

@ -1,7 +1,4 @@
#ifndef STRING_UTIL_H
#define STRING_UTIL_H
#include <string>
#include <string>
#include <locale>
#include <codecvt>
@ -19,6 +16,3 @@ std::string Wchar2String(const WCHAR* input) {
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.to_bytes(input);
}
#endif // STRING_CONVERSION_H

View File

@ -1,10 +1,8 @@
#include "ScreenManager.h"
#include <Windows.h>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "Utils/StringUtil.h"
#include "Utils/Log.h"
#include <dxgi.h>
ScreenManager::ScreenManager()
{
@ -43,43 +41,43 @@ void ScreenManager::_UpdateDisplayDeviceList()
void ScreenManager::_UpdateDisplayAdapterList()
{
LOG_FUNC_START();
HRESULT hr = S_OK;
IDXGIFactory* pFactory = nullptr;
hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory));
if (FAILED(hr)) {
spdlog::error("CreateDXGIFactory failed");
return;
}
LOG_FUNC_START();
HRESULT hr = S_OK;
IDXGIFactory* pFactory = nullptr;
hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory));
if (FAILED(hr)) {
spdlog::error("CreateDXGIFactory failed");
return;
}
IDXGIAdapter* pAdapter = nullptr;
for (UINT adapterIndex = 0; pFactory->EnumAdapters(adapterIndex, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex)
{
DXGI_ADAPTER_DESC adapterDesc;
pAdapter->GetDesc(&adapterDesc);
spdlog::info("Adapter Index:{0}, Description:{1}, DeviceId:{2}, VendorId:{3}, SubSysId:{4}, Revision:{5}, AdapterLuid(H-L):{6}-{7} ",
adapterIndex, Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
adapterDesc.Revision, adapterDesc.AdapterLuid.HighPart, adapterDesc.AdapterLuid.LowPart);
IDXGIAdapter* pAdapter = nullptr;
for (UINT adapterIndex = 0; pFactory->EnumAdapters(adapterIndex, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex)
{
DXGI_ADAPTER_DESC adapterDesc;
pAdapter->GetDesc(&adapterDesc);
spdlog::info("Adapter Index:{0}, Description:{1}, DeviceId:{2}, VendorId:{3}, SubSysId:{4}, Revision:{5}, AdapterLuid(H-L):{6}-{7} ",
adapterIndex, Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
adapterDesc.Revision, adapterDesc.AdapterLuid.HighPart, adapterDesc.AdapterLuid.LowPart);
// print adapter output info
IDXGIOutput* pOutput;
int outputCount = 0;
for (UINT j = 0; pAdapter->EnumOutputs(j, &pOutput) != DXGI_ERROR_NOT_FOUND; ++j) {
DXGI_OUTPUT_DESC outputDesc;
pOutput->GetDesc(&outputDesc);
// print adapter output info
IDXGIOutput* pOutput;
int outputCount = 0;
for (UINT j = 0; pAdapter->EnumOutputs(j, &pOutput) != DXGI_ERROR_NOT_FOUND; ++j) {
DXGI_OUTPUT_DESC outputDesc;
pOutput->GetDesc(&outputDesc);
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFOEX);
if (GetMonitorInfo(outputDesc.Monitor, &monitorInfo))
{
// 输出友好名称
spdlog::info("Adapter Output Index:{0}, DeviceName:{1}, szDevice:{2}, right:{3}, bottom:{4}",
j, Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
}
}
}
pFactory->Release();
LOG_FUNC_END();
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFOEX);
if (GetMonitorInfo(outputDesc.Monitor, &monitorInfo))
{
// 输出友好名称
spdlog::info("Adapter Output Index:{0}, DeviceName:{1}, szDevice:{2}, right:{3}, bottom:{4}",
j, Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
}
}
}
pFactory->Release();
LOG_FUNC_END();
}
BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)

View File

@ -1,9 +1,7 @@
#pragma once
#include <vector>
#include <map>
#include <Mmdeviceapi.h>
#include <dxgi1_6.h>
#include <dxgi.h>
class ScreenManager
{

8
WinDevice/src/main.cpp Normal file
View File

@ -0,0 +1,8 @@
//
// Created by zyz on 2023/12/20.
//
#include "Video/ScreenManager.h"
int main() {
ScreenManager screenManager;
screenManager.UpdateDisplayInfo();
}