Blame server/Windows/wf_dxgi.c

Packit 1fb8d4
/**
Packit 1fb8d4
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit 1fb8d4
 * FreeRDP Windows Server
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
Packit 1fb8d4
 *
Packit 1fb8d4
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1fb8d4
 * you may not use this file except in compliance with the License.
Packit 1fb8d4
 * You may obtain a copy of the License at
Packit 1fb8d4
 *
Packit 1fb8d4
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1fb8d4
 *
Packit 1fb8d4
 * Unless required by applicable law or agreed to in writing, software
Packit 1fb8d4
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1fb8d4
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1fb8d4
 * See the License for the specific language governing permissions and
Packit 1fb8d4
 * limitations under the License.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifdef HAVE_CONFIG_H
Packit 1fb8d4
#include "config.h"
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#include "wf_interface.h"
Packit 1fb8d4
Packit 1fb8d4
#ifdef WITH_DXGI_1_2
Packit 1fb8d4
Packit 1fb8d4
#define CINTERFACE
Packit 1fb8d4
Packit 1fb8d4
#include <D3D11.h>
Packit 1fb8d4
#include <dxgi1_2.h>
Packit 1fb8d4
Packit 1fb8d4
#include <tchar.h>
Packit 1fb8d4
#include "wf_dxgi.h"
Packit 1fb8d4
Packit 1fb8d4
#include <freerdp/log.h>
Packit 1fb8d4
#define TAG SERVER_TAG("windows")
Packit 1fb8d4
Packit 1fb8d4
/* Driver types supported */
Packit Service 5a9772
D3D_DRIVER_TYPE DriverTypes[] = {
Packit 1fb8d4
	D3D_DRIVER_TYPE_HARDWARE,
Packit 1fb8d4
	D3D_DRIVER_TYPE_WARP,
Packit 1fb8d4
	D3D_DRIVER_TYPE_REFERENCE,
Packit 1fb8d4
};
Packit 1fb8d4
UINT NumDriverTypes = ARRAYSIZE(DriverTypes);
Packit 1fb8d4
Packit 1fb8d4
/* Feature levels supported */
Packit Service 5a9772
D3D_FEATURE_LEVEL FeatureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1,
Packit Service 5a9772
	                                  D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_1 };
Packit 1fb8d4
Packit 1fb8d4
UINT NumFeatureLevels = ARRAYSIZE(FeatureLevels);
Packit 1fb8d4
Packit 1fb8d4
D3D_FEATURE_LEVEL FeatureLevel;
Packit 1fb8d4
Packit 1fb8d4
ID3D11Device* gDevice = NULL;
Packit 1fb8d4
ID3D11DeviceContext* gContext = NULL;
Packit 1fb8d4
IDXGIOutputDuplication* gOutputDuplication = NULL;
Packit 1fb8d4
ID3D11Texture2D* gAcquiredDesktopImage = NULL;
Packit 1fb8d4
Packit 1fb8d4
IDXGISurface* surf;
Packit 1fb8d4
ID3D11Texture2D* sStage;
Packit 1fb8d4
Packit 1fb8d4
DXGI_OUTDUPL_FRAME_INFO FrameInfo;
Packit 1fb8d4
Packit 1fb8d4
int wf_dxgi_init(wfInfo* wfi)
Packit 1fb8d4
{
Packit 1fb8d4
	gAcquiredDesktopImage = NULL;
Packit 1fb8d4
Packit 1fb8d4
	if (wf_dxgi_createDevice(wfi) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (wf_dxgi_getDuplication(wfi) != 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int wf_dxgi_createDevice(wfInfo* wfi)
Packit 1fb8d4
{
Packit 1fb8d4
	HRESULT status;
Packit 1fb8d4
	UINT DriverTypeIndex;
Packit 1fb8d4
Packit 1fb8d4
	for (DriverTypeIndex = 0; DriverTypeIndex < NumDriverTypes; ++DriverTypeIndex)
Packit 1fb8d4
	{
Packit Service 5a9772
		status = D3D11CreateDevice(NULL, DriverTypes[DriverTypeIndex], NULL, 0, FeatureLevels,
Packit Service 5a9772
		                           NumFeatureLevels, D3D11_SDK_VERSION, &gDevice, &FeatureLevel,
Packit Service 5a9772
		                           &gContext);
Packit 1fb8d4
		if (SUCCEEDED(status))
Packit 1fb8d4
			break;
Packit 1fb8d4
Packit Service 5a9772
		WLog_INFO(TAG, "D3D11CreateDevice returned [%ld] for Driver Type %d", status,
Packit Service 5a9772
		          DriverTypes[DriverTypeIndex]);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to create device in InitializeDx");
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int wf_dxgi_getDuplication(wfInfo* wfi)
Packit 1fb8d4
{
Packit 1fb8d4
	HRESULT status;
Packit 1fb8d4
	UINT dTop, i = 0;
Packit 1fb8d4
	DXGI_OUTPUT_DESC desc;
Packit Service 5a9772
	IDXGIOutput* pOutput;
Packit 1fb8d4
	IDXGIDevice* DxgiDevice = NULL;
Packit 1fb8d4
	IDXGIAdapter* DxgiAdapter = NULL;
Packit 1fb8d4
	IDXGIOutput* DxgiOutput = NULL;
Packit 1fb8d4
	IDXGIOutput1* DxgiOutput1 = NULL;
Packit 1fb8d4
Packit Service 5a9772
	status = gDevice->lpVtbl->QueryInterface(gDevice, &IID_IDXGIDevice, (void**)&DxgiDevice);
Packit 1fb8d4
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to get QI for DXGI Device");
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit Service 5a9772
Packit Service 5a9772
	status = DxgiDevice->lpVtbl->GetParent(DxgiDevice, &IID_IDXGIAdapter, (void**)&DxgiAdapter);
Packit 1fb8d4
	DxgiDevice->lpVtbl->Release(DxgiDevice);
Packit 1fb8d4
	DxgiDevice = NULL;
Packit Service 5a9772
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to get parent DXGI Adapter");
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit Service 5a9772
Packit 1fb8d4
	ZeroMemory(&desc, sizeof(desc));
Packit 1fb8d4
	pOutput = NULL;
Packit 1fb8d4
Packit 1fb8d4
	while (DxgiAdapter->lpVtbl->EnumOutputs(DxgiAdapter, i, &pOutput) != DXGI_ERROR_NOT_FOUND)
Packit 1fb8d4
	{
Packit 1fb8d4
		DXGI_OUTPUT_DESC* pDesc = &des;;
Packit 1fb8d4
Packit 1fb8d4
		status = pOutput->lpVtbl->GetDesc(pOutput, pDesc);
Packit 1fb8d4
Packit 1fb8d4
		if (FAILED(status))
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "Failed to get description");
Packit 1fb8d4
			return 1;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		WLog_INFO(TAG, "Output %u: [%s] [%d]", i, pDesc->DeviceName, pDesc->AttachedToDesktop);
Packit 1fb8d4
Packit 1fb8d4
		if (pDesc->AttachedToDesktop)
Packit 1fb8d4
			dTop = i;
Packit 1fb8d4
Packit 1fb8d4
		pOutput->lpVtbl->Release(pOutput);
Packit 1fb8d4
		++i;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	dTop = wfi->screenID;
Packit 1fb8d4
Packit 1fb8d4
	status = DxgiAdapter->lpVtbl->EnumOutputs(DxgiAdapter, dTop, &DxgiOutput);
Packit 1fb8d4
	DxgiAdapter->lpVtbl->Release(DxgiAdapter);
Packit 1fb8d4
	DxgiAdapter = NULL;
Packit Service 5a9772
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to get output");
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	status =
Packit Service 5a9772
	    DxgiOutput->lpVtbl->QueryInterface(DxgiOutput, &IID_IDXGIOutput1, (void**)&DxgiOutput1);
Packit 1fb8d4
	DxgiOutput->lpVtbl->Release(DxgiOutput);
Packit 1fb8d4
	DxgiOutput = NULL;
Packit Service 5a9772
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to get IDXGIOutput1");
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	status =
Packit Service 5a9772
	    DxgiOutput1->lpVtbl->DuplicateOutput(DxgiOutput1, (IUnknown*)gDevice, &gOutputDuplication);
Packit 1fb8d4
	DxgiOutput1->lpVtbl->Release(DxgiOutput1);
Packit 1fb8d4
	DxgiOutput1 = NULL;
Packit Service 5a9772
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		if (status == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE)
Packit 1fb8d4
		{
Packit Service 5a9772
			WLog_ERR(
Packit Service 5a9772
			    TAG,
Packit Service 5a9772
			    "There is already the maximum number of applications using the Desktop Duplication "
Packit Service 5a9772
			    "API running, please close one of those applications and then try again.");
Packit 1fb8d4
			return 1;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to get duplicate output. Status = %ld", status);
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int wf_dxgi_cleanup(wfInfo* wfi)
Packit 1fb8d4
{
Packit 1fb8d4
	if (wfi->framesWaiting > 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		wf_dxgi_releasePixelData(wfi);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (gAcquiredDesktopImage)
Packit 1fb8d4
	{
Packit 1fb8d4
		gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage);
Packit 1fb8d4
		gAcquiredDesktopImage = NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (gOutputDuplication)
Packit 1fb8d4
	{
Packit 1fb8d4
		gOutputDuplication->lpVtbl->Release(gOutputDuplication);
Packit 1fb8d4
		gOutputDuplication = NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	if (gContext)
Packit 1fb8d4
	{
Packit 1fb8d4
		gContext->lpVtbl->Release(gContext);
Packit 1fb8d4
		gContext = NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	if (gDevice)
Packit 1fb8d4
	{
Packit 1fb8d4
		gDevice->lpVtbl->Release(gDevice);
Packit 1fb8d4
		gDevice = NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout)
Packit 1fb8d4
{
Packit 1fb8d4
	HRESULT status = 0;
Packit 1fb8d4
	UINT i = 0;
Packit 1fb8d4
	UINT DataBufferSize = 0;
Packit 1fb8d4
	BYTE* DataBuffer = NULL;
Packit 1fb8d4
	IDXGIResource* DesktopResource = NULL;
Packit 1fb8d4
Packit 1fb8d4
	if (wfi->framesWaiting > 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		wf_dxgi_releasePixelData(wfi);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (gAcquiredDesktopImage)
Packit 1fb8d4
	{
Packit 1fb8d4
		gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage);
Packit 1fb8d4
		gAcquiredDesktopImage = NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	status = gOutputDuplication->lpVtbl->AcquireNextFrame(gOutputDuplication, timeout, &FrameInfo,
Packit Service 5a9772
	                                                      &DesktopResource);
Packit 1fb8d4
Packit 1fb8d4
	if (status == DXGI_ERROR_WAIT_TIMEOUT)
Packit 1fb8d4
	{
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		if (status == DXGI_ERROR_ACCESS_LOST)
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "Failed to acquire next frame with status=%ld", status);
Packit 1fb8d4
			WLog_ERR(TAG, "Trying to reinitialize due to ACCESS LOST...");
Packit 1fb8d4
Packit 1fb8d4
			if (gAcquiredDesktopImage)
Packit 1fb8d4
			{
Packit 1fb8d4
				gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage);
Packit 1fb8d4
				gAcquiredDesktopImage = NULL;
Packit 1fb8d4
			}
Packit 1fb8d4
Packit 1fb8d4
			if (gOutputDuplication)
Packit 1fb8d4
			{
Packit 1fb8d4
				gOutputDuplication->lpVtbl->Release(gOutputDuplication);
Packit 1fb8d4
				gOutputDuplication = NULL;
Packit Service 5a9772
			}
Packit 1fb8d4
Packit 1fb8d4
			wf_dxgi_getDuplication(wfi);
Packit 1fb8d4
Packit 1fb8d4
			return 1;
Packit 1fb8d4
		}
Packit 1fb8d4
		else
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "Failed to acquire next frame with status=%ld", status);
Packit 1fb8d4
			status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication);
Packit 1fb8d4
Packit 1fb8d4
			if (FAILED(status))
Packit 1fb8d4
			{
Packit 1fb8d4
				WLog_ERR(TAG, "Failed to release frame with status=%ld", status);
Packit 1fb8d4
			}
Packit Service 5a9772
Packit 1fb8d4
			return 1;
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit Service 5a9772
Packit Service 5a9772
	status = DesktopResource->lpVtbl->QueryInterface(DesktopResource, &IID_ID3D11Texture2D,
Packit Service 5a9772
	                                                 (void**)&gAcquiredDesktopImage);
Packit 1fb8d4
	DesktopResource->lpVtbl->Release(DesktopResource);
Packit 1fb8d4
	DesktopResource = NULL;
Packit 1fb8d4
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit Service 5a9772
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	wfi->framesWaiting = FrameInfo.AccumulatedFrames;
Packit 1fb8d4
Packit 1fb8d4
	if (FrameInfo.AccumulatedFrames == 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication);
Packit 1fb8d4
Packit 1fb8d4
		if (FAILED(status))
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "Failed to release frame with status=%ld", status);
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int wf_dxgi_getPixelData(wfInfo* wfi, BYTE** data, int* pitch, RECT* invalid)
Packit 1fb8d4
{
Packit 1fb8d4
	HRESULT status;
Packit 1fb8d4
	D3D11_BOX Box;
Packit 1fb8d4
	DXGI_MAPPED_RECT mappedRect;
Packit 1fb8d4
	D3D11_TEXTURE2D_DESC tDesc;
Packit 1fb8d4
Packit 1fb8d4
	tDesc.Width = (invalid->right - invalid->left);
Packit 1fb8d4
	tDesc.Height = (invalid->bottom - invalid->top);
Packit 1fb8d4
	tDesc.MipLevels = 1;
Packit 1fb8d4
	tDesc.ArraySize = 1;
Packit 1fb8d4
	tDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
Packit 1fb8d4
	tDesc.SampleDesc.Count = 1;
Packit 1fb8d4
	tDesc.SampleDesc.Quality = 0;
Packit 1fb8d4
	tDesc.Usage = D3D11_USAGE_STAGING;
Packit 1fb8d4
	tDesc.BindFlags = 0;
Packit 1fb8d4
	tDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
Packit 1fb8d4
	tDesc.MiscFlags = 0;
Packit 1fb8d4
Packit 1fb8d4
	Box.top = invalid->top;
Packit 1fb8d4
	Box.left = invalid->left;
Packit 1fb8d4
	Box.right = invalid->right;
Packit 1fb8d4
	Box.bottom = invalid->bottom;
Packit 1fb8d4
	Box.front = 0;
Packit 1fb8d4
	Box.back = 1;
Packit 1fb8d4
Packit 1fb8d4
	status = gDevice->lpVtbl->CreateTexture2D(gDevice, &tDesc, NULL, &sStage);
Packit 1fb8d4
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to create staging surface");
Packit 1fb8d4
		exit(1);
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	gContext->lpVtbl->CopySubresourceRegion(gContext, (ID3D11Resource*)sStage, 0, 0, 0, 0,
Packit Service 5a9772
	                                        (ID3D11Resource*)gAcquiredDesktopImage, 0, &Box;;
Packit Service 5a9772
Packit Service 5a9772
	status = sStage->lpVtbl->QueryInterface(sStage, &IID_IDXGISurface, (void**)&surf);
Packit 1fb8d4
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to QI staging surface");
Packit 1fb8d4
		exit(1);
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	surf->lpVtbl->Map(surf, &mappedRect, DXGI_MAP_READ);
Packit 1fb8d4
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to map staging surface");
Packit 1fb8d4
		exit(1);
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit Service 5a9772
Packit 1fb8d4
	*data = mappedRect.pBits;
Packit 1fb8d4
	*pitch = mappedRect.Pitch;
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int wf_dxgi_releasePixelData(wfInfo* wfi)
Packit 1fb8d4
{
Packit 1fb8d4
	HRESULT status;
Packit 1fb8d4
Packit 1fb8d4
	surf->lpVtbl->Unmap(surf);
Packit 1fb8d4
	surf->lpVtbl->Release(surf);
Packit 1fb8d4
	surf = NULL;
Packit 1fb8d4
	sStage->lpVtbl->Release(sStage);
Packit 1fb8d4
	sStage = NULL;
Packit 1fb8d4
Packit 1fb8d4
	status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication);
Packit 1fb8d4
Packit 1fb8d4
	if (FAILED(status))
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Failed to release frame");
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	wfi->framesWaiting = 0;
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int wf_dxgi_getInvalidRegion(RECT* invalid)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT i;
Packit 1fb8d4
	HRESULT status;
Packit 1fb8d4
	UINT dirty;
Packit 1fb8d4
	UINT BufSize;
Packit 1fb8d4
	RECT* pRect;
Packit 1fb8d4
	BYTE* DirtyRects;
Packit 1fb8d4
	UINT DataBufferSize = 0;
Packit 1fb8d4
	BYTE* DataBuffer = NULL;
Packit 1fb8d4
Packit 1fb8d4
	if (FrameInfo.AccumulatedFrames == 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		return 1;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (FrameInfo.TotalMetadataBufferSize)
Packit 1fb8d4
	{
Packit 1fb8d4
Packit 1fb8d4
		if (FrameInfo.TotalMetadataBufferSize > DataBufferSize)
Packit 1fb8d4
		{
Packit 1fb8d4
			if (DataBuffer)
Packit 1fb8d4
			{
Packit 1fb8d4
				free(DataBuffer);
Packit 1fb8d4
				DataBuffer = NULL;
Packit 1fb8d4
			}
Packit 1fb8d4
Packit Service 5a9772
			DataBuffer = (BYTE*)malloc(FrameInfo.TotalMetadataBufferSize);
Packit Service 5a9772
Packit 1fb8d4
			if (!DataBuffer)
Packit 1fb8d4
			{
Packit 1fb8d4
				DataBufferSize = 0;
Packit 1fb8d4
				WLog_ERR(TAG, "Failed to allocate memory for metadata");
Packit 1fb8d4
				exit(1);
Packit 1fb8d4
			}
Packit 1fb8d4
Packit 1fb8d4
			DataBufferSize = FrameInfo.TotalMetadataBufferSize;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		BufSize = FrameInfo.TotalMetadataBufferSize;
Packit 1fb8d4
Packit Service 5a9772
		status = gOutputDuplication->lpVtbl->GetFrameMoveRects(
Packit Service 5a9772
		    gOutputDuplication, BufSize, (DXGI_OUTDUPL_MOVE_RECT*)DataBuffer, &BufSize);
Packit 1fb8d4
Packit 1fb8d4
		if (FAILED(status))
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "Failed to get frame move rects");
Packit 1fb8d4
			return 1;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		DirtyRects = DataBuffer + BufSize;
Packit 1fb8d4
		BufSize = FrameInfo.TotalMetadataBufferSize - BufSize;
Packit 1fb8d4
Packit Service 5a9772
		status = gOutputDuplication->lpVtbl->GetFrameDirtyRects(gOutputDuplication, BufSize,
Packit Service 5a9772
		                                                        (RECT*)DirtyRects, &BufSize);
Packit 1fb8d4
Packit 1fb8d4
		if (FAILED(status))
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "Failed to get frame dirty rects");
Packit 1fb8d4
			return 1;
Packit 1fb8d4
		}
Packit 1fb8d4
		dirty = BufSize / sizeof(RECT);
Packit 1fb8d4
Packit Service 5a9772
		pRect = (RECT*)DirtyRects;
Packit 1fb8d4
Packit Service 5a9772
		for (i = 0; i < dirty; ++i)
Packit 1fb8d4
		{
Packit 1fb8d4
			UnionRect(invalid, invalid, pRect);
Packit 1fb8d4
			++pRect;
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
#endif