Exemplo n.º 1
0
//
// 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;
}
Exemplo n.º 2
0
void
GGI_directx_DDRedraw(struct ggi_visual *vis, int x, int y, int w, int h)
{
	directx_priv *priv = GGIDIRECTX_PRIV(vis);
	RECT SrcWinPos, DestWinPos;
	HRESULT hr;

	hr = IDirectDrawSurface_IsLost(priv->lppdds);
	if (FAILED(hr))
		return;

	SrcWinPos.left   = x;
	SrcWinPos.right  = x + w;
	SrcWinPos.top    = y;
	SrcWinPos.bottom = y + h;
	DestWinPos = SrcWinPos;
	DestWinPos.right -= vis->origin_x;
	if (DestWinPos.right <= 0)
		return;
	DestWinPos.bottom -= vis->origin_y;
	if (DestWinPos.bottom <= 0)
		return;
	DestWinPos.left -= vis->origin_x;
	if (DestWinPos.left < 0) {
		SrcWinPos.left -= DestWinPos.left;
		DestWinPos.left = 0;
	}
	DestWinPos.top -= vis->origin_y;
	if (DestWinPos.top < 0) {
		SrcWinPos.top -= DestWinPos.top;
		DestWinPos.top = 0;
	}
	ClientToScreen(priv->hWnd, (POINT *) & DestWinPos.left);
	ClientToScreen(priv->hWnd, (POINT *) & DestWinPos.right);
	/* draw the stored image on the primary surface */
	IDirectDrawSurface_Blt(priv->lppdds, &DestWinPos,
			       priv->lpbdds[vis->d_frame_num], &SrcWinPos,
			       DDBLT_WAIT, NULL);
}
Exemplo n.º 3
0
void
GGI_directx_DDRedrawAll(struct ggi_visual *vis)
{
	directx_priv *priv = GGIDIRECTX_PRIV(vis);
	RECT SrcWinPos, DestWinPos;
	HRESULT hr;

	hr = IDirectDrawSurface_IsLost(priv->lppdds);
	if (FAILED(hr))
		return;

	GetClientRect(priv->hWnd, &SrcWinPos);
	SrcWinPos.left   += vis->origin_x;
	SrcWinPos.top    += vis->origin_y;
	SrcWinPos.right  += vis->origin_x;
	SrcWinPos.bottom += vis->origin_y;
	GetClientRect(priv->hWnd, &DestWinPos);
	ClientToScreen(priv->hWnd, (POINT *) & DestWinPos.left);
	ClientToScreen(priv->hWnd, (POINT *) & DestWinPos.right);
	/* draw the stored image on the primary surface */
	IDirectDrawSurface_Blt(priv->lppdds, &DestWinPos,
			       priv->lpbdds[vis->d_frame_num], &SrcWinPos,
			       DDBLT_WAIT, NULL);
}
Exemplo n.º 4
0
static long FAR PASCAL
WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	LPCREATESTRUCT lpcs;
	PAINTSTRUCT ps;
	RECT dirty;
	HDC hdc;
	struct ggi_visual *vis = (struct ggi_visual *) GetWindowLong(hWnd, GWL_USERDATA);
	directx_priv *priv = NULL;
	HRESULT hr;

	if (vis)
		priv = GGIDIRECTX_PRIV(vis);

	switch (message) {

	case WM_DDSETPALETTE:
		{
			int setpalette;
			GGI_directx_Lock(priv->spincs);
			setpalette = priv->setpalette;
			GGI_directx_Unlock(priv->spincs);
			if(setpalette)
				/* setpalette canceled */
				return 0;
		}
		if(GGI_directx_TryLock(priv->cs)) {
			/* spin */
			PostMessage(hWnd, message, wParam, lParam);
			return 0;
		}
		if(priv->lpddp)
			GGI_directx_DDChangePalette(vis);
		GGI_directx_Lock(priv->spincs);
		priv->setpalette = 1;
		GGI_directx_Unlock(priv->spincs);
		GGI_directx_Unlock(priv->cs);
		return 0;

	case WM_TIMER:
		if (wParam != 1)
			break;
		if (GGI_directx_TryLock(priv->cs)) {
			int redraw = 0;
			GGI_directx_Lock(priv->spincs);
			redraw = priv->redraw;
			priv->redraw = 0;
			GGI_directx_Unlock(priv->spincs);
			if (redraw)
				/* spin */
				PostMessage(hWnd, WM_USER, wParam, lParam);
			return 0;
		}
		GGI_directx_DDRedrawAll(vis);
		GGI_directx_Unlock(priv->cs);
		return 0;

	case WM_PAINT:
		if (GGI_directx_TryLock(priv->cs)) {
			int redraw = 0;
			GGI_directx_Lock(priv->spincs);
			redraw = priv->redraw;
			priv->redraw = 0;
			GGI_directx_Unlock(priv->spincs);
			if (redraw)
				/* spin */
				InvalidateRect(hWnd, NULL, 0);
			return 0;
		}
		if (GetUpdateRect(hWnd, &dirty, FALSE)) {
			/* I have a back buffer to update from,
			 * no need to involve the application...
			if (priv->inp) {
				gii_event ev;

				ev.any.size = sizeof(gii_expose_event);
				ev.any.type = evExpose;
				ev.any.target = priv->inp->origin;
				ev.expose.x = vis->origin_x + dirty.left;
				ev.expose.y = vis->origin_y + dirty.top;
				ev.expose.w = dirty.right - dirty.left;
				ev.expose.h = dirty.bottom - dirty.top;

				giiEventSend(priv->inp, &ev);
			}
			*/
			hr = IDirectDrawSurface_IsLost(priv->lppdds);
			if (hr == DDERR_SURFACELOST)
				hr = IDirectDrawSurface_Restore(
					priv->lppdds);

			hdc = BeginPaint(hWnd, &ps);
			GGI_directx_DDRedraw(
				vis,
				vis->origin_x + ps.rcPaint.left,
				vis->origin_y + ps.rcPaint.top,
				ps.rcPaint.right - ps.rcPaint.left,
				ps.rcPaint.bottom - ps.rcPaint.top);
			EndPaint(hWnd, &ps);
		}
		GGI_directx_Unlock(priv->cs);
		return 0;

	case WM_SIZING:
		GGI_directx_Lock(priv->sizingcs);
		if (priv->xstep < 0) {
			GGI_directx_Unlock(priv->sizingcs);
			break;
		}
		DDSizing(vis, wParam, (LPRECT) lParam);
		GGI_directx_Unlock(priv->sizingcs);
		return TRUE;

	case WM_SIZE:
		switch(wParam) {
		case SIZE_MAXIMIZED:
		case SIZE_RESTORED:
			break;
		default:
			return 0;
		}
		GGI_directx_Lock(priv->sizingcs);
		if (priv->xstep < 0) {
			GGI_directx_Unlock(priv->sizingcs);
			break;
		}
		DDNotifyResize(vis, LOWORD(lParam), HIWORD(lParam));
		GGI_directx_Unlock(priv->sizingcs);
		return 0;

	case WM_QUERYNEWPALETTE:
		if(GGI_directx_TryLock(priv->cs)) {
			int setpalette = 0;
			GGI_directx_Lock(priv->spincs);
			setpalette = priv->setpalette;
			priv->redraw = 0;
			GGI_directx_Unlock(priv->spincs);
			if(setpalette)
				/* spin */
				PostMessage(hWnd, WM_DDSETPALETTE,
					wParam, lParam);
			return 0;
		}
		if(!priv->lpddp) {
			GGI_directx_Unlock(priv->cs);
			break;
		}
		GGI_directx_DDChangePalette(vis);
		GGI_directx_Unlock(priv->cs);
		return TRUE;

	case WM_CREATE:
		lpcs = (LPCREATESTRUCT) lParam;
		SetWindowLong(hWnd,
			      GWL_USERDATA, (DWORD) lpcs->lpCreateParams);
		return 0;

	case WM_CLOSE:
		DPRINT_EVENTS("WM_CLOSE\n");
		if (priv->hParent)
			break;

		ggBroadcast(vis->instance.channel, GGI_CMDCODE_CLOSE, NULL);

		if (priv->exit_on_close_window)
			exit(0);
		return 0;

	case WM_RENDERFORMAT:
	case WM_RENDERALLFORMATS:
		{
			struct ggi_directx_cmddata_render_cb format;
			format.format = wParam;

			ggBroadcast(vis->instance.channel,
				GGI_DIRECTX_RENDERCLIPBOARD, &format);
			return 0;
		}

	case WM_DESTROYCLIPBOARD:
		ggBroadcast(vis->instance.channel,
			GGI_DIRECTX_DESTROYCLIPBOARD, NULL);
		return 0;

#if 0 /* WM_CLIPBOARDUPDATE is >= Vista :-( */
	case WM_CLIPBOARDUPDATE:
		ggBroadcast(vis->instance.channel,
			GGI_DIRECTX_CLIPBOARDUPDATE, NULL);
		return 0;
#endif

	case WM_SETTINGCHANGE:
		GGI_directx_Lock(priv->cs);
		if (priv->settings_changed) {
			DPRINT("tell inputlib about "
				"new system parameters\n");
			priv->settings_changed(priv->settings_changed_arg);
			GGI_directx_Unlock(priv->cs);
			return 0;
		}
		GGI_directx_Unlock(priv->cs);
		break;

	case WM_SETFOCUS:
		if (priv->grab_hotkeys) {
			DPRINT("Grab hotkeys (focus)\n");
			PostThreadMessage(priv->nThreadID, WM_DDHOTKEY, 1, 0);
		}
		priv->focus = 1;
		break;

	case WM_KILLFOCUS:
		if (priv->grab_hotkeys) {
			DPRINT("Ungrab hotkeys (unfocus)\n");
			PostThreadMessage(priv->nThreadID, WM_DDHOTKEY, 0, 0);
		}
		priv->focus = 0;
		break;

	case WM_HOTKEY:
		if (priv->grab_hotkeys && priv->inp) {
			gii_inputdx_hotkey hotkey;
			hotkey.id = wParam;
			hotkey.mod = LOWORD(lParam);
			hotkey.vk = HIWORD(lParam);
			DPRINT("WM_HOTKEY id=%d, mod=%04x, vk=%d\n",
				hotkey.id, hotkey.mod, hotkey.vk);
			ggControl(priv->inp->channel, GII_INPUTDX_HOTKEY,
				&hotkey);
		}
		break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}