Esempio n. 1
0
/**
 * Create a clipper that will be used when blitting the RGB surface to the main display.
 *
 * This clipper prevents us to modify by mistake anything on the screen
 * which doesn't belong to our window. For example when a part of our video
 * window is hidden by another window.
 */
static void DirectXCreateClipper(vout_display_t *vd)
{
    vout_display_sys_t *sys = vd->sys;
    HRESULT hr;

    /* Create the clipper */
    hr = IDirectDraw2_CreateClipper(sys->ddobject, 0, &sys->clipper, NULL);
    if (hr != DD_OK) {
        msg_Warn(vd, "cannot create clipper (error %li)", hr);
        goto error;
    }

    /* Associate the clipper to the window */
    hr = IDirectDrawClipper_SetHWnd(sys->clipper, 0, sys->hvideownd);
    if (hr != DD_OK) {
        msg_Warn(vd, "cannot attach clipper to window (error %li)", hr);
        goto error;
    }

    /* associate the clipper with the surface */
    hr = IDirectDrawSurface_SetClipper(sys->display, sys->clipper);
    if (hr != DD_OK)
    {
        msg_Warn(vd, "cannot attach clipper to surface (error %li)", hr);
        goto error;
    }

    return;

error:
    if (sys->clipper)
        IDirectDrawClipper_Release(sys->clipper);
    sys->clipper = NULL;
}
Esempio n. 2
0
HRESULT d3drm_device_create_surfaces_from_clipper(struct d3drm_device *object, IDirectDraw *ddraw, IDirectDrawClipper *clipper, int width, int height, IDirectDrawSurface **surface)
{
    DDSURFACEDESC surface_desc;
    IDirectDrawSurface *primary_surface, *render_target;
    HWND window;
    HRESULT hr;

    hr = IDirectDrawClipper_GetHWnd(clipper, &window);
    if (FAILED(hr))
        return hr;

    hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
    if (FAILED(hr))
        return hr;

    memset(&surface_desc, 0, sizeof(surface_desc));
    surface_desc.dwSize = sizeof(surface_desc);
    surface_desc.dwFlags = DDSD_CAPS;
    surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &primary_surface, NULL);
    if (FAILED(hr))
        return hr;
    hr = IDirectDrawSurface_SetClipper(primary_surface, clipper);
    if (FAILED(hr))
    {
        IDirectDrawSurface_Release(primary_surface);
        return hr;
    }

    memset(&surface_desc, 0, sizeof(surface_desc));
    surface_desc.dwSize = sizeof(surface_desc);
    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
    surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
    surface_desc.dwWidth = width;
    surface_desc.dwHeight = height;

    hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &render_target, NULL);
    if (FAILED(hr))
    {
        IDirectDrawSurface_Release(primary_surface);
        return hr;
    }

    object->primary_surface = primary_surface;
    object->clipper = clipper;
    IDirectDrawClipper_AddRef(clipper);
    *surface = render_target;

    return D3DRM_OK;
}
Esempio n. 3
0
EXPORT void CALL RomOpen (void)
{
	RECT bigrect, smallrect, statusrect;
	
	GetWindowRect(gfx.hWnd,&bigrect);
	GetClientRect(gfx.hWnd,&smallrect);
	int rightdiff = screen_width - smallrect.right;
	int bottomdiff = screen_height - smallrect.bottom;
	if (gfx.hStatusBar)
	{
		GetClientRect(gfx.hStatusBar, &statusrect);
		bottomdiff += statusrect.bottom;
	}
	MoveWindow(gfx.hWnd, bigrect.left, bigrect.top, bigrect.right - bigrect.left + rightdiff, bigrect.bottom - bigrect.top + bottomdiff, TRUE);
	

	DDPIXELFORMAT ftpixel;
	LPDIRECTDRAWCLIPPER lpddcl;

	res = DirectDrawCreateEx(0, (LPVOID*)&lpdd, IID_IDirectDraw7, 0);
	if(res != DD_OK) 
		fatalerror("Couldn't create a DirectDraw object");
	res = IDirectDraw_SetCooperativeLevel(lpdd, gfx.hWnd, DDSCL_NORMAL);
	if(res != DD_OK) 
		fatalerror("Couldn't set a cooperative level. Error code %x", res);

	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
	
	
	res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsprimary, 0);
	if(res != DD_OK)
		fatalerror("CreateSurface for a primary surface failed. Error code %x", res);

	
	ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
	ddsd.dwWidth = PRESCALE_WIDTH;
	ddsd.dwHeight = PRESCALE_HEIGHT;
	memset(&ftpixel, 0, sizeof(ftpixel));
	ftpixel.dwSize = sizeof(ftpixel);
	ftpixel.dwFlags = DDPF_RGB;
	ftpixel.dwRGBBitCount = 32;
	ftpixel.dwRBitMask = 0xff0000;
	ftpixel.dwGBitMask = 0xff00;
	ftpixel.dwBBitMask = 0xff;
	ddsd.ddpfPixelFormat = ftpixel;
	res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsback, 0);
	if (res == DDERR_INVALIDPIXELFORMAT)
		fatalerror("ARGB8888 is not supported. You can try changing desktop color depth to 32-bit, but most likely that won't help.");
	else if(res != DD_OK)
		fatalerror("CreateSurface for a secondary surface failed. Error code %x", res);

	
	res = IDirectDrawSurface_GetSurfaceDesc(lpddsback, &ddsd);
	if (res != DD_OK)
		fatalerror("GetSurfaceDesc failed.");
	if ((ddsd.lPitch & 3) || ddsd.lPitch < (PRESCALE_WIDTH << 2))
		fatalerror("Pitch of a secondary surface is either not 32 bit aligned or two small.");
	pitchindwords = ddsd.lPitch >> 2;

	
	res = IDirectDraw_CreateClipper(lpdd, 0, &lpddcl, 0);
	if (res != DD_OK)
		fatalerror("Couldn't create a clipper.");
	res = IDirectDrawClipper_SetHWnd(lpddcl, 0, gfx.hWnd);
	if (res != DD_OK)
		fatalerror("Couldn't register a windows handle as a clipper.");
	res = IDirectDrawSurface_SetClipper(lpddsprimary, lpddcl);
	if (res != DD_OK)
		fatalerror("Couldn't attach a clipper to a surface.");

	
	src.top = src.left = 0; 
	src.bottom = 0;
	src.right = PRESCALE_WIDTH;

	POINT p;
	p.x = p.y = 0;
	GetClientRect(gfx.hWnd, &dst);
	ClientToScreen(gfx.hWnd, &p);
	OffsetRect(&dst, p.x, p.y);
	GetClientRect(gfx.hStatusBar, &statusrect);
	dst.bottom -= statusrect.bottom;

	rdp_init();


}
Esempio n. 4
0
//
// - returns true if DirectDraw was initialized properly
//
int  InitDirectDrawe (HWND appWin, int width, int height, int bpp, int fullScr)
{
	DDSURFACEDESC ddsd; // DirectDraw surface description for allocating
	DDSCAPS       ddscaps;
	HRESULT       ddrval;

	DWORD         dwStyle;
	RECT          rect;

	// enumerate directdraw devices
	//if (FAILED(DirectDrawEnumerate (myEnumDDDevicesCallback, NULL)))
	//      I_Error("Error with DirectDrawEnumerate");

	if (!DDr2)
		CreateDirectDrawInstance();

	// remember what screen mode we are in
	bAppFullScreen = fullScr;
	ScreenHeight = height;
	ScreenWidth = width;

	if (bAppFullScreen)
	{
		// Change window attributes
		dwStyle = WS_POPUP | WS_VISIBLE;
		SetWindowLong (appWin, GWL_STYLE, dwStyle);
		SetWindowPos(appWin, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE |
			SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);

		// Get exclusive mode
		ddrval = IDirectDraw2_SetCooperativeLevel(DDr2, appWin, DDSCL_EXCLUSIVE |
		                                          DDSCL_FULLSCREEN |
		                                          DDSCL_ALLOWREBOOT);
		if (ddrval != DD_OK)
			I_Error("SetCooperativeLevel FAILED: %s\n", DXErrorToString(ddrval));

		// Switch from windows desktop to fullscreen

#ifdef NT4COMPAT
		ddrval = IDirectDraw2_SetDisplayMode(DDr2, width, height, bpp, 0, 0);
#else
		ddrval = IDirectDraw2_SetDisplayMode(DDr2, width, height, bpp, 0, DDSDM_STANDARDVGAMODE);
#endif
		if (ddrval != DD_OK)
			I_Error("SetDisplayMode FAILED: %s\n", DXErrorToString(ddrval));

		// This is not really needed, except in certain cases. One case
		// is while using MFC. When the desktop is initally at 16bpp, a mode
		// switch to 8bpp somehow causes the MFC window to not fully initialize
		// and a CreateSurface will fail with DDERR_NOEXCLUSIVEMODE. This will
		// ensure that the window is initialized properly after a mode switch.

		ShowWindow(appWin, SW_SHOW);

		// Create the primary surface with 1 back buffer. Always zero the
		// DDSURFACEDESC structure and set the dwSize member!

		ZeroMemory(&ddsd, sizeof (ddsd));
		ddsd.dwSize = sizeof (ddsd);
		ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
		ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;

		// for fullscreen we use page flipping, for windowed mode, we blit the hidden surface to
		// the visible surface, in both cases we have a visible (or 'real') surface, and a hidden
		// (or 'virtual', or 'backbuffer') surface.
		ddsd.dwBackBufferCount = 2;

		ddrval = IDirectDraw2_CreateSurface(DDr2,&ddsd, &ScreenReal, NULL);
		if (ddrval != DD_OK)
			I_Error("CreateSurface Primary Screen FAILED");

		// Get a pointer to the back buffer

		ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
		ddrval = IDirectDrawSurface_GetAttachedSurface(ScreenReal,&ddscaps, &ScreenVirtual);
		if (ddrval != DD_OK)
			I_Error("GetAttachedSurface FAILED");
	}
	else
	{
		rect.top = 0;
		rect.left = 0;
		rect.bottom = height;
		rect.right = width;

		// Change window attributes

		dwStyle = GetWindowStyle(appWin);
		dwStyle &= ~WS_POPUP;
		dwStyle |= WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION;

		SetWindowLong(appWin, GWL_STYLE, dwStyle);

		// Resize the window so that the client area is the requested width/height

		AdjustWindowRectEx(&rect, GetWindowStyle(appWin), GetMenu(appWin) != NULL,
		                   GetWindowExStyle(appWin));

		// Just in case the window was moved off the visible area of the
		// screen.

		SetWindowPos(appWin, NULL, 0, 0, rect.right-rect.left,
		             rect.bottom-rect.top, SWP_NOMOVE | SWP_NOZORDER |
		             SWP_NOACTIVATE);

		SetWindowPos(appWin, HWND_NOTOPMOST, 0, 0, 0, 0,
		             SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);

		// Exclusive mode is normal since it's in windowed mode and needs
		// to cooperate with GDI

		ddrval = IDirectDraw2_SetCooperativeLevel(DDr2,appWin, DDSCL_NORMAL);
		if (ddrval != DD_OK)
			I_Error("SetCooperativeLevel FAILED");

		// Always zero the DDSURFACEDESC structure and set the dwSize member!

		ZeroMemory(&ddsd, sizeof (ddsd));
		ddsd.dwSize = sizeof (ddsd);
		ddsd.dwFlags = DDSD_CAPS;
		ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

		// Create the primary surface

		ddrval = IDirectDraw2_CreateSurface(DDr2,&ddsd, &ScreenReal, NULL);
		if (ddrval != DD_OK)
			I_Error("CreateSurface Primary Screen FAILED");

		// Create a back buffer for offscreen rendering, this will be used to
		// blt to the primary

		ScreenVirtual = CreateNewSurface(width, height, DDSCAPS_OFFSCREENPLAIN |
		                                 DDSCAPS_SYSTEMMEMORY);
		if (ScreenVirtual == NULL)
			I_Error("CreateSurface Secondary Screen FAILED");

		/// \todo get the desktop bit depth, and build a lookup table
		/// for quick conversions of 8bit color indexes 0-255 to desktop colors
		/// eg: 256 entries of equivalent of palette colors 0-255 in 15,16,24,32 bit format
		/// when blit virtual to real, convert pixels through lookup table..

		// Use a clipper object for clipping when in windowed mode
		// (make sure our drawing doesn't affect other windows)

		ddrval = IDirectDraw2_CreateClipper (DDr2, 0, &windclip, 0);
		if (ddrval != DD_OK)
			I_Error("CreateClipper FAILED");

		// Associate the clipper with the window.
		ddrval = IDirectDrawClipper_SetHWnd (windclip,0, appWin);
		if (ddrval != DD_OK)
			I_Error("Clipper -> SetHWnd  FAILED");

		// Attach the clipper to the surface.
		ddrval = IDirectDrawSurface_SetClipper (ScreenReal,windclip);
		if (ddrval != DD_OK)
			I_Error("PrimaryScreen -> SetClipperClipper  FAILED");
	}

	return TRUE;
}
Esempio n. 5
0
BOOL DDInit(int mode)
{
	LPDIRECTDRAW lpdd;
	DDCAPS ddcaps, ddcaps2;
	HRESULT ddresult;
	int num;

	DDWnd = GetLibraryWindow();

//	Create Direct Draw Object (Use Emulation if Hardware is off)
	if (!_lpDD)	{
		ddresult = DirectDrawCreate(NULL, &lpdd, NULL);
		
		if (ddresult == DDERR_NODIRECTDRAWHW) {
         ddresult = DirectDrawCreate( (LPVOID) DDCREATE_EMULATIONONLY, &lpdd, NULL );
			if (!CheckDDResult(ddresult, "InitDD:DirectDrawCreate emulation"))
				return FALSE;
			DDUseEmulation = TRUE;
			logentry("DirectDraw: forcing emulation.\n");
		}
		else if (ddresult != DD_OK) return FALSE;
		logentry("DirectDraw: DirectX API hardware compliant.\n");
	}
	else return FALSE;

	atexit(DDKill);

//	Determine hardware caps
//	Determine capture mode (fullscreen takes exclusive, window is normal)
	if (mode == DDGR_FULLSCREEN) {
		DWORD flags;

		flags = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;

	#ifndef NDEBUG
		if (!FindArg("-nomodex")) flags |= DDSCL_ALLOWMODEX;
	#else
		flags |= DDSCL_ALLOWMODEX;
	#endif

		if (!FindArg("-disallowreboot")) flags |= DDSCL_ALLOWREBOOT;
 
		ddresult = IDirectDraw_SetCooperativeLevel(lpdd, DDWnd, flags); 

		if (!CheckDDResult(ddresult, "DDInit::SetCooperativeLevel")) {	
			IDirectDraw_Release(lpdd);
			return FALSE;
		}

		_DDExclusive = TRUE;
		_DDFullScreen = TRUE;			
	}
	else if (mode == DDGR_EXWINDOW) {
		ddresult = IDirectDraw_SetCooperativeLevel(lpdd, DDWnd,
										DDSCL_EXCLUSIVE |
										DDSCL_FULLSCREEN);
		if (!CheckDDResult(ddresult, "DDInit::SetCooperativeLevel"))
			return FALSE;
		_DDExclusive = TRUE;
		_DDFullScreen = FALSE;
	}
	else if (mode == DDGR_WINDOW) {
		ddresult = IDirectDraw_SetCooperativeLevel(lpdd, DDWnd,
										DDSCL_NORMAL);
		if (!CheckDDResult(ddresult, "DDInit::SetCooperativeLevel"))
			return FALSE;
		_DDExclusive = FALSE;
		_DDFullScreen = FALSE;
	}
	else return FALSE;
	
//	Get Display modes/Window Sizes
//	Force invalidation of all modes for now
	for (num = 0; num < 16; num++)
	{
		_DDModeList[num].rw = _DDModeList[num].w = -1;
		_DDModeList[num].rh = _DDModeList[num].h = -1;
	}

	W95DisplayMode = SM95_640x480x8;
	num = 0;
	if (mode == DDGR_FULLSCREEN) {
		ddresult = IDirectDraw_EnumDisplayModes(lpdd, 0, NULL, 0, 
									EnumDispModesCB);
		if(!CheckDDResult(ddresult, "DDInit::EnumDisplayModes")) {
			IDirectDraw_Release(lpdd);
			return FALSE;
		}
	}
	else if (mode == DDGR_EXWINDOW) {
		_DDModeList[SM95_320x200x8X].rw = 320;
		_DDModeList[SM95_320x200x8X].rh = 200;
		_DDModeList[SM95_320x200x8X].w = 640;
		_DDModeList[SM95_320x200x8X].h = 480;
		_DDModeList[SM95_320x200x8X].emul = 1;
		_DDModeList[SM95_320x200x8X].dbuf = 0;
		_DDModeList[SM95_320x200x8X].modex = 0;
		_DDModeList[SM95_320x200x8X].paged = 0; 

		_DDModeList[SM95_640x480x8].rw = 640;
		_DDModeList[SM95_640x480x8].rh = 480;
		_DDModeList[SM95_640x480x8].w = 640;
		_DDModeList[SM95_640x480x8].h = 480;
		_DDModeList[SM95_640x480x8].emul = 1;
		_DDModeList[SM95_640x480x8].dbuf = 0;
		_DDModeList[SM95_640x480x8].modex = 0;
		_DDModeList[SM95_640x480x8].paged = 0; 

		_DDModeList[SM95_800x600x8].rw = 800;
		_DDModeList[SM95_800x600x8].rh = 600;
		_DDModeList[SM95_800x600x8].w = 640;
		_DDModeList[SM95_800x600x8].h = 480;
		_DDModeList[SM95_800x600x8].emul = 1;
		_DDModeList[SM95_800x600x8].dbuf = 0;
		_DDModeList[SM95_800x600x8].modex = 0;
		_DDModeList[SM95_800x600x8].paged = 0; 
		_DDNumModes = 3;
	}
	else if (mode == DDGR_WINDOW) {	
		_DDModeList[SM95_320x200x8X].rw = 320;
		_DDModeList[SM95_320x200x8X].rh = 200;
		_DDModeList[SM95_320x200x8X].w = 640;
		_DDModeList[SM95_320x200x8X].h = 480;
		_DDModeList[SM95_320x200x8X].emul = 1;
		_DDModeList[SM95_320x200x8X].dbuf = 0;
		_DDModeList[SM95_320x200x8X].modex = 0;
		_DDModeList[SM95_320x200x8X].paged = 0; 

		_DDModeList[SM95_640x480x8].rw = 640;
		_DDModeList[SM95_640x480x8].rh = 480;
		_DDModeList[SM95_640x480x8].w = 640;
		_DDModeList[SM95_640x480x8].h = 480;
		_DDModeList[SM95_640x480x8].emul = 1;
		_DDModeList[SM95_640x480x8].dbuf = 0;
		_DDModeList[SM95_640x480x8].modex = 0;
		_DDModeList[SM95_640x480x8].paged = 0; 

		_DDModeList[SM95_800x600x8].rw = 800;
		_DDModeList[SM95_800x600x8].rh = 600;
		_DDModeList[SM95_800x600x8].w = 800;
		_DDModeList[SM95_800x600x8].h = 600;
		_DDModeList[SM95_800x600x8].emul = 1;
		_DDModeList[SM95_800x600x8].dbuf = 0;
		_DDModeList[SM95_800x600x8].modex = 0;
		_DDModeList[SM95_800x600x8].paged = 0; 
		_DDNumModes = 3;
	}
	else return FALSE;

//	Set appropriate display mode or window mode

	_lpDD = lpdd;

	memset(&ddcaps, 0, sizeof(ddcaps));
	ddcaps.dwSize = sizeof(ddcaps);
	ddcaps2.dwSize = sizeof(ddcaps);
	ddresult = IDirectDraw_GetCaps(_lpDD, &ddcaps, NULL);
	if (!CheckDDResult(ddresult, "InitDD::GetCaps")) 
		return FALSE;

	logentry("DirectDraw: VRAM free:  %d\n", ddcaps.dwVidMemFree);	
	logentry("DirectDraw: VRAM total: %d\n", ddcaps.dwVidMemTotal);

#ifndef NDEBUG
	if (FindArg("-TsengDebug1")) {
		IDirectDraw_Release(lpdd);
		return FALSE;
	}
#endif

	DDSetDisplayMode(W95DisplayMode, 0);

#ifndef NDEBUG
	if (FindArg("-TsengDebug2")) {
		IDirectDraw_Release(lpdd);
		return FALSE;
	}
#endif
	
	// If 'windowed' do this.
	if (!_DDFullScreen) 
	{
			ddresult = IDirectDraw_CreateClipper(_lpDD, 0, &_lpDDClipper, NULL);
			if (!CheckDDResult(ddresult, "DDCreateScreen::CreateClipper"))
				return FALSE;

			ddresult = IDirectDrawClipper_SetHWnd(_lpDDClipper, 0, DDWnd);
			if (!CheckDDResult(ddresult, "DDCreateScreen::SetHWnd"))
				return FALSE;

			ddresult = IDirectDrawSurface_SetClipper(_lpDDSPrimary, _lpDDClipper);
			if (!CheckDDResult(ddresult, "DDCreateScreen::SetClipper"))
				return FALSE;
	}

//	Register Optimizations

	ddcaps.dwSize = sizeof(ddcaps);
	ddcaps2.dwSize = sizeof(ddcaps);
	ddresult = IDirectDraw_GetCaps(lpdd, &ddcaps, &ddcaps2);
	if (!CheckDDResult(ddresult, "DDInit::GetCaps"))
		return FALSE;

#ifndef NDEBUG
	if (FindArg("-TsengDebug3")) {
		IDirectDraw_Release(lpdd);
		return FALSE;
	}
#endif

	if (FindArg("-vidram")) {
		logentry("DirectDraw: Forcing VRAM rendering.\n");
		_DDSysMemSurfacing = FALSE;
	}
	else if (FindArg("-sysram")) {
		logentry("DirectDraw: Forcing SRAM rendering.\n");
		_DDSysMemSurfacing = TRUE;
	}
	else if (ddcaps.dwCaps & DDCAPS_BANKSWITCHED) {
		logentry("DirectDraw: Hardware is bank-switched.  Using SRAM rendering.\n");
		_DDSysMemSurfacing = TRUE;
	}
	else {
		logentry("DirectDraw: Hardware is not bank-switched.  Using VRAM rendering.\n");
		_DDSysMemSurfacing = FALSE;
	}
		
	if (ddcaps.dwCaps	& DDCAPS_COLORKEYHWASSIST) 
		ddDriverCaps.hwcolorkey = 1;
	else 
		ddDriverCaps.hwcolorkey = 0;
	if (ddcaps.dwCaps & DDCAPS_BLTSTRETCH)
		ddDriverCaps.hwbltstretch = 1;
	else 
		ddDriverCaps.hwbltstretch = 0;
		

//@@	mprintf((0, "DD::Hardware="));
//@@	if (ddcaps.dwCaps & DDCAPS_NOHARDWARE) mprintf((0, "Off\n"));
//@@	else mprintf((0, "On\n"));
//@@
//@@	mprintf((0, "DD::VideoMem=%u bytes\n", ddcaps.dwVidMemTotal));

//@@	mprintf((0, "DD::SrcColorKey="));	
//@@	if (ddcaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT) mprintf((0, "Hardware\n"));
//@@	else mprintf((0, "Emulation\n"));

	return TRUE;
}
Esempio n. 6
0
static int
DDCreateSurface(directx_priv *priv, ggi_mode *mode)
{
	HRESULT hr;
	LPDIRECTDRAWCLIPPER pClipper;
	DDSURFACEDESC pddsd, bddsd;
	int i;

	if (!priv->fullscreen)
		IDirectDraw2_SetCooperativeLevel(priv->lpddext, priv->hWnd,
						DDSCL_NORMAL);
	else {
		/* Only the thread that has excluse access (Cooperative level)
		 * may restore the surfaces when they are lost. Therefore
		 * let the helper thread get exclusive access so that it can
		 * later do restores.
		 */
		directx_fullscreen dxfull;
		dxfull.priv = priv;
		dxfull.mode = mode;
		dxfull.event = CreateEvent(NULL, FALSE, FALSE, NULL);
		PostThreadMessage(priv->nThreadID,
			WM_DDFULLSCREEN, 0, (long)&dxfull);
		WaitForSingleObject(dxfull.event, INFINITE);
		CloseHandle(dxfull.event);
	}

	/* create the primary surface */
	memset(&pddsd, 0, sizeof(pddsd));
	pddsd.dwSize = sizeof(pddsd);
	pddsd.dwFlags = DDSD_CAPS;
	pddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
	if (priv->fullscreen)
		pddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
	hr = IDirectDraw2_CreateSurface(priv->lpddext, &pddsd,
				       &priv->lppdds, NULL);
	if (hr != 0) {
		fprintf(stderr,
			"Init Primary Surface Failed RC = %lx. Exiting\n",
			hr);
		exit(-1);
	}
	IDirectDraw2_CreateClipper(priv->lpddext, 0, &pClipper, NULL);
	IDirectDrawClipper_SetHWnd(pClipper, 0, priv->hWnd);
	IDirectDrawSurface_SetClipper(priv->lppdds, pClipper);
	IDirectDrawClipper_Release(pClipper);
	pddsd.dwSize = sizeof(pddsd);
	IDirectDrawSurface_GetSurfaceDesc(priv->lppdds, &pddsd);

	DPRINT_MISC("DDraw pixel format:\n");
	DPRINT_MISC("  Size %u\n", pddsd.ddpfPixelFormat.dwSize);
	DPRINT_MISC("  Flags %08x\n", pddsd.ddpfPixelFormat.dwFlags);
	DPRINT_MISC("  FourCC %08x\n", pddsd.ddpfPixelFormat.dwFourCC);
	DPRINT_MISC("  Count %u\n", pddsd.ddpfPixelFormat.dwRGBBitCount);
	DPRINT_MISC("  R-Mask(etc) %08x\n", pddsd.ddpfPixelFormat.dwRBitMask);
	DPRINT_MISC("  G-Mask(etc) %08x\n", pddsd.ddpfPixelFormat.dwGBitMask);
	DPRINT_MISC("  B-Mask(etc) %08x\n", pddsd.ddpfPixelFormat.dwBBitMask);
	DPRINT_MISC("  Z-Mask(etc) %08x\n",
		pddsd.ddpfPixelFormat.dwRGBZBitMask);

	/* create the back storages */
	for (i = 0; i < mode->frames; ++i) {
		memset(&bddsd, 0, sizeof(bddsd));
		bddsd.dwSize = sizeof(bddsd);
		bddsd.dwFlags =
		    DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
		bddsd.ddsCaps.dwCaps =
		    DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
		bddsd.dwWidth = mode->virt.x;
		bddsd.dwHeight = mode->virt.y;

		/* set up the pixel format */
		ZeroMemory(&bddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT));
		bddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
		bddsd.ddpfPixelFormat.dwFlags =
		    pddsd.ddpfPixelFormat.dwFlags;
		bddsd.ddpfPixelFormat.dwFourCC =
		    pddsd.ddpfPixelFormat.dwFourCC;
		bddsd.ddpfPixelFormat.dwRGBBitCount =
		    pddsd.ddpfPixelFormat.dwRGBBitCount;
		bddsd.ddpfPixelFormat.dwRBitMask =
		    pddsd.ddpfPixelFormat.dwRBitMask;
		bddsd.ddpfPixelFormat.dwGBitMask =
		    pddsd.ddpfPixelFormat.dwGBitMask;
		bddsd.ddpfPixelFormat.dwBBitMask =
		    pddsd.ddpfPixelFormat.dwBBitMask;
		bddsd.ddpfPixelFormat.dwRGBAlphaBitMask =
		    pddsd.ddpfPixelFormat.dwRGBAlphaBitMask;

		hr = IDirectDraw2_CreateSurface(priv->lpddext,
					       &bddsd, &priv->lpbdds[i],
					       NULL);
		if (hr) {
			fprintf(stderr,
				"Init Backup Failed RC = %lx. Exiting\n", hr);
			exit(-1);
		}
		IDirectDrawSurface2_Lock(priv->lpbdds[i], NULL, &bddsd,
					 DDLOCK_SURFACEMEMORYPTR, NULL);
		priv->lpSurfaceAdd[i] = (char *) bddsd.lpSurface;
		IDirectDrawSurface2_Unlock(priv->lpbdds[i],
					   bddsd.lpSurface);
	}

	/* set private mode parameters */
	priv->maxX = mode->virt.x;
	priv->maxY = mode->virt.y;
	priv->ColorDepth = pddsd.ddpfPixelFormat.dwRGBBitCount;
	priv->pitch = bddsd.lPitch;

	if (pddsd.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
		static PALETTEENTRY pal[256];
		/* todo fill in pal */
		hr = IDirectDraw_CreatePalette(priv->lpddext,
			DDPCAPS_8BIT|DDPCAPS_ALLOW256,
			pal, &priv->lpddp, NULL);
		if (hr) {
			fprintf(stderr,
				"Init Palette failed RC = %lx. Exiting\n",
				hr);
			exit(-1);
		}
		hr = IDirectDrawSurface_SetPalette(priv->lppdds, priv->lpddp);
		if (hr) {
			fprintf(stderr,
				 "Install Palette failed RC = %lx. Exiting\n",
				hr);
			exit(-1);
		}
	}

	return 1;
}
Esempio n. 7
0
static boolean CreatePrimary( win32_driver_t * win32_driver )
{
  LPDIRECTDRAW			ddobj;
  DDSURFACEDESC			ddsd;
  HRESULT					result;

  /* create direct draw object */

  result = DirectDrawCreate( 0, &ddobj, 0 );
  if( result != DD_OK )
    {
      Error( 0, "DirectDrawCreate : error %ld", result );
      xprintf(win32_driver->xine, XINE_VERBOSITY_DEBUG, "vo_out_directx : DirectDrawCreate : error %ld\n", result );
      return 0;
    }

  /* set cooperative level */

  result = IDirectDraw_SetCooperativeLevel( ddobj, win32_driver->win32_visual->WndHnd, DDSCL_NORMAL );
  if( result != DD_OK )
    {
      Error( 0, "SetCooperativeLevel : error 0x%lx", result );
      return 0;
    }

  /* try to get new interface */

  result = IDirectDraw_QueryInterface( ddobj, &IID_IDirectDraw, (LPVOID *) &win32_driver->ddobj );
  if( result != DD_OK )
    {
      Error( 0, "ddobj->QueryInterface : DirectX required" );
      return 0;
    }

  /* release our old interface */

  IDirectDraw_Release( ddobj );

  /* create primary_surface */

  memset( &ddsd, 0, sizeof( ddsd ) );
  ddsd.dwSize         = sizeof( ddsd );
  ddsd.dwFlags        = DDSD_CAPS;
  ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

  result = IDirectDraw_CreateSurface( win32_driver->ddobj, &ddsd, &win32_driver->primary, 0 );
  if( result != DD_OK )
    {
      Error( 0, "CreateSurface ( primary ) : error 0x%lx", result );
      return 0;
    }

  /* create our clipper object */

  result = IDirectDraw_CreateClipper( win32_driver->ddobj, 0, &win32_driver->ddclipper, 0 );
  if( result != DD_OK )
    {
      Error( 0, "CreateClipper : error 0x%lx", result );
      return 0;
    }

  /* associate our clipper with our window */

  result = IDirectDrawClipper_SetHWnd( win32_driver->ddclipper, 0, win32_driver->win32_visual->WndHnd );
  if( result != DD_OK )
    {
      Error( 0, "ddclipper->SetHWnd : error 0x%lx", result );
      return 0;
    }

  /* associate our primary surface with our clipper */

  result = IDirectDrawSurface_SetClipper( win32_driver->primary, win32_driver->ddclipper );
  if( result != DD_OK )
    {
      Error( 0, "ddclipper->SetHWnd : error 0x%lx", result );
      return 0;
    }

  /* store our objects in our visual struct */

  UpdateRect( win32_driver->win32_visual );

  return 1;
}
Esempio n. 8
0
static int ResizeDD(int fullscreen)
{
    HRESULT ddrval;
    DDSURFACEDESC ddsd;
    /*DDCAPS2 ddscaps; */
    LPDIRECTDRAWCLIPPER pClipper;
    int dxwidth;
    int dxheight;
    int dxbpp;

    // free DirectX objects
    if (lpSurfaces[0])
	IDirectDrawSurface_Release(lpSurfaces[0]);
    lpSurfaces[0] = NULL;
    if (dxPalette)
	IDirectDrawPalette_Release(dxPalette);
    dxPalette = NULL;
    /* Set cooperative level */
    ddrval = IDirectDraw2_SetCooperativeLevel(lpDD2, hWnd,
					      fullscreen
					      ? (DDSCL_FULLSCREEN |
						 DDSCL_EXCLUSIVE |
						 DDSCL_ALLOWREBOOT)
					      : DDSCL_NORMAL);
    if (ddrval != DD_OK) {
	DeInitDD();
	x_error("Failed to set cooperative level");
	return 0;
    }

    if (fullscreen) {
	if (sscanf(dxsize, "%ix%ix%i", &dxwidth, &dxheight, &dxbpp) != 3) {
	    dxwidth = DXWIDTH;
	    dxheight = DXHEIGHT;
	    dxbpp = DXBPP;
	}
	displayX = dxwidth;
	displayY = dxheight;
	bitDepth = dxbpp;
	if (bitDepth < 10)
	    bitDepth = 8;
	if (bitDepth >= 10 && bitDepth < 20)
	    bitDepth = 16;
	if (bitDepth >= 20 && bitDepth < 28)
	    bitDepth = 24;
	if (bitDepth >= 32 && bitDepth < 32)
	    bitDepth = 32;

	/* set resolution and bit depth */
	ddrval =
	    IDirectDraw2_SetDisplayMode(lpDD2, displayX, displayY,
					bitDepth, 0, 0);
	if (ddrval != DD_OK) {
	    /* The display mode cannot be changed. 
	       The mode is either not supported or 
	       another application has exclusive mode.

	       Try 320x200x256 and 640x480x256 modes before giving up */
	    displayX = 320;
	    displayY = 200;
	    bitDepth = 8;
	    ddrval =
		IDirectDraw2_SetDisplayMode(lpDD2, displayX, displayY,
					    bitDepth, 0, 0);
	    if (ddrval != DD_OK) {
		displayY = 240;
		if (ddrval != DD_OK) {
		    displayX = 640;
		    displayY = 480;
		    ddrval =
			IDirectDraw2_SetDisplayMode(lpDD2, displayX,
						    displayY, bitDepth, 0,
						    0);
		    if (ddrval != DD_OK) {
			/* Bad luck... give up. */
			DeInitDD();
			return 0;
		    }
		}
	    }
	}
	SetRect(&rcViewport, 0, 0, displayX, displayY);
	rcScreen = rcViewport;
    } else {
	/* Get the dimensions of the viewport and screen bounds */
	GetClientRect(hWnd, &rcViewport);
	GetClientRect(hWnd, &rcScreen);
	ClientToScreen(hWnd, (POINT *) & rcScreen.left);
	ClientToScreen(hWnd, (POINT *) & rcScreen.right);
	/*bitDepth = GetDeviceCaps (hDC, BITSPIXEL); */

	/* Create clipper object for window */
	ddrval = IDirectDraw_CreateClipper(lpDD, 0, &pClipper, NULL);
	if (ddrval != DD_OK) {
	    DeInitDD();
	    x_error("Failed to create clipper object");
	    return 0;
	}
	/* Asociate it */
	IDirectDrawClipper_SetHWnd(pClipper, 0, hWnd);
    }
    /* Create the primary surface with one back buffer */
    CalculateBITMAPINFO();	// calculate BITMAPINFO structure

    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

    ddrval = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpSurfaces[0], NULL);
    if (ddrval != DD_OK) {
	DeInitDD();
	x_error("Failed to create flipping surface");
	return 0;
    }

    if (!fullscreen) {
	IDirectDrawSurface_SetClipper(lpSurfaces[0], pClipper);
	IDirectDrawClipper_Release(pClipper);
	if (IDirectDrawSurface_GetSurfaceDesc(lpSurfaces[0], &ddsd) !=
	    DD_OK) {
	    DeInitDD();
	    x_error("Failed to get pixel format");
	    return 0;
	}
	bitDepth = ddsd.ddpfPixelFormat.u1.dwRGBBitCount;
    }

    if (bitDepth == 8) {
	/* create palette */
	ddrval =
	    IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT,
				      (LPPALETTEENTRY) bmp->bmiColors,
				      &dxPalette, NULL);
	if (ddrval != DD_OK) {
	    DeInitDD();
	    x_error("Failed to create palette");
	    return 0;
	}

	/* set palette */
	IDirectDrawSurface_SetPalette(lpSurfaces[0], dxPalette);
    }
    if (fullscreen)
	SetCursor(NULL);
    needredraw = 1;
    return 1;

}
EXPORT int CALL angrylionRomOpen (void)
{
#ifndef HAVE_DIRECTDRAW
   screen_width = SCREEN_WIDTH;
   screen_height = SCREEN_HEIGHT;
   blitter_buf = (uint32_t*)calloc(screen_width * screen_height, sizeof(uint32_t));
   pitchindwords = screen_width * 4;
   screen_pitch = PRESCALE_WIDTH << 2;
#else
    DDPIXELFORMAT ftpixel;
    LPDIRECTDRAWCLIPPER lpddcl;
    RECT bigrect, smallrect, statusrect;
    POINT p;
    int rightdiff;
    int bottomdiff;
    GetWindowRect(gfx.hWnd,&bigrect);
    GetClientRect(gfx.hWnd,&smallrect);
    rightdiff = screen_width - smallrect.right;
    bottomdiff = screen_height - smallrect.bottom;

    if (gfx.hStatusBar)
    {
        GetClientRect(gfx.hStatusBar, &statusrect);
        bottomdiff += statusrect.bottom;
    }
    MoveWindow(gfx.hWnd, bigrect.left, bigrect.top, bigrect.right - bigrect.left + rightdiff, bigrect.bottom - bigrect.top + bottomdiff, true);

    res = DirectDrawCreateEx(0, (LPVOID*)&lpdd, &IID_IDirectDraw7, 0);
    if (res != DD_OK)
    {
        DisplayError("Couldn't create a DirectDraw object.");
        return; /* to-do:  move to InitiateGFX? */
    }
    res = IDirectDraw_SetCooperativeLevel(lpdd, gfx.hWnd, DDSCL_NORMAL);
    if (res != DD_OK)
    {
        DisplayError("Couldn't set a cooperative level.");
        return; /* to-do:  move to InitiateGFX? */
    }

    zerobuf(&ddsd, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsprimary, 0);
    if (res != DD_OK)
    {
        DisplayError("CreateSurface for a primary surface failed.");
        return; /* to-do:  move to InitiateGFX? */
    }

    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    ddsd.dwWidth = PRESCALE_WIDTH;
    ddsd.dwHeight = PRESCALE_HEIGHT;
    zerobuf(&ftpixel, sizeof(ftpixel));
    ftpixel.dwSize = sizeof(ftpixel);
    ftpixel.dwFlags = DDPF_RGB;
    ftpixel.dwRGBBitCount = 32;
    ftpixel.dwRBitMask = 0xff0000;
    ftpixel.dwGBitMask = 0xff00;
    ftpixel.dwBBitMask = 0xff;
    ddsd.ddpfPixelFormat = ftpixel;
    res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsback, 0);
    if (res == DDERR_INVALIDPIXELFORMAT)
    {
        DisplayError(
            "ARGB8888 is not supported. You can try changing desktop color "\
            "depth to 32-bit, but most likely that won't help.");
        return; /* InitiateGFX fails. */
    }
    else if (res != DD_OK)
    {
        DisplayError("CreateSurface for a secondary surface failed.");
        return; /* InitiateGFX should fail. */
    }

    res = IDirectDrawSurface_GetSurfaceDesc(lpddsback, &ddsd);
    if (res != DD_OK)
    {
        DisplayError("GetSurfaceDesc failed.");
        return; /* InitiateGFX should fail. */
    }
    if ((ddsd.lPitch & 3) || ddsd.lPitch < (PRESCALE_WIDTH << 2))
    {
        DisplayError(
            "Pitch of a secondary surface is either not 32 bit aligned or "\
            "too small.");
        return; /* InitiateGFX should fail. */
    }
    pitchindwords = ddsd.lPitch >> 2;

    res = IDirectDraw_CreateClipper(lpdd, 0, &lpddcl, 0);
    if (res != DD_OK)
    {
        DisplayError("Couldn't create a clipper.");
        return; /* InitiateGFX should fail. */
    }
    res = IDirectDrawClipper_SetHWnd(lpddcl, 0, gfx.hWnd);
    if (res != DD_OK)
    {
        DisplayError("Couldn't register a windows handle as a clipper.");
        return; /* InitiateGFX should fail. */
    }
    res = IDirectDrawSurface_SetClipper(lpddsprimary, lpddcl);
    if (res != DD_OK)
    {
        DisplayError("Couldn't attach a clipper to a surface.");
        return; /* InitiateGFX should fail. */
    }

    src.top = src.left = 0; 
    src.bottom = 0;
#if SCREEN_WIDTH < PRESCALE_WIDTH
    src.right = PRESCALE_WIDTH - 1; /* fix for undefined video card behavior */
#else
    src.right = PRESCALE_WIDTH;
#endif
    p.x = p.y = 0;
    GetClientRect(gfx.hWnd, &dst);
    ClientToScreen(gfx.hWnd, &p);
    OffsetRect(&dst, p.x, p.y);
    GetClientRect(gfx.hStatusBar, &statusrect);
    dst.bottom -= statusrect.bottom;
#endif

    rdp_init();
    overlay = 0;
    return 1;
}