no message
parent
aafe88ac8b
commit
fb5a48bc84
|
@ -28,239 +28,20 @@ int RegiesterOwnType(){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDirect3DDevice9* g_pd3dDevice = nullptr;
|
|
||||||
|
|
||||||
// 全???======================================================
|
|
||||||
|
|
||||||
// 建立D3DDevice
|
|
||||||
|
|
||||||
LPDIRECT3D9 g_pD3D = nullptr; // Used to create the D3DDevice
|
|
||||||
|
|
||||||
// (我?的?)render?置,用??生最後影像的?置
|
|
||||||
|
|
||||||
|
|
||||||
// =============================================================
|
|
||||||
HRESULT ScreenGrab(LPDIRECT3DDEVICE9 pDev)
|
|
||||||
|
|
||||||
{
|
|
||||||
HRESULT hr;
|
|
||||||
D3DDISPLAYMODE mode;
|
|
||||||
if (FAILED(hr=pDev->GetDisplayMode(0, &mode))) //第一???是Swap Chain,跟?重???有防止破碎
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
IDirect3DSurface9* pSurface;
|
|
||||||
|
|
||||||
if (FAILED(hr=pDev->CreateOffscreenPlainSurface(mode.Width,mode.Height,
|
|
||||||
D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL)))
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
|
|
||||||
if (FAILED(hr=pDev->GetFrontBufferData(0,pSurface))) {
|
|
||||||
pSurface->Release();
|
|
||||||
return hr;
|
|
||||||
}
|
|
||||||
D3DLOCKED_RECT lockedRect;
|
|
||||||
if(FAILED(pSurface->LockRect(&lockedRect,NULL,D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY)))
|
|
||||||
{
|
|
||||||
printf("Unable to Lock Front Buffer Surface");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
BYTE* pBits = new BYTE[2960*1440*3];
|
|
||||||
for(int i=0;i<mode.Height;i++)
|
|
||||||
{
|
|
||||||
memcpy((BYTE*)pBits+(mode.Height-i-1)*mode.Width*3/8,(BYTE*)lockedRect.pBits+i*lockedRect.Pitch,
|
|
||||||
mode.Width*3/8);//g_d3dpp.BackBufferHeight*g_d3dpp.BackBufferWidth*4);
|
|
||||||
|
|
||||||
}
|
|
||||||
pSurface->UnlockRect();
|
|
||||||
|
|
||||||
SetCursor(LoadCursor(NULL,IDC_ARROW));
|
|
||||||
|
|
||||||
// release the image surface
|
|
||||||
|
|
||||||
// ?放影像表面
|
|
||||||
|
|
||||||
pSurface->Release();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// return status of save operation to caller
|
|
||||||
|
|
||||||
// 回?Handler
|
|
||||||
|
|
||||||
return hr;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QVector<tagDublicatorMonitorInfo> GetMonitors()
|
|
||||||
{
|
|
||||||
QVector<tagDublicatorMonitorInfo> ret;
|
|
||||||
HRESULT hr = S_OK;
|
|
||||||
CDXGICapture dxgiCapture;
|
|
||||||
hr = dxgiCapture.Initialize();
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
printf("Error[0x%08X]: CDXGICapture::Initialize failed.\n", hr);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int nMonitorCount = dxgiCapture.GetDublicatorMonitorInfoCount();
|
|
||||||
printf("{\n");
|
|
||||||
if (nMonitorCount > 0) {
|
|
||||||
printf(" \"count\" : %u,\n", nMonitorCount);
|
|
||||||
printf(" \"monitors\" : [\n");
|
|
||||||
for (int i = 0; i < nMonitorCount; ++i) {
|
|
||||||
const tagDublicatorMonitorInfo *pInfo = dxgiCapture.GetDublicatorMonitorInfo(i);
|
|
||||||
if (nullptr != pInfo) {
|
|
||||||
printf(" {\n");
|
|
||||||
printf(" \"idx\" : %u,\n", pInfo->Idx);
|
|
||||||
printf(" \"name\" : \"%S\",\n", pInfo->DisplayName);
|
|
||||||
printf(" \"x\" : %d,\n", pInfo->Bounds.X);
|
|
||||||
printf(" \"y\" : %d,\n", pInfo->Bounds.Y);
|
|
||||||
printf(" \"width\" : %d,\n", pInfo->Bounds.Width);
|
|
||||||
printf(" \"height\" : %d,\n", pInfo->Bounds.Height);
|
|
||||||
printf(" \"rotation\" : %d\n", pInfo->RotationDegrees);
|
|
||||||
if (i < (nMonitorCount - 1)) {
|
|
||||||
printf(" },\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" }\n");
|
|
||||||
}
|
|
||||||
ret.push_back(*pInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf(" ]\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(" \"count\" : %u\n", nMonitorCount);
|
|
||||||
}
|
|
||||||
printf("}\n");
|
|
||||||
|
|
||||||
dxgiCapture.Terminate();
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT InitD3D( HWND hWnd )
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
// Create the D3D object, which is needed to create the D3DDevice.
|
|
||||||
|
|
||||||
// D3DDevice所需要的D3D物件,Direct3DCreate9回?D3DDevice,?入值?使用者安?DirectX的版本
|
|
||||||
|
|
||||||
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
|
|
||||||
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Set up the structure used to create the D3DDevice. Most parameters are
|
|
||||||
|
|
||||||
// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
|
|
||||||
|
|
||||||
// window, and then set the SwapEffect to "discard", which is the most
|
|
||||||
|
|
||||||
// efficient method of presenting the back buffer to the display. And
|
|
||||||
|
|
||||||
// we request a back buffer format that matches the current desktop display
|
|
||||||
|
|
||||||
// format.
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
用?建立D3DDevice的??。大多????0。
|
|
||||||
|
|
||||||
?定是否?"?窗化"?真,就是?示??窗化。
|
|
||||||
|
|
||||||
如果?D3D於?窗?行,?SwapEffect定"discard",??在後端??呈???最有效率。
|
|
||||||
|
|
||||||
?且我?要求後端??的?示格式??在的?面相符。
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
D3DPRESENT_PARAMETERS d3dpp;
|
|
||||||
|
|
||||||
ZeroMemory( &d3dpp, sizeof( d3dpp ) ); //初始化d3d的??
|
|
||||||
|
|
||||||
d3dpp.Windowed = TRUE; //?定?窗化
|
|
||||||
|
|
||||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //提高效率
|
|
||||||
|
|
||||||
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; //??有呈??面相符格式(竟然是?定未知= =)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Create the Direct3D device. Here we are using the default adapter (most
|
|
||||||
|
|
||||||
// systems only have one, unless they have multiple graphics hardware cards
|
|
||||||
|
|
||||||
// installed) and requesting the HAL (which is saying we want the hardware
|
|
||||||
|
|
||||||
// device rather than a software one). Software vertex processing is
|
|
||||||
|
|
||||||
// specified since we know it will work on all cards. On cards that support
|
|
||||||
|
|
||||||
// hardware vertex processing, though, we would see a big performance gain
|
|
||||||
|
|
||||||
// by specifying hardware vertex processing.
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
建立Direct3D?置。我?使用??的adapter(?似?置的意思= =)。
|
|
||||||
|
|
||||||
?大多?的使用者??只有一??置(?示卡),除非他?有其多的?示卡。
|
|
||||||
|
|
||||||
?且要求HAL,也就是?先用?示卡?示,而不是用???理。
|
|
||||||
|
|
||||||
既然我?知道????(角)?理的?理方式被定?所有?示卡。
|
|
||||||
|
|
||||||
於支援硬????理的?示卡上,我??看到?佳的?行效率。
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, //??adapter
|
|
||||||
|
|
||||||
D3DDEVTYPE_HAL, //硬?加速
|
|
||||||
|
|
||||||
hWnd, //Handler名?
|
|
||||||
|
|
||||||
//D3DCREATE_SOFTWARE_VERTEXPROCESSING, //最後竟然用???
|
|
||||||
|
|
||||||
D3DCREATE_HARDWARE_VERTEXPROCESSING, //改用硬?加速吧
|
|
||||||
|
|
||||||
&d3dpp, //D3D??
|
|
||||||
|
|
||||||
&g_pd3dDevice //D3D最後?示?置??
|
|
||||||
|
|
||||||
) ) )
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
return E_FAIL;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Device state would normally be set here
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
setbuf(stdout, NULL);//让printf立即输出
|
setbuf(stdout, NULL);//让printf立即输出
|
||||||
|
ScreenCapture p;
|
||||||
|
p.EnumScreen();
|
||||||
|
|
||||||
|
Direct3D9TakeScreenshots(0,4);
|
||||||
QssEventFilter filter;
|
QssEventFilter filter;
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
|
||||||
MainWindow main;
|
MainWindow main;
|
||||||
InitD3D((HWND)main.winId());
|
|
||||||
ScreenGrab( g_pd3dDevice);
|
|
||||||
main.setWindowTitle("流媒体测试工具");
|
main.setWindowTitle("流媒体测试工具");
|
||||||
main.setFixedSize(1920,1080);
|
main.setFixedSize(1920,1080);
|
||||||
main.show();
|
main.show();
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#if _MSC_VER >= 1600
|
||||||
|
#pragma execution_character_set("utf-8")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define WIDEN2(x) L ## x
|
#define WIDEN2(x) L ## x
|
||||||
#define WIDEN(x) WIDEN2(x)
|
#define WIDEN(x) WIDEN2(x)
|
||||||
#define __WFILE__ WIDEN(__FILE__)
|
#define __WFILE__ WIDEN(__FILE__)
|
||||||
|
@ -14,7 +19,8 @@
|
||||||
// ȱenum·½·¨
|
// ȱenum·½·¨
|
||||||
// https://www.gamedev.net/forums/topic/132636-enum-displaymode--dx9--false/
|
// https://www.gamedev.net/forums/topic/132636-enum-displaymode--dx9--false/
|
||||||
|
|
||||||
HRESULT SavePixelsToFile32bppPBGRA(UINT width, UINT height, UINT stride, LPBYTE pixels, LPWSTR filePath, const GUID &format)
|
HRESULT SavePixelsToFile32bppPBGRA(UINT width, UINT height, UINT stride,
|
||||||
|
LPBYTE pixels, LPWSTR filePath, const GUID &format)
|
||||||
{
|
{
|
||||||
if (!filePath || !pixels)
|
if (!filePath || !pixels)
|
||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
|
@ -129,10 +135,12 @@ cleanup:
|
||||||
|
|
||||||
ScreenCapture::ScreenCapture()
|
ScreenCapture::ScreenCapture()
|
||||||
{
|
{
|
||||||
|
m_d3d9_dev = ::Direct3DCreate9(D3D_SDK_VERSION);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor,HDC hdcMonitor,LPRECT lprcMonitor,LPARAM dwData)
|
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor,HDC hdcMonitor,
|
||||||
|
LPRECT lprcMonitor,LPARAM dwData)
|
||||||
{
|
{
|
||||||
MONITORINFOEX mi;
|
MONITORINFOEX mi;
|
||||||
mi.cbSize=sizeof(MONITORINFOEX);
|
mi.cbSize=sizeof(MONITORINFOEX);
|
||||||
|
@ -149,5 +157,22 @@ BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor,HDC hdcMonitor,LPRECT lprcMonito
|
||||||
|
|
||||||
void ScreenCapture::EnumScreen()
|
void ScreenCapture::EnumScreen()
|
||||||
{
|
{
|
||||||
EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,NULL);
|
// EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,NULL);
|
||||||
|
if(m_d3d9_dev == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
D3DADAPTER_IDENTIFIER9 adapterID; // Used to store device info
|
||||||
|
char strBuffer[20480];
|
||||||
|
DWORD dwDisplayCount = m_d3d9_dev->GetAdapterCount();
|
||||||
|
for(DWORD i = 0; i < dwDisplayCount; i++)
|
||||||
|
{
|
||||||
|
if( m_d3d9_dev->GetAdapterIdentifier( i/*D3DADAPTER_DEFAULT*/, 0,&adapterID ) != D3D_OK )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug()<<adapterID.DeviceName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,20 @@
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <Wincodec.h> // we use WIC for saving images
|
#include <Wincodec.h> // we use WIC for saving images
|
||||||
#include <d3d9.h> // DirectX 9 header
|
#include <d3d9.h> // DirectX 9 header
|
||||||
|
#include <d3d9helper.h>
|
||||||
|
|
||||||
|
|
||||||
|
HRESULT Direct3D9TakeScreenshots(UINT adapter, UINT count);
|
||||||
|
|
||||||
|
|
||||||
class ScreenCapture
|
class ScreenCapture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScreenCapture();
|
ScreenCapture();
|
||||||
void EnumScreen();
|
void EnumScreen();
|
||||||
|
void PrintDisplayModeInfo(IDirect3D9 *pD3D, D3DFORMAT fmt);
|
||||||
|
private:
|
||||||
|
IDirect3D9* m_d3d9_dev = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SCREEN_CAPTURE_H
|
#endif // SCREEN_CAPTURE_H
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.11.0, 2021-10-05T02:07:58. -->
|
<!-- Written by QtCreator 4.11.0, 2021-10-05T15:43:08. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
|
Loading…
Reference in New Issue