multimedia/client/qt_gl_/yuvgl/main.cpp

269 lines
6.7 KiB
C++
Raw Normal View History

2020-06-04 15:28:45 +00:00
#include "mainwindow.h"
#include <QApplication>
#include "cplaywidget.h"
#include <QTimer>
#include "CameraCapture.h"
#include "mainwindow.h"
2020-12-06 16:01:38 +00:00
#include <qlibrary.h>
#include <qsysinfo.h>
#include <qt_windows.h>
2021-10-04 14:45:36 +00:00
#include "media/screen_capture.h"
2021-10-05 02:27:53 +00:00
#include "media/DXGICapture.h"
#include <QVector>
#include <stdio.h>
#include <tchar.h>
#include <shlobj.h>
#include <D3D9.h>
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
2021-10-02 05:58:29 +00:00
#ifdef __MINGW32__
2020-12-06 16:01:38 +00:00
#include <Tlhelp32.h>
2021-10-02 05:58:29 +00:00
#include "winuser.h"
#endif
2020-06-06 07:39:55 +00:00
int RegiesterOwnType(){
return 0;
}
2021-10-04 14:45:36 +00:00
2021-10-05 02:27:53 +00:00
IDirect3DDevice9* g_pd3dDevice = nullptr;
// ȫ???======================================================
// <20><><EFBFBD><EFBFBD>D3DDevice
LPDIRECT3D9 g_pD3D = nullptr; // Used to create the D3DDevice
// (<28><>?<3F><>?)render?<3F>ã<EFBFBD><C3A3><EFBFBD>??<3F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD>?<3F><>
// =============================================================
HRESULT ScreenGrab(LPDIRECT3DDEVICE9 pDev)
{
HRESULT hr;
D3DDISPLAYMODE mode;
if (FAILED(hr=pDev->GetDisplayMode(0, &mode))) //<2F><>һ???<3F><>Swap Chain<69><6E><EFBFBD><EFBFBD>?<3F><>???<3F>з<EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
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
// ?<3F><>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pSurface->Release();
// return status of save operation to caller
// <20><>?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<63><65><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>D3D<33><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Direct3DCreate9<65><39>?D3DDevice<63><65>?<3F><>ֵ?ʹ<><CAB9><EFBFBD>߰<EFBFBD>?DirectX<74>İ汾
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.
/*
<EFBFBD><EFBFBD>?<EFBFBD><EFBFBD><EFBFBD><EFBFBD>D3DDevice<EFBFBD><EFBFBD>??<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>????0<EFBFBD><EFBFBD>
?<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>?"?<3F><><EFBFBD><EFBFBD>"?<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?ʾ??<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?D3D<EFBFBD><EFBFBD>?<EFBFBD><EFBFBD>?<EFBFBD>У<EFBFBD>?SwapEffect<EFBFBD><EFBFBD>"discard"<EFBFBD><EFBFBD>??<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>??<EFBFBD><EFBFBD>???<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ʡ<EFBFBD>
?<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>??<EFBFBD><EFBFBD>?ʾ<EFBFBD><EFBFBD>ʽ??<EFBFBD>ڵ<EFBFBD>?<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) ); //<2F><>ʼ<EFBFBD><CABC>d3d<33><64>??
d3dpp.Windowed = TRUE; //?<3F><>?<3F><><EFBFBD><EFBFBD>
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //<2F><><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; //??<3F>г<EFBFBD>??<3F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ(<28><>Ȼ<EFBFBD><C8BB>?<3F><>δ֪= =)
// 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.
/*
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Direct3D?<EFBFBD>á<EFBFBD><EFBFBD><EFBFBD>?ʹ<EFBFBD><EFBFBD>??<EFBFBD><EFBFBD>adapter(?<EFBFBD><EFBFBD>?<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>˼= =)<EFBFBD><EFBFBD>
?<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>??ֻ<EFBFBD><EFBFBD>һ??<EFBFBD><EFBFBD>(?ʾ<EFBFBD><EFBFBD>)<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
?<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>HAL<EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?ʾ<EFBFBD><EFBFBD>?ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>???<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD>?֪<EFBFBD><EFBFBD>????(<EFBFBD><EFBFBD>)?<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD>֧ԮӲ????<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?ʾ<EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>??<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD>ѵ<EFBFBD>?<EFBFBD><EFBFBD>Ч<EFBFBD>ʡ<EFBFBD>
*/
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, //??adapter
D3DDEVTYPE_HAL, //Ӳ?<3F><><EFBFBD><EFBFBD>
hWnd, //Handler<65><72>?
//D3DCREATE_SOFTWARE_VERTEXPROCESSING, //<2F><><EFBFBD>ᾹȻ<E1BEB9><C8BB>??<3F><>
D3DCREATE_HARDWARE_VERTEXPROCESSING, //<2F><><EFBFBD><EFBFBD>Ӳ?<3F><><EFBFBD>ٰ<EFBFBD>
&d3dpp, //D3D??
&g_pd3dDevice //D3D<33><44><EFBFBD><EFBFBD>?ʾ?<3F><>??
) ) )
{
return E_FAIL;
}
// Device state would normally be set here
return S_OK;
}
2020-06-04 15:28:45 +00:00
int main(int argc, char *argv[])
{
2021-10-05 02:27:53 +00:00
setbuf(stdout, NULL);//<2F><>printf<74><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2021-10-02 05:58:29 +00:00
2020-12-06 16:01:38 +00:00
QssEventFilter filter;
QApplication app(argc, argv);
2020-06-04 15:28:45 +00:00
2021-10-05 02:27:53 +00:00
2020-06-04 15:28:45 +00:00
MainWindow main;
2021-10-05 02:27:53 +00:00
InitD3D((HWND)main.winId());
ScreenGrab( g_pd3dDevice);
2021-10-04 14:45:36 +00:00
main.setWindowTitle("<EFBFBD><EFBFBD>ý<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><EFBFBD><EFBFBD>");
2021-10-02 05:58:29 +00:00
main.setFixedSize(1920,1080);
2020-06-04 15:28:45 +00:00
main.show();
2020-12-06 16:01:38 +00:00
return app.exec();
2020-06-04 15:28:45 +00:00
}