From fb5a48bc84b704e49a8fe565c5c6f6df59cd5867 Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Wed, 6 Oct 2021 23:31:47 +0800 Subject: [PATCH] no message --- client/qt_gl_/yuvgl/main.cpp | 227 +------------------ client/qt_gl_/yuvgl/media/screen_capture.cpp | 45 +++- client/qt_gl_/yuvgl/media/screen_capture.h | 8 + client/qt_gl_/yuvgl/yuvgl.pro.user | 2 +- 4 files changed, 48 insertions(+), 234 deletions(-) diff --git a/client/qt_gl_/yuvgl/main.cpp b/client/qt_gl_/yuvgl/main.cpp index 9a81bfe..00bc876 100644 --- a/client/qt_gl_/yuvgl/main.cpp +++ b/client/qt_gl_/yuvgl/main.cpp @@ -28,239 +28,20 @@ int RegiesterOwnType(){ 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;iUnlockRect(); - - SetCursor(LoadCursor(NULL,IDC_ARROW)); - - // release the image surface - - // ?放影像表面 - - pSurface->Release(); - - - - // return status of save operation to caller - - // 回?Handler - - return hr; - -} - - - -QVector GetMonitors() -{ - QVector 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[]) { setbuf(stdout, NULL);//让printf立即输出 + ScreenCapture p; + p.EnumScreen(); - + Direct3D9TakeScreenshots(0,4); QssEventFilter filter; QApplication app(argc, argv); - MainWindow main; - InitD3D((HWND)main.winId()); - ScreenGrab( g_pd3dDevice); + main.setWindowTitle("流媒体测试工具"); main.setFixedSize(1920,1080); main.show(); diff --git a/client/qt_gl_/yuvgl/media/screen_capture.cpp b/client/qt_gl_/yuvgl/media/screen_capture.cpp index 41b21a5..3cbcaaa 100644 --- a/client/qt_gl_/yuvgl/media/screen_capture.cpp +++ b/client/qt_gl_/yuvgl/media/screen_capture.cpp @@ -5,17 +5,23 @@ #include #include +#if _MSC_VER >= 1600 +#pragma execution_character_set("utf-8") +#endif + + #define WIDEN2(x) L ## x - #define WIDEN(x) WIDEN2(x) - #define __WFILE__ WIDEN(__FILE__) - #define HRCHECK(__expr) {hr=(__expr);if(FAILED(hr)){wprintf(L"FAILURE 0x%08X (%i)\n\tline: %u file: '%s'\n\texpr: '" WIDEN(#__expr) L"'\n",hr, hr, __LINE__,__WFILE__);goto cleanup;}} - #define RELEASE(__p) {if(__p!=nullptr){__p->Release();__p=nullptr;}} +#define WIDEN(x) WIDEN2(x) +#define __WFILE__ WIDEN(__FILE__) +#define HRCHECK(__expr) {hr=(__expr);if(FAILED(hr)){wprintf(L"FAILURE 0x%08X (%i)\n\tline: %u file: '%s'\n\texpr: '" WIDEN(#__expr) L"'\n",hr, hr, __LINE__,__WFILE__);goto cleanup;}} +#define RELEASE(__p) {if(__p!=nullptr){__p->Release();__p=nullptr;}} // 缺enum方法 // 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) return E_INVALIDARG; @@ -40,14 +46,14 @@ HRESULT SavePixelsToFile32bppPBGRA(UINT width, UINT height, UINT stride, LPBYTE HRCHECK(frame->Commit()); HRCHECK(encoder->Commit()); - cleanup: + cleanup: RELEASE(stream); RELEASE(frame); RELEASE(encoder); RELEASE(factory); if (coInit) CoUninitialize(); return hr; - } +} HRESULT Direct3D9TakeScreenshots(UINT adapter, UINT count) { @@ -129,10 +135,12 @@ cleanup: 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; mi.cbSize=sizeof(MONITORINFOEX); @@ -149,5 +157,22 @@ BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor,HDC hdcMonitor,LPRECT lprcMonito 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()< #include // we use WIC for saving images #include // DirectX 9 header +#include + + +HRESULT Direct3D9TakeScreenshots(UINT adapter, UINT count); + class ScreenCapture { public: ScreenCapture(); void EnumScreen(); + void PrintDisplayModeInfo(IDirect3D9 *pD3D, D3DFORMAT fmt); +private: + IDirect3D9* m_d3d9_dev = nullptr; }; #endif // SCREEN_CAPTURE_H diff --git a/client/qt_gl_/yuvgl/yuvgl.pro.user b/client/qt_gl_/yuvgl/yuvgl.pro.user index 2a58f87..c7df5ea 100644 --- a/client/qt_gl_/yuvgl/yuvgl.pro.user +++ b/client/qt_gl_/yuvgl/yuvgl.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId