📄 winroot.cpp
字号:
rectBounds.right = (m_compositionSize.cx + textSize.cx)/2 + 2;
rectBounds.top = 0;
rectBounds.bottom = textSize.cy+4;
int delta = 2;
BOOL ret = Rectangle(hMemDC, rectBounds.top - delta, rectBounds.left - delta, rectBounds.bottom + delta, rectBounds.right + delta);
COLORREF oldColor = SetTextColor(hMemDC, m_textColor);
COLORREF oldBkColor = SetBkColor(hMemDC, m_nTextBackgroundColor);
ret = TextOut(hMemDC, textOffset.x, textOffset.y, finalString, finalString.GetLength());
SetBkColor(hMemDC, oldBkColor);
SetTextColor(hMemDC, oldColor);
UnSelectFont(hMemDC);
SelectObject(hMemDC, hOldBrush);
SelectObject(hMemDC, hOldPen);
GdiFlush();
pOverlay->ReleaseDC(hMemDC);
pOverlay->SetSrcRect((HXxRect&)rectBounds);
CreateTextAlpha(pOverlay);
rectBounds.top = m_compositionSize.cy - (textSize.cy+4);
rectBounds.bottom = m_compositionSize.cy;
pOverlay->SetDestRect((HXxRect&)rectBounds, &m_compositionSurface);
}
void CWinBaseRootSurface::_FillBorders()
{
HXxWindow* pWindow = m_pSite->GetWindow();
if (pWindow && pWindow->window)
{
HWND hwnd = (HWND) pWindow->window;
HDC hDC = GetDC(hwnd);
RECT destRect;
GetClientRect(hwnd, &destRect);
HXxSize size;
m_pSite->GetSize(size);
HBRUSH blackBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
HBRUSH oldBrush = (HBRUSH)SelectObject(hDC, blackBrush);
HPEN nullPen = (HPEN)GetStockObject(NULL_PEN);
HPEN oldPen = (HPEN)SelectObject(hDC, nullPen);
if (size.cx < destRect.right)
{
Rectangle(hDC, 0, 0, (destRect.right - size.cx + 1) / 2 + 1, destRect.bottom+1);
Rectangle(hDC, destRect.right - ((destRect.right - size.cx + 1) / 2), 0, destRect.right+1, destRect.bottom+1);
}
else
{
Rectangle(hDC, 0, 0, destRect.right+1, (destRect.bottom - size.cy + 1) / 2 + 1);
Rectangle(hDC, 0, destRect.bottom - ((destRect.bottom - size.cy + 1) / 2), destRect.right+1, destRect.bottom+1);
}
SelectObject(hDC, oldBrush);
SelectObject(hDC, oldPen);
ReleaseDC(hwnd, hDC);
}
}
BOOL CWinBaseRootSurface::_IsHardwareAccelerationAvail()
{
return WinDraw2_IsDDAvailable(&m_windrawCaps);
}
BOOL CWinBaseRootSurface::_AcquireHardwareAcceleration()
{
if (!m_bWindrawOpened)
return FALSE;
m_pCompMutex->Lock();
// Close accelerated windraw instance
if (m_bWindrawCapsOpened)
{
WinDraw2_Close(&m_windrawCaps);
memset(&m_windrawCaps, 0, sizeof(m_windrawCaps));
m_bWindrawCapsOpened = FALSE;
}
_DestroyCompositionSurface();
// Close the non accelrated windraw instance
WinDraw2_Close(&m_windraw);
m_bWindrawOpened = FALSE;
// Turn on acceleration
m_fSurfaceType |= HX_ACCELERATION_ON;
if (m_bUseCardMemory)
m_fSurfaceType |= HX_USE_VIDEO_MEMORY;
else
m_fSurfaceType |= HX_USE_SYSTEM_MEMORY;
_CreateCompositionSurface();
m_pCompMutex->Unlock();
return TRUE;
}
BOOL CWinBaseRootSurface::_LoseHardwareAcceleration()
{
if (!m_bWindrawOpened)
return FALSE;
m_pCompMutex->Lock();
_DestroyCompositionSurface();
m_overlayMgr.RemoveAll();
m_windrawCaps = m_windraw;
memset(&m_windraw, 0, sizeof(m_windraw));
m_bWindrawOpened = FALSE;
// Preserve the DD instance
m_bWindrawCapsOpened = TRUE;
// Turn off acceleration
m_fSurfaceType &= ~HX_ACCELERATION_ON;
m_fSurfaceType &= ~HX_USE_VIDEO_MEMORY;
m_fSurfaceType &= ~HX_USE_SYSTEM_MEMORY;
_CreateCompositionSurface();
m_pCompMutex->Unlock();
return TRUE;
}
BOOL CWinBaseRootSurface::_EnableHardwareAcceleration()
{
// If hardware acceleration is disabled, enabled it
if ((m_fSurfaceType & HX_ACCELERATION_ON) != HX_ACCELERATION_ON)
{
BOOL bCreateCompSurface = FALSE;
m_pCompMutex->Lock();
// If we have an "unaccelerated" composition surface, destroy it
if(HXR_OK == _DestroyCompositionSurface())
bCreateCompSurface = TRUE;
// Close rgb windraw instance
if (m_bWindrawOpened)
{
m_overlayMgr.RemoveAll();
WinDraw2_Close(&m_windraw);
m_bWindrawOpened = FALSE;
}
// Turn on acceleration
m_fSurfaceType |= HX_ACCELERATION_ON;
if (m_bUseCardMemory)
m_fSurfaceType |= HX_USE_VIDEO_MEMORY;
else
m_fSurfaceType |= HX_USE_SYSTEM_MEMORY;
// Create an "accelerated" composition surface if we need one
if(bCreateCompSurface)
_CreateCompositionSurface();
m_pCompMutex->Unlock();
}
return TRUE;
}
BOOL CWinBaseRootSurface::_DisableHardwareAcceleration()
{
// If hardware acceleration is enabled, disable it
if ((m_fSurfaceType & HX_ACCELERATION_ON) == HX_ACCELERATION_ON)
{
BOOL bCreateCompSurface = FALSE;
m_pCompMutex->Lock();
// If we have an "accelerated" composition surface, destroy it
if(HXR_OK == _DestroyCompositionSurface())
bCreateCompSurface = TRUE;
// Close yuv windraw instance
if (m_bWindrawOpened)
{
m_overlayMgr.RemoveAll();
WinDraw2_Close(&m_windraw);
m_bWindrawOpened = FALSE;
}
// Close yuv caps windraw instance
if (m_bWindrawCapsOpened)
{
WinDraw2_Close(&m_windrawCaps);
m_bWindrawCapsOpened = FALSE;
}
// Turn off acceleration
m_fSurfaceType &= ~HX_ACCELERATION_ON;
m_fSurfaceType &= ~HX_USE_VIDEO_MEMORY;
m_fSurfaceType &= ~HX_USE_SYSTEM_MEMORY;
// Create an "unaccelerated" composition surface if we need one
if(bCreateCompSurface)
_CreateCompositionSurface();
m_pCompMutex->Unlock();
}
return TRUE;
}
/**********************************************************************
*
* COverlayMgr
*
* A class which manages the internals of video overlays.
*
**********************************************************************/
COverlayMgr::COverlayMgr()
{
}
COverlayMgr::~COverlayMgr()
{
RemoveAll();
}
BOOL COverlayMgr::GetOverlay(const char* pName, COverlay** pOverlay)
{
return m_overlayMap.Lookup(pName, (void*&)pOverlay);
}
void COverlayMgr::RemoveOverlay(const char* pName, WINDRAWSURFACE* pDestSurface)
{
COverlay* pOverlay;
if (m_overlayMap.Lookup(pName, (void*&)pOverlay))
{
m_overlayMap.RemoveKey(pName);
pOverlay->RemoveOverlay(pDestSurface);
HX_DELETE(pOverlay);
}
}
void COverlayMgr::RemoveAll()
{
COverlay* pOverlay;
CHXMapStringToOb::Iterator i = m_overlayMap.Begin();
for(;i != m_overlayMap.End(); ++i)
{
pOverlay = (COverlay*) *i;
HX_DELETE(pOverlay);
}
m_overlayMap.RemoveAll();
}
void COverlayMgr::AddOverlay(const char* pName, COverlay* pOverlay)
{
m_overlayMap.SetAt(pName, (void*)pOverlay);
}
void COverlayMgr::UpdateOverlays(HXxRect* pRect, WINDRAWSURFACE* pSrcSurface)
{
CHXMapStringToOb::Iterator i = m_overlayMap.Begin();
for(;i!=m_overlayMap.End();++i)
{
COverlay* pOverlay = (COverlay*)*i;
pOverlay->UpdateOverlay(pRect, pSrcSurface);
}
}
/**********************************************************************
*
* COverlay
*
* A class which manages the internals of video overlays.
*
**********************************************************************/
COverlay::COverlay(WINDRAW* pWindraw)
: m_nCID(0)
, m_nAlpha(0)
, m_pWindraw(0)
{
m_pWindraw = pWindraw;
memset(&m_backgroundSurface, 0, sizeof(WINDRAWSURFACE));
memset(&m_overlaySurface, 0, sizeof(WINDRAWSURFACE));
memset(&m_destRect, 0, sizeof(HXxRect));
memset(&m_srcRect, 0, sizeof(HXxRect));
memset(&m_backgroundSrcRect, 0, sizeof(HXxRect));
memset(&m_allocSize, 0, sizeof(HXxRect));
}
COverlay::~COverlay()
{
WinDraw2_ReleaseSurface(m_pWindraw, &m_overlaySurface);
WinDraw2_ReleaseSurface(m_pWindraw, &m_backgroundSurface);
}
void COverlay::CreateOverlay(REF(HXxSize) size, int nCID)
{
BMI textBMI;
m_nCID = nCID;
memcpy(&m_allocSize, &size, sizeof(HXxSize)); /* Flawfinder: ignore */
MakeBitmap((LPBITMAPINFO)&textBMI, sizeof(BITMAPINFO), m_nCID, size.cx, size.cy, NULL, NULL);
HX_VERIFY(NOERROR == WinDraw2_CreateSurface(m_pWindraw, &m_overlaySurface, &textBMI, NULL, 0, 0));
}
void COverlay::SetSrcRect(REF(HXxRect) rect)
{
memcpy(&m_srcRect, &rect, sizeof(HXxRect)); /* Flawfinder: ignore */
}
void COverlay::SetAlpha(int nAlpha)
{
m_nAlpha = nAlpha;
}
void COverlay::GetSize(REF(HXxSize) size)
{
memcpy(&size, &m_allocSize, sizeof(HXxSize)); /* Flawfinder: ignore */
}
UCHAR* COverlay::LockOverlay()
{
UCHAR* retVal;
LONG pitch;
WinDrawSurface_Lock(m_pWindraw, &m_overlaySurface, 0, (void**)&retVal, &pitch);
return retVal;
}
void COverlay::UnlockOverlay()
{
WinDrawSurface_Unlock(m_pWindraw, &m_overlaySurface, 0);
}
UCHAR* COverlay::GetAlpha()
{
UCHAR* retVal = NULL;
WinDraw2_CreateAlphaSurface(m_pWindraw, &m_overlaySurface);
WinDraw2_GetAlphaSurface(m_pWindraw, &m_overlaySurface, &retVal);
return retVal;
}
int COverlay::GetCID()
{
return m_nCID;
}
void COverlay::GetDC(HDC* phDC)
{
WinDrawSurface_GetDC(m_pWindraw, &m_overlaySurface, phDC);
}
void COverlay::ReleaseDC(HDC hDC)
{
WinDrawSurface_ReleaseDC(m_pWindraw, &m_overlaySurface, hDC);
}
void COverlay::SetDestRect(REF(HXxRect) rect, WINDRAWSURFACE* pDestSurface)
{
/*
* if the dest rect changes it is time to recreate the surface.
*/
if (memcmp(&m_destRect, &rect, sizeof(RECT)))
{
/*
* get a buffer of what is on the composition surface
*/
if (rect.right - rect.left != m_destRect.right - m_destRect.left ||
rect.bottom - rect.top != m_destRect.bottom - m_destRect.top )
{
BMI textBMI;
MakeBitmap((LPBITMAPINFO)&textBMI, sizeof(BITMAPINFO), m_nCID, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL);
WinDraw2_ReleaseSurface(m_pWindraw, &m_backgroundSurface);
HX_VERIFY(NOERROR == WinDraw2_CreateSurface(m_pWindraw, &m_backgroundSurface, &textBMI, NULL, 0, 0));
}
memcpy(&m_destRect, &rect, sizeof(HXxRect)); /* Flawfinder: ignore */
memset(&m_backgroundSrcRect, 0, sizeof(RECT));
m_backgroundSrcRect.right = rect.right - rect.left;
m_backgroundSrcRect.bottom = rect.bottom - rect.top;
WinDrawSurface_BltIndirect(m_pWindraw, &m_backgroundSurface, pDestSurface, (RECT*)&m_backgroundSrcRect, (RECT*)&rect);
}
}
void COverlay::DrawOverlay(WINDRAWSURFACE* pDestSurface)
{
WinDrawSurface_BltIndirect(m_pWindraw, pDestSurface, &m_backgroundSurface, (RECT*)&m_backgroundSrcRect, (RECT*)&m_destRect);
WinDrawSurface_BltIndirect(m_pWindraw, pDestSurface, &m_overlaySurface, (RECT*)&m_srcRect, (RECT*)&m_destRect);
}
void COverlay::RemoveOverlay(WINDRAWSURFACE* pDestSurface)
{
WinDrawSurface_BltIndirect(m_pWindraw, pDestSurface, &m_backgroundSurface, (RECT*)&m_backgroundSrcRect, (RECT*)&m_destRect);
}
void COverlay::UpdateOverlay(HXxRect* pRect, WINDRAWSURFACE* pSrcSurface)
{
RECT tempRect;
if (IntersectRect( &tempRect, (RECT*)pRect, (RECT*) &m_destRect))
{
/* yes they intersected */
RECT destRect;
destRect.left = tempRect.left - m_destRect.left;
destRect.top = tempRect.top - m_destRect.top;
destRect.right = tempRect.right - m_destRect.left;
destRect.bottom = tempRect.bottom - m_destRect.top;
/* update the background */
WinDrawSurface_BltIndirect(m_pWindraw, &m_backgroundSurface, pSrcSurface, &destRect, &tempRect);
destRect.right = tempRect.right;
destRect.left = tempRect.left;
/* Now blt */
WinDrawSurface_BltIndirect(m_pWindraw, pSrcSurface, &m_overlaySurface, (RECT*)&tempRect, &destRect);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -