wfreerdp-server: refactoring and stabilizing windows 8 parts
This commit is contained in:
parent
909e617ce0
commit
052896eb3d
@ -59,6 +59,7 @@ ID3D11Texture2D * sStage;
|
||||
|
||||
DXGI_OUTDUPL_FRAME_INFO FrameInfo;
|
||||
|
||||
|
||||
int wf_dxgi_init(wfInfo* context)
|
||||
{
|
||||
HRESULT hr;
|
||||
@ -201,6 +202,8 @@ int wf_dxgi_init(wfInfo* context)
|
||||
return 1;
|
||||
}
|
||||
_tprintf(_T("Gut! Init Complete!\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wf_dxgi_cleanup(wfInfo* context)
|
||||
@ -232,16 +235,18 @@ int wf_dxgi_cleanup(wfInfo* context)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wf_dxgi_nextFrame(wfInfo* context, UINT timeout)
|
||||
int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout)
|
||||
{
|
||||
HRESULT hr;
|
||||
IDXGIResource* DesktopResource = NULL;
|
||||
BYTE* DirtyRects;
|
||||
UINT dirty;
|
||||
RECT* pRect;
|
||||
BYTE* MeinMetaDataBuffer = NULL;
|
||||
UINT MeinMetaDataSize = 0;
|
||||
UINT i = 0, BufSize;
|
||||
UINT i = 0;
|
||||
|
||||
if(wfi->framesWaiting > 0)
|
||||
{
|
||||
wf_dxgi_releasePixelData(wfi);
|
||||
}
|
||||
|
||||
if(MeinAcquiredDesktopImage)
|
||||
{
|
||||
@ -284,76 +289,8 @@ int wf_dxgi_nextFrame(wfInfo* context, UINT timeout)
|
||||
}
|
||||
_tprintf(_T("Gut!\n"));
|
||||
|
||||
if(FrameInfo.AccumulatedFrames == 0)
|
||||
{
|
||||
//we dont care
|
||||
return 1;
|
||||
}
|
||||
wfi->framesWaiting = FrameInfo.AccumulatedFrames;
|
||||
|
||||
_tprintf(_T("FrameInfo\n"));
|
||||
_tprintf(_T("\tAccumulated Frames: %d\n"), FrameInfo.AccumulatedFrames);
|
||||
_tprintf(_T("\tCoalesced Rectangles: %d\n"), FrameInfo.RectsCoalesced);
|
||||
_tprintf(_T("\tMetadata buffer size: %d\n"), FrameInfo.TotalMetadataBufferSize);
|
||||
|
||||
|
||||
if(FrameInfo.TotalMetadataBufferSize)
|
||||
{
|
||||
|
||||
if (FrameInfo.TotalMetadataBufferSize > MeinMetaDataSize)
|
||||
{
|
||||
if (MeinMetaDataBuffer)
|
||||
{
|
||||
free(MeinMetaDataBuffer);
|
||||
MeinMetaDataBuffer = NULL;
|
||||
}
|
||||
MeinMetaDataBuffer = (BYTE*) malloc(FrameInfo.TotalMetadataBufferSize);
|
||||
if (!MeinMetaDataBuffer)
|
||||
{
|
||||
MeinMetaDataSize = 0;
|
||||
_tprintf(_T("Failed to allocate memory for metadata\n"));
|
||||
return 1;
|
||||
}
|
||||
MeinMetaDataSize = FrameInfo.TotalMetadataBufferSize;
|
||||
}
|
||||
|
||||
BufSize = FrameInfo.TotalMetadataBufferSize;
|
||||
|
||||
// Get move rectangles
|
||||
hr = MeinDeskDupl->lpVtbl->GetFrameMoveRects(MeinDeskDupl, BufSize, (DXGI_OUTDUPL_MOVE_RECT*) MeinMetaDataBuffer, &BufSize);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
_tprintf(_T("Failed to get frame move rects\n"));
|
||||
return 1;
|
||||
}
|
||||
_tprintf(_T("Move rects: %d\n"), BufSize / sizeof(DXGI_OUTDUPL_MOVE_RECT));
|
||||
|
||||
DirtyRects = MeinMetaDataBuffer + BufSize;
|
||||
BufSize = FrameInfo.TotalMetadataBufferSize - BufSize;
|
||||
|
||||
// Get dirty rectangles
|
||||
hr = MeinDeskDupl->lpVtbl->GetFrameDirtyRects(MeinDeskDupl, BufSize, (RECT*) DirtyRects, &BufSize);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
_tprintf(_T("Failed to get frame dirty rects\n"));
|
||||
return 1;
|
||||
}
|
||||
dirty = BufSize / sizeof(RECT);
|
||||
_tprintf(_T("Dirty rects: %d\n"), dirty);
|
||||
|
||||
pRect = (RECT*) DirtyRects;
|
||||
for(i = 0; i<dirty; ++i)
|
||||
{
|
||||
_tprintf(_T("\tRect: (%d, %d), (%d, %d)\n"),
|
||||
pRect->left,
|
||||
pRect->top,
|
||||
pRect->right,
|
||||
pRect->bottom);
|
||||
|
||||
++pRect;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -366,12 +303,6 @@ int wf_dxgi_getPixelData(wfInfo* context, BYTE** data, int* pitch, RECT* invalid
|
||||
D3D11_TEXTURE2D_DESC tDesc;
|
||||
D3D11_BOX Box;
|
||||
|
||||
if(wf_dxgi_getInvalidRegion(invalid))
|
||||
{
|
||||
_tprintf(_T("dxgi_getInvalidRegion failed\n"));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
tDesc.Width = (invalid->right - invalid->left) + 1;
|
||||
tDesc.Height = (invalid->bottom - invalid->top) + 1;
|
||||
tDesc.MipLevels = 1;
|
||||
@ -397,6 +328,7 @@ int wf_dxgi_getPixelData(wfInfo* context, BYTE** data, int* pitch, RECT* invalid
|
||||
{
|
||||
_tprintf(_T("Failed to create staging surface\n"));
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
_tprintf(_T("Gut!\n"));
|
||||
|
||||
@ -408,6 +340,7 @@ int wf_dxgi_getPixelData(wfInfo* context, BYTE** data, int* pitch, RECT* invalid
|
||||
{
|
||||
_tprintf(_T("Failed to QI staging surface\n"));
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
_tprintf(_T("Gut!\n"));
|
||||
|
||||
@ -417,6 +350,7 @@ int wf_dxgi_getPixelData(wfInfo* context, BYTE** data, int* pitch, RECT* invalid
|
||||
{
|
||||
_tprintf(_T("Failed to map staging surface\n"));
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
_tprintf(_T("Gut!\n"));
|
||||
|
||||
@ -425,10 +359,10 @@ int wf_dxgi_getPixelData(wfInfo* context, BYTE** data, int* pitch, RECT* invalid
|
||||
*data = MeinData.pBits;
|
||||
*pitch = MeinData.Pitch;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wf_dxgi_releasePixelData(wfInfo* context)
|
||||
int wf_dxgi_releasePixelData(wfInfo* wfi)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
@ -444,6 +378,10 @@ int wf_dxgi_releasePixelData(wfInfo* context)
|
||||
_tprintf(_T("Failed to release frame\n"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
wfi->framesWaiting = 0;
|
||||
_tprintf(_T("PixelData Release\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wf_dxgi_getInvalidRegion(RECT* invalid)
|
||||
@ -459,7 +397,11 @@ int wf_dxgi_getInvalidRegion(RECT* invalid)
|
||||
//optimization note: make this buffer global and allocate only once (or grow only when needed)
|
||||
BYTE* MeinMetaDataBuffer = NULL;
|
||||
|
||||
|
||||
if(FrameInfo.AccumulatedFrames == 0)
|
||||
{
|
||||
//we dont care
|
||||
return 1;
|
||||
}
|
||||
|
||||
_tprintf(_T("FrameInfo\n"));
|
||||
_tprintf(_T("\tAccumulated Frames: %d\n"), FrameInfo.AccumulatedFrames);
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "wf_info.h"
|
||||
#include "wf_update.h"
|
||||
#include "wf_mirage.h"
|
||||
#include "wf_dxgi.h"
|
||||
|
||||
static wfInfo* wfInfoInstance = NULL;
|
||||
|
||||
@ -99,6 +100,12 @@ wfInfo* wf_info_init()
|
||||
{
|
||||
wfInfo* wfi;
|
||||
|
||||
OSVERSIONINFOEX osvi;
|
||||
SYSTEM_INFO si;
|
||||
BOOL bOsVersionInfoEx;
|
||||
|
||||
|
||||
|
||||
wfi = (wfInfo*) malloc(sizeof(wfInfo));
|
||||
ZeroMemory(wfi, sizeof(wfInfo));
|
||||
|
||||
@ -130,7 +137,7 @@ wfInfo* wf_info_init()
|
||||
|
||||
wfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * 32);
|
||||
|
||||
wfi->framesPerSecond = 24;
|
||||
wfi->framesPerSecond = 10;
|
||||
|
||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
||||
|
||||
@ -142,6 +149,27 @@ wfInfo* wf_info_init()
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
//detect windows version
|
||||
ZeroMemory(&si, sizeof(SYSTEM_INFO));
|
||||
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
|
||||
|
||||
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
||||
bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi);
|
||||
|
||||
wfi->win8 = FALSE;
|
||||
if(bOsVersionInfoEx != 0 )
|
||||
{
|
||||
if ( VER_PLATFORM_WIN32_NT==osvi.dwPlatformId &&
|
||||
osvi.dwMajorVersion > 4 )
|
||||
{
|
||||
if ( osvi.dwMajorVersion == 6 &&
|
||||
osvi.dwMinorVersion == 2)
|
||||
{
|
||||
wfi->win8 = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wfi;
|
||||
@ -163,7 +191,15 @@ void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
|
||||
context->info = wfi;
|
||||
context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
wf_mirror_driver_activate(wfi);
|
||||
if(wfi->win8 &&
|
||||
(wfi->peerCount == 0))
|
||||
{
|
||||
wf_dxgi_init(wfi);
|
||||
}
|
||||
else
|
||||
{
|
||||
wf_mirror_driver_activate(wfi);
|
||||
}
|
||||
|
||||
wfi->peers[wfi->peerCount++] = ((rdpContext*) context)->peer;
|
||||
|
||||
@ -182,40 +218,68 @@ void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context)
|
||||
|
||||
printf("Unregistering Peer: %d\n", wfi->peerCount);
|
||||
|
||||
if(wfi->win8 &&
|
||||
(wfi->peerCount == 0))
|
||||
{
|
||||
wf_dxgi_cleanup(wfi);
|
||||
}
|
||||
|
||||
wf_info_unlock(wfi);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL wf_info_have_updates(wfInfo* wfi)
|
||||
{
|
||||
if (wfi->nextUpdate == wfi->lastUpdate)
|
||||
return FALSE;
|
||||
if(wfi->win8)
|
||||
{
|
||||
if(wfi->framesWaiting == 0)
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wfi->nextUpdate == wfi->lastUpdate)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wf_info_update_changes(wfInfo* wfi)
|
||||
{
|
||||
GETCHANGESBUF* buf;
|
||||
if(wfi->win8)
|
||||
{
|
||||
wf_dxgi_nextFrame(wfi, wfi->framesPerSecond / 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
GETCHANGESBUF* buf;
|
||||
|
||||
buf = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
wfi->nextUpdate = buf->buffer->counter;
|
||||
buf = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
wfi->nextUpdate = buf->buffer->counter;
|
||||
}
|
||||
}
|
||||
|
||||
void wf_info_find_invalid_region(wfInfo* wfi)
|
||||
{
|
||||
int i;
|
||||
GETCHANGESBUF* buf;
|
||||
|
||||
buf = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
|
||||
for (i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF)
|
||||
if(wfi->win8)
|
||||
{
|
||||
UnionRect(&wfi->invalid, &wfi->invalid, &buf->buffer->pointrect[i].rect);
|
||||
wf_dxgi_getInvalidRegion(&wfi->invalid);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
GETCHANGESBUF* buf;
|
||||
|
||||
buf = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
|
||||
for (i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF)
|
||||
{
|
||||
UnionRect(&wfi->invalid, &wfi->invalid, &buf->buffer->pointrect[i].rect);
|
||||
}
|
||||
}
|
||||
|
||||
if (wfi->invalid.left < 0)
|
||||
wfi->invalid.left = 0;
|
||||
wfi->invalid.left = 0;
|
||||
|
||||
if (wfi->invalid.top < 0)
|
||||
wfi->invalid.top = 0;
|
||||
@ -225,6 +289,7 @@ void wf_info_find_invalid_region(wfInfo* wfi)
|
||||
|
||||
if (wfi->invalid.bottom >= wfi->height)
|
||||
wfi->invalid.bottom = wfi->height - 1;
|
||||
|
||||
}
|
||||
|
||||
void wf_info_clear_invalid_region(wfInfo* wfi)
|
||||
@ -242,3 +307,21 @@ BOOL wf_info_have_invalid_region(wfInfo* wfi)
|
||||
{
|
||||
return IsRectEmpty(&wfi->invalid);
|
||||
}
|
||||
|
||||
void wf_info_getScreenData(wfInfo* wfi, uint8** pBits, int* pitch)
|
||||
{
|
||||
if(wfi->win8)
|
||||
{
|
||||
wf_dxgi_getPixelData(wfi, pBits, pitch, &wfi->invalid);
|
||||
}
|
||||
else
|
||||
{
|
||||
long offset;
|
||||
GETCHANGESBUF* changes;
|
||||
changes = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
|
||||
offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->width * 4);
|
||||
*pBits = ((uint8*) (changes->Userbuffer)) + offset;
|
||||
*pitch = wfi->width * 4;
|
||||
}
|
||||
}
|
@ -19,59 +19,13 @@
|
||||
|
||||
#ifndef WF_INFO_H
|
||||
#define WF_INFO_H
|
||||
|
||||
|
||||
#define CINTERFACE
|
||||
#include <D3D11.h>
|
||||
#include <dxgi1_2.h>
|
||||
|
||||
#include "wf_interface.h"
|
||||
#include <freerdp/codec/rfx.h>
|
||||
|
||||
struct wf_peer_context;
|
||||
typedef struct wf_peer_context wfPeerContext;
|
||||
|
||||
struct wf_dxgi_info
|
||||
{
|
||||
ID3D11Device* Device;
|
||||
ID3D11DeviceContext* DeviceContext;
|
||||
IDXGIOutputDuplication* DeskDupl;
|
||||
ID3D11Texture2D* AcquiredDesktopImage;
|
||||
};
|
||||
typedef struct wf_dxgi_info wfDxgiInfo;
|
||||
|
||||
struct wf_info
|
||||
{
|
||||
STREAM* s;
|
||||
HDC driverDC;
|
||||
BOOL activated;
|
||||
void* changeBuffer;
|
||||
LPTSTR deviceKey;
|
||||
TCHAR deviceName[32];
|
||||
int subscribers;
|
||||
int threadCount;
|
||||
int height;
|
||||
int width;
|
||||
int bitsPerPix;
|
||||
|
||||
RECT invalid;
|
||||
HANDLE mutex;
|
||||
BOOL updatePending;
|
||||
HANDLE updateEvent;
|
||||
RFX_CONTEXT* rfx_context;
|
||||
unsigned long lastUpdate;
|
||||
unsigned long nextUpdate;
|
||||
|
||||
wfDxgiInfo dxgi;
|
||||
};
|
||||
typedef struct wf_info wfInfo;
|
||||
|
||||
int wf_info_lock(wfInfo* wfi);
|
||||
int wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds);
|
||||
int wf_info_unlock(wfInfo* wfi);
|
||||
|
||||
void wf_info_get_screen_info(wfInfo* wfi);
|
||||
|
||||
wfInfo* wf_info_get_instance();
|
||||
void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context);
|
||||
void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context);
|
||||
@ -82,5 +36,6 @@ void wf_info_find_invalid_region(wfInfo* wfi);
|
||||
void wf_info_clear_invalid_region(wfInfo* wfi);
|
||||
void wf_info_invalidate_full_screen(wfInfo* wfi);
|
||||
BOOL wf_info_have_invalid_region(wfInfo* wfi);
|
||||
void wf_info_getScreenData(wfInfo* wfi, uint8** pBits, int* pitch);
|
||||
|
||||
#endif /* WF_INFO_H */
|
||||
#endif /* WF_INFO_H */
|
@ -48,6 +48,8 @@ struct wf_info
|
||||
TCHAR deviceName[32];
|
||||
freerdp_peer** peers;
|
||||
BOOL mirrorDriverActive;
|
||||
BOOL win8;
|
||||
UINT framesWaiting;
|
||||
|
||||
RECT invalid;
|
||||
HANDLE mutex;
|
||||
|
@ -172,6 +172,7 @@ void wf_mirror_driver_print_display_change_status(LONG status)
|
||||
|
||||
BOOL wf_mirror_driver_update(wfInfo* context, int unload)
|
||||
{
|
||||
HDC dc;
|
||||
BOOL status;
|
||||
DWORD* extHdr;
|
||||
WORD drvExtraSaved;
|
||||
@ -180,7 +181,7 @@ BOOL wf_mirror_driver_update(wfInfo* context, int unload)
|
||||
DWORD dmf_devmodewext_magic_sig = 0xDF20C0DE;
|
||||
|
||||
if (!unload)
|
||||
{
|
||||
{
|
||||
/*
|
||||
* Will have to come back to this for supporting non primary displays and multimonitor setups
|
||||
*/
|
||||
@ -209,7 +210,6 @@ BOOL wf_mirror_driver_update(wfInfo* context, int unload)
|
||||
deviceMode->dmSize = sizeof(DEVMODE);
|
||||
deviceMode->dmDriverExtra = drvExtraSaved;
|
||||
|
||||
|
||||
deviceMode->dmPelsWidth = context->width;
|
||||
deviceMode->dmPelsHeight = context->height;
|
||||
deviceMode->dmBitsPerPel = context->bitsPerPixel;
|
||||
@ -311,4 +311,4 @@ void wf_mirror_driver_deactivate(wfInfo* wfi)
|
||||
wf_mirror_driver_update(wfi, 1);
|
||||
wfi->mirrorDriverActive = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,8 @@
|
||||
|
||||
#include "wf_peer.h"
|
||||
|
||||
BOOL win8;
|
||||
|
||||
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
|
||||
{
|
||||
context->info = wf_info_get_instance();
|
||||
|
@ -99,18 +99,21 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void wf_update_encode(wfInfo* wfi)
|
||||
{
|
||||
long offset;
|
||||
|
||||
RFX_RECT rect;
|
||||
long height, width;
|
||||
GETCHANGESBUF* changes;
|
||||
uint8* pDataBits = NULL;
|
||||
int stride;
|
||||
|
||||
SURFACE_BITS_COMMAND* cmd;
|
||||
|
||||
wf_info_find_invalid_region(wfi);
|
||||
|
||||
cmd = &wfi->cmd;
|
||||
changes = (GETCHANGESBUF*) wfi->changeBuffer;
|
||||
|
||||
|
||||
width = (wfi->invalid.right - wfi->invalid.left) + 1;
|
||||
height = (wfi->invalid.bottom - wfi->invalid.top) + 1;
|
||||
@ -124,10 +127,10 @@ void wf_update_encode(wfInfo* wfi)
|
||||
|
||||
//printf("x:%d y:%d w:%d h:%d\n", wfi->invalid.left, wfi->invalid.top, width, height);
|
||||
|
||||
offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->width * 4);
|
||||
wf_info_getScreenData(wfi, &pDataBits, &stride);
|
||||
|
||||
rfx_compose_message(wfi->rfx_context, wfi->s, &rect, 1,
|
||||
((uint8*) (changes->Userbuffer)) + offset, width, height, wfi->width * 4);
|
||||
pDataBits, width, height, stride);
|
||||
|
||||
wfi->frame_idx = wfi->rfx_context->frame_idx;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user