vreg.cpp revision a61d11f3152f6e51d5210d4d38be612a60131c06
/* $Id$ */
/** @file
* Visible Regions processing API implementation
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <cr_vreg.h>
#include <iprt/memcache.h>
#ifndef IN_RING0
#include <cr_error.h>
#else
#endif
typedef struct VBOXVR_REG
{
} VBOXVR_REG, *PVBOXVR_REG;
#define PVBOXVR_REG_FROM_ENTRY(_pEntry) ((PVBOXVR_REG)(((uint8_t*)(_pEntry)) - RT_OFFSETOF(VBOXVR_REG, ListEntry)))
#ifdef DEBUG_misha
//# define VBOXVDBG_VR_LAL_DISABLE
#endif
#ifndef VBOXVDBG_VR_LAL_DISABLE
static RTMEMCACHE g_VBoxVrLookasideList;
#endif
static PVBOXVR_REG vboxVrRegCreate()
{
#ifndef VBOXVDBG_VR_LAL_DISABLE
if (!pReg)
{
WARN(("ExAllocateFromLookasideListEx failed!"));
}
return pReg;
#else
#endif
}
{
#ifndef VBOXVDBG_VR_LAL_DISABLE
#else
#endif
}
{
{
}
}
#define VBOXVR_MEMTAG 'vDBV'
VBOXVREGDECL(int) VBoxVrInit()
{
#ifndef VBOXVDBG_VR_LAL_DISABLE
0, /* size_t cbAlignment */
UINT32_MAX, /* uint32_t cMaxObjects */
NULL, /* PFNMEMCACHECTOR pfnCtor*/
NULL, /* PFNMEMCACHEDTOR pfnDtor*/
NULL, /* void *pvUser*/
0 /* uint32_t fFlags*/
);
if (!RT_SUCCESS(rc))
{
return rc;
}
#endif
return VINF_SUCCESS;
}
VBOXVREGDECL(void) VBoxVrTerm()
{
#ifndef VBOXVDBG_VR_LAL_DISABLE
#endif
}
static DECLCALLBACK(int) vboxVrRegNonintersectedComparator(const RTRECT* pRect1, const RTRECT* pRect2)
{
}
#ifdef DEBUG_misha
{
{
for (RTLISTNODE *pEntry2 = pReg1->ListEntry.pNext; pEntry2 != &pList->ListHead; pEntry2 = pEntry2->pNext)
{
}
}
}
#else
#define vboxVrDbgListVerify(_p) do {} while (0)
#endif
#define VBOXVR_INVALID_COORD (~0U)
DECLINLINE(void) vboxVrListRegAdd(PVBOXVR_LIST pList, PVBOXVR_REG pReg, PRTLISTNODE pPlace, bool fAfter)
{
if (fAfter)
else
}
{
}
{
do
{
{
{
continue;
}
}
break;
} while (1);
}
{
for (PRTLISTNODE pEntry2 = pList2->ListHead.pNext; pEntry2 != &pList2->ListHead; pEntry2 = pList2->ListHead.pNext)
{
do {
{
{
continue;
}
}
break;
} while (1);
}
}
static int vboxVrListRegIntersectSubstNoJoin(PVBOXVR_LIST pList1, PVBOXVR_REG pReg1, const RTRECT * pRect2)
{
#ifdef DEBUG_misha
#endif
RTListInit(&List);
{
}
{
}
{
}
{
}
if (pBottomReg)
if (RTListIsEmpty(&List))
return VINF_SUCCESS; /* the region is covered by the pRect2 */
{
pMemberEntry = pEntry->pNext; /* the following elements should go after the given pEntry since they are ordered already */
}
return VINF_SUCCESS;
}
typedef DECLCALLBACK(PRTLISTNODE) FNVBOXVR_CB_INTERSECTED_VISITOR(PVBOXVR_LIST pList1, PVBOXVR_REG pReg1, const RTRECT * pRect2, void *pvContext, PRTLISTNODE *ppNext);
static void vboxVrListVisitIntersected(PVBOXVR_LIST pList1, uint32_t cRects, const RTRECT *aRects, PFNVBOXVR_CB_INTERSECTED_VISITOR pfnVisitor, void* pvVisitor)
{
{
{
continue;
continue;
/* y coords intersect */
continue;
continue;
/* x coords intersect */
/* the visitor can modify the list 1, apply necessary adjustments after it */
break;
}
}
}
{
{
{
if (fHorizontal)
{
{
{
/* join rectangles */
{
/* restart the pNext1 & pNext2 since regs are splitted into smaller ones in y dimension
* and thus can match one of the previous rects */
break;
}
{
/* restart the pNext1 & pNext2 since regs are splitted into smaller ones in y dimension
* and thus can match one of the previous rects */
break;
}
else
{
/* reset the pNext1 since it could be the pReg2 being destroyed */
/* pNext2 stays the same since it is pReg2->ListEntry.pNext, which is kept intact */
}
}
continue;
}
{
Assert(pReg1->Rect.yTop < pReg2->Rect.yTop); /* <- since pReg1 > pReg2 && pReg1->Rect.yTop != pReg2->Rect.yTop*/
{
/* join rectangles */
/* restart the pNext1 & pNext2 since regs are splitted into smaller ones in y dimension
* and thus can match one of the previous rects */
break;
}
{
/* join rectangles */
/* restart the pNext1 & pNext2 since regs are splitted into smaller ones in y dimension
* and thus can match one of the previous rects */
break;
}
continue;
}
}
else
{
{
{
{
/* join rects */
/* reset the pNext1 since it could be the pReg2 being destroyed */
/* pNext2 stays the same since it is pReg2->ListEntry.pNext, which is kept intact */
continue;
}
/* no more to be done for for pReg1 */
break;
}
{
/* no more to be done for for pReg1 */
break;
}
continue;
}
{
/* no more to be done for for pReg1 */
break;
}
}
}
}
}
{
vboxVrListJoinRectsHV(pList, true);
vboxVrListJoinRectsHV(pList, false);
}
typedef struct VBOXVR_CBDATA_SUBST
{
int rc;
bool fChanged;
static DECLCALLBACK(PRTLISTNODE) vboxVrListSubstNoJoinCb(PVBOXVR_LIST pList, PVBOXVR_REG pReg1, const RTRECT *pRect2, void *pvContext, PRTLISTNODE *ppNext)
{
/* store the prev to get the new pNext out of it*/
/* NOTE: the pReg1 will be invalid after the vboxVrListRegIntersectSubstNoJoin call!!! */
if (RT_SUCCESS(rc))
{
}
WARN(("vboxVrListRegIntersectSubstNoJoin failed!"));
}
static int vboxVrListSubstNoJoin(PVBOXVR_LIST pList, uint32_t cRects, const RTRECT * aRects, bool *pfChanged)
{
if (VBoxVrListIsEmpty(pList))
return VINF_SUCCESS;
*pfChanged = false;
{
WARN(("vboxVrListVisitIntersected failed!"));
}
return VINF_SUCCESS;
}
#if 0
{
#ifdef DEBUG
{
{
{
}
}
}
#endif
/* check if rects are ordered already */
{
continue;
WARN(("rects are unoreded!"));
{
if (!pRects)
{
WARN(("RTMemAlloc failed!"));
return NULL;
}
}
int j = (int)i - 1;
do {
if (j < 0)
break;
break;
--j;
} while (1);
}
return pRects;
}
#endif
{
for (PRTLISTNODE pEntry1 = pList->ListHead.pNext; pEntry1 != &pList->ListHead; pEntry1 = pEntry1->pNext)
{
}
}
VBOXVREGDECL(int) VBoxVrListRectsSubst(PVBOXVR_LIST pList, uint32_t cRects, const RTRECT * aRects, bool *pfChanged)
{
#if 0
if (!pRects)
{
WARN(("vboxVrRectsOrder failed!"));
return VERR_NO_MEMORY;
}
#endif
if (!RT_SUCCESS(rc))
{
WARN(("vboxVrListSubstNoJoin failed!"));
goto done;
}
if (!*pfChanged)
goto done;
done:
#if 0
#endif
return rc;
}
VBOXVREGDECL(int) VBoxVrListRectsAdd(PVBOXVR_LIST pList, uint32_t cRects, const RTRECT * aRects, bool *pfChanged)
{
#if 0
#ifdef DEBUG
{
{
{
}
}
}
#endif
#endif
/* early sort out the case when there are no new rects */
{
for (PRTLISTNODE pEntry1 = pList->ListHead.pNext; pEntry1 != &pList->ListHead; pEntry1 = pEntry1->pNext)
{
{
cCovered++;
break;
}
}
}
{
*pfChanged = false;
return VINF_SUCCESS;
}
/* rects are not covered, need to go the slow way */
uint32_t cAllocatedRects = 0;
bool fNeedRectreate = true;
bool fChanged = false;
int rc = VINF_SUCCESS;
{
if (!pReg)
{
WARN(("vboxVrRegCreate failed!"));
rc = VERR_NO_MEMORY;
break;
}
if (!cListRects)
{
fChanged = true;
continue;
}
else
{
}
if (cAllocatedRects < cListRects)
{
if (pListRects)
if (!pListRects)
{
WARN(("RTMemAlloc failed!"));
rc = VERR_NO_MEMORY;
break;
}
}
if (fNeedRectreate)
{
fNeedRectreate = false;
}
bool fDummyChanged = false;
if (!RT_SUCCESS(rc))
{
WARN(("vboxVrListSubstNoJoin failed!"));
rc = VERR_NO_MEMORY;
break;
}
if (!VBoxVrListIsEmpty(&DiffList))
{
fNeedRectreate = true;
fChanged = true;
}
}
if (pListRects)
if (fChanged)
return VINF_SUCCESS;
}
{
return VERR_BUFFER_OVERFLOW;
uint32_t i = 0;
for (PRTLISTNODE pEntry1 = pList->ListHead.pNext; pEntry1 != &pList->ListHead; pEntry1 = pEntry1->pNext, ++i)
{
}
return VINF_SUCCESS;
}
{
if (cTmp)
return cTmp;
{
if (cTmp)
return cTmp;
}
return 0;
}
VBOXVREGDECL(void) VBoxVrCompositorInit(PVBOXVR_COMPOSITOR pCompositor, PFNVBOXVRCOMPOSITOR_ENTRY_REMOVED pfnEntryRemoved)
{
}
{
{
}
}
DECLINLINE(void) vboxVrCompositorEntryAdd(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry)
{
}
DECLINLINE(void) vboxVrCompositorEntryRemove(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, PVBOXVR_COMPOSITOR_ENTRY pReplacingEntry)
{
if (pCompositor->pfnEntryRemoved)
}
{
}
VBOXVREGDECL(bool) VBoxVrCompositorEntryRemove(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry)
{
return false;
return true;
}
static int vboxVrCompositorEntryRegionsSubst(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, uint32_t cRects, const RTRECT * paRects, bool *pfChanged)
{
bool fChanged;
if (RT_SUCCESS(rc))
{
{
}
if (pfChanged)
*pfChanged = false;
return VINF_SUCCESS;
}
return rc;
}
VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsAdd(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, uint32_t cRects, const RTRECT *paRects, uint32_t *pfChangeFlags)
{
bool fOthersChanged = false, fCurChanged = false, fEntryChanged = false, fEntryInList = false, fEntryReplaces = false;
int rc = VINF_SUCCESS;
if (!cRects)
{
if (pfChangeFlags)
*pfChangeFlags = 0;
return VINF_SUCCESS;
}
if (pEntry)
{
if (RT_SUCCESS(rc))
{
{
WARN(("Empty rectangles passed in, is it expected?"));
if (pfChangeFlags)
*pfChangeFlags = 0;
return VINF_SUCCESS;
}
}
else
{
return rc;
}
}
{
{
}
else
{
{
fEntryReplaces = true;
}
else
{
if (RT_SUCCESS(rc))
else
{
return rc;
}
}
}
}
if (pEntry && !fEntryInList)
{
}
if (pfChangeFlags)
{
if (fOthersChanged)
fFlags = VBOXVR_COMPOSITOR_CF_ENTRIES_REGIONS_CHANGED | VBOXVR_COMPOSITOR_CF_COMPOSITED_REGIONS_CHANGED;
else if (fEntryReplaces)
{
}
else if (fEntryChanged)
fFlags = VBOXVR_COMPOSITOR_CF_ENTRIES_REGIONS_CHANGED | VBOXVR_COMPOSITOR_CF_COMPOSITED_REGIONS_CHANGED;
*pfChangeFlags = fFlags;
}
return VINF_SUCCESS;
}
VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsSubst(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, uint32_t cRects, const RTRECT * paRects, bool *pfChanged)
{
if (!pEntry)
{
WARN(("VBoxVrCompositorEntryRegionsSubst called with zero entry, unsupported!"));
if (pfChanged)
*pfChanged = false;
return VERR_INVALID_PARAMETER;
}
{
if (pfChanged)
*pfChanged = false;
return VINF_SUCCESS;
}
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
return rc;
}
VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsSet(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, uint32_t cRects, const RTRECT *paRects, bool *pfChanged)
{
if (!pEntry)
{
WARN(("VBoxVrCompositorEntryRegionsSet called with zero entry, unsupported!"));
if (pfChanged)
*pfChanged = false;
return VERR_INVALID_PARAMETER;
}
bool fChanged = false, fCurChanged = false;
uint32_t fChangeFlags = 0;
int rc;
fChanged |= fCurChanged;
if (RT_SUCCESS(rc))
fChanged |= !!fChangeFlags;
else
{
return rc;
}
if (pfChanged)
return VINF_SUCCESS;
}
VBOXVREGDECL(int) VBoxVrCompositorEntryRegionsTranslate(PVBOXVR_COMPOSITOR pCompositor, PVBOXVR_COMPOSITOR_ENTRY pEntry, int32_t x, int32_t y, bool *pfChanged)
{
if (!pEntry)
{
WARN(("VBoxVrCompositorEntryRegionsTranslate called with zero entry, unsupported!"));
if (pfChanged)
*pfChanged = false;
return VERR_INVALID_PARAMETER;
}
if ((!x && !y)
{
if (pfChanged)
*pfChanged = false;
return VINF_SUCCESS;
}
int rc = VINF_SUCCESS;
{
continue;
if (!paRects)
{
if (!paRects)
{
WARN(("RTMemAlloc failed!"));
rc = VERR_NO_MEMORY;
break;
}
if (!RT_SUCCESS(rc))
{
break;
}
}
if (!RT_SUCCESS(rc))
{
break;
}
}
if (pfChanged)
*pfChanged = true;
if (paRects)
return rc;
}
VBOXVREGDECL(void) VBoxVrCompositorVisit(PVBOXVR_COMPOSITOR pCompositor, PFNVBOXVRCOMPOSITOR_VISITOR pfnVisitor, void *pvVisitor)
{
{
return;
}
}