#define STRICT #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include #include #include #include #include KOverlaySurface:: KOverlaySurface() { m_no_src_color_keying = true; m_src_rect_not_set = true; } KOverlaySurface:: ~KOverlaySurface() { Discharge(); } bool KOverlaySurface:: Init(DDCAPS & ddcaps, DWORD w, DWORD h, int buf_count) { // Check for overlay support. if(!(ddcaps.dwCaps & DDCAPS_OVERLAY)) { return false; } m_flag = DDOVER_SHOW; m_ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; m_ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY ; m_ddsd.dwWidth = w; m_ddsd.dwHeight = h; ::SetPixelFormat(m_ddsd.ddpfPixelFormat, 32); // Make arrangements for a swap chain. if( buf_count ) { m_ddsd.dwFlags |= DDSD_BACKBUFFERCOUNT; m_ddsd.dwBackBufferCount = buf_count; m_ddsd.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; } return true; } void KOverlaySurface:: Discharge(void) { KDDSurface::Discharge(); } HRESULT KOverlaySurface:: CreateOverlaySurface(IDirectDraw7 * pDD) { HRESULT hr; hr = pDD->CreateSurface(& m_ddsd, & m_pSurface, NULL); #ifdef KDEBUG e_dx.Test(hr, __FILE__, __LINE__, "CreateOverlaySurface:CreateSurface"); #endif return hr; } HRESULT KOverlaySurface:: UpdateOverlay(IDirectDrawSurface7 * dest_surface) { HRESULT hr; if(m_src_rect_not_set) { if(m_no_src_color_keying) { hr = m_pSurface->UpdateOverlay( 0, dest_surface, &m_dest_rect, m_flag, 0); #ifdef KDEBUG e_dx.Test(hr, __FILE__, __LINE__, "UpdateOverlay:UpdateOverlay"); #endif } else { hr = m_pSurface->UpdateOverlay( 0, dest_surface, &m_dest_rect, m_flag, & m_fx); #ifdef KDEBUG e_dx.Test(hr, __FILE__, __LINE__, "UpdateOverlay:UpdateOverlay"); #endif } } else { if(m_no_src_color_keying) { hr = m_pSurface->UpdateOverlay( &m_src_rect, dest_surface, &m_dest_rect, m_flag, 0); #ifdef KDEBUG e_dx.Test(hr, __FILE__, __LINE__, "UpdateOverlay:UpdateOverlay"); #endif } else { hr = m_pSurface->UpdateOverlay( &m_src_rect, dest_surface, &m_dest_rect, m_flag, & m_fx); #ifdef KDEBUG e_dx.Test(hr, __FILE__, __LINE__, "UpdateOverlay:UpdateOverlay"); #endif } } return hr; } void KOverlaySurface:: Hide(void) { m_flag &= ~DDOVER_SHOW; m_flag |= DDOVER_HIDE; } void KOverlaySurface:: Show(void) { m_flag &= ~DDOVER_HIDE; m_flag |= DDOVER_SHOW; } void KOverlaySurface:: SetDestRect(RECT& rect) { m_dest_rect.left = rect.left; m_dest_rect.top = rect.top ; m_dest_rect.right = rect.right ; m_dest_rect.bottom = rect.bottom ; } RECT& KOverlaySurface:: GetDestRect(void) { return m_dest_rect; } void KOverlaySurface:: SetSrcRect(RECT& rect) { m_src_rect.left = rect.left; m_src_rect.top = rect.top ; m_src_rect.right = rect.right ; m_src_rect.bottom = rect.bottom ; m_src_rect_not_set = false; } RECT& KOverlaySurface:: GetSrcRect(void) { return m_src_rect; } HRESULT KOverlaySurface:: GetBackBuffer(KOverlaySurface& back_buf) { HRESULT hr; DDSCAPS2 ddscaps; ZeroMemory(&ddscaps, sizeof(ddscaps)); ddscaps.dwCaps = DDSCAPS_BACKBUFFER; IDirectDrawSurface7 * surf = back_buf.GetSurface(); hr = m_pSurface->GetAttachedSurface(&ddscaps, &surf); #ifdef KDEBUG e_dx.Test(hr, __FILE__, __LINE__, "GetBackBuffer:GetAttachedSurface"); #endif back_buf.SetSurface(surf); return hr; } HRESULT KOverlaySurface:: Flip(void) { HRESULT hr; hr = m_pSurface->Flip(0, DDFLIP_WAIT); #ifdef KDEBUG e_dx.Test(hr, __FILE__, __LINE__, "Flip:Flip"); #endif return hr; } IDirectDrawSurface7 * KOverlaySurface:: GetSurface() { return m_pSurface; } void KOverlaySurface:: SetSurface(IDirectDrawSurface7 * surface) { m_pSurface = surface; } void KOverlaySurface:: SetOverlaySourceColorKey(DDCAPS & ddcaps, DWORD color) { // Check if the overlay hardware supports source colour keying. if(ddcaps.dwCKeyCaps & DDCKEYCAPS_SRCOVERLAY) { m_flag |= DDOVER_DDFX | DDOVER_KEYSRCOVERRIDE; // Setup the overlay FX structure and set the color key to black. memset(& m_fx, 0, sizeof(m_fx)); m_fx.dwSize=sizeof(m_fx); m_fx.dckDestColorkey.dwColorSpaceLowValue = 0; m_fx.dckDestColorkey.dwColorSpaceHighValue = 0; m_no_src_color_keying = false; } } bool KOverlaySurface:: OverlaySourceColorKeySet(void) { return !m_no_src_color_keying; }