Mercurial > sdl-ios-xcode
comparison src/video/dummy/SDL_nullvideo.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | c439dad53df8 |
children | 6e7ec5cb83c3 |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
47 #include "SDL_nullmouse_c.h" | 47 #include "SDL_nullmouse_c.h" |
48 | 48 |
49 #define DUMMYVID_DRIVER_NAME "dummy" | 49 #define DUMMYVID_DRIVER_NAME "dummy" |
50 | 50 |
51 /* Initialization/Query functions */ | 51 /* Initialization/Query functions */ |
52 static int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat); | 52 static int DUMMY_VideoInit (_THIS); |
53 static SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | 53 static int DUMMY_SetDisplayMode (_THIS, const SDL_DisplayMode * mode); |
54 static SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | 54 static SDL_Surface *DUMMY_CreateWindowSurface (_THIS, SDL_Window * window); |
55 static int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | 55 static void DUMMY_VideoQuit (_THIS); |
56 static void DUMMY_VideoQuit(_THIS); | |
57 | |
58 /* Hardware surface functions */ | |
59 static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface); | |
60 static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface); | |
61 static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
62 static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface); | |
63 | |
64 /* etc. */ | |
65 static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects); | |
66 | 56 |
67 /* DUMMY driver bootstrap functions */ | 57 /* DUMMY driver bootstrap functions */ |
68 | 58 |
69 static int DUMMY_Available(void) | 59 static int |
70 { | 60 DUMMY_Available (void) |
71 const char *envr = SDL_getenv("SDL_VIDEODRIVER"); | 61 { |
72 if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) { | 62 const char *envr = SDL_getenv ("SDL_VIDEODRIVER"); |
73 return(1); | 63 if ((envr) && (SDL_strcmp (envr, DUMMYVID_DRIVER_NAME) == 0)) { |
74 } | 64 return (1); |
75 | 65 } |
76 return(0); | 66 |
77 } | 67 return (0); |
78 | 68 } |
79 static void DUMMY_DeleteDevice(SDL_VideoDevice *device) | 69 |
80 { | 70 static void |
81 SDL_free(device->hidden); | 71 DUMMY_DeleteDevice (SDL_VideoDevice * device) |
82 SDL_free(device); | 72 { |
83 } | 73 SDL_free (device->hidden); |
84 | 74 SDL_free (device); |
85 static SDL_VideoDevice *DUMMY_CreateDevice(int devindex) | 75 } |
86 { | 76 |
87 SDL_VideoDevice *device; | 77 static SDL_VideoDevice * |
88 | 78 DUMMY_CreateDevice (int devindex) |
89 /* Initialize all variables that we clean on shutdown */ | 79 { |
90 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); | 80 SDL_VideoDevice *device; |
91 if ( device ) { | 81 |
92 SDL_memset(device, 0, (sizeof *device)); | 82 /* Initialize all variables that we clean on shutdown */ |
93 device->hidden = (struct SDL_PrivateVideoData *) | 83 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); |
94 SDL_malloc((sizeof *device->hidden)); | 84 if (device) { |
95 } | 85 SDL_memset (device, 0, (sizeof *device)); |
96 if ( (device == NULL) || (device->hidden == NULL) ) { | 86 device->hidden = (struct SDL_PrivateVideoData *) |
97 SDL_OutOfMemory(); | 87 SDL_malloc ((sizeof *device->hidden)); |
98 if ( device ) { | 88 } |
99 SDL_free(device); | 89 if ((device == NULL) || (device->hidden == NULL)) { |
100 } | 90 SDL_OutOfMemory (); |
101 return(0); | 91 if (device) { |
102 } | 92 SDL_free (device); |
103 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); | 93 } |
104 | 94 return (0); |
105 /* Set the function pointers */ | 95 } |
106 device->VideoInit = DUMMY_VideoInit; | 96 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); |
107 device->ListModes = DUMMY_ListModes; | 97 |
108 device->SetVideoMode = DUMMY_SetVideoMode; | 98 /* Set the function pointers */ |
109 device->CreateYUVOverlay = NULL; | 99 device->VideoInit = DUMMY_VideoInit; |
110 device->SetColors = DUMMY_SetColors; | 100 device->SetDisplayMode = DUMMY_SetDisplayMode; |
111 device->UpdateRects = DUMMY_UpdateRects; | 101 device->VideoQuit = DUMMY_VideoQuit; |
112 device->VideoQuit = DUMMY_VideoQuit; | 102 device->InitOSKeymap = DUMMY_InitOSKeymap; |
113 device->AllocHWSurface = DUMMY_AllocHWSurface; | 103 device->PumpEvents = DUMMY_PumpEvents; |
114 device->CheckHWBlit = NULL; | 104 |
115 device->FillHWRect = NULL; | 105 device->free = DUMMY_DeleteDevice; |
116 device->SetHWColorKey = NULL; | 106 |
117 device->SetHWAlpha = NULL; | 107 return device; |
118 device->LockHWSurface = DUMMY_LockHWSurface; | |
119 device->UnlockHWSurface = DUMMY_UnlockHWSurface; | |
120 device->FlipHWSurface = NULL; | |
121 device->FreeHWSurface = DUMMY_FreeHWSurface; | |
122 device->SetCaption = NULL; | |
123 device->SetIcon = NULL; | |
124 device->IconifyWindow = NULL; | |
125 device->GrabInput = NULL; | |
126 device->GetWMInfo = NULL; | |
127 device->InitOSKeymap = DUMMY_InitOSKeymap; | |
128 device->PumpEvents = DUMMY_PumpEvents; | |
129 | |
130 device->free = DUMMY_DeleteDevice; | |
131 | |
132 return device; | |
133 } | 108 } |
134 | 109 |
135 VideoBootStrap DUMMY_bootstrap = { | 110 VideoBootStrap DUMMY_bootstrap = { |
136 DUMMYVID_DRIVER_NAME, "SDL dummy video driver", | 111 DUMMYVID_DRIVER_NAME, "SDL dummy video driver", |
137 DUMMY_Available, DUMMY_CreateDevice | 112 DUMMY_Available, DUMMY_CreateDevice |
138 }; | 113 }; |
139 | 114 |
140 | 115 |
141 int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat) | 116 int |
142 { | 117 DUMMY_VideoInit (_THIS) |
143 /* | 118 { |
144 fprintf(stderr, "WARNING: You are using the SDL dummy video driver!\n"); | 119 SDL_AddBasicVideoDisplay (NULL); |
145 */ | 120 |
146 | 121 /* We're done! */ |
147 /* Determine the screen depth (use default 8-bit depth) */ | 122 return 0; |
148 /* we change this during the SDL_SetVideoMode implementation... */ | 123 } |
149 vformat->BitsPerPixel = 8; | 124 |
150 vformat->BytesPerPixel = 1; | 125 static int |
151 | 126 DUMMY_SetDisplayMode (_THIS, const SDL_DisplayMode * mode) |
152 /* We're done! */ | 127 { |
153 return(0); | 128 return 0; |
154 } | 129 } |
155 | 130 |
156 SDL_Rect **DUMMY_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | 131 static SDL_Surface * |
157 { | 132 DUMMY_CreateWindowSurface (_THIS, SDL_Window * window) |
158 return (SDL_Rect **) -1; | 133 { |
159 } | 134 int bpp; |
160 | 135 Uint32 Rmask, Gmask, Bmask, Amask; |
161 SDL_Surface *DUMMY_SetVideoMode(_THIS, SDL_Surface *current, | 136 |
162 int width, int height, int bpp, Uint32 flags) | 137 if (_this->hidden->buffer) { |
163 { | 138 SDL_free (_this->hidden->buffer); |
164 if ( this->hidden->buffer ) { | 139 } |
165 SDL_free( this->hidden->buffer ); | 140 |
166 } | 141 _this->hidden->buffer = |
167 | 142 SDL_malloc (mode->w * mode->h * SDL_BYTESPERPIXEL (mode->format)); |
168 this->hidden->buffer = SDL_malloc(width * height * (bpp / 8)); | 143 if (!_this->hidden->buffer) { |
169 if ( ! this->hidden->buffer ) { | 144 SDL_SetError ("Couldn't allocate buffer for requested mode"); |
170 SDL_SetError("Couldn't allocate buffer for requested mode"); | 145 return (NULL); |
171 return(NULL); | 146 } |
172 } | |
173 | 147 |
174 /* printf("Setting mode %dx%d\n", width, height); */ | 148 /* printf("Setting mode %dx%d\n", width, height); */ |
175 | 149 |
176 SDL_memset(this->hidden->buffer, 0, width * height * (bpp / 8)); | 150 SDL_memset (_this->hidden->buffer, 0, |
177 | 151 mode->w * mode->h * SDL_BYTESPERPIXEL (mode->format)); |
178 /* Allocate the new pixel format for the screen */ | 152 |
179 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { | 153 /* Allocate the new pixel format for the screen */ |
180 SDL_free(this->hidden->buffer); | 154 SDL_PixelFormatEnumToMasks (mode->format, &bpp, &Rmask, &Gmask, &Bmask, |
181 this->hidden->buffer = NULL; | 155 &Amask); |
182 SDL_SetError("Couldn't allocate new pixel format for requested mode"); | 156 if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, Amask)) { |
183 return(NULL); | 157 SDL_free (_this->hidden->buffer); |
184 } | 158 _this->hidden->buffer = NULL; |
185 | 159 SDL_SetError |
186 /* Set up the new mode framebuffer */ | 160 ("Couldn't allocate new pixel format for requested mode"); |
187 current->flags = flags & SDL_FULLSCREEN; | 161 return (NULL); |
188 this->hidden->w = current->w = width; | 162 } |
189 this->hidden->h = current->h = height; | 163 |
190 current->pitch = current->w * (bpp / 8); | 164 /* Set up the new mode framebuffer */ |
191 current->pixels = this->hidden->buffer; | 165 current->flags = flags & SDL_FULLSCREEN; |
192 | 166 _this->hidden->w = current->w = mode->w; |
193 /* We're done */ | 167 _this->hidden->h = current->h = mode->h; |
194 return(current); | 168 current->pitch = current->w * SDL_BYTESPERPIXEL (mode->format); |
195 } | 169 current->pixels = _this->hidden->buffer; |
196 | 170 |
197 /* We don't actually allow hardware surfaces other than the main one */ | 171 /* We're done */ |
198 static int DUMMY_AllocHWSurface(_THIS, SDL_Surface *surface) | 172 return (current); |
199 { | 173 } |
200 return(-1); | 174 |
201 } | 175 SDL_Surface * |
202 static void DUMMY_FreeHWSurface(_THIS, SDL_Surface *surface) | 176 DUMMY_SetVideoMode (_THIS, SDL_Surface * current, |
203 { | 177 const SDL_DisplayMode * mode, Uint32 flags) |
204 return; | 178 { |
205 } | 179 int bpp; |
206 | 180 Uint32 Rmask, Gmask, Bmask, Amask; |
207 /* We need to wait for vertical retrace on page flipped displays */ | 181 |
208 static int DUMMY_LockHWSurface(_THIS, SDL_Surface *surface) | 182 if (_this->hidden->buffer) { |
209 { | 183 SDL_free (_this->hidden->buffer); |
210 return(0); | 184 } |
211 } | 185 |
212 | 186 _this->hidden->buffer = |
213 static void DUMMY_UnlockHWSurface(_THIS, SDL_Surface *surface) | 187 SDL_malloc (mode->w * mode->h * SDL_BYTESPERPIXEL (mode->format)); |
214 { | 188 if (!_this->hidden->buffer) { |
215 return; | 189 SDL_SetError ("Couldn't allocate buffer for requested mode"); |
216 } | 190 return (NULL); |
217 | 191 } |
218 static void DUMMY_UpdateRects(_THIS, int numrects, SDL_Rect *rects) | 192 |
219 { | 193 /* printf("Setting mode %dx%d\n", width, height); */ |
220 /* do nothing. */ | 194 |
221 } | 195 SDL_memset (_this->hidden->buffer, 0, |
222 | 196 mode->w * mode->h * SDL_BYTESPERPIXEL (mode->format)); |
223 int DUMMY_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | 197 |
224 { | 198 /* Allocate the new pixel format for the screen */ |
225 /* do nothing of note. */ | 199 SDL_PixelFormatEnumToMasks (mode->format, &bpp, &Rmask, &Gmask, &Bmask, |
226 return(1); | 200 &Amask); |
201 if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, Amask)) { | |
202 SDL_free (_this->hidden->buffer); | |
203 _this->hidden->buffer = NULL; | |
204 SDL_SetError | |
205 ("Couldn't allocate new pixel format for requested mode"); | |
206 return (NULL); | |
207 } | |
208 | |
209 /* Set up the new mode framebuffer */ | |
210 current->flags = flags & SDL_FULLSCREEN; | |
211 _this->hidden->w = current->w = mode->w; | |
212 _this->hidden->h = current->h = mode->h; | |
213 current->pitch = current->w * SDL_BYTESPERPIXEL (mode->format); | |
214 current->pixels = _this->hidden->buffer; | |
215 | |
216 /* We're done */ | |
217 return (current); | |
227 } | 218 } |
228 | 219 |
229 /* Note: If we are terminated, this could be called in the middle of | 220 /* Note: If we are terminated, this could be called in the middle of |
230 another SDL video routine -- notably UpdateRects. | 221 another SDL video routine -- notably UpdateRects. |
231 */ | 222 */ |
232 void DUMMY_VideoQuit(_THIS) | 223 void |
233 { | 224 DUMMY_VideoQuit (_THIS) |
234 if (this->screen->pixels != NULL) | 225 { |
235 { | 226 if (_this->hidden->buffer) { |
236 SDL_free(this->screen->pixels); | 227 SDL_free (_this->hidden->buffer); |
237 this->screen->pixels = NULL; | 228 } |
238 } | 229 } |
239 } | 230 |
231 /* vi: set ts=4 sw=4 expandtab: */ |