surf.cpp
来自「6410BSP3」· C++ 代码 · 共 474 行 · 第 1/2 页
CPP
474 行
if (pHeap != NULL)
{
DWORD dwVideoMemoryOffset = pHeap->Address() - (DWORD)m_VideoMemoryVirtualBase;
RETAILMSG(DISP_ZONE_CREATE,(_T("[DISPDRV] AllocSurfaceVideo() : Allocated PA = 0x%08x\n\r"), dwVideoMemoryOffset+m_VideoMemoryPhysicalBase));
*ppSurf = new S3C6410Surf(width, height, dwVideoMemoryOffset, (PVOID)pHeap->Address(), stride, format, pixelFormat, pHeap);
if (*ppSurf == NULL)
{
RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] AllocSurfaceVideo() : Create S3C6410Surf() Failed\n\r")));
pHeap->Free();
return E_OUTOFMEMORY;
}
RETAILMSG(DISP_ZONE_CREATE,(_T("[DISPDRV] %s() Allocated in Video Memory\n\r"), _T(__FUNCTION__)));
return S_OK;
}
else
{
RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] AllocSurfaceVideo() : SurfaceHeap Alloc() Failed\n\r")));
*ppSurf = (DDGPESurf *)NULL;
return E_OUTOFMEMORY;
}
}
void S3C6410Disp::SetVisibleSurface(GPESurf *pSurf, BOOL bWaitForVBlank)
{
S3C6410Surf *pDDSurf = (S3C6410Surf *)pSurf;
if(pDDSurf->IsOverlay() == TRUE)
{
m_OverlayCtxt.pPrevSurface = m_OverlayCtxt.pSurface; // Being Flipped Surface
m_OverlayCtxt.pSurface = pDDSurf;
}
else
{
m_pVisibleSurface = pDDSurf;
}
EnterCriticalSection(&m_csDevice);
DevSetVisibleSurface(pDDSurf, bWaitForVBlank);
LeaveCriticalSection(&m_csDevice);
}
//-----------------------------------------------------------------------------
S3C6410Surf::S3C6410Surf(int width, int height, DWORD offset, VOID *pBits, int stride,
EGPEFormat format, EDDGPEPixelFormat pixelFormat, SurfaceHeap *pHeap)
: DDGPESurf(width, height, pBits, stride, format, pixelFormat)
{
dwSurfaceCount++;
m_fInVideoMemory = TRUE;
m_nOffsetInVideoMemory = offset;
m_pSurfHeap = pHeap;
if (pixelFormat == ddgpePixelFormat_I420) // 3Plane
{
m_uiOffsetCb = width*height;
m_uiOffsetCr = m_uiOffsetCb+width*height/4;
}
else if (pixelFormat == ddgpePixelFormat_YV12) // 3Plane
{
m_uiOffsetCr = width*height;
m_uiOffsetCb = m_uiOffsetCr+width*height/4;
}
else
{
m_uiOffsetCr = 0;
m_uiOffsetCb = 0;
}
RETAILMSG(DISP_ZONE_CREATE,(_T("[DISPDRV:INF] %S() : @ 0x%08x, %d\n\r"), _T(__FUNCTION__), m_nOffsetInVideoMemory, dwSurfaceCount));
}
S3C6410Surf::~S3C6410Surf()
{
dwSurfaceCount--;
if(m_pSurfHeap)
{
RETAILMSG(DISP_ZONE_CREATE,(_T("[DISPDRV:INF] %s() : Heap 0x%08x Addr:0x%x, Avail:%d, Size:%d\n\r"),
m_pSurfHeap, m_pSurfHeap->Address(), m_pSurfHeap->Available(), m_pSurfHeap->Size()));
m_pSurfHeap->Free();
RETAILMSG(DISP_ZONE_CREATE,(_T("[DISPDRV:INF] %s() : @ 0x%08x, %d\n\r"), _T(__FUNCTION__), m_nOffsetInVideoMemory, dwSurfaceCount));
}
else
{
RETAILMSG(DISP_ZONE_ERROR, (_T("ERROR, Invalid SurfaceHeap Address")));
}
}
/**
* @class PACSurf
* @desc This Surface will try to allocate physically linear address
*
**/
/**
* @fn PACSurf::PACSurf
* @brief try to allocate memory region that is physically linear
* @param GPESurf **ppSurf, INT width, INT height, EGPEFormat format, int surfaceFlags
* @sa GPESurf
* @note This Surface format is compatible to GPESurf
**/
PACSurf::PACSurf(int width, int height, EGPEFormat format)
{
RETAILMSG(DISP_ZONE_CREATE, (_T("[DISPDRV] PACSurf Constructor(%d, %d, %d)\n\r"), width, height, format));
// Even though "width" and "height" are int's, they must be positive.
ASSERT(width > 0);
ASSERT(height > 0);
DWORD m_pPhysAddr;
memset( &m_Format, 0, sizeof ( m_Format ) );
m_pVirtAddr = NULL;
m_nStrideBytes = 0;
m_eFormat = gpeUndefined;
m_fInVideoMemory = 0;
m_fInUserMemory = FALSE;
m_fOwnsBuffer = 0;
m_nWidth = 0;
m_nHeight = 0;
m_nOffsetInVideoMemory = 0;
m_iRotate = DMDO_0;
m_ScreenWidth = 0;
m_ScreenHeight = 0;
m_BytesPixel = 0;
m_nHandle = NULL;
// m_fPLAllocated = 0;
if (width > 0 && height > 0)
{
m_nWidth = width;
m_nHeight = height;
m_eFormat = format;
m_nStrideBytes = ( (EGPEFormatToBpp[ format ] * width + 7 )/ 8 + 3 ) & ~3L;
m_pVirtAddr = (ADDRESS) AllocPhysMem( m_nStrideBytes * height, PAGE_READWRITE, 0, 0,&m_pPhysAddr);
if(m_pVirtAddr != NULL)
{
// m_fPLAllocated = 1;
// m_fInVideoMemory = 1;
// RETAILMSG(DISP_ZONE_2D,(TEXT("\nPAC Surf PA Base : 0x%x VA Base : 0x%x STRIDE : %d"), m_pPhysAddr, m_pVirtAddr, m_nStrideBytes));
}
else
{
// m_fPLAllocated = 0;
RETAILMSG(DISP_ZONE_WARNING,(TEXT("\nPAC Surf PA Base : 0x%x VA Base : 0x%x STRIDE : %d new unsigned char"), m_pPhysAddr, m_pVirtAddr, m_nStrideBytes));
m_pVirtAddr = (ADDRESS) new unsigned char[ m_nStrideBytes * height ];
}
m_fOwnsBuffer = 1;
m_BytesPixel = EGPEFormatToBpp[m_eFormat] >> 3;
}
}
PACSurf::~PACSurf()
{
if( m_fOwnsBuffer )
{
// if(m_fPLAllocated)
// {
if(m_pVirtAddr)
{
if( !FreePhysMem((LPVOID)m_pVirtAddr) )
{
RETAILMSG(DISP_ZONE_ERROR,(TEXT("PACSurface deallocation is failed\r\n")));
RETAILMSG(DISP_ZONE_WARNING,(TEXT("PACSurface dealloc is trying for non-contigious\r\n")));
delete [] (void *)m_pVirtAddr;
m_pVirtAddr = NULL;
m_fOwnsBuffer = 0;
}
else
{
m_pVirtAddr = NULL;
// m_fPLAllocated = 0;
m_fOwnsBuffer = 0;
RETAILMSG(DISP_ZONE_CREATE,(TEXT("PACSurface deallocation is succeeded\r\n")));
}
}
// }
// else if( m_pVirtAddr )
// {
// RETAILMSG(DISP_ZONE_WARNING,(TEXT("PACSurface dealloc is trying for non-contigious\r\n")));
// delete [] (void *)m_pVirtAddr;
// m_pVirtAddr = NULL;
// m_fOwnsBuffer = 0;
// }
}
}
//-----------------------------------------------------------------------------
#if 0
//------------------------------------------------------------------------------
//
// Method: WriteBack
//
// Flush surface memory in cache.
//
VOID S3C6410Surf::WriteBack()
{
ASSERT(m_pSurface != NULL);
RETAILMSG(DBGLCD, (TEXT("S3C6410Surf::WriteBack\n")));
if (m_pSurface != NULL)
CacheRangeFlush((VOID*)m_pSurface, m_nStrideBytes * m_nHeight, CACHE_SYNC_WRITEBACK);
}
//------------------------------------------------------------------------------
//
// Method: Discard
//
// Flush and invalidate surface memory in cache.
//
VOID S3C6410Surf::Discard()
{
ASSERT(m_pSurface != NULL);
RETAILMSG(DBGLCD, (TEXT("S3C6410Surf::Discard\n")));
if (m_pSurface != NULL)
CacheRangeFlush((VOID*)m_pSurface, m_nStrideBytes * m_nHeight, CACHE_SYNC_DISCARD);
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?