📄 surf.cpp
字号:
else /// PAC Allocation succeeded.
{
RETAILMSG(DBGLCD,(_T("\n[DISPDRV] AllocSurface() : PACSurf() Allocated in System Memory")));
return S_OK;
}
}
#endif
/// if allocation is failed or boundary condition is not met, just create GPESurf in normal system memory that can be non-linear physically.
RETAILMSG(DBGLCD, (TEXT("* Allocating surface in system memory normal*\r\n")));
*ppSurf = new GPESurf(width, height, format);
if (*ppSurf == NULL || (*ppSurf)->Buffer() == NULL)
{
RETAILMSG(DBGLCD, (L"ERROR: S3C2450Surf::AllocSurface: Failed allocate surface (width: %d, height: %d, format %d)\r\n",width, height, format));
delete *ppSurf;
*ppSurf = NULL;
sc = E_OUTOFMEMORY;
goto cleanUp;
}
// We are done
RETAILMSG(DBGLCD, (L"S3C2450Surf::AllocSurface: Surface in memory (width: %d, height: %d, format %d, pixelformat %d 0x%08x)\r\n",
width, height, format, EGPEFormatToEDDGPEPixelFormat[format], (*ppSurf)->Buffer()));
cleanUp:
return sc;
}
void S3C2450DISP::SetVisibleSurface( GPESurf *pTempSurf, BOOL bWaitForVBlank)
{
static int timeoutcnt=0;
DWORD we;
#ifdef HIGH_PRIORITY_INTR
int iPriority;
HANDLE hThread;
hThread = GetCurrentThread();
iPriority = CeGetThreadPriority(hThread);
CeSetThreadPriority(hThread, DISPDRV_IST_PRIORITY);
#endif
S3C2450Surf *pSurf = (S3C2450Surf *) pTempSurf;
EnterCriticalSection(&m_CS);
// assume Synchronous to VSYNC
EnableInterrupt();
we = WaitForSingleObject(m_hVSYNCInterruptEvent,1000/*INFINITE*/);
DisableInterrupt();
InterruptDone(m_dwVSYNCSysIntr);
if(we != WAIT_OBJECT_0)
{
timeoutcnt++;
RETAILMSG(1,(TEXT("Surface Flipping Time Out %d !!!\n"), timeoutcnt));
for(int i=0;i<78;i++)
RETAILMSG(1,(TEXT("0x%08X = 0x%08X\n"),(DWORD*)((DWORD*)m_pLCDReg + i),*(DWORD*)((DWORD*)m_pLCDReg + i)));
RETAILMSG(1,(TEXT("saved_x=%d"),saved_x));
RETAILMSG(1,(TEXT("saved_y=%d"),saved_y));
RETAILMSG(1,(TEXT("saved_width=%d"),saved_width));
RETAILMSG(1,(TEXT("saved_height=%d"),saved_height));
while(1);
}
if(pSurf->m_bIsOverlay == FALSE)
{
//RETAILMSG(1,(TEXT("pSurf->OffsetInVideoMemory()=0x%08X\n"),pSurf->OffsetInVideoMemory()));
m_pVisibleSurface = pSurf;
m_pLCDReg->VIDW00ADD0B0 = (UINT32)(pSurf->OffsetInVideoMemory() + IMAGE_FRAMEBUFFER_DMA_BASE);
// buffer end address
m_pLCDReg->VIDW00ADD1B0 = (UINT32)(pSurf->OffsetInVideoMemory() + IMAGE_FRAMEBUFFER_DMA_BASE) + (LCD_XSIZE_TFT*LCD_YSIZE_TFT*2);
// buffer size
m_pLCDReg->VIDW00ADD2B0 = (0<<VIDWxADD2_OFFSET_SIZE_S)|(LCD_XSIZE_TFT*2);
}
else
{
m_pLCDReg->VIDW01ADD0 = (UINT32)(pSurf->OffsetInVideoMemory() + IMAGE_FRAMEBUFFER_DMA_BASE);
// buffer end address
m_pLCDReg->VIDW01ADD1 = (UINT32)(pSurf->OffsetInVideoMemory() + IMAGE_FRAMEBUFFER_DMA_BASE) +
(pSurf->Width()*pSurf->Height()*2);
// buffer size
m_pLCDReg->VIDW01ADD2 = (0<<VIDWxADD2_OFFSET_SIZE_S)|(pSurf->Width()*2);
}
RETAILMSG(DBGLCD, (TEXT("S3C2450DISP::SetVisibleSurface\r\n")));
LeaveCriticalSection(&m_CS);
#ifdef HIGH_PRIORITY_INTR
CeSetThreadPriority(hThread, iPriority);
#endif
}
S3C2450Surf::S3C2450Surf(int width, int height, DWORD pa, VOID *pBits, int stride,
EGPEFormat format, EDDGPEPixelFormat pixelFormat, SurfaceHeap *pHeap)
: DDGPESurf(width, height, pBits, stride, format, pixelFormat)
{
BOOL rc = FALSE;
RETAILMSG(DBGLCD, (TEXT("nCount = %d\r\n"), ++nCount));
m_pHeap = pHeap;
m_nOffsetInVideoMemory = pa;
m_fInVideoMemory = TRUE;//(pa != 0);
RETAILMSG(DBGLCD,(TEXT("m_nOffsetInVideoMemory=0x%08X m_fInVideoMemory=0x%08X\n "),m_nOffsetInVideoMemory,m_fInVideoMemory));
m_hSurface = NULL;
m_pSurface = NULL;
}
//-----------------------------------------------------------------------------
S3C2450Surf::~S3C2450Surf()
{
RETAILMSG(DBGLCD, (TEXT("+++++++++++++++++++S3C2450Surf::~S3C2450Surf 0x%08x\r\n"),m_nOffsetInVideoMemory));
// Delete surface mapping if exists
if (m_pSurface != NULL)
{
ADDRESS address = (ADDRESS)m_pSurface;
address &= ~(PAGE_SIZE - 1);
UnmapViewOfFile((VOID*)address);
}
if (m_hSurface != NULL)
CloseHandle(m_hSurface);
// Free memory if it was allocated in SRAM...
if (m_pHeap != NULL)
m_pHeap->Free();
//RETAILMSG(1, (TEXT("-------------------S3C2450Surf::~S3C2450Surf \r\n")));
RETAILMSG(DBGLCD, (TEXT("-------------------S3C2450Surf::~S3C2450Surf nCount = %d\r\n"), --nCount));
}
#if USE_PACSURF
/**
* @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(DBGLCD, (_T("\n[DISPDRV] PACSurf Constructor(%d, %d, %d)"), width, height, format));
// Even though "width" and "height" are int's, they must be positive.
ASSERT(width > 0);
ASSERT(height > 0);
memset( &m_Format, 0, sizeof ( m_Format ) );
m_pVirtAddr = NULL;
m_nStrideBytes = 0;
m_eFormat = gpeUndefined;
m_fInVideoMemory = 0;
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(DBGLCD,(TEXT("\nPAC Surf PA Base : 0x%x VA Base : 0x%x STRIDE : %d"), m_pPhysAddr, m_pVirtAddr, m_nStrideBytes));
}
else
{
m_fPLAllocated = 0;
RETAILMSG(DBGLCD,(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(1,(TEXT("\nPACSurface deallocation is failed")));
}
else
{
RETAILMSG(DBGLCD,(TEXT("\nPACSurface deallocation is succeeded : 0x%x"), m_pVirtAddr));
m_pVirtAddr = NULL;
m_fPLAllocated = 0;
m_fOwnsBuffer = 0;
}
}
}
else if( m_pVirtAddr )
{
RETAILMSG(TRUE,(TEXT("\nPACSurface dealloc is trying for non-contigious physical memory : 0x%x"),m_pVirtAddr));
delete [] (void *)m_pVirtAddr;
m_pVirtAddr = NULL;
m_fOwnsBuffer = 0;
}
}
}
#endif
//-----------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// Method: WriteBack
//
// Flush surface memory in cache.
//
VOID S3C2450Surf::WriteBack()
{
ASSERT(m_pSurface != NULL);
RETAILMSG(DBGLCD, (TEXT("S3C2450Surf::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 S3C2450Surf::Discard()
{
ASSERT(m_pSurface != NULL);
RETAILMSG(DBGLCD, (TEXT("S3C2450Surf::Discard\n")));
if (m_pSurface != NULL)
CacheRangeFlush((VOID*)m_pSurface, m_nStrideBytes * m_nHeight, CACHE_SYNC_DISCARD);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -