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

📄 sdl_gemvideo.c

📁 linux下面的一个开源的多媒体中间件
💻 C
📖 第 1 页 / 共 3 页
字号:
/*    SDL - Simple DirectMedia Layer    Copyright (C) 1997-2006 Sam Lantinga    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA    Sam Lantinga    slouken@libsdl.org*/#include "SDL_config.h"/*	GEM video driver	Patrice Mandin	and work from	Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard*//* Mint includes */#include <gem.h>#include <gemx.h>#include <mint/osbind.h>#include <mint/cookie.h>#include "SDL_endian.h"#include "SDL_video.h"#include "SDL_mouse.h"#include "../SDL_sysvideo.h"#include "../SDL_pixels_c.h"#include "../../events/SDL_events_c.h"#include "../SDL_cursor_c.h"#include "../ataricommon/SDL_ataric2p_s.h"#include "../ataricommon/SDL_atarieddi_s.h"#include "../ataricommon/SDL_atarimxalloc_c.h"#include "../ataricommon/SDL_atarigl_c.h"#include "SDL_gemvideo.h"#include "SDL_gemevents_c.h"#include "SDL_gemmouse_c.h"#include "SDL_gemwm_c.h"#include "../ataricommon/SDL_xbiosevents_c.h"#include "../ataricommon/SDL_ataridevmouse_c.h"/* Defines *//*#define DEBUG_VIDEO_GEM	1*/#define GEM_VID_DRIVER_NAME "gem"#undef MIN#define MIN(a,b) (((a)<(b)) ? (a) : (b))#undef MAX#define MAX(a,b) (((a)>(b)) ? (a) : (b))/* Variables */static unsigned char vdi_index[256] = {	0,  2,  3,  6,  4,  7,  5,   8,	9, 10, 11, 14, 12, 15, 13, 255};static const unsigned char empty_name[]="";/* Initialization/Query functions */static int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat);static SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);static SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);static void GEM_VideoQuit(_THIS);/* Hardware surface functions */static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface);static int GEM_LockHWSurface(_THIS, SDL_Surface *surface);static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface);static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface);static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface);static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects);#if 0static int GEM_ToggleFullScreen(_THIS, int on);#endif/* Internal functions */static void GEM_FreeBuffers(_THIS);static void GEM_ClearScreen(_THIS);static void GEM_ClearRect(_THIS, short *rect);static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3]);static void GEM_LockScreen(_THIS);static void GEM_UnlockScreen(_THIS);static void refresh_window(_THIS, int winhandle, short *rect);#if SDL_VIDEO_OPENGL/* OpenGL functions */static void GEM_GL_SwapBuffers(_THIS);#endif/* GEM driver bootstrap functions */static int GEM_Available(void){	/* Test if AES available */	if (appl_init() == -1)		return 0;	appl_exit();	return 1;}static void GEM_DeleteDevice(SDL_VideoDevice *device){	SDL_free(device->hidden);	SDL_free(device);}static SDL_VideoDevice *GEM_CreateDevice(int devindex){	SDL_VideoDevice *device;	int vectors_mask;	unsigned long dummy;	/* Initialize all variables that we clean on shutdown */	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));	if ( device ) {		SDL_memset(device, 0, (sizeof *device));		device->hidden = (struct SDL_PrivateVideoData *)				SDL_malloc((sizeof *device->hidden));		device->gl_data = (struct SDL_PrivateGLData *)				SDL_malloc((sizeof *device->gl_data));	}	if ( (device == NULL) || (device->hidden == NULL) ) {		SDL_OutOfMemory();		if ( device ) {			SDL_free(device);		}		return(0);	}	SDL_memset(device->hidden, 0, (sizeof *device->hidden));	SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));	/* Set the function pointers */	device->VideoInit = GEM_VideoInit;	device->ListModes = GEM_ListModes;	device->SetVideoMode = GEM_SetVideoMode;	device->SetColors = GEM_SetColors;	device->UpdateRects = NULL /*GEM_UpdateRects*/;	device->VideoQuit = GEM_VideoQuit;	device->AllocHWSurface = GEM_AllocHWSurface;	device->LockHWSurface = GEM_LockHWSurface;	device->UnlockHWSurface = GEM_UnlockHWSurface;	device->FlipHWSurface = GEM_FlipHWSurface;	device->FreeHWSurface = GEM_FreeHWSurface;	device->ToggleFullScreen = NULL /*GEM_ToggleFullScreen*/;	/* Window manager */	device->SetCaption = GEM_SetCaption;	device->SetIcon = GEM_SetIcon;	device->IconifyWindow = GEM_IconifyWindow;	device->GrabInput = GEM_GrabInput;	/* Events */	device->InitOSKeymap = GEM_InitOSKeymap;	device->PumpEvents = GEM_PumpEvents;	/* Mouse */	device->FreeWMCursor = GEM_FreeWMCursor;	device->CreateWMCursor = GEM_CreateWMCursor;	device->ShowWMCursor = GEM_ShowWMCursor;	device->WarpWMCursor = NULL /*GEM_WarpWMCursor*/;	device->CheckMouseMode = GEM_CheckMouseMode;#if SDL_VIDEO_OPENGL	/* OpenGL functions */	device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;	device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;	device->GL_GetAttribute = SDL_AtariGL_GetAttribute;	device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;	device->GL_SwapBuffers = GEM_GL_SwapBuffers;#endif	device->hidden->use_dev_mouse =		(SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */	if (!(device->hidden->use_dev_mouse)) {		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */	}	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {		vectors_mask = 0;	}	SDL_AtariXbios_InstallVectors(vectors_mask);	device->free = GEM_DeleteDevice;	return device;}VideoBootStrap GEM_bootstrap = {	GEM_VID_DRIVER_NAME, "Atari GEM video driver",	GEM_Available, GEM_CreateDevice};static void VDI_ReadExtInfo(_THIS, short *work_out){	unsigned long EdDI_version;	unsigned long cookie_EdDI;	Uint32 num_colours;	Uint16 clut_type, num_bits;	/* Read EdDI informations */	if  (Getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND) {		return;	}		EdDI_version = Atari_get_EdDI_version( (void *)cookie_EdDI);	vq_scrninfo(VDI_handle, work_out);	VDI_format = work_out[0];	clut_type = work_out[1];	num_bits = work_out[2];	num_colours = *((Uint32 *) &work_out[3]);	/* With EdDI>=1.1, we can have screen pitch, address and format	 * so we can directly write to screen without using vro_cpyfm	 */	if (EdDI_version >= EDDI_11) {		VDI_pitch = work_out[5];		VDI_screen = (void *) *((unsigned long *) &work_out[6]);	}	switch(clut_type) {		case VDI_CLUT_HARDWARE:			{				int i;				Uint16 *tmp_p;				tmp_p = (Uint16 *)&work_out[16];				for (i=0;i<256;i++) {					vdi_index[*tmp_p++] = i;				}			}			break;		case VDI_CLUT_SOFTWARE:			{				int component; /* red, green, blue, alpha, overlay */				int num_bit;				unsigned short *tmp_p;				/* We can build masks with info here */				tmp_p = (unsigned short *) &work_out[16];				for (component=0;component<5;component++) {					for (num_bit=0;num_bit<16;num_bit++) {						unsigned short valeur;						valeur = *tmp_p++;						if (valeur == 0xffff) {							continue;						}						switch(component) {							case 0:								VDI_redmask |= 1<< valeur;								break;							case 1:								VDI_greenmask |= 1<< valeur;								break;							case 2:								VDI_bluemask |= 1<< valeur;								break;							case 3:								VDI_alphamask |= 1<< valeur;								break;						}					}				}			}			/* Remove lower green bits for Intel endian screen */			if ((VDI_greenmask == ((7<<13)|3)) || (VDI_greenmask == ((7<<13)|7))) {				VDI_greenmask &= ~(7<<13);			}			break;		case VDI_CLUT_NONE:			break;	}}int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat){	int i, menubar_size;	short work_in[12], work_out[272], dummy;	/* Open AES (Application Environment Services) */	if (appl_init() == -1) {		fprintf(stderr,"Can not open AES\n");		return 1;	}	/* Read version and features */	GEM_version = aes_global[0];	if (GEM_version >= 0x0410) {		short ap_gout[4], errorcode;				GEM_wfeatures=0;		errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]);		if (errorcode==0) {			GEM_wfeatures=ap_gout[0];					}	}		/* Ask VDI physical workstation handle opened by AES */	VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);	if (VDI_handle<1) {		fprintf(stderr,"Wrong VDI handle %d returned by AES\n",VDI_handle);		return 1;	}	/* Open virtual VDI workstation */	work_in[0]=Getrez()+2;	for(i = 1; i < 10; i++)		work_in[i] = 1;	work_in[10] = 2;	v_opnvwk(work_in, &VDI_handle, work_out);	if (VDI_handle == 0) {		fprintf(stderr,"Can not open VDI virtual workstation\n");		return 1;	}	/* Read fullscreen size */	VDI_w = work_out[0] + 1;	VDI_h = work_out[1] + 1;	/* Read desktop size and position */	if (!wind_get(DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, &GEM_desk_h)) {		fprintf(stderr,"Can not read desktop properties\n");		return 1;	}	/* Read bit depth */	vq_extnd(VDI_handle, 1, work_out);	VDI_bpp = work_out[4];	VDI_oldnumcolors=0;	switch(VDI_bpp) {		case 8:			VDI_pixelsize=1;			break;		case 15:		case 16:			VDI_pixelsize=2;			break;		case 24:			VDI_pixelsize=3;			break;		case 32:			VDI_pixelsize=4;			break;		default:			fprintf(stderr,"%d bits colour depth not supported\n",VDI_bpp);			return 1;	}	/* Setup hardware -> VDI palette mapping */	for(i = 16; i < 255; i++) {		vdi_index[i] = i;	}	vdi_index[255] = 1;	/* Save current palette */	if (VDI_bpp>8) {		VDI_oldnumcolors=1<<8;	} else {		VDI_oldnumcolors=1<<VDI_bpp;	}		for(i = 0; i < VDI_oldnumcolors; i++) {		short rgb[3];		vq_color(VDI_handle, i, 0, rgb);		VDI_oldpalette[i][0] = rgb[0];		VDI_oldpalette[i][1] = rgb[1];		VDI_oldpalette[i][2] = rgb[2];	}	VDI_setpalette = GEM_SetNewPalette;	SDL_memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette));	/* Setup screen info */	GEM_title_name = empty_name;	GEM_icon_name = empty_name;	GEM_handle = -1;	GEM_locked = SDL_FALSE;	GEM_win_fulled = SDL_FALSE;	GEM_fullscreen = SDL_FALSE;	GEM_lock_redraw = SDL_TRUE;	/* Prevent redraw till buffers are setup */	VDI_screen = NULL;	VDI_pitch = VDI_w * VDI_pixelsize;	VDI_format = ( (VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);	VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;	VDI_ReadExtInfo(this, work_out);#ifdef DEBUG_VIDEO_GEM	printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen, VDI_pitch);	printf("sdl:video:gem: format=%d\n", VDI_format);	printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",		VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask	);#endif	/* Setup destination mfdb */	VDI_dst_mfdb.fd_addr = NULL;	/* Determine the current screen size */	this->info.current_w = VDI_w;	this->info.current_h = VDI_h;	/* Determine the screen depth */	/* we change this during the SDL_SetVideoMode implementation... */	vformat->BitsPerPixel = VDI_bpp;	/* Set mouse cursor to arrow */	graf_mouse(ARROW, NULL);	GEM_cursor = NULL;	/* Init chunky to planar routine */	SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;

⌨️ 快捷键说明

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