⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_dx5video.c

📁 linux下面的一个开源的多媒体中间件
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif#ifndef IDirectDrawGammaControl_SetGammaRamp	/*if gamma is undefined then we really have directx <= 0x500*/	DDCAPS DDCaps;#else	DDCAPS_DX5 DDCaps;#endif	HRESULT result;	/* Fill in our hardware acceleration capabilities */	SDL_memset(&DDCaps, 0, sizeof(DDCaps));	DDCaps.dwSize = sizeof(DDCaps);	result = IDirectDraw2_GetCaps(ddraw2, (DDCAPS *)&DDCaps, NULL);	if ( result != DD_OK ) {		SetDDerror("DirectDraw2::GetCaps", result);		return(-1);	}	this->info.hw_available = 1;	if ( (DDCaps.dwCaps & DDCAPS_BLT) == DDCAPS_BLT ) {		this->info.blit_hw = 1;	}	if ( ((DDCaps.dwCaps & DDCAPS_COLORKEY) == DDCAPS_COLORKEY) &&	     ((DDCaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT) == DDCKEYCAPS_SRCBLT) ) {		this->info.blit_hw_CC = 1;	}	if ( (DDCaps.dwCaps & DDCAPS_ALPHA) == DDCAPS_ALPHA ) {		/* This is only for alpha channel, and DirectX 6		   doesn't support 2D alpha blits yet, so set it 0		 */		this->info.blit_hw_A = 0;	}	if ( (DDCaps.dwCaps & DDCAPS_CANBLTSYSMEM) == DDCAPS_CANBLTSYSMEM ) {		this->info.blit_sw = 1;		/* This isn't necessarily true, but the HEL will cover us */		this->info.blit_sw_CC = this->info.blit_hw_CC;		this->info.blit_sw_A = this->info.blit_hw_A;	}	if ( (DDCaps.dwCaps & DDCAPS_BLTCOLORFILL) == DDCAPS_BLTCOLORFILL ) {		this->info.blit_fill = 1;	}	/* Find out how much video memory is available */	{ DDSCAPS ddsCaps;	  DWORD total_mem;		ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;		result = IDirectDraw2_GetAvailableVidMem(ddraw2,						&ddsCaps, &total_mem, NULL);		if ( result != DD_OK ) {			total_mem = DDCaps.dwVidMemTotal; 		}		this->info.video_mem = total_mem/1024;	}	return(0);}int DX5_VideoInit(_THIS, SDL_PixelFormat *vformat){	HRESULT result;	LPDIRECTDRAW ddraw;	int i, j;	HDC hdc;	/* Intialize everything */	ddraw2 = NULL;	SDL_primary = NULL;	SDL_clipper = NULL;	SDL_palette = NULL;	for ( i=0; i<NUM_MODELISTS; ++i ) {		SDL_nummodes[i] = 0;		SDL_modelist[i] = NULL;		SDL_modeindex[i] = 0;	}	colorchange_expected = 0;	/* Create the window */	if ( DX5_CreateWindow(this) < 0 ) {		return(-1);	}#if !SDL_AUDIO_DISABLED	DX5_SoundFocus(SDL_Window);#endif	/* Create the DirectDraw object */	result = DDrawCreate(NULL, &ddraw, NULL);	if ( result != DD_OK ) {		SetDDerror("DirectDrawCreate", result);		return(-1);	}	result = IDirectDraw_QueryInterface(ddraw, &IID_IDirectDraw2,							(LPVOID *)&ddraw2);	IDirectDraw_Release(ddraw);	if ( result != DD_OK ) {		SetDDerror("DirectDraw::QueryInterface", result);		return(-1);	}	/* Determine the screen depth */	hdc = GetDC(SDL_Window);	vformat->BitsPerPixel = GetDeviceCaps(hdc,PLANES) *					GetDeviceCaps(hdc,BITSPIXEL);	ReleaseDC(SDL_Window, hdc);#ifndef NO_CHANGEDISPLAYSETTINGS	/* Query for the desktop resolution */	EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);	this->info.current_w = SDL_desktop_mode.dmPelsWidth;	this->info.current_h = SDL_desktop_mode.dmPelsHeight;#endif	/* Enumerate the available fullscreen modes */	for ( i=0; i<NUM_MODELISTS; ++i )		enumlists[i] = NULL;	result = IDirectDraw2_EnumDisplayModes(ddraw2,DDEDM_REFRESHRATES,NULL,this,EnumModes2);	if ( result != DD_OK ) {		SetDDerror("DirectDraw2::EnumDisplayModes", result);		return(-1);	}	for ( i=0; i<NUM_MODELISTS; ++i ) {		struct DX5EnumRect *rect;		SDL_modelist[i] = (SDL_Rect **)				SDL_malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *));		if ( SDL_modelist[i] == NULL ) {			SDL_OutOfMemory();			return(-1);		}		for ( j = 0, rect = enumlists[i]; rect; ++j, rect = rect->next ) {			SDL_modelist[i][j] = &rect->r;		}		SDL_modelist[i][j] = NULL;		if ( SDL_nummodes[i] > 0 ) {			SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);		}	}		/* Fill in some window manager capabilities */	this->info.wm_available = 1;	/* Fill in the video hardware capabilities */	DX5_UpdateVideoInfo(this);	return(0);}SDL_Rect **DX5_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags){	int bpp;	bpp = format->BitsPerPixel;	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {		/* FIXME:  No support for 1 bpp or 4 bpp formats */		switch (bpp) {  /* Does windows support other BPP? */			case 8:			case 16:			case 24:			case 32:				bpp = (bpp/8)-1;				if ( SDL_nummodes[bpp] > 0 )					return(SDL_modelist[bpp]);				/* Fall through */			default:				return((SDL_Rect **)0);		}	} else {		if ( this->screen->format->BitsPerPixel == bpp ) {			return((SDL_Rect **)-1);		} else {			return((SDL_Rect **)0);		}	}}/* Various screen update functions available */static void DX5_WindowUpdate(_THIS, int numrects, SDL_Rect *rects);static void DX5_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current,				int width, int height, int bpp, Uint32 flags){	SDL_Surface *video;	HRESULT result;	DWORD sharemode;	DWORD style;	const DWORD directstyle =			(WS_POPUP);	const DWORD windowstyle = 			(WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX);	const DWORD resizestyle =			(WS_THICKFRAME|WS_MAXIMIZEBOX);	DDSURFACEDESC ddsd;	LPDIRECTDRAWSURFACE  dd_surface1;	LPDIRECTDRAWSURFACE3 dd_surface3;	SDL_resizing = 1;#ifdef DDRAW_DEBUG fprintf(stderr, "Setting %dx%dx%d video mode\n", width, height, bpp);#endif	/* Clean up any previous DirectDraw surfaces */	if ( current->hwdata ) {		this->FreeHWSurface(this, current);		current->hwdata = NULL;	}	if ( SDL_primary != NULL ) {		IDirectDrawSurface3_Release(SDL_primary);		SDL_primary = NULL;	}#ifndef NO_CHANGEDISPLAYSETTINGS	/* Unset any previous OpenGL fullscreen mode */	if ( (current->flags & (SDL_OPENGL|SDL_FULLSCREEN)) ==	                       (SDL_OPENGL|SDL_FULLSCREEN) ) {		ChangeDisplaySettings(NULL, 0);	}#endif	/* Clean up any GL context that may be hanging around */	if ( current->flags & SDL_OPENGL ) {		WIN_GL_ShutDown(this);	}	/* If we are setting a GL mode, use GDI, not DirectX (yuck) */	if ( flags & SDL_OPENGL ) {		Uint32 Rmask, Gmask, Bmask;		/* Recalculate the bitmasks if necessary */		if ( bpp == current->format->BitsPerPixel ) {			video = current;		} else {			switch (bpp) {			    case 15:			    case 16:				if ( 0 /*DIB_SussScreenDepth() == 15*/ ) {					/* 5-5-5 */					Rmask = 0x00007c00;					Gmask = 0x000003e0;					Bmask = 0x0000001f;				} else {					/* 5-6-5 */					Rmask = 0x0000f800;					Gmask = 0x000007e0;					Bmask = 0x0000001f;				}				break;			    case 24:			    case 32:				/* GDI defined as 8-8-8 */				Rmask = 0x00ff0000;				Gmask = 0x0000ff00;				Bmask = 0x000000ff;				break;			    default:				Rmask = 0x00000000;				Gmask = 0x00000000;				Bmask = 0x00000000;				break;			}			video = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp,			                             Rmask, Gmask, Bmask, 0);			if ( video == NULL ) {				SDL_OutOfMemory();				return(NULL);			}		}		/* Fill in part of the video surface */		video->flags = 0;	/* Clear flags */		video->w = width;		video->h = height;		video->pitch = SDL_CalculatePitch(video);#ifndef NO_CHANGEDISPLAYSETTINGS		/* Set fullscreen mode if appropriate.		   Ugh, since our list of valid video modes comes from		   the DirectX driver, we may not actually be able to		   change to the desired resolution here.		   FIXME: Should we do a closest match?		 */		if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {			DEVMODE settings;			BOOL changed;			SDL_memset(&settings, 0, sizeof(DEVMODE));			settings.dmSize = sizeof(DEVMODE);			settings.dmBitsPerPel = video->format->BitsPerPixel;			settings.dmPelsWidth = width;			settings.dmPelsHeight = height;			settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;			if ( width <= (int)SDL_desktop_mode.dmPelsWidth &&			     height <= (int)SDL_desktop_mode.dmPelsHeight ) {				settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;				settings.dmFields |= DM_DISPLAYFREQUENCY;			}			changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);			if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) {				settings.dmFields &= ~DM_DISPLAYFREQUENCY;				changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL);			}			if ( changed ) {				video->flags |= SDL_FULLSCREEN;				SDL_fullscreen_mode = settings;			}		}#endif /* !NO_CHANGEDISPLAYSETTINGS */		style = GetWindowLong(SDL_Window, GWL_STYLE);		style &= ~(resizestyle|WS_MAXIMIZE);		if ( video->flags & SDL_FULLSCREEN ) {			style &= ~windowstyle;			style |= directstyle;		} else {			if ( flags & SDL_NOFRAME ) {				style &= ~windowstyle;				style |= directstyle;				video->flags |= SDL_NOFRAME;			} else {				style &= ~directstyle;				style |= windowstyle;				if ( flags & SDL_RESIZABLE ) {					style |= resizestyle;					video->flags |= SDL_RESIZABLE;				}			}#if WS_MAXIMIZE			if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;#endif		}		/* DJM: Don't piss of anyone who has setup his own window */		if ( !SDL_windowid )			SetWindowLong(SDL_Window, GWL_STYLE, style);		/* Resize the window (copied from SDL WinDIB driver) */		if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {			RECT bounds;			int x, y;			HWND top;			UINT swp_flags;			const char *window = NULL;			const char *center = NULL;			if ( !SDL_windowX && !SDL_windowY ) {				window = SDL_getenv("SDL_VIDEO_WINDOW_POS");				center = SDL_getenv("SDL_VIDEO_CENTERED");				if ( window ) {					if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) {						SDL_windowX = x;						SDL_windowY = y;					}					if ( SDL_strcmp(window, "center") == 0 ) {						center = window;					}				}			}			swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);			bounds.left = SDL_windowX;			bounds.top = SDL_windowY;			bounds.right = SDL_windowX+video->w;			bounds.bottom = SDL_windowY+video->h;			AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), (GetMenu(SDL_Window) != NULL), 0);			width = bounds.right-bounds.left;			height = bounds.bottom-bounds.top;			if ( (flags & SDL_FULLSCREEN) ) {				x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;				y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;			} else if ( center ) {				x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;				y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;			} else if ( SDL_windowX || SDL_windowY || window ) {				x = bounds.left;				y = bounds.top;			} else {				x = y = -1;				swp_flags |= SWP_NOMOVE;			}			if ( flags & SDL_FULLSCREEN ) {				top = HWND_TOPMOST;			} else {				top = HWND_NOTOPMOST;			}			SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags);			if ( !(flags & SDL_FULLSCREEN) ) {				SDL_windowX = SDL_bounds.left;				SDL_windowY = SDL_bounds.top;			}			SetForegroundWindow(SDL_Window);		}		SDL_resizing = 0;		/* Set up for OpenGL */		if ( WIN_GL_SetupWindow(this) < 0 ) {			return(NULL);		}		video->flags |= SDL_OPENGL;		return(video);	}	/* Set the appropriate window style */	style = GetWindowLong(SDL_Window, GWL_STYLE);	style &= ~(resizestyle|WS_MAXIMIZE);	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {		style &= ~windowstyle;		style |= directstyle;	} else {		if ( flags & SDL_NOFRAME ) {			style &= ~windowstyle;			style |= directstyle;		} else {			style &= ~directstyle;			style |= windowstyle;			if ( flags & SDL_RESIZABLE ) {				style |= resizestyle;			}		}#if WS_MAXIMIZE		if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -