Ejemplo n.º 1
0
/**
 * vdraw_ddraw_restore_graphics(): Restore the DirectDraw surface if it is lost.
 * @return HRESULT.
 */
HRESULT vdraw_ddraw_restore_graphics(void)
{
	HRESULT rval1 = lpDDS_Primary->Restore();
	HRESULT rval2 = lpDDS_Back->Restore();
	
	// Modif N. -- fixes lost surface handling when the color depth has changed
	if (rval1 == DDERR_WRONGMODE || rval2 == DDERR_WRONGMODE)
		return vdraw_ddraw_init() ? DD_OK : DDERR_GENERIC;
	
	return SUCCEEDED(rval2) ? rval1 : rval2;
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
// Name: Flip()
// Desc: this function flips a surface onto the primary surface
//-----------------------------------------------------------------------------   
int Flip(LPDIRECTDRAWSURFACE7 lpddsSurface, RECT destrect)
{// this function flips a surface onto the primary surface
	
	//Blt the frame
	ddReturnVal = lpddsPrimary->Blt(&destrect/*dest rect*/,lpddsSurface, //pointer to source surface
									  NULL, //pointer to the source rectangle
									  DDBLT_WAIT | DDBLT_KEYSRC, NULL/*ddbltfx struct*/);//NULL means entire surface
	if(ddReturnVal!=DD_OK)
		if(ddReturnVal==DDERR_SURFACELOST)
		{	OutputDebugString("Surfacelost Flip(RECT)\n"); lpddsSurface->Restore(); lpddsPrimary->Restore(); return(1);	}
		else
			if (DDFailedCheck(ddReturnVal, "Flip(lpddsSurface, RECT), Blt failed", cpErrorBuf ))
			{	MessageBox(NULL, cpErrorBuf, "SurfaceFuncs", MB_ICONEXCLAMATION);   return(0); }
		
	return 1;
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
// Name: dx_CopieBitmap(...)
// Desc: Copie le contenu d'un bitmap dans le buffer d'affichage
//-----------------------------------------------------------------------------
bool dx_CopieBitmap (HBITMAP pBitmap, uint16 pPosX, uint16 pTailleX,
                     uint16 pPosY, uint16 pTailleY)
{
    HDC           hdcImage;
    HDC           hdc;
    BITMAP        bm;

    if (pBitmap == NULL) return false;

    SurfaceBack->Restore();

    hdcImage = CreateCompatibleDC (NULL);
    SelectObject (hdcImage, pBitmap);
    GetObject (pBitmap, sizeof(bm), &bm);

    pTailleX = pTailleX == 0 ? bm.bmWidth  : pTailleX;
    pTailleY = pTailleY == 0 ? bm.bmHeight : pTailleY;

    SurfaceBack->GetDC(&hdc);

    BitBlt (hdc, pPosX, pPosY, pTailleX, pTailleY, hdcImage, 0, 0, SRCCOPY);

    SurfaceBack->ReleaseDC(hdc);

    DeleteDC (hdcImage);

    return true;
}
Ejemplo n.º 4
0
void DDAccurateUpdateDisplay(bool singlestep)
{
        static int framecounter=0;
        HRESULT hRet;
        RECT rDest;

        if (++framecounter > zx81.frameskip || singlestep)
                framecounter=0;
        else
                return;

        DDFrame->Unlock(NULL);

        POINT p = {0, 0};
        if(!Form1->FullScreen) p=Form1->ClientToScreen(p);

        rDest=rcdest;
        rDest.left += p.x;
        rDest.top += p.y;
        rDest.right += p.x;
        rDest.bottom += p.y;

        //if (Form1->FullScreen) DDDrawBorder();
        while(1)
        {
                hRet = m_pddsFrontBuffer->Blt(&rDest, DDFrame, &rcsource, DDBLT_WAIT, NULL);

                if (hRet == DD_OK) break;
                else
                if(hRet == DDERR_SURFACELOST)
                {
                        m_pddsFrontBuffer->Restore();
                        m_pddsFrame->Restore();
                }
                else if(hRet != DDERR_WASSTILLDRAWING) return;
        }


        DDFrame->Lock(NULL, &DDFrameSurface, DDLOCK_WAIT |  DDLOCK_NOSYSLOCK, NULL);
        dest=buffer= (BYTE*)DDFrameSurface.lpSurface;
}
Ejemplo n.º 5
0
//-----------------------------------------------------------------------------
// Name: Flip()
// Desc: this function flips a surface onto the primary surface 
//       primary surface expected to be a normal window (non-fullscreen).
//       flips to client area only
//-----------------------------------------------------------------------------   
int FlipToClient(LPDIRECTDRAWSURFACE7 lpddsSurface)
{// this function flips a surface onto the primary surface
	static RECT temp;

	GetWindowRect(main_window_handle, &temp);
	temp.top +=20;
	temp.left +=4;
	temp.right -=4;
	temp.bottom -=4;
	//Blt the frame
	ddReturnVal = lpddsPrimary->Blt(&temp/*dest rect*/,lpddsSurface, //pointer to source surface
									  NULL, //pointer to the source rectangle
									  DDBLT_WAIT | DDBLT_KEYSRC, NULL/*ddbltfx struct*/);//NULL means entire surface
	if(ddReturnVal!=DD_OK)
		if(ddReturnVal==DDERR_SURFACELOST)
		{	OutputDebugString("Surfacelost FlipToClient()\n"); lpddsSurface->Restore(); lpddsPrimary->Restore(); return(1);	}
		else
			if (DDFailedCheck(ddReturnVal, "FlipToClient(lpddsSurface), Blt failed", cpErrorBuf ))
			{	MessageBox(NULL, cpErrorBuf, "SurfaceFuncs", MB_ICONEXCLAMATION);   return(0); }
		
	return 1;
}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
// Name: Flip()
// Desc: this function flip the primary surface with the secondary surface
//-----------------------------------------------------------------------------   
int Flip()
{// this function flip the primary surface with the secondary surface

	// flip pages
	while( (ddReturnVal=lpddsPrimary->Flip(NULL, DDFLIP_WAIT) )!= DD_OK)
	{
		if(ddReturnVal!=DD_OK)
			if(ddReturnVal==DDERR_SURFACELOST)
			{	OutputDebugString("Surfacelost Flip()\n"); lpddsPrimary->Restore(); return(1);	}
			else
				if (DDFailedCheck(ddReturnVal, "Flip()", cpErrorBuf ))
				{	MessageBox(NULL, cpErrorBuf, "SurfaceFuncs", MB_ICONEXCLAMATION);   return(0); }
	}

	// return success
	return(1);

} // end DD_Flip
Ejemplo n.º 7
0
void ProcessIdle()
{
	HRESULT hRet;
	static int iX = 0, iY = 0;
	static iLastBlit;

	if(GetTickCount() - iLastBlit < 50)
	{
		return;
	}

	g_surfCar.Draw(g_pDDSBack, 245, 170, iX, iY, 150, 140);

	while( 1 )
	{
		hRet = g_pDDSFront->Flip(NULL, 0 );
		if( hRet == DD_OK )
		{
			break;
		}
		if( hRet == DDERR_SURFACELOST )
		{
			g_pDDSFront->Restore();
		}
		if( hRet != DDERR_WASSTILLDRAWING )
		{
			break;
		}
	}

	iX += 150;
	if(iX >= 1500)
	{
		iX = 0;
		iY += 140;
		if(iY >= 280)
		{
			iY = 0;
		}
	}

	iLastBlit = GetTickCount();
}
Ejemplo n.º 8
0
//-----------------------------------------------------------------------------
// Name: Lock()
// Desc: Fucntion to lock the entire surface
//-----------------------------------------------------------------------------
int Lock(LPDIRECTDRAWSURFACE7 lpddsSurface)
{
	memset(&ddsd,0,sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	
	ddReturnVal  = lpddsSurface->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
	if (DDFailedCheck(ddReturnVal, "Lock() failed", cpErrorBuf ))
	{	
		if(ddReturnVal==DDERR_SURFACELOST)
		{
			lpddsSurface->Restore();
			return(1);
		}
		else
		{
			MessageBox(main_window_handle, cpErrorBuf, "Lock()", MB_ICONEXCLAMATION);
			return(0); 
		}
	}
	
	return (1);
}
Ejemplo n.º 9
0
HRESULT STDMETHODCALLTYPE Restore(LPDIRECTDRAWSURFACE7 surface)
{
    //logOutput << CurrentTimeString() << "Hooked Restore()" << endl;

    ddrawSurfaceRestore.Unhook();
    HRESULT hr = surface->Restore();

    if (bHasTextures)
    {
        if (surface == g_frontSurface)
        {
            logOutput << CurrentTimeString() << "SurfaceRestore: restoring offscreen buffers" << endl;
            bool success = true;
            for (UINT i = 0; i < NUM_BUFFERS; i++)
            {
                HRESULT err;
                if (FAILED(err = ddCaptures[i]->Restore()))
                {
                    logOutput << CurrentTimeString() << "SurfaceRestore: error restoring offscreen buffer" << endl;
                    printDDrawError(err, "Restore");
                    success = false;
                }
            }
            if (!success)
            {
                CleanUpDDraw();
            }
        }
    }
    ddrawSurfaceRestore.Rehook();

    if (!bHasTextures)
    {
        getFrontSurface(surface);
    }

    return hr;
}
// Draw video to DirectDraw surface.
BOOL CDShow::Draw(LPDIRECTDRAWSURFACE7 lpDDSurface7)
{
	// Return FALSE if media was not open
	if (!m_bMediaOpen) {
		return FALSE;
	}


	// Update media stream. 
	// If it does not return S_OK, we are not playing.
	if (m_pSample->Update(0,NULL,NULL,0)!=S_OK) {
		m_bPlaying=FALSE;

	}
	
	// Now blit video to specified surface and rect.
	// Restore surface if lost.
	if (lpDDSurface7->Blt(NULL,m_pDDSurface7, &m_rSrcRect,DDBLT_WAIT,NULL)==DDERR_SURFACELOST)
		lpDDSurface7->Restore();
	
	// Ok. return TRUE.
	return TRUE;
}
Ejemplo n.º 11
0
////FUNCTIONS//////////////////
//-----------------------------------------------------------------------------
// Name: Main()
// Desc: Whwere all work is done
//-----------------------------------------------------------------------------
bool main()
{
    static SCCOLOR col;
    static UCHAR* back_buf;
    static HDC hDC;
    static int iFrames=0;
    static int x=0;

    col.b = col.r = col.g = 255;

    if(GetKeyStatus(VK_ESCAPE) == true)
        return(0);

    //Clear the surface
    if(!ClrS(lpddsSecondary,wndRect))//can't be within a lock-Unlock block or u can't blt
        return(0);

    //Write text to the Secondary surface remember to Release the DC
    ddReturnVal = lpddsSecondary->GetDC(&hDC);
    if (DDFailedCheck(ddReturnVal, "GetDC() failed", cpErrorBuf ))
    {
        if(ddReturnVal == DDERR_SURFACELOST)
        {
            lpddsSecondary->Restore();
            lpddsSecondary->GetDC(&hDC);
        }
        else
        {
            MessageBox(main_window_handle, cpErrorBuf, "main()", MB_ICONEXCLAMATION);
            return(0);
        }
    }

    static char buffer[1024];
    SetBkColor(hDC,RGB(0,0,0));
    SetBkMode(hDC,OPAQUE);
    sprintf(buffer, "Time elapsed(s)= %d", (int)(gametimer.GetStartElapsedTime()*0.001) );//0.00001666666f
    static DWORD starttime=GetTickCount();
    if( gametimer.Elapsed(starttime,(60/0.001)) )
        sprintf(buffer,"TIME!"," 1 minute");
    SetTextColor(hDC,RGB(255,255,255));
    iFrames++;
    static int FramesPerSec=0;
    FramesPerSec = iFrames/( ((int)(gametimer.GetStartElapsedTime()*0.001)+1) );
    sprintf(buffer, "Frames/s = %d", FramesPerSec);
    TextOut(hDC, 100,100, buffer, strlen(buffer));

    sprintf(buffer, "X= %d", x);
    TextOut(hDC, 100,140, buffer, strlen(buffer));
    ddReturnVal = lpddsSecondary->ReleaseDC(hDC);
    if (DDFailedCheck(ddReturnVal, "ReleaseDC() failed", cpErrorBuf ))
    {
        MessageBox(main_window_handle, cpErrorBuf, "main()", MB_ICONEXCLAMATION);
        return(0);
    }

    //Lock the surface for drawing
    if(!Lock(lpddsSecondary))
        return(0);

    back_buf = (UCHAR*)ddsd.lpSurface;

    //test drawing pixels
    DrawPixel(ddsd,x+200,100,col);
    DrawPixel(ddsd,x+200,101,col);
    DrawPixel(ddsd,x+200,102,col);
    DrawPixel(ddsd,x+200,103,col);
    DrawPixel(ddsd,x+200,104,col);
    DrawPixel(ddsd,x+200,105,col);
    DrawPixel(ddsd,x+200,106,col);
    DrawPixel(ddsd,x+200,107,col);
    DrawPixel(ddsd,x+200,108,col);
    x++;
    if(x>780)
        x=0;

    //test bitmap class
    for (int y=0; y < bitmap1.GetHeight(); y++)
    {
        // copy the line
        memcpy(&back_buf[100+(y+200)*ddsd.lPitch], // dest address
               &bitmap1.GetImageData()[y*bitmap1.GetWidth()*2],   // src address
               bitmap1.GetWidth()*2);                         // bytes to copy
    } // end for y

    //Unlock the surface
    if(!UnLock(lpddsSecondary))
        return(0);

    if(!Lock(Temp))
        return(0);
    back_buf = (UCHAR*)ddsd.lpSurface;
    for (int y=0; y < bitmap2.GetHeight(); y++)
    {
        // copy the line
        memcpy(&back_buf[y*ddsd.lPitch], // dest address
               &bitmap2.GetImageData()[y*bitmap2.GetWidth()*2],   // src address
               bitmap2.GetWidth()*2);                         // bytes to copy
    } // end for y
    if(!UnLock(Temp))
        return(0);
    static RECT temprect= {200,200,520,400};
    static RECT sorc_rect= {0,0,320,200};
    ddReturnVal = lpddsSecondary->Blt(&temprect/*dest rect*/,Temp, //pointer to source surface
                                      &sorc_rect, //pointer to the source rectangle
                                      DDBLT_WAIT | DDBLT_KEYSRC,NULL);
    if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf ))
    {
        MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION);
        return(0);
    }


    static RECT temprect2;
    temprect2.top=200;
    temprect2.left=500;
    temprect2.right=sprite.GetWidth()+500;
    temprect2.bottom=sprite.GetHeight()+200;
    static int i=0;
    ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,sprite.GetFrame(i), //pointer to source surface
                                      NULL, //pointer to the source rectangle
                                      DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/);
    if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf ))
    {
        MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION);
        return(0);
    }
    static DWORD start = GetTickCount();
    if(gametimer.Elapsed(start,120))
    {
        i++;
        start = GetTickCount();
    }
    if(i>13)
        i=0;

    static int size=0;
    temprect2.top=500+size;
    temprect2.left=300+size;
    temprect2.bottom=500+myface.GetWidth()+size;
    temprect2.right=300+myface.GetWidth()+size;
    ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,myface.GetFrame(0), //pointer to source surface
                                      NULL, //pointer to the source rectangle
                                      DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/);
    if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf ))
    {
        MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION);
        return(0);
    }

    static int what=0;
    what++;
    size= sin(what)+cos(what+5);

    static int j=0;
    static DWORD start2=GetTickCount();
    if(gametimer.Elapsed(start2,50))
    {
        j++;
        start2=GetTickCount();
    }
    if(j>=3)j=0;
    temprect2.top=500;
    temprect2.left=100;
    temprect2.bottom=500+ship.GetHeight();
    temprect2.right=100+ship.GetWidth();
    ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,ship.GetFrame(j), //pointer to source surface
                                      NULL, //pointer to the source rectangle
                                      DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/);
    if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf ))
    {
        MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION);
        return(0);
    }

    temprect2.top=400;
    temprect2.left=500;
    temprect2.bottom=400+recttest.GetHeight()+50;
    temprect2.right=500+recttest.GetWidth()+50;

    ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,recttest.GetFrame(0), //pointer to source surface
                                      &recttest.GetRect(), //pointer to the source rectangle
                                      DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/);
    if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf ))
    {
        MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION);
        return(0);
    }

    temprect2.top=485;
    temprect2.left=160;
    temprect2.bottom=485+ship2.GetHeight();
    temprect2.right=160+ship2.GetWidth();
    static int k=0;
    static DWORD start3;
    if(gametimer.Elapsed(start3,0))
    {
        k++;
        start3=GetTickCount();
    }
    if(k>=11)k=0;

    ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,ship2.GetFrame(0), //pointer to source surface
                                      &ship2.GetRect(), //pointer to the source rectangle
                                      DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/);
    if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf ))
    {
        MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION);
        return(0);
    }

    Flip();

    return(1);
}