VBoxDispVrdpBmp.cpp revision b43f00592f321690997ff22fcb243059b0440091
/* $Id$ */
/** @file
* VBox XPDM Display driver
*/
/*
* Copyright (C) 2011-2013 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 "VBoxDisp.h"
/*
* Cache has a fixed number of preallocated entries. Entries are linked in the MRU lists.
*
* A new bitmap hash is added to the "temporary" list, and the caller is told that the
* bitmap was not cached. If the hash is used again, then it is moved to the "cached" list.
* This protects against "cache, memblt, cache, memblt, ..." sequences.
*
* "Temporary" list contains free and temporary entries. Temporary entries are at the head,
* free entries are at the tail. New temporary entries are inserted in the head.
*
* "Cached" list contains cached entries. When a entry is used, it is moved to the head.
*
* The purpose of the cache is to answer whether the bitmap was already encountered
* before.
*
* No serialization because the code is executed under vboxHwBuffer* semaphore.
*/
{
while (h > 0)
{
h--;
}
return u64CRC;
} /* Hash function end. */
{
if (bytesPerPixel == 0)
{
return FALSE;
}
return TRUE;
}
{
{
}
else
{
}
{
}
else
{
}
}
{
{
}
else
{
}
{
}
else
{
}
}
{
if (pCache->headCached)
{
}
else
{
}
}
{
{
}
else
{
}
}
/* Moves an entry to the head of MRU list. */
{
{
/* The entry is not yet in the head. Exclude from list. */
/* Insert the entry at the head of MRU list. */
}
}
{
{
/* The entry is not yet in the head. Exclude from list. */
/* Insert the entry at the head of MRU list. */
}
}
{
/* Remove from Tmp list. */
/* Insert the entry at the head of Cached list. */
}
{
/* Remove from cached list. */
/* Insert the entry at the head of Tmp list. */
}
/* Returns pointer to the entry if the hash already presents in the cache.
* Moves the found entry to the head of cached MRU list.
*/
{
/* Search the "Cached" MRU list. */
while (pEntry)
{
{
/* Found the entry. Move it to the head of Cached MRU list. */
return pEntry;
}
}
/* Search the "Temporary" MRU list. */
while ( pEntry
{
{
/* Found the entry. It will be removed from the list by the caller. */
return pEntry;
}
}
return NULL;
}
/* Returns TRUE is a entry was also deleted to make room for new entry. */
static int bcInsertHash (VRDPBC *pCache, const VRDPBCHASH *phash, VRDPBCHASH *phashDeleted, BOOL bForce)
{
LOG(("bcInsertHash %p, tmp tail %p, cached tail %p.", pCache, pCache->tailTmp, pCache->tailCached));
/* Get the free entry to be used. Try Tmp list, then the tail of the Cached list. */
{
/* Insert to the head of Tmp list. */
}
else
{
{
}
}
if (!pEntry)
{
return VRDPBMP_RC_NOT_CACHED;
}
{
/* The cache is full. Remove the tail hash. */
bHashDeleted = TRUE;
}
else
{
}
/* The just inserted entry is at the head of Tmp list, so the temporary
* entries will be deleted when there is no room in the cache.
*/
int rc;
if (bForce)
{
LOG(("Force cache"));
}
else
{
}
if (bHashDeleted)
{
}
return rc;
}
/* Find out whether the surface already in the cache.
* Insert in the cache if not.
* Protection against "cache, memblt, cache, memblt, ..." sequence:
* first time just append the bitmap hash and mark it as "temporary";
* if the hash is used again, mark as cached and tell the caller to cache the bitmap;
* remove "temporary" entries before any other.
*
*/
int vrdpbmpCacheSurface(VRDPBC *pCache, const SURFOBJ *pso, VRDPBCHASH *phash, VRDPBCHASH *phashDeleted, BOOL bForce)
{
if (!bResult)
{
WARN(("MEMBLT: vrdpbmpCacheSurface: could not compute hash."));
return VRDPBMP_RC_NOT_CACHED;
}
if (pEntry)
{
{
return VRDPBMP_RC_ALREADY_CACHED;
}
/* The status must be VRDP_BC_ENTRY_STATUS_TEMPORARY here.
* Update it to *_CACHED.
*/
{
return VRDPBMP_RC_NOT_CACHED;
}
return VRDPBMP_RC_CACHED;
}
return rc;
}
/* Setup the initial state of the cache. */
{
int i;
/* Reinitialize the cache structure. */
{
{
}
{
}
}
}