// // Flip the real page with virtual page // - in bAppFullScreen mode, do page flipping // - in windowed mode, copy the hidden surface to the visible surface // // waitflip : if not 0, wait for page flip to end BOOL ScreenFlip(int waitflip) { HRESULT hr; RECT rect; UNREFERENCED_PARAMETER(waitflip); if (bAppFullScreen) { //hr = IDirectDrawSurface_GetFlipStatus (ScreenReal, DDGFS_); // In full-screen exclusive mode, do a hardware flip. hr = IDirectDrawSurface_Flip(ScreenReal, NULL, DDFLIP_WAIT); //return immediately // If the surface was lost, restore it. if (hr == DDERR_SURFACELOST) { IDirectDrawSurface_Restore(ScreenReal); // The restore worked, so try the flip again. hr = IDirectDrawSurface_Flip(ScreenReal, 0, DDFLIP_WAIT); } } else { rect.left = windowPosX; rect.top = windowPosY; rect.right = windowPosX + ScreenWidth - 1; rect.bottom = windowPosY + ScreenHeight - 1; // Copy the back buffer to front. hr = IDirectDrawSurface_Blt(ScreenReal, &rect, ScreenVirtual, 0, DDBLT_WAIT, 0); if (hr != DD_OK) { // If the surfaces were lost, restore them. if (IDirectDrawSurface_IsLost(ScreenReal) == DDERR_SURFACELOST) IDirectDrawSurface_Restore(ScreenReal); if (IDirectDrawSurface_IsLost(ScreenVirtual) == DDERR_SURFACELOST) IDirectDrawSurface_Restore(ScreenVirtual); // Retry the copy. hr = IDirectDrawSurface_Blt(ScreenReal,&rect, ScreenVirtual, 0, DDBLT_WAIT, 0); } } if (hr != DD_OK) I_Error("ScreenFlip() : couldn't Flip surfaces because %s", DXErrorToString(hr)); return FALSE; }
static void testsurface(void) { const char* testMsg = "ddraw device context test"; HDC hdc; HRESULT rc; rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc); ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %x\n",rc); SetBkColor(hdc, RGB(0, 0, 255)); SetTextColor(hdc, RGB(255, 255, 0)); TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg)); IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc); ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %x\n",rc); while (1) { rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT); ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %x\n",rc); if (rc == DD_OK) { break; } else if (rc == DDERR_SURFACELOST) { rc = IDirectDrawSurface_Restore(lpDDSPrimary); ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %x\n",rc); } } }
static void flip_page(void) { DDSURFACEDESC2 ddsd; HRESULT dxresult; IDirectDrawSurface_Unlock(g_lpddsBack, NULL); if (g_doublebuffer) { dxresult = IDirectDrawSurface_Flip(g_lpddsOverlay, NULL, DDFLIP_WAIT); if (dxresult == DDERR_SURFACELOST) { av_log(NULL, AV_LOG_INFO, "vo_directx: Lost, Restoring Surface\n"); IDirectDrawSurface_Restore(g_lpddsBack); IDirectDrawSurface_Restore(g_lpddsOverlay); IDirectDrawSurface_Restore(g_lpddsPrimary); dxresult = IDirectDrawSurface_Flip(g_lpddsOverlay, NULL, DDFLIP_WAIT); } if (dxresult != DD_OK) { av_log(NULL, AV_LOG_ERROR, "vo_directx: can not flip page\n"); } } else { DDBLTFX ddbltfx; memset(&ddbltfx, 0, sizeof(DDBLTFX)); ddbltfx.dwSize = sizeof(DDBLTFX); ddbltfx.dwDDFX = DDBLTFX_NOTEARING; IDirectDrawSurface_Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT, &ddbltfx); } memset(&ddsd, 0, sizeof(DDSURFACEDESC2)); ddsd.dwSize = sizeof(DDSURFACEDESC2); if (IDirectDrawSurface_Lock(g_lpddsBack, NULL, &ddsd, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL) == DD_OK) { if (tmp_image) { free(tmp_image); tmp_image = NULL; } g_dstride = ddsd.lPitch; g_image = ddsd.lpSurface; } else { if (!tmp_image) { av_log(NULL, AV_LOG_INFO, "Locking the surface failed, rendering to a hidden surface!\n"); tmp_image = g_image = calloc(1, g_image_height * g_dstride * 2); } } }
// DDFlip // Flip Screens using DirectDraw::Flip // ---------------------------------------------------------------------------- void DDFlip() { HRESULT ddresult; ddresult = IDirectDrawSurface_Flip(_lpDDSPrimary, NULL, 0); if (ddresult != DD_OK) { mprintf((1, "DDFlip:: Unable to flip screen (%X)\n", ddresult)); Int3(); // Bad flipping } }