Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 2744:1aede15771d0
Ran GNU indent on file
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Tue, 02 Sep 2008 20:11:06 +0000 |
parents | 453ec0c21f6f |
children | 587d2b5fb805 |
comparison
equal
deleted
inserted
replaced
2743:453ec0c21f6f | 2744:1aede15771d0 |
---|---|
37 | 37 |
38 /* On Windows, windows.h defines CreateWindow */ | 38 /* On Windows, windows.h defines CreateWindow */ |
39 #ifdef CreateWindow | 39 #ifdef CreateWindow |
40 #undef CreateWindow | 40 #undef CreateWindow |
41 #endif | 41 #endif |
42 #endif /* SDL_VIDEO_OPENGL */ | 42 #endif /* SDL_VIDEO_OPENGL */ |
43 | 43 |
44 /* Available video drivers */ | 44 /* Available video drivers */ |
45 static VideoBootStrap *bootstrap[] = { | 45 static VideoBootStrap *bootstrap[] = { |
46 #if SDL_VIDEO_DRIVER_COCOA | 46 #if SDL_VIDEO_DRIVER_COCOA |
47 &COCOA_bootstrap, | 47 &COCOA_bootstrap, |
48 #endif | 48 #endif |
49 #if SDL_VIDEO_DRIVER_X11 | 49 #if SDL_VIDEO_DRIVER_X11 |
50 &X11_bootstrap, | 50 &X11_bootstrap, |
51 #endif | 51 #endif |
52 #if SDL_VIDEO_DRIVER_NANOX | 52 #if SDL_VIDEO_DRIVER_NANOX |
53 &NX_bootstrap, | 53 &NX_bootstrap, |
54 #endif | 54 #endif |
55 #if SDL_VIDEO_DRIVER_IPOD | 55 #if SDL_VIDEO_DRIVER_IPOD |
56 &iPod_bootstrap, | 56 &iPod_bootstrap, |
57 #endif | 57 #endif |
58 #if SDL_VIDEO_DRIVER_WSCONS | 58 #if SDL_VIDEO_DRIVER_WSCONS |
59 &WSCONS_bootstrap, | 59 &WSCONS_bootstrap, |
60 #endif | 60 #endif |
61 #if SDL_VIDEO_DRIVER_FBCON | 61 #if SDL_VIDEO_DRIVER_FBCON |
62 &FBCON_bootstrap, | 62 &FBCON_bootstrap, |
63 #endif | 63 #endif |
64 #if SDL_VIDEO_DRIVER_DIRECTFB | 64 #if SDL_VIDEO_DRIVER_DIRECTFB |
65 &DirectFB_bootstrap, | 65 &DirectFB_bootstrap, |
66 #endif | 66 #endif |
67 #if SDL_VIDEO_DRIVER_PS2GS | 67 #if SDL_VIDEO_DRIVER_PS2GS |
68 &PS2GS_bootstrap, | 68 &PS2GS_bootstrap, |
69 #endif | 69 #endif |
70 #if SDL_VIDEO_DRIVER_VGL | 70 #if SDL_VIDEO_DRIVER_VGL |
71 &VGL_bootstrap, | 71 &VGL_bootstrap, |
72 #endif | 72 #endif |
73 #if SDL_VIDEO_DRIVER_SVGALIB | 73 #if SDL_VIDEO_DRIVER_SVGALIB |
74 &SVGALIB_bootstrap, | 74 &SVGALIB_bootstrap, |
75 #endif | 75 #endif |
76 #if SDL_VIDEO_DRIVER_GAPI | 76 #if SDL_VIDEO_DRIVER_GAPI |
77 &GAPI_bootstrap, | 77 &GAPI_bootstrap, |
78 #endif | 78 #endif |
79 #if SDL_VIDEO_DRIVER_WIN32 | 79 #if SDL_VIDEO_DRIVER_WIN32 |
80 &WIN32_bootstrap, | 80 &WIN32_bootstrap, |
81 #endif | 81 #endif |
82 #if SDL_VIDEO_DRIVER_BWINDOW | 82 #if SDL_VIDEO_DRIVER_BWINDOW |
83 &BWINDOW_bootstrap, | 83 &BWINDOW_bootstrap, |
84 #endif | 84 #endif |
85 #if SDL_VIDEO_DRIVER_PHOTON | 85 #if SDL_VIDEO_DRIVER_PHOTON |
86 &ph_bootstrap, | 86 &ph_bootstrap, |
87 #endif | 87 #endif |
88 #if SDL_VIDEO_DRIVER_EPOC | 88 #if SDL_VIDEO_DRIVER_EPOC |
89 &EPOC_bootstrap, | 89 &EPOC_bootstrap, |
90 #endif | 90 #endif |
91 #if SDL_VIDEO_DRIVER_XBIOS | 91 #if SDL_VIDEO_DRIVER_XBIOS |
92 &XBIOS_bootstrap, | 92 &XBIOS_bootstrap, |
93 #endif | 93 #endif |
94 #if SDL_VIDEO_DRIVER_GEM | 94 #if SDL_VIDEO_DRIVER_GEM |
95 &GEM_bootstrap, | 95 &GEM_bootstrap, |
96 #endif | 96 #endif |
97 #if SDL_VIDEO_DRIVER_DC | 97 #if SDL_VIDEO_DRIVER_DC |
98 &DC_bootstrap, | 98 &DC_bootstrap, |
99 #endif | 99 #endif |
100 #if SDL_VIDEO_DRIVER_RISCOS | 100 #if SDL_VIDEO_DRIVER_RISCOS |
101 &RISCOS_bootstrap, | 101 &RISCOS_bootstrap, |
102 #endif | 102 #endif |
103 #if SDL_VIDEO_DRIVER_OS2FS | 103 #if SDL_VIDEO_DRIVER_OS2FS |
104 &OS2FSLib_bootstrap, | 104 &OS2FSLib_bootstrap, |
105 #endif | 105 #endif |
106 #if SDL_VIDEO_DRIVER_NDS | 106 #if SDL_VIDEO_DRIVER_NDS |
107 &NDS_bootstrap, | 107 &NDS_bootstrap, |
108 #endif | 108 #endif |
109 #if SDL_VIDEO_DRIVER_DUMMY | 109 #if SDL_VIDEO_DRIVER_DUMMY |
110 &DUMMY_bootstrap, | 110 &DUMMY_bootstrap, |
111 #endif | 111 #endif |
112 NULL | 112 NULL |
113 }; | 113 }; |
114 | 114 |
115 static SDL_VideoDevice *_this = NULL; | 115 static SDL_VideoDevice *_this = NULL; |
116 | 116 |
117 /* Various local functions */ | 117 /* Various local functions */ |
118 int SDL_VideoInit(const char *driver_name, Uint32 flags); | 118 int SDL_VideoInit(const char *driver_name, Uint32 flags); |
119 void SDL_VideoQuit(void); | 119 void SDL_VideoQuit(void); |
120 | 120 |
121 static int | 121 static int |
122 cmpmodes(const void *A, const void *B) | 122 cmpmodes(const void *A, const void *B) |
123 { | 123 { |
124 SDL_DisplayMode a = *(const SDL_DisplayMode *) A; | 124 SDL_DisplayMode a = *(const SDL_DisplayMode *) A; |
125 SDL_DisplayMode b = *(const SDL_DisplayMode *) B; | 125 SDL_DisplayMode b = *(const SDL_DisplayMode *) B; |
126 | 126 |
127 if (a.w != b.w) { | 127 if (a.w != b.w) { |
128 return b.w - a.w; | 128 return b.w - a.w; |
129 } | 129 } |
130 if (a.h != b.h) { | 130 if (a.h != b.h) { |
131 return b.h - a.h; | 131 return b.h - a.h; |
132 } | 132 } |
133 if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) { | 133 if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) { |
134 return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format); | 134 return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format); |
135 } | 135 } |
136 if (a.refresh_rate != b.refresh_rate) { | 136 if (a.refresh_rate != b.refresh_rate) { |
137 return b.refresh_rate - a.refresh_rate; | 137 return b.refresh_rate - a.refresh_rate; |
138 } | 138 } |
139 return 0; | 139 return 0; |
140 } | 140 } |
141 | 141 |
142 static void | 142 static void |
143 SDL_UninitializedVideo() | 143 SDL_UninitializedVideo() |
144 { | 144 { |
145 SDL_SetError("Video subsystem has not been initialized"); | 145 SDL_SetError("Video subsystem has not been initialized"); |
146 } | 146 } |
147 | 147 |
148 int | 148 int |
149 SDL_GetNumVideoDrivers(void) | 149 SDL_GetNumVideoDrivers(void) |
150 { | 150 { |
151 return SDL_arraysize(bootstrap) - 1; | 151 return SDL_arraysize(bootstrap) - 1; |
152 } | 152 } |
153 | 153 |
154 const char * | 154 const char * |
155 SDL_GetVideoDriver(int index) | 155 SDL_GetVideoDriver(int index) |
156 { | 156 { |
157 if (index >= 0 && index < SDL_GetNumVideoDrivers()) { | 157 if (index >= 0 && index < SDL_GetNumVideoDrivers()) { |
158 return bootstrap[index]->name; | 158 return bootstrap[index]->name; |
159 } | 159 } |
160 return NULL; | 160 return NULL; |
161 } | 161 } |
162 | 162 |
163 /* | 163 /* |
164 * Initialize the video and event subsystems -- determine native pixel format | 164 * Initialize the video and event subsystems -- determine native pixel format |
165 */ | 165 */ |
166 int | 166 int |
167 SDL_VideoInit(const char *driver_name, Uint32 flags) | 167 SDL_VideoInit(const char *driver_name, Uint32 flags) |
168 { | 168 { |
169 SDL_VideoDevice *video; | 169 SDL_VideoDevice *video; |
170 int index; | 170 int index; |
171 int i; | 171 int i; |
172 | 172 |
173 /* Toggle the event thread flags, based on OS requirements */ | 173 /* Toggle the event thread flags, based on OS requirements */ |
174 #if defined(MUST_THREAD_EVENTS) | 174 #if defined(MUST_THREAD_EVENTS) |
175 flags |= SDL_INIT_EVENTTHREAD; | 175 flags |= SDL_INIT_EVENTTHREAD; |
176 #elif defined(CANT_THREAD_EVENTS) | 176 #elif defined(CANT_THREAD_EVENTS) |
177 if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { | 177 if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { |
178 SDL_SetError("OS doesn't support threaded events"); | 178 SDL_SetError("OS doesn't support threaded events"); |
179 return -1; | 179 return -1; |
180 } | 180 } |
181 #endif | 181 #endif |
182 | 182 |
183 /* Start the event loop */ | 183 /* Start the event loop */ |
184 if (SDL_StartEventLoop(flags) < 0) { | 184 if (SDL_StartEventLoop(flags) < 0) { |
185 return -1; | 185 return -1; |
186 } | 186 } |
187 | 187 /* Check to make sure we don't overwrite '_this' */ |
188 /* Check to make sure we don't overwrite '_this' */ | 188 if (_this != NULL) { |
189 if (_this != NULL) { | 189 SDL_VideoQuit(); |
190 SDL_VideoQuit(); | 190 } |
191 } | 191 /* Select the proper video driver */ |
192 | 192 index = 0; |
193 /* Select the proper video driver */ | 193 video = NULL; |
194 index = 0; | 194 if (driver_name == NULL) { |
195 video = NULL; | 195 driver_name = SDL_getenv("SDL_VIDEODRIVER"); |
196 if (driver_name == NULL) { | 196 } |
197 driver_name = SDL_getenv("SDL_VIDEODRIVER"); | 197 if (driver_name != NULL) { |
198 } | 198 for (i = 0; bootstrap[i]; ++i) { |
199 if (driver_name != NULL) { | 199 if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) { |
200 for (i = 0; bootstrap[i]; ++i) { | 200 if (bootstrap[i]->available()) { |
201 if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) { | 201 video = bootstrap[i]->create(index); |
202 if (bootstrap[i]->available()) { | 202 } |
203 video = bootstrap[i]->create(index); | 203 break; |
204 } | 204 } |
205 break; | 205 } |
206 } | 206 } else { |
207 } | 207 for (i = 0; bootstrap[i]; ++i) { |
208 } else { | 208 if (bootstrap[i]->available()) { |
209 for (i = 0; bootstrap[i]; ++i) { | 209 video = bootstrap[i]->create(index); |
210 if (bootstrap[i]->available()) { | 210 if (video != NULL) { |
211 video = bootstrap[i]->create(index); | 211 break; |
212 if (video != NULL) { | 212 } |
213 break; | 213 } |
214 } | 214 } |
215 } | 215 } |
216 } | 216 if (video == NULL) { |
217 } | 217 if (driver_name) { |
218 if (video == NULL) { | 218 SDL_SetError("%s not available", driver_name); |
219 if (driver_name) { | 219 } else { |
220 SDL_SetError("%s not available", driver_name); | 220 SDL_SetError("No available video device"); |
221 } else { | 221 } |
222 SDL_SetError("No available video device"); | 222 return -1; |
223 } | 223 } |
224 return -1; | 224 _this = video; |
225 } | 225 _this->name = bootstrap[i]->name; |
226 _this = video; | 226 _this->next_object_id = 1; |
227 _this->name = bootstrap[i]->name; | 227 |
228 _this->next_object_id = 1; | 228 |
229 | 229 /* Set some very sane GL defaults */ |
230 | 230 _this->gl_config.driver_loaded = 0; |
231 /* Set some very sane GL defaults */ | 231 _this->gl_config.dll_handle = NULL; |
232 _this->gl_config.driver_loaded = 0; | 232 _this->gl_config.red_size = 3; |
233 _this->gl_config.dll_handle = NULL; | 233 _this->gl_config.green_size = 3; |
234 _this->gl_config.red_size = 3; | 234 _this->gl_config.blue_size = 2; |
235 _this->gl_config.green_size = 3; | 235 _this->gl_config.alpha_size = 0; |
236 _this->gl_config.blue_size = 2; | 236 _this->gl_config.buffer_size = 0; |
237 _this->gl_config.alpha_size = 0; | 237 _this->gl_config.depth_size = 16; |
238 _this->gl_config.buffer_size = 0; | 238 _this->gl_config.stencil_size = 0; |
239 _this->gl_config.depth_size = 16; | 239 _this->gl_config.double_buffer = 1; |
240 _this->gl_config.stencil_size = 0; | 240 _this->gl_config.accum_red_size = 0; |
241 _this->gl_config.double_buffer = 1; | 241 _this->gl_config.accum_green_size = 0; |
242 _this->gl_config.accum_red_size = 0; | 242 _this->gl_config.accum_blue_size = 0; |
243 _this->gl_config.accum_green_size = 0; | 243 _this->gl_config.accum_alpha_size = 0; |
244 _this->gl_config.accum_blue_size = 0; | 244 _this->gl_config.stereo = 0; |
245 _this->gl_config.accum_alpha_size = 0; | 245 _this->gl_config.multisamplebuffers = 0; |
246 _this->gl_config.stereo = 0; | 246 _this->gl_config.multisamplesamples = 0; |
247 _this->gl_config.multisamplebuffers = 0; | 247 _this->gl_config.accelerated = -1; /* not known, don't set */ |
248 _this->gl_config.multisamplesamples = 0; | 248 |
249 _this->gl_config.accelerated = -1; /* not known, don't set */ | 249 /* Initialize the video subsystem */ |
250 | 250 if (_this->VideoInit(_this) < 0) { |
251 /* Initialize the video subsystem */ | 251 SDL_VideoQuit(); |
252 if (_this->VideoInit(_this) < 0) { | 252 return -1; |
253 SDL_VideoQuit(); | 253 } |
254 return -1; | 254 /* Make sure some displays were added */ |
255 } | 255 if (_this->num_displays == 0) { |
256 | 256 SDL_SetError("The video driver did not add any displays"); |
257 /* Make sure some displays were added */ | 257 SDL_VideoQuit(); |
258 if (_this->num_displays == 0) { | 258 return (-1); |
259 SDL_SetError("The video driver did not add any displays"); | 259 } |
260 SDL_VideoQuit(); | 260 /* The software renderer is always available */ |
261 return (-1); | 261 for (i = 0; i < _this->num_displays; ++i) { |
262 } | |
263 | |
264 /* The software renderer is always available */ | |
265 for (i = 0; i < _this->num_displays; ++i) { | |
266 #if SDL_VIDEO_RENDER_OGL | 262 #if SDL_VIDEO_RENDER_OGL |
267 SDL_AddRenderDriver(i, &GL_RenderDriver); | 263 SDL_AddRenderDriver(i, &GL_RenderDriver); |
268 #endif | 264 #endif |
269 if (_this->displays[i].num_render_drivers > 0) { | 265 if (_this->displays[i].num_render_drivers > 0) { |
270 SDL_AddRenderDriver(i, &SW_RenderDriver); | 266 SDL_AddRenderDriver(i, &SW_RenderDriver); |
271 } | 267 } |
272 } | 268 } |
273 | 269 |
274 /* We're ready to go! */ | 270 /* We're ready to go! */ |
275 return 0; | 271 return 0; |
276 } | 272 } |
277 | 273 |
278 const char * | 274 const char * |
279 SDL_GetCurrentVideoDriver() | 275 SDL_GetCurrentVideoDriver() |
280 { | 276 { |
281 if (!_this) { | 277 if (!_this) { |
282 SDL_UninitializedVideo(); | 278 SDL_UninitializedVideo(); |
283 return NULL; | 279 return NULL; |
284 } | 280 } |
285 return _this->name; | 281 return _this->name; |
286 } | 282 } |
287 | 283 |
288 SDL_VideoDevice * | 284 SDL_VideoDevice * |
289 SDL_GetVideoDevice() | 285 SDL_GetVideoDevice() |
290 { | 286 { |
291 return _this; | 287 return _this; |
292 } | 288 } |
293 | 289 |
294 int | 290 int |
295 SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode) | 291 SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode) |
296 { | 292 { |
297 SDL_VideoDisplay display; | 293 SDL_VideoDisplay display; |
298 | 294 |
299 SDL_zero(display); | 295 SDL_zero(display); |
300 if (desktop_mode) { | 296 if (desktop_mode) { |
301 display.desktop_mode = *desktop_mode; | 297 display.desktop_mode = *desktop_mode; |
302 } | 298 } |
303 display.current_mode = display.desktop_mode; | 299 display.current_mode = display.desktop_mode; |
304 | 300 |
305 return SDL_AddVideoDisplay(&display); | 301 return SDL_AddVideoDisplay(&display); |
306 } | 302 } |
307 | 303 |
308 int | 304 int |
309 SDL_AddVideoDisplay(const SDL_VideoDisplay * display) | 305 SDL_AddVideoDisplay(const SDL_VideoDisplay * display) |
310 { | 306 { |
311 SDL_VideoDisplay *displays; | 307 SDL_VideoDisplay *displays; |
312 int index = -1; | 308 int index = -1; |
313 | 309 |
314 displays = | 310 displays = |
315 SDL_realloc(_this->displays, | 311 SDL_realloc(_this->displays, |
316 (_this->num_displays + 1) * sizeof(*displays)); | 312 (_this->num_displays + 1) * sizeof(*displays)); |
317 if (displays) { | 313 if (displays) { |
318 index = _this->num_displays++; | 314 index = _this->num_displays++; |
319 displays[index] = *display; | 315 displays[index] = *display; |
320 displays[index].device = _this; | 316 displays[index].device = _this; |
321 _this->displays = displays; | 317 _this->displays = displays; |
322 } else { | 318 } else { |
323 SDL_OutOfMemory(); | 319 SDL_OutOfMemory(); |
324 } | 320 } |
325 return index; | 321 return index; |
326 } | 322 } |
327 | 323 |
328 int | 324 int |
329 SDL_GetNumVideoDisplays(void) | 325 SDL_GetNumVideoDisplays(void) |
330 { | 326 { |
331 if (!_this) { | 327 if (!_this) { |
332 SDL_UninitializedVideo(); | 328 SDL_UninitializedVideo(); |
333 return 0; | 329 return 0; |
334 } | 330 } |
335 return _this->num_displays; | 331 return _this->num_displays; |
336 } | 332 } |
337 | 333 |
338 int | 334 int |
339 SDL_SelectVideoDisplay(int index) | 335 SDL_SelectVideoDisplay(int index) |
340 { | 336 { |
341 if (!_this) { | 337 if (!_this) { |
342 SDL_UninitializedVideo(); | 338 SDL_UninitializedVideo(); |
343 return (-1); | 339 return (-1); |
344 } | 340 } |
345 if (index < 0 || index >= _this->num_displays) { | 341 if (index < 0 || index >= _this->num_displays) { |
346 SDL_SetError("index must be in the range 0 - %d", | 342 SDL_SetError("index must be in the range 0 - %d", |
347 _this->num_displays - 1); | 343 _this->num_displays - 1); |
348 return -1; | 344 return -1; |
349 } | 345 } |
350 _this->current_display = index; | 346 _this->current_display = index; |
351 return 0; | 347 return 0; |
352 } | 348 } |
353 | 349 |
354 int | 350 int |
355 SDL_GetCurrentVideoDisplay(void) | 351 SDL_GetCurrentVideoDisplay(void) |
356 { | 352 { |
357 if (!_this) { | 353 if (!_this) { |
358 SDL_UninitializedVideo(); | 354 SDL_UninitializedVideo(); |
359 return (-1); | 355 return (-1); |
360 } | 356 } |
361 return _this->current_display; | 357 return _this->current_display; |
362 } | 358 } |
363 | 359 |
364 SDL_bool | 360 SDL_bool |
365 SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode) | 361 SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode) |
366 { | 362 { |
367 SDL_VideoDisplay *display = &_this->displays[displayIndex]; | 363 SDL_VideoDisplay *display = &_this->displays[displayIndex]; |
368 SDL_DisplayMode *modes; | 364 SDL_DisplayMode *modes; |
369 int i, nmodes; | 365 int i, nmodes; |
370 | 366 |
371 /* Make sure we don't already have the mode in the list */ | 367 /* Make sure we don't already have the mode in the list */ |
372 modes = display->display_modes; | 368 modes = display->display_modes; |
373 nmodes = display->num_display_modes; | 369 nmodes = display->num_display_modes; |
374 for (i = nmodes; i--;) { | 370 for (i = nmodes; i--;) { |
375 if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) { | 371 if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) { |
376 return SDL_FALSE; | 372 return SDL_FALSE; |
377 } | 373 } |
378 } | 374 } |
379 | 375 |
380 /* Go ahead and add the new mode */ | 376 /* Go ahead and add the new mode */ |
381 if (nmodes == display->max_display_modes) { | 377 if (nmodes == display->max_display_modes) { |
382 modes = | 378 modes = |
383 SDL_realloc(modes, | 379 SDL_realloc(modes, |
384 (display->max_display_modes + 32) * sizeof(*modes)); | 380 (display->max_display_modes + 32) * sizeof(*modes)); |
385 if (!modes) { | 381 if (!modes) { |
386 return SDL_FALSE; | 382 return SDL_FALSE; |
387 } | 383 } |
388 display->display_modes = modes; | 384 display->display_modes = modes; |
389 display->max_display_modes += 32; | 385 display->max_display_modes += 32; |
390 } | 386 } |
391 modes[nmodes] = *mode; | 387 modes[nmodes] = *mode; |
392 display->num_display_modes++; | 388 display->num_display_modes++; |
393 | 389 |
394 return SDL_TRUE; | 390 return SDL_TRUE; |
395 } | 391 } |
396 | 392 |
397 int | 393 int |
398 SDL_GetNumDisplayModes() | 394 SDL_GetNumDisplayModes() |
399 { | 395 { |
400 if (_this) { | 396 if (_this) { |
401 SDL_VideoDisplay *display = &SDL_CurrentDisplay; | 397 SDL_VideoDisplay *display = &SDL_CurrentDisplay; |
402 if (!display->num_display_modes && _this->GetDisplayModes) { | 398 if (!display->num_display_modes && _this->GetDisplayModes) { |
403 _this->GetDisplayModes(_this); | 399 _this->GetDisplayModes(_this); |
404 SDL_qsort(display->display_modes, display->num_display_modes, | 400 SDL_qsort(display->display_modes, display->num_display_modes, |
405 sizeof(SDL_DisplayMode), cmpmodes); | 401 sizeof(SDL_DisplayMode), cmpmodes); |
406 } | 402 } |
407 return display->num_display_modes; | 403 return display->num_display_modes; |
408 } | 404 } |
409 return 0; | 405 return 0; |
410 } | 406 } |
411 | 407 |
412 int | 408 int |
413 SDL_GetDisplayMode(int index, SDL_DisplayMode * mode) | 409 SDL_GetDisplayMode(int index, SDL_DisplayMode * mode) |
414 { | 410 { |
415 if (index < 0 || index >= SDL_GetNumDisplayModes()) { | 411 if (index < 0 || index >= SDL_GetNumDisplayModes()) { |
416 SDL_SetError("index must be in the range of 0 - %d", | 412 SDL_SetError("index must be in the range of 0 - %d", |
417 SDL_GetNumDisplayModes() - 1); | 413 SDL_GetNumDisplayModes() - 1); |
418 return -1; | 414 return -1; |
419 } | 415 } |
420 if (mode) { | 416 if (mode) { |
421 *mode = SDL_CurrentDisplay.display_modes[index]; | 417 *mode = SDL_CurrentDisplay.display_modes[index]; |
422 } | 418 } |
423 return 0; | 419 return 0; |
424 } | 420 } |
425 | 421 |
426 int | 422 int |
427 SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode) | 423 SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode) |
428 { | 424 { |
429 if (!_this) { | 425 if (!_this) { |
430 SDL_UninitializedVideo(); | 426 SDL_UninitializedVideo(); |
431 return -1; | 427 return -1; |
432 } | 428 } |
433 if (mode) { | 429 if (mode) { |
434 *mode = SDL_CurrentDisplay.desktop_mode; | 430 *mode = SDL_CurrentDisplay.desktop_mode; |
435 } | 431 } |
436 return 0; | 432 return 0; |
437 } | 433 } |
438 | 434 |
439 int | 435 int |
440 SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode) | 436 SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode) |
441 { | 437 { |
442 if (!_this) { | 438 if (!_this) { |
443 SDL_UninitializedVideo(); | 439 SDL_UninitializedVideo(); |
444 return -1; | 440 return -1; |
445 } | 441 } |
446 if (mode) { | 442 if (mode) { |
447 *mode = SDL_CurrentDisplay.current_mode; | 443 *mode = SDL_CurrentDisplay.current_mode; |
448 } | 444 } |
449 return 0; | 445 return 0; |
450 } | 446 } |
451 | 447 |
452 SDL_DisplayMode * | 448 SDL_DisplayMode * |
453 SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode, | 449 SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode, |
454 SDL_DisplayMode * closest) | 450 SDL_DisplayMode * closest) |
455 { | 451 { |
456 Uint32 target_format; | 452 Uint32 target_format; |
457 int target_refresh_rate; | 453 int target_refresh_rate; |
458 int i; | 454 int i; |
459 SDL_DisplayMode *current, *match; | 455 SDL_DisplayMode *current, *match; |
460 | 456 |
461 if (!_this || !mode || !closest) { | 457 if (!_this || !mode || !closest) { |
462 return NULL; | 458 return NULL; |
463 } | 459 } |
464 | 460 /* Default to the desktop format */ |
465 /* Default to the desktop format */ | 461 if (mode->format) { |
466 if (mode->format) { | 462 target_format = mode->format; |
467 target_format = mode->format; | 463 } else { |
468 } else { | 464 target_format = SDL_CurrentDisplay.desktop_mode.format; |
469 target_format = SDL_CurrentDisplay.desktop_mode.format; | 465 } |
470 } | 466 |
471 | 467 /* Default to the desktop refresh rate */ |
472 /* Default to the desktop refresh rate */ | 468 if (mode->refresh_rate) { |
473 if (mode->refresh_rate) { | 469 target_refresh_rate = mode->refresh_rate; |
474 target_refresh_rate = mode->refresh_rate; | 470 } else { |
475 } else { | 471 target_refresh_rate = SDL_CurrentDisplay.desktop_mode.refresh_rate; |
476 target_refresh_rate = SDL_CurrentDisplay.desktop_mode.refresh_rate; | 472 } |
477 } | 473 |
478 | 474 match = NULL; |
479 match = NULL; | 475 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { |
480 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { | 476 current = &SDL_CurrentDisplay.display_modes[i]; |
481 current = &SDL_CurrentDisplay.display_modes[i]; | 477 |
482 | 478 if ((current->w && current->h) && |
483 if ((current->w && current->h) && | 479 (current->w < mode->w || current->h < mode->h)) { |
484 (current->w < mode->w || current->h < mode->h)) { | 480 /* Out of sorted modes large enough here */ |
485 /* Out of sorted modes large enough here */ | 481 break; |
486 break; | 482 } |
487 } | 483 if (!match || current->w < match->w || current->h < match->h) { |
488 if (!match || current->w < match->w || current->h < match->h) { | 484 match = current; |
489 match = current; | 485 continue; |
490 continue; | 486 } |
491 } | 487 if (current->format != match->format) { |
492 if (current->format != match->format) { | 488 /* Sorted highest depth to lowest */ |
493 /* Sorted highest depth to lowest */ | 489 if (current->format == target_format || |
494 if (current->format == target_format || | 490 (SDL_BITSPERPIXEL(current->format) >= |
495 (SDL_BITSPERPIXEL(current->format) >= | 491 SDL_BITSPERPIXEL(target_format) |
496 SDL_BITSPERPIXEL(target_format) | 492 && SDL_PIXELTYPE(current->format) == |
497 && SDL_PIXELTYPE(current->format) == | 493 SDL_PIXELTYPE(target_format))) { |
498 SDL_PIXELTYPE(target_format))) { | 494 match = current; |
499 match = current; | 495 } |
500 } | 496 continue; |
501 continue; | 497 } |
502 } | 498 if (current->refresh_rate != match->refresh_rate) { |
503 if (current->refresh_rate != match->refresh_rate) { | 499 /* Sorted highest refresh to lowest */ |
504 /* Sorted highest refresh to lowest */ | 500 if (current->refresh_rate >= target_refresh_rate) { |
505 if (current->refresh_rate >= target_refresh_rate) { | 501 match = current; |
506 match = current; | 502 } |
507 } | 503 } |
508 } | 504 } |
509 } | 505 if (match) { |
510 if (match) { | 506 if (match->format) { |
511 if (match->format) { | 507 closest->format = match->format; |
512 closest->format = match->format; | 508 } else { |
513 } else { | 509 closest->format = mode->format; |
514 closest->format = mode->format; | 510 } |
515 } | 511 if (match->w && match->h) { |
516 if (match->w && match->h) { | 512 closest->w = match->w; |
517 closest->w = match->w; | 513 closest->h = match->h; |
518 closest->h = match->h; | 514 } else { |
519 } else { | 515 closest->w = mode->w; |
520 closest->w = mode->w; | 516 closest->h = mode->h; |
521 closest->h = mode->h; | 517 } |
522 } | 518 if (match->refresh_rate) { |
523 if (match->refresh_rate) { | 519 closest->refresh_rate = match->refresh_rate; |
524 closest->refresh_rate = match->refresh_rate; | 520 } else { |
525 } else { | 521 closest->refresh_rate = mode->refresh_rate; |
526 closest->refresh_rate = mode->refresh_rate; | 522 } |
527 } | 523 closest->driverdata = match->driverdata; |
528 closest->driverdata = match->driverdata; | 524 |
529 | 525 /* |
530 /* Pick some reasonable defaults if the app and driver don't care */ | 526 * Pick some reasonable defaults if the app and driver don't |
531 if (!closest->format) { | 527 * care |
532 closest->format = SDL_PIXELFORMAT_RGB888; | 528 */ |
533 } | 529 if (!closest->format) { |
534 if (!closest->w) { | 530 closest->format = SDL_PIXELFORMAT_RGB888; |
535 closest->w = 640; | 531 } |
536 } | 532 if (!closest->w) { |
537 if (!closest->h) { | 533 closest->w = 640; |
538 closest->h = 480; | 534 } |
539 } | 535 if (!closest->h) { |
540 return closest; | 536 closest->h = 480; |
541 } | 537 } |
542 return NULL; | 538 return closest; |
539 } | |
540 return NULL; | |
543 } | 541 } |
544 | 542 |
545 int | 543 int |
546 SDL_SetDisplayMode(const SDL_DisplayMode * mode) | 544 SDL_SetDisplayMode(const SDL_DisplayMode * mode) |
547 { | 545 { |
548 SDL_VideoDisplay *display; | 546 SDL_VideoDisplay *display; |
549 SDL_DisplayMode display_mode; | 547 SDL_DisplayMode display_mode; |
550 SDL_DisplayMode current_mode; | 548 SDL_DisplayMode current_mode; |
551 int i, ncolors; | 549 int i, ncolors; |
552 | 550 |
553 if (!_this) { | 551 if (!_this) { |
554 SDL_UninitializedVideo(); | 552 SDL_UninitializedVideo(); |
555 return -1; | 553 return -1; |
556 } | 554 } |
557 | 555 display = &SDL_CurrentDisplay; |
558 display = &SDL_CurrentDisplay; | 556 if (!mode) { |
559 if (!mode) { | 557 mode = &display->desktop_mode; |
560 mode = &display->desktop_mode; | 558 } |
561 } | 559 display_mode = *mode; |
562 display_mode = *mode; | 560 |
563 | 561 /* Default to the current mode */ |
564 /* Default to the current mode */ | 562 if (!display_mode.format) { |
565 if (!display_mode.format) { | 563 display_mode.format = display->current_mode.format; |
566 display_mode.format = display->current_mode.format; | 564 } |
567 } | 565 if (!display_mode.w) { |
568 if (!display_mode.w) { | 566 display_mode.w = display->current_mode.w; |
569 display_mode.w = display->current_mode.w; | 567 } |
570 } | 568 if (!display_mode.h) { |
571 if (!display_mode.h) { | 569 display_mode.h = display->current_mode.h; |
572 display_mode.h = display->current_mode.h; | 570 } |
573 } | 571 if (!display_mode.refresh_rate) { |
574 if (!display_mode.refresh_rate) { | 572 display_mode.refresh_rate = display->current_mode.refresh_rate; |
575 display_mode.refresh_rate = display->current_mode.refresh_rate; | 573 } |
576 } | 574 /* Get a good video mode, the closest one possible */ |
577 | 575 if (!SDL_GetClosestDisplayMode(&display_mode, &display_mode)) { |
578 /* Get a good video mode, the closest one possible */ | 576 SDL_SetError("No video mode large enough for %dx%d", |
579 if (!SDL_GetClosestDisplayMode(&display_mode, &display_mode)) { | 577 display_mode.w, display_mode.h); |
580 SDL_SetError("No video mode large enough for %dx%d", | 578 return -1; |
581 display_mode.w, display_mode.h); | 579 } |
582 return -1; | 580 /* See if there's anything left to do */ |
583 } | 581 SDL_GetCurrentDisplayMode(¤t_mode); |
584 | 582 if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) { |
585 /* See if there's anything left to do */ | 583 return 0; |
586 SDL_GetCurrentDisplayMode(¤t_mode); | 584 } |
587 if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) { | 585 /* Actually change the display mode */ |
588 return 0; | 586 if (_this->SetDisplayMode(_this, &display_mode) < 0) { |
589 } | 587 return -1; |
590 | 588 } |
591 /* Actually change the display mode */ | 589 display->current_mode = display_mode; |
592 if (_this->SetDisplayMode(_this, &display_mode) < 0) { | 590 |
593 return -1; | 591 /* Set up a palette, if necessary */ |
594 } | 592 if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) { |
595 display->current_mode = display_mode; | 593 ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format)); |
596 | 594 } else { |
597 /* Set up a palette, if necessary */ | 595 ncolors = 0; |
598 if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) { | 596 } |
599 ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format)); | 597 if ((!ncolors && display->palette) || (ncolors && !display->palette) |
600 } else { | 598 || (ncolors && ncolors != display->palette->ncolors)) { |
601 ncolors = 0; | 599 if (display->palette) { |
602 } | 600 SDL_FreePalette(display->palette); |
603 if ((!ncolors && display->palette) || (ncolors && !display->palette) | 601 display->palette = NULL; |
604 || (ncolors && ncolors != display->palette->ncolors)) { | 602 } |
605 if (display->palette) { | 603 if (ncolors) { |
606 SDL_FreePalette(display->palette); | 604 display->palette = SDL_AllocPalette(ncolors); |
607 display->palette = NULL; | 605 if (!display->palette) { |
608 } | 606 return -1; |
609 if (ncolors) { | 607 } |
610 display->palette = SDL_AllocPalette(ncolors); | 608 SDL_DitherColors(display->palette->colors, |
611 if (!display->palette) { | 609 SDL_BITSPERPIXEL(display_mode.format)); |
612 return -1; | 610 } |
613 } | 611 } |
614 SDL_DitherColors(display->palette->colors, | 612 /* Move any fullscreen windows into position */ |
615 SDL_BITSPERPIXEL(display_mode.format)); | 613 for (i = 0; i < display->num_windows; ++i) { |
616 } | 614 SDL_Window *window = &display->windows[i]; |
617 } | 615 if (FULLSCREEN_VISIBLE(window)) { |
618 | 616 SDL_SetWindowPosition(window->id, SDL_WINDOWPOS_CENTERED, |
619 /* Move any fullscreen windows into position */ | 617 SDL_WINDOWPOS_CENTERED); |
620 for (i = 0; i < display->num_windows; ++i) { | 618 } |
621 SDL_Window *window = &display->windows[i]; | 619 } |
622 if (FULLSCREEN_VISIBLE(window)) { | 620 |
623 SDL_SetWindowPosition(window->id, SDL_WINDOWPOS_CENTERED, | 621 return 0; |
624 SDL_WINDOWPOS_CENTERED); | |
625 } | |
626 } | |
627 | |
628 return 0; | |
629 } | 622 } |
630 | 623 |
631 int | 624 int |
632 SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode) | 625 SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode) |
633 { | 626 { |
634 SDL_VideoDisplay *display; | 627 SDL_VideoDisplay *display; |
635 SDL_DisplayMode fullscreen_mode; | 628 SDL_DisplayMode fullscreen_mode; |
636 int i; | 629 int i; |
637 | 630 |
638 if (!_this) { | 631 if (!_this) { |
639 SDL_UninitializedVideo(); | 632 SDL_UninitializedVideo(); |
640 return -1; | 633 return -1; |
641 } | 634 } |
642 | 635 display = &SDL_CurrentDisplay; |
643 display = &SDL_CurrentDisplay; | 636 if (!mode) { |
644 if (!mode) { | 637 mode = &display->desktop_mode; |
645 mode = &display->desktop_mode; | 638 } |
646 } | 639 SDL_GetClosestDisplayMode(mode, &fullscreen_mode); |
647 | 640 if (SDL_memcmp |
648 SDL_GetClosestDisplayMode(mode, &fullscreen_mode); | 641 (&fullscreen_mode, &display->fullscreen_mode, |
649 if (SDL_memcmp | 642 sizeof(fullscreen_mode)) == 0) { |
650 (&fullscreen_mode, &display->fullscreen_mode, | 643 /* Nothing to do... */ |
651 sizeof(fullscreen_mode)) == 0) { | 644 return 0; |
652 /* Nothing to do... */ | 645 } |
653 return 0; | 646 display->fullscreen_mode = fullscreen_mode; |
654 } | 647 |
655 display->fullscreen_mode = fullscreen_mode; | 648 /* Actually set the mode if we have a fullscreen window visible */ |
656 | 649 for (i = 0; i < display->num_windows; ++i) { |
657 /* Actually set the mode if we have a fullscreen window visible */ | 650 SDL_Window *window = &display->windows[i]; |
658 for (i = 0; i < display->num_windows; ++i) { | 651 if (FULLSCREEN_VISIBLE(window)) { |
659 SDL_Window *window = &display->windows[i]; | 652 if (SDL_SetDisplayMode(&display->fullscreen_mode) < 0) { |
660 if (FULLSCREEN_VISIBLE(window)) { | 653 return -1; |
661 if (SDL_SetDisplayMode(&display->fullscreen_mode) < 0) { | 654 } |
662 return -1; | 655 } |
663 } | 656 if (window->flags & SDL_WINDOW_FULLSCREEN) { |
664 } | 657 SDL_OnWindowResized(window); |
665 if (window->flags & SDL_WINDOW_FULLSCREEN) { | 658 } |
666 SDL_OnWindowResized(window); | 659 } |
667 } | 660 return 0; |
668 } | |
669 return 0; | |
670 } | 661 } |
671 | 662 |
672 int | 663 int |
673 SDL_GetFullscreenDisplayMode(SDL_DisplayMode * mode) | 664 SDL_GetFullscreenDisplayMode(SDL_DisplayMode * mode) |
674 { | 665 { |
675 if (!_this) { | 666 if (!_this) { |
676 SDL_UninitializedVideo(); | 667 SDL_UninitializedVideo(); |
677 return -1; | 668 return -1; |
678 } | 669 } |
679 if (mode) { | 670 if (mode) { |
680 *mode = SDL_CurrentDisplay.fullscreen_mode; | 671 *mode = SDL_CurrentDisplay.fullscreen_mode; |
681 } | 672 } |
682 return 0; | 673 return 0; |
683 } | 674 } |
684 | 675 |
685 int | 676 int |
686 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors) | 677 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors) |
687 { | 678 { |
688 SDL_Palette *palette; | 679 SDL_Palette *palette; |
689 int status = 0; | 680 int status = 0; |
690 | 681 |
691 if (!_this) { | 682 if (!_this) { |
692 SDL_UninitializedVideo(); | 683 SDL_UninitializedVideo(); |
693 return -1; | 684 return -1; |
694 } | 685 } |
695 palette = SDL_CurrentDisplay.palette; | 686 palette = SDL_CurrentDisplay.palette; |
696 if (!palette) { | 687 if (!palette) { |
697 SDL_SetError("Display mode does not have a palette"); | 688 SDL_SetError("Display mode does not have a palette"); |
698 return -1; | 689 return -1; |
699 } | 690 } |
700 | 691 status = SDL_SetPaletteColors(palette, colors, firstcolor, ncolors); |
701 status = SDL_SetPaletteColors(palette, colors, firstcolor, ncolors); | 692 |
702 | 693 if (_this->SetDisplayPalette) { |
703 if (_this->SetDisplayPalette) { | 694 if (_this->SetDisplayPalette(_this, palette) < 0) { |
704 if (_this->SetDisplayPalette(_this, palette) < 0) { | 695 status = -1; |
705 status = -1; | 696 } |
706 } | 697 } |
707 } | 698 return status; |
708 return status; | |
709 } | 699 } |
710 | 700 |
711 int | 701 int |
712 SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) | 702 SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) |
713 { | 703 { |
714 SDL_Palette *palette; | 704 SDL_Palette *palette; |
715 | 705 |
716 if (!_this) { | 706 if (!_this) { |
717 SDL_UninitializedVideo(); | 707 SDL_UninitializedVideo(); |
718 return -1; | 708 return -1; |
719 } | 709 } |
720 | 710 palette = SDL_CurrentDisplay.palette; |
721 palette = SDL_CurrentDisplay.palette; | 711 if (!palette->ncolors) { |
722 if (!palette->ncolors) { | 712 SDL_SetError("Display mode does not have a palette"); |
723 SDL_SetError("Display mode does not have a palette"); | 713 return -1; |
724 return -1; | 714 } |
725 } | 715 if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) { |
726 | 716 SDL_SetError("Palette indices are out of range"); |
727 if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) { | 717 return -1; |
728 SDL_SetError("Palette indices are out of range"); | 718 } |
729 return -1; | 719 SDL_memcpy(colors, &palette->colors[firstcolor], |
730 } | 720 ncolors * sizeof(*colors)); |
731 | 721 return 0; |
732 SDL_memcpy(colors, &palette->colors[firstcolor], | |
733 ncolors * sizeof(*colors)); | |
734 return 0; | |
735 } | 722 } |
736 | 723 |
737 SDL_WindowID | 724 SDL_WindowID |
738 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) | 725 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) |
739 { | 726 { |
740 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | | 727 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | |
741 SDL_WINDOW_OPENGL | | 728 SDL_WINDOW_OPENGL | |
742 SDL_WINDOW_BORDERLESS | | 729 SDL_WINDOW_BORDERLESS | |
743 SDL_WINDOW_RESIZABLE); | 730 SDL_WINDOW_RESIZABLE); |
744 SDL_VideoDisplay *display; | 731 SDL_VideoDisplay *display; |
745 SDL_Window window; | 732 SDL_Window window; |
746 int num_windows; | 733 int num_windows; |
747 SDL_Window *windows; | 734 SDL_Window *windows; |
748 | 735 |
749 if (!_this) { | 736 if (!_this) { |
750 SDL_UninitializedVideo(); | 737 SDL_UninitializedVideo(); |
751 return 0; | 738 return 0; |
752 } | 739 } |
753 | 740 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { |
754 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { | 741 SDL_SetError("No OpenGL support in video driver"); |
755 SDL_SetError("No OpenGL support in video driver"); | 742 return 0; |
756 return 0; | 743 } |
757 } | 744 /* Fullscreen windows don't have any window decorations */ |
758 | 745 if (flags & SDL_WINDOW_FULLSCREEN) { |
759 /* Fullscreen windows don't have any window decorations */ | 746 flags |= SDL_WINDOW_BORDERLESS; |
760 if (flags & SDL_WINDOW_FULLSCREEN) { | 747 flags &= ~SDL_WINDOW_RESIZABLE; |
761 flags |= SDL_WINDOW_BORDERLESS; | 748 } |
762 flags &= ~SDL_WINDOW_RESIZABLE; | 749 SDL_zero(window); |
763 } | 750 window.id = _this->next_object_id++; |
764 | 751 window.x = x; |
765 SDL_zero(window); | 752 window.y = y; |
766 window.id = _this->next_object_id++; | 753 window.w = w; |
767 window.x = x; | 754 window.h = h; |
768 window.y = y; | 755 window.flags = (flags & allowed_flags); |
769 window.w = w; | 756 window.display = _this->current_display; |
770 window.h = h; | 757 |
771 window.flags = (flags & allowed_flags); | 758 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { |
772 window.display = _this->current_display; | 759 return 0; |
773 | 760 } |
774 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { | 761 display = &SDL_CurrentDisplay; |
775 return 0; | 762 num_windows = display->num_windows; |
776 } | 763 windows = |
777 | 764 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); |
778 display = &SDL_CurrentDisplay; | 765 if (!windows) { |
779 num_windows = display->num_windows; | 766 if (_this->DestroyWindow) { |
780 windows = | 767 _this->DestroyWindow(_this, &window); |
781 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); | 768 } |
782 if (!windows) { | 769 return 0; |
783 if (_this->DestroyWindow) { | 770 } |
784 _this->DestroyWindow(_this, &window); | 771 windows[num_windows] = window; |
785 } | 772 display->windows = windows; |
786 return 0; | 773 display->num_windows++; |
787 } | 774 |
788 windows[num_windows] = window; | 775 if (title) { |
789 display->windows = windows; | 776 SDL_SetWindowTitle(window.id, title); |
790 display->num_windows++; | 777 } |
791 | 778 if (flags & SDL_WINDOW_MAXIMIZED) { |
792 if (title) { | 779 SDL_MaximizeWindow(window.id); |
793 SDL_SetWindowTitle(window.id, title); | 780 } |
794 } | 781 if (flags & SDL_WINDOW_MINIMIZED) { |
795 if (flags & SDL_WINDOW_MAXIMIZED) { | 782 SDL_MinimizeWindow(window.id); |
796 SDL_MaximizeWindow(window.id); | 783 } |
797 } | 784 if (flags & SDL_WINDOW_SHOWN) { |
798 if (flags & SDL_WINDOW_MINIMIZED) { | 785 SDL_ShowWindow(window.id); |
799 SDL_MinimizeWindow(window.id); | 786 } |
800 } | 787 if (flags & SDL_WINDOW_INPUT_GRABBED) { |
801 if (flags & SDL_WINDOW_SHOWN) { | 788 SDL_SetWindowGrab(window.id, 1); |
802 SDL_ShowWindow(window.id); | 789 } |
803 } | 790 return window.id; |
804 if (flags & SDL_WINDOW_INPUT_GRABBED) { | |
805 SDL_SetWindowGrab(window.id, 1); | |
806 } | |
807 return window.id; | |
808 } | 791 } |
809 | 792 |
810 SDL_WindowID | 793 SDL_WindowID |
811 SDL_CreateWindowFrom(const void *data) | 794 SDL_CreateWindowFrom(const void *data) |
812 { | 795 { |
813 SDL_VideoDisplay *display; | 796 SDL_VideoDisplay *display; |
814 SDL_Window window; | 797 SDL_Window window; |
815 int num_windows; | 798 int num_windows; |
816 SDL_Window *windows; | 799 SDL_Window *windows; |
817 | 800 |
818 if (!_this) { | 801 if (!_this) { |
819 SDL_UninitializedVideo(); | 802 SDL_UninitializedVideo(); |
820 return (0); | 803 return (0); |
821 } | 804 } |
822 | 805 SDL_zero(window); |
823 SDL_zero(window); | 806 window.id = _this->next_object_id++; |
824 window.id = _this->next_object_id++; | 807 window.display = _this->current_display; |
825 window.display = _this->current_display; | 808 |
826 | 809 if (!_this->CreateWindowFrom || |
827 if (!_this->CreateWindowFrom || | 810 _this->CreateWindowFrom(_this, &window, data) < 0) { |
828 _this->CreateWindowFrom(_this, &window, data) < 0) { | 811 return 0; |
829 return 0; | 812 } |
830 } | 813 display = &SDL_CurrentDisplay; |
831 | 814 num_windows = display->num_windows; |
832 display = &SDL_CurrentDisplay; | 815 windows = |
833 num_windows = display->num_windows; | 816 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); |
834 windows = | 817 if (!windows) { |
835 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); | 818 if (_this->DestroyWindow) { |
836 if (!windows) { | 819 _this->DestroyWindow(_this, &window); |
837 if (_this->DestroyWindow) { | 820 } |
838 _this->DestroyWindow(_this, &window); | 821 if (window.title) { |
839 } | 822 SDL_free(window.title); |
840 if (window.title) { | 823 } |
841 SDL_free(window.title); | 824 return 0; |
842 } | 825 } |
843 return 0; | 826 windows[num_windows] = window; |
844 } | 827 display->windows = windows; |
845 windows[num_windows] = window; | 828 display->num_windows++; |
846 display->windows = windows; | 829 |
847 display->num_windows++; | 830 return window.id; |
848 | |
849 return window.id; | |
850 } | 831 } |
851 | 832 |
852 int | 833 int |
853 SDL_RecreateWindow(SDL_Window * window, Uint32 flags) | 834 SDL_RecreateWindow(SDL_Window * window, Uint32 flags) |
854 { | 835 { |
855 char *title = window->title; | 836 char *title = window->title; |
856 | 837 |
857 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { | 838 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { |
858 SDL_SetError("No OpenGL support in video driver"); | 839 SDL_SetError("No OpenGL support in video driver"); |
859 return -1; | 840 return -1; |
860 } | 841 } |
861 | 842 if (_this->DestroyWindow) { |
862 if (_this->DestroyWindow) { | 843 _this->DestroyWindow(_this, window); |
863 _this->DestroyWindow(_this, window); | 844 } |
864 } | 845 window->title = NULL; |
865 | 846 window->flags = |
866 window->title = NULL; | 847 (flags & |
867 window->flags = | 848 ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_SHOWN | |
868 (flags & | 849 SDL_WINDOW_INPUT_GRABBED)); |
869 ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_SHOWN | | 850 |
870 SDL_WINDOW_INPUT_GRABBED)); | 851 if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) { |
871 | 852 return -1; |
872 if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) { | 853 } |
873 return -1; | 854 if (title) { |
874 } | 855 SDL_SetWindowTitle(window->id, title); |
875 | 856 SDL_free(title); |
876 if (title) { | 857 } |
877 SDL_SetWindowTitle(window->id, title); | 858 if (flags & SDL_WINDOW_MAXIMIZED) { |
878 SDL_free(title); | 859 SDL_MaximizeWindow(window->id); |
879 } | 860 } |
880 if (flags & SDL_WINDOW_MAXIMIZED) { | 861 if (flags & SDL_WINDOW_MINIMIZED) { |
881 SDL_MaximizeWindow(window->id); | 862 SDL_MinimizeWindow(window->id); |
882 } | 863 } |
883 if (flags & SDL_WINDOW_MINIMIZED) { | 864 if (flags & SDL_WINDOW_SHOWN) { |
884 SDL_MinimizeWindow(window->id); | 865 SDL_ShowWindow(window->id); |
885 } | 866 } |
886 if (flags & SDL_WINDOW_SHOWN) { | 867 if (flags & SDL_WINDOW_INPUT_GRABBED) { |
887 SDL_ShowWindow(window->id); | 868 SDL_SetWindowGrab(window->id, 1); |
888 } | 869 } |
889 if (flags & SDL_WINDOW_INPUT_GRABBED) { | 870 return 0; |
890 SDL_SetWindowGrab(window->id, 1); | 871 } |
891 } | 872 |
892 return 0; | 873 SDL_Window * |
893 } | |
894 | |
895 SDL_Window * | |
896 SDL_GetWindowFromID(SDL_WindowID windowID) | 874 SDL_GetWindowFromID(SDL_WindowID windowID) |
897 { | 875 { |
898 int i, j; | 876 int i, j; |
899 | 877 |
900 if (!_this) { | 878 if (!_this) { |
901 SDL_UninitializedVideo(); | 879 SDL_UninitializedVideo(); |
902 return NULL; | 880 return NULL; |
903 } | 881 } |
904 | 882 for (i = 0; i < _this->num_displays; ++i) { |
905 for (i = 0; i < _this->num_displays; ++i) { | 883 SDL_VideoDisplay *display = &_this->displays[i]; |
906 SDL_VideoDisplay *display = &_this->displays[i]; | 884 for (j = 0; j < display->num_windows; ++j) { |
907 for (j = 0; j < display->num_windows; ++j) { | 885 SDL_Window *window = &display->windows[j]; |
908 SDL_Window *window = &display->windows[j]; | 886 if (window->id == windowID) { |
909 if (window->id == windowID) { | 887 return window; |
910 return window; | 888 } |
911 } | 889 } |
912 } | 890 } |
913 } | 891 return NULL; |
914 return NULL; | |
915 } | 892 } |
916 | 893 |
917 SDL_VideoDisplay * | 894 SDL_VideoDisplay * |
918 SDL_GetDisplayFromWindow(SDL_Window * window) | 895 SDL_GetDisplayFromWindow(SDL_Window * window) |
919 { | 896 { |
920 if (!_this) { | 897 if (!_this) { |
921 SDL_UninitializedVideo(); | 898 SDL_UninitializedVideo(); |
922 return NULL; | 899 return NULL; |
923 } | 900 } |
924 if (!window) { | 901 if (!window) { |
925 return NULL; | 902 return NULL; |
926 } | 903 } |
927 return &_this->displays[window->display]; | 904 return &_this->displays[window->display]; |
928 } | 905 } |
929 | 906 |
930 Uint32 | 907 Uint32 |
931 SDL_GetWindowFlags(SDL_WindowID windowID) | 908 SDL_GetWindowFlags(SDL_WindowID windowID) |
932 { | 909 { |
933 SDL_Window *window = SDL_GetWindowFromID(windowID); | 910 SDL_Window *window = SDL_GetWindowFromID(windowID); |
934 | 911 |
935 if (!window) { | 912 if (!window) { |
936 return 0; | 913 return 0; |
937 } | 914 } |
938 return window->flags; | 915 return window->flags; |
939 } | 916 } |
940 | 917 |
941 void | 918 void |
942 SDL_SetWindowTitle(SDL_WindowID windowID, const char *title) | 919 SDL_SetWindowTitle(SDL_WindowID windowID, const char *title) |
943 { | 920 { |
944 SDL_Window *window = SDL_GetWindowFromID(windowID); | 921 SDL_Window *window = SDL_GetWindowFromID(windowID); |
945 | 922 |
946 if (!window || title == window->title) { | 923 if (!window || title == window->title) { |
947 return; | 924 return; |
948 } | 925 } |
949 | 926 if (window->title) { |
950 if (window->title) { | 927 SDL_free(window->title); |
951 SDL_free(window->title); | 928 } |
952 } | 929 if (title) { |
953 if (title) { | 930 window->title = SDL_strdup(title); |
954 window->title = SDL_strdup(title); | 931 } else { |
955 } else { | 932 window->title = NULL; |
956 window->title = NULL; | 933 } |
957 } | 934 |
958 | 935 if (_this->SetWindowTitle) { |
959 if (_this->SetWindowTitle) { | 936 _this->SetWindowTitle(_this, window); |
960 _this->SetWindowTitle(_this, window); | 937 } |
961 } | 938 } |
962 } | 939 |
963 | 940 const char * |
964 const char * | |
965 SDL_GetWindowTitle(SDL_WindowID windowID) | 941 SDL_GetWindowTitle(SDL_WindowID windowID) |
966 { | 942 { |
967 SDL_Window *window = SDL_GetWindowFromID(windowID); | 943 SDL_Window *window = SDL_GetWindowFromID(windowID); |
968 | 944 |
969 if (!window) { | 945 if (!window) { |
970 return NULL; | 946 return NULL; |
971 } | 947 } |
972 return window->title; | 948 return window->title; |
973 } | 949 } |
974 | 950 |
975 void | 951 void |
976 SDL_SetWindowData(SDL_WindowID windowID, void *userdata) | 952 SDL_SetWindowData(SDL_WindowID windowID, void *userdata) |
977 { | 953 { |
978 SDL_Window *window = SDL_GetWindowFromID(windowID); | 954 SDL_Window *window = SDL_GetWindowFromID(windowID); |
979 | 955 |
980 if (!window) { | 956 if (!window) { |
981 return; | 957 return; |
982 } | 958 } |
983 window->userdata = userdata; | 959 window->userdata = userdata; |
984 } | 960 } |
985 | 961 |
986 void * | 962 void * |
987 SDL_GetWindowData(SDL_WindowID windowID) | 963 SDL_GetWindowData(SDL_WindowID windowID) |
988 { | 964 { |
989 SDL_Window *window = SDL_GetWindowFromID(windowID); | 965 SDL_Window *window = SDL_GetWindowFromID(windowID); |
990 | 966 |
991 if (!window) { | 967 if (!window) { |
992 return NULL; | 968 return NULL; |
993 } | 969 } |
994 return window->userdata; | 970 return window->userdata; |
995 } | 971 } |
996 | 972 |
997 void | 973 void |
998 SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y) | 974 SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y) |
999 { | 975 { |
1000 SDL_Window *window = SDL_GetWindowFromID(windowID); | 976 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1001 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 977 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
1002 | 978 |
1003 if (!window) { | 979 if (!window) { |
1004 return; | 980 return; |
1005 } | 981 } |
1006 | 982 if (x == SDL_WINDOWPOS_CENTERED) { |
1007 if (x == SDL_WINDOWPOS_CENTERED) { | 983 window->x = (display->current_mode.w - window->w) / 2; |
1008 window->x = (display->current_mode.w - window->w) / 2; | 984 } else if (x != SDL_WINDOWPOS_UNDEFINED) { |
1009 } else if (x != SDL_WINDOWPOS_UNDEFINED) { | 985 window->x = x; |
1010 window->x = x; | 986 } |
1011 } | 987 if (y == SDL_WINDOWPOS_CENTERED) { |
1012 if (y == SDL_WINDOWPOS_CENTERED) { | 988 window->y = (display->current_mode.h - window->h) / 2; |
1013 window->y = (display->current_mode.h - window->h) / 2; | 989 } else if (y != SDL_WINDOWPOS_UNDEFINED) { |
1014 } else if (y != SDL_WINDOWPOS_UNDEFINED) { | 990 window->y = y; |
1015 window->y = y; | 991 } |
1016 } | 992 if (_this->SetWindowPosition) { |
1017 | 993 _this->SetWindowPosition(_this, window); |
1018 if (_this->SetWindowPosition) { | 994 } |
1019 _this->SetWindowPosition(_this, window); | |
1020 } | |
1021 } | 995 } |
1022 | 996 |
1023 void | 997 void |
1024 SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y) | 998 SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y) |
1025 { | 999 { |
1026 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1000 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1027 | 1001 |
1028 if (!window) { | 1002 if (!window) { |
1029 return; | 1003 return; |
1030 } | 1004 } |
1031 if (x) { | 1005 if (x) { |
1032 *x = window->x; | 1006 *x = window->x; |
1033 } | 1007 } |
1034 if (y) { | 1008 if (y) { |
1035 *y = window->y; | 1009 *y = window->y; |
1036 } | 1010 } |
1037 } | 1011 } |
1038 | 1012 |
1039 void | 1013 void |
1040 SDL_SetWindowSize(SDL_WindowID windowID, int w, int h) | 1014 SDL_SetWindowSize(SDL_WindowID windowID, int w, int h) |
1041 { | 1015 { |
1042 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1016 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1043 | 1017 |
1044 if (!window) { | 1018 if (!window) { |
1045 return; | 1019 return; |
1046 } | 1020 } |
1047 | 1021 window->w = w; |
1048 window->w = w; | 1022 window->h = h; |
1049 window->h = h; | 1023 |
1050 | 1024 if (_this->SetWindowSize) { |
1051 if (_this->SetWindowSize) { | 1025 _this->SetWindowSize(_this, window); |
1052 _this->SetWindowSize(_this, window); | 1026 } |
1053 } | |
1054 } | 1027 } |
1055 | 1028 |
1056 void | 1029 void |
1057 SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h) | 1030 SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h) |
1058 { | 1031 { |
1059 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1032 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1060 | 1033 |
1061 if (!window) { | 1034 if (!window) { |
1062 return; | 1035 return; |
1063 } | 1036 } |
1064 if (w) { | 1037 if (w) { |
1065 *w = window->w; | 1038 *w = window->w; |
1066 } | 1039 } |
1067 if (h) { | 1040 if (h) { |
1068 *h = window->h; | 1041 *h = window->h; |
1069 } | 1042 } |
1070 } | 1043 } |
1071 | 1044 |
1072 void | 1045 void |
1073 SDL_ShowWindow(SDL_WindowID windowID) | 1046 SDL_ShowWindow(SDL_WindowID windowID) |
1074 { | 1047 { |
1075 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1048 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1076 | 1049 |
1077 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { | 1050 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { |
1078 return; | 1051 return; |
1079 } | 1052 } |
1080 | 1053 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0); |
1081 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0); | 1054 |
1082 | 1055 if (_this->ShowWindow) { |
1083 if (_this->ShowWindow) { | 1056 _this->ShowWindow(_this, window); |
1084 _this->ShowWindow(_this, window); | 1057 } |
1085 } | |
1086 } | 1058 } |
1087 | 1059 |
1088 void | 1060 void |
1089 SDL_HideWindow(SDL_WindowID windowID) | 1061 SDL_HideWindow(SDL_WindowID windowID) |
1090 { | 1062 { |
1091 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1063 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1092 | 1064 |
1093 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { | 1065 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { |
1094 return; | 1066 return; |
1095 } | 1067 } |
1096 | 1068 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0); |
1097 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0); | 1069 |
1098 | 1070 if (_this->HideWindow) { |
1099 if (_this->HideWindow) { | 1071 _this->HideWindow(_this, window); |
1100 _this->HideWindow(_this, window); | 1072 } |
1101 } | |
1102 } | 1073 } |
1103 | 1074 |
1104 void | 1075 void |
1105 SDL_RaiseWindow(SDL_WindowID windowID) | 1076 SDL_RaiseWindow(SDL_WindowID windowID) |
1106 { | 1077 { |
1107 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1078 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1108 | 1079 |
1109 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { | 1080 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { |
1110 return; | 1081 return; |
1111 } | 1082 } |
1112 | 1083 if (_this->RaiseWindow) { |
1113 if (_this->RaiseWindow) { | 1084 _this->RaiseWindow(_this, window); |
1114 _this->RaiseWindow(_this, window); | 1085 } |
1115 } | |
1116 } | 1086 } |
1117 | 1087 |
1118 void | 1088 void |
1119 SDL_MaximizeWindow(SDL_WindowID windowID) | 1089 SDL_MaximizeWindow(SDL_WindowID windowID) |
1120 { | 1090 { |
1121 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1091 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1122 | 1092 |
1123 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { | 1093 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { |
1124 return; | 1094 return; |
1125 } | 1095 } |
1126 | 1096 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); |
1127 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); | 1097 |
1128 | 1098 if (_this->MaximizeWindow) { |
1129 if (_this->MaximizeWindow) { | 1099 _this->MaximizeWindow(_this, window); |
1130 _this->MaximizeWindow(_this, window); | 1100 } |
1131 } | |
1132 } | 1101 } |
1133 | 1102 |
1134 void | 1103 void |
1135 SDL_MinimizeWindow(SDL_WindowID windowID) | 1104 SDL_MinimizeWindow(SDL_WindowID windowID) |
1136 { | 1105 { |
1137 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1106 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1138 | 1107 |
1139 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { | 1108 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { |
1140 return; | 1109 return; |
1141 } | 1110 } |
1142 | 1111 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
1143 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0); | 1112 |
1144 | 1113 if (_this->MinimizeWindow) { |
1145 if (_this->MinimizeWindow) { | 1114 _this->MinimizeWindow(_this, window); |
1146 _this->MinimizeWindow(_this, window); | 1115 } |
1147 } | |
1148 } | 1116 } |
1149 | 1117 |
1150 void | 1118 void |
1151 SDL_RestoreWindow(SDL_WindowID windowID) | 1119 SDL_RestoreWindow(SDL_WindowID windowID) |
1152 { | 1120 { |
1153 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1121 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1154 | 1122 |
1155 if (!window | 1123 if (!window |
1156 || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { | 1124 || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { |
1157 return; | 1125 return; |
1158 } | 1126 } |
1159 | 1127 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0); |
1160 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0); | 1128 |
1161 | 1129 if (_this->RestoreWindow) { |
1162 if (_this->RestoreWindow) { | 1130 _this->RestoreWindow(_this, window); |
1163 _this->RestoreWindow(_this, window); | 1131 } |
1164 } | |
1165 } | 1132 } |
1166 | 1133 |
1167 int | 1134 int |
1168 SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen) | 1135 SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen) |
1169 { | 1136 { |
1170 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1137 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1171 | 1138 |
1172 if (!window) { | 1139 if (!window) { |
1173 return -1; | 1140 return -1; |
1174 } | 1141 } |
1175 | 1142 if (fullscreen) { |
1176 if (fullscreen) { | 1143 fullscreen = SDL_WINDOW_FULLSCREEN; |
1177 fullscreen = SDL_WINDOW_FULLSCREEN; | 1144 } |
1178 } | 1145 if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) { |
1179 if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) { | 1146 return 0; |
1180 return 0; | 1147 } |
1181 } | 1148 if (fullscreen) { |
1182 | 1149 window->flags |= SDL_WINDOW_FULLSCREEN; |
1183 if (fullscreen) { | 1150 |
1184 window->flags |= SDL_WINDOW_FULLSCREEN; | 1151 if (FULLSCREEN_VISIBLE(window)) { |
1185 | 1152 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
1186 if (FULLSCREEN_VISIBLE(window)) { | 1153 |
1187 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 1154 /* Hide any other fullscreen windows */ |
1188 | 1155 int i; |
1189 /* Hide any other fullscreen windows */ | 1156 for (i = 0; i < display->num_windows; ++i) { |
1190 int i; | 1157 SDL_Window *other = &display->windows[i]; |
1191 for (i = 0; i < display->num_windows; ++i) { | 1158 if (other->id != windowID && FULLSCREEN_VISIBLE(other)) { |
1192 SDL_Window *other = &display->windows[i]; | 1159 SDL_MinimizeWindow(other->id); |
1193 if (other->id != windowID && FULLSCREEN_VISIBLE(other)) { | 1160 } |
1194 SDL_MinimizeWindow(other->id); | 1161 } |
1195 } | 1162 |
1196 } | 1163 SDL_SetDisplayMode(&display->fullscreen_mode); |
1197 | 1164 } |
1198 SDL_SetDisplayMode(&display->fullscreen_mode); | 1165 } else { |
1199 } | 1166 window->flags &= ~SDL_WINDOW_FULLSCREEN; |
1200 } else { | 1167 |
1201 window->flags &= ~SDL_WINDOW_FULLSCREEN; | 1168 if (FULLSCREEN_VISIBLE(window)) { |
1202 | 1169 SDL_SetDisplayMode(NULL); |
1203 if (FULLSCREEN_VISIBLE(window)) { | 1170 } |
1204 SDL_SetDisplayMode(NULL); | 1171 } |
1205 } | 1172 return 0; |
1206 } | |
1207 return 0; | |
1208 } | 1173 } |
1209 | 1174 |
1210 void | 1175 void |
1211 SDL_SetWindowGrab(SDL_WindowID windowID, int mode) | 1176 SDL_SetWindowGrab(SDL_WindowID windowID, int mode) |
1212 { | 1177 { |
1213 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1178 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1214 | 1179 |
1215 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { | 1180 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { |
1216 return; | 1181 return; |
1217 } | 1182 } |
1218 | 1183 if (mode) { |
1219 if (mode) { | 1184 window->flags |= SDL_WINDOW_INPUT_GRABBED; |
1220 window->flags |= SDL_WINDOW_INPUT_GRABBED; | 1185 } else { |
1221 } else { | 1186 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; |
1222 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; | 1187 } |
1223 } | 1188 |
1224 | 1189 if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) { |
1225 if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) { | 1190 _this->SetWindowGrab(_this, window); |
1226 _this->SetWindowGrab(_this, window); | 1191 } |
1227 } | |
1228 } | 1192 } |
1229 | 1193 |
1230 int | 1194 int |
1231 SDL_GetWindowGrab(SDL_WindowID windowID) | 1195 SDL_GetWindowGrab(SDL_WindowID windowID) |
1232 { | 1196 { |
1233 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1197 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1234 | 1198 |
1235 if (!window) { | 1199 if (!window) { |
1236 return 0; | 1200 return 0; |
1237 } | 1201 } |
1238 | 1202 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); |
1239 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); | |
1240 } | 1203 } |
1241 | 1204 |
1242 void | 1205 void |
1243 SDL_OnWindowShown(SDL_Window * window) | 1206 SDL_OnWindowShown(SDL_Window * window) |
1244 { | 1207 { |
1250 } | 1213 } |
1251 | 1214 |
1252 void | 1215 void |
1253 SDL_OnWindowResized(SDL_Window * window) | 1216 SDL_OnWindowResized(SDL_Window * window) |
1254 { | 1217 { |
1255 SDL_Renderer *renderer = window->renderer; | 1218 SDL_Renderer *renderer = window->renderer; |
1256 | 1219 |
1257 if (renderer && renderer->DisplayModeChanged) { | 1220 if (renderer && renderer->DisplayModeChanged) { |
1258 renderer->DisplayModeChanged(renderer); | 1221 renderer->DisplayModeChanged(renderer); |
1259 } | 1222 } |
1260 } | 1223 } |
1261 | 1224 |
1262 void | 1225 void |
1263 SDL_OnWindowFocusGained(SDL_Window * window) | 1226 SDL_OnWindowFocusGained(SDL_Window * window) |
1264 { | 1227 { |
1265 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 1228 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
1266 | 1229 |
1267 if (window->flags & SDL_WINDOW_FULLSCREEN) { | 1230 if (window->flags & SDL_WINDOW_FULLSCREEN) { |
1268 SDL_SetDisplayMode(&display->fullscreen_mode); | 1231 SDL_SetDisplayMode(&display->fullscreen_mode); |
1269 } | 1232 } |
1270 if (display->gamma && _this->SetDisplayGammaRamp) { | 1233 if (display->gamma && _this->SetDisplayGammaRamp) { |
1271 _this->SetDisplayGammaRamp(_this, display->gamma); | 1234 _this->SetDisplayGammaRamp(_this, display->gamma); |
1272 } | 1235 } |
1273 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) { | 1236 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) { |
1274 _this->SetWindowGrab(_this, window); | 1237 _this->SetWindowGrab(_this, window); |
1275 } | 1238 } |
1276 } | 1239 } |
1277 | 1240 |
1278 void | 1241 void |
1279 SDL_OnWindowFocusLost(SDL_Window * window) | 1242 SDL_OnWindowFocusLost(SDL_Window * window) |
1280 { | 1243 { |
1281 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 1244 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); |
1282 | 1245 |
1283 if (window->flags & SDL_WINDOW_FULLSCREEN) { | 1246 if (window->flags & SDL_WINDOW_FULLSCREEN) { |
1284 SDL_MinimizeWindow(window->id); | 1247 SDL_MinimizeWindow(window->id); |
1285 SDL_SetDisplayMode(NULL); | 1248 SDL_SetDisplayMode(NULL); |
1286 } | 1249 } |
1287 if (display->gamma && _this->SetDisplayGammaRamp) { | 1250 if (display->gamma && _this->SetDisplayGammaRamp) { |
1288 _this->SetDisplayGammaRamp(_this, display->saved_gamma); | 1251 _this->SetDisplayGammaRamp(_this, display->saved_gamma); |
1289 } | 1252 } |
1290 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) { | 1253 if ((window->flags & SDL_WINDOW_INPUT_GRABBED) && _this->SetWindowGrab) { |
1291 _this->SetWindowGrab(_this, window); | 1254 _this->SetWindowGrab(_this, window); |
1292 } | 1255 } |
1293 } | 1256 } |
1294 | 1257 |
1295 SDL_WindowID | 1258 SDL_WindowID |
1296 SDL_GetFocusWindow(void) | 1259 SDL_GetFocusWindow(void) |
1297 { | 1260 { |
1298 SDL_VideoDisplay *display; | 1261 SDL_VideoDisplay *display; |
1299 int i; | 1262 int i; |
1300 | 1263 |
1301 if (!_this) { | 1264 if (!_this) { |
1302 return 0; | 1265 return 0; |
1303 } | 1266 } |
1304 | 1267 display = &SDL_CurrentDisplay; |
1305 display = &SDL_CurrentDisplay; | 1268 for (i = 0; i < display->num_windows; ++i) { |
1306 for (i = 0; i < display->num_windows; ++i) { | 1269 SDL_Window *window = &display->windows[i]; |
1307 SDL_Window *window = &display->windows[i]; | 1270 |
1308 | 1271 if (window->flags & SDL_WINDOW_INPUT_FOCUS) { |
1309 if (window->flags & SDL_WINDOW_INPUT_FOCUS) { | 1272 return window->id; |
1310 return window->id; | 1273 } |
1311 } | 1274 } |
1312 } | 1275 return 0; |
1313 return 0; | |
1314 } | 1276 } |
1315 | 1277 |
1316 void | 1278 void |
1317 SDL_DestroyWindow(SDL_WindowID windowID) | 1279 SDL_DestroyWindow(SDL_WindowID windowID) |
1318 { | 1280 { |
1319 int i, j; | 1281 int i, j; |
1320 | 1282 |
1321 if (!_this) { | 1283 if (!_this) { |
1322 return; | 1284 return; |
1323 } | 1285 } |
1324 | 1286 /* Restore video mode, etc. */ |
1325 /* Restore video mode, etc. */ | 1287 SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); |
1326 SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); | 1288 |
1327 | 1289 for (i = 0; i < _this->num_displays; ++i) { |
1328 for (i = 0; i < _this->num_displays; ++i) { | 1290 SDL_VideoDisplay *display = &_this->displays[i]; |
1329 SDL_VideoDisplay *display = &_this->displays[i]; | 1291 for (j = 0; j < display->num_windows; ++j) { |
1330 for (j = 0; j < display->num_windows; ++j) { | 1292 SDL_Window *window = &display->windows[j]; |
1331 SDL_Window *window = &display->windows[j]; | 1293 if (window->id != windowID) { |
1332 if (window->id != windowID) { | 1294 continue; |
1333 continue; | 1295 } |
1334 } | 1296 if (window->title) { |
1335 if (window->title) { | 1297 SDL_free(window->title); |
1336 SDL_free(window->title); | 1298 window->title = NULL; |
1337 window->title = NULL; | 1299 } |
1338 } | 1300 if (window->renderer) { |
1339 if (window->renderer) { | 1301 SDL_DestroyRenderer(window->id); |
1340 SDL_DestroyRenderer(window->id); | 1302 window->renderer = NULL; |
1341 window->renderer = NULL; | 1303 } |
1342 } | 1304 if (_this->DestroyWindow) { |
1343 if (_this->DestroyWindow) { | 1305 _this->DestroyWindow(_this, window); |
1344 _this->DestroyWindow(_this, window); | 1306 } |
1345 } | 1307 if (j != display->num_windows - 1) { |
1346 if (j != display->num_windows - 1) { | 1308 SDL_memcpy(&display->windows[i], |
1347 SDL_memcpy(&display->windows[i], | 1309 &display->windows[i + 1], |
1348 &display->windows[i + 1], | 1310 (display->num_windows - i - 1) * sizeof(*window)); |
1349 (display->num_windows - i - 1) * sizeof(*window)); | 1311 } |
1350 } | 1312 --display->num_windows; |
1351 --display->num_windows; | 1313 return; |
1352 return; | 1314 } |
1353 } | 1315 } |
1354 } | |
1355 } | 1316 } |
1356 | 1317 |
1357 void | 1318 void |
1358 SDL_AddRenderDriver(int displayIndex, const SDL_RenderDriver * driver) | 1319 SDL_AddRenderDriver(int displayIndex, const SDL_RenderDriver * driver) |
1359 { | 1320 { |
1360 SDL_VideoDisplay *display; | 1321 SDL_VideoDisplay *display; |
1361 SDL_RenderDriver *render_drivers; | 1322 SDL_RenderDriver *render_drivers; |
1362 | 1323 |
1363 if (displayIndex >= _this->num_displays) { | 1324 if (displayIndex >= _this->num_displays) { |
1364 return; | 1325 return; |
1365 } | 1326 } |
1366 display = &_this->displays[displayIndex]; | 1327 display = &_this->displays[displayIndex]; |
1367 | 1328 |
1368 render_drivers = | 1329 render_drivers = |
1369 SDL_realloc(display->render_drivers, | 1330 SDL_realloc(display->render_drivers, |
1370 (display->num_render_drivers + | 1331 (display->num_render_drivers + |
1371 1) * sizeof(*render_drivers)); | 1332 1) * sizeof(*render_drivers)); |
1372 if (render_drivers) { | 1333 if (render_drivers) { |
1373 render_drivers[display->num_render_drivers] = *driver; | 1334 render_drivers[display->num_render_drivers] = *driver; |
1374 display->render_drivers = render_drivers; | 1335 display->render_drivers = render_drivers; |
1375 display->num_render_drivers++; | 1336 display->num_render_drivers++; |
1376 } | 1337 } |
1377 } | 1338 } |
1378 | 1339 |
1379 int | 1340 int |
1380 SDL_GetNumRenderDrivers(void) | 1341 SDL_GetNumRenderDrivers(void) |
1381 { | 1342 { |
1382 if (_this) { | 1343 if (_this) { |
1383 return SDL_CurrentDisplay.num_render_drivers; | 1344 return SDL_CurrentDisplay.num_render_drivers; |
1384 } | 1345 } |
1385 return 0; | 1346 return 0; |
1386 } | 1347 } |
1387 | 1348 |
1388 int | 1349 int |
1389 SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info) | 1350 SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info) |
1390 { | 1351 { |
1391 if (!_this) { | 1352 if (!_this) { |
1392 SDL_UninitializedVideo(); | 1353 SDL_UninitializedVideo(); |
1393 return -1; | 1354 return -1; |
1394 } | 1355 } |
1395 | 1356 if (index < 0 || index >= SDL_GetNumRenderDrivers()) { |
1396 if (index < 0 || index >= SDL_GetNumRenderDrivers()) { | 1357 SDL_SetError("index must be in the range of 0 - %d", |
1397 SDL_SetError("index must be in the range of 0 - %d", | 1358 SDL_GetNumRenderDrivers() - 1); |
1398 SDL_GetNumRenderDrivers() - 1); | 1359 return -1; |
1399 return -1; | 1360 } |
1400 } | 1361 *info = SDL_CurrentDisplay.render_drivers[index].info; |
1401 *info = SDL_CurrentDisplay.render_drivers[index].info; | 1362 return 0; |
1402 return 0; | |
1403 } | 1363 } |
1404 | 1364 |
1405 int | 1365 int |
1406 SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags) | 1366 SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags) |
1407 { | 1367 { |
1408 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1368 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1409 | 1369 |
1410 if (!window) { | 1370 if (!window) { |
1411 return 0; | 1371 return 0; |
1412 } | 1372 } |
1413 | 1373 if (index < 0) { |
1414 if (index < 0) { | 1374 const char *override = SDL_getenv("SDL_VIDEO_RENDERER"); |
1415 const char *override = SDL_getenv("SDL_VIDEO_RENDERER"); | 1375 int n = SDL_GetNumRenderDrivers(); |
1416 int n = SDL_GetNumRenderDrivers(); | 1376 for (index = 0; index < n; ++index) { |
1417 for (index = 0; index < n; ++index) { | 1377 SDL_RenderDriver *driver = |
1418 SDL_RenderDriver *driver = | 1378 &SDL_CurrentDisplay.render_drivers[index]; |
1419 &SDL_CurrentDisplay.render_drivers[index]; | 1379 |
1420 | 1380 if (override) { |
1421 if (override) { | 1381 if (SDL_strcasecmp(override, driver->info.name) == 0) { |
1422 if (SDL_strcasecmp(override, driver->info.name) == 0) { | 1382 break; |
1423 break; | 1383 } |
1424 } | 1384 } else { |
1425 } else { | 1385 if ((driver->info.flags & flags) == flags) { |
1426 if ((driver->info.flags & flags) == flags) { | 1386 break; |
1427 break; | 1387 } |
1428 } | 1388 } |
1429 } | 1389 } |
1430 } | 1390 if (index == n) { |
1431 if (index == n) { | 1391 SDL_SetError("Couldn't find matching render driver"); |
1432 SDL_SetError("Couldn't find matching render driver"); | 1392 return -1; |
1433 return -1; | 1393 } |
1434 } | 1394 } |
1435 } | 1395 if (index >= SDL_GetNumRenderDrivers()) { |
1436 | 1396 SDL_SetError("index must be -1 or in the range of 0 - %d", |
1437 if (index >= SDL_GetNumRenderDrivers()) { | 1397 SDL_GetNumRenderDrivers() - 1); |
1438 SDL_SetError("index must be -1 or in the range of 0 - %d", | 1398 return -1; |
1439 SDL_GetNumRenderDrivers() - 1); | 1399 } |
1440 return -1; | 1400 /* Free any existing renderer */ |
1441 } | 1401 SDL_DestroyRenderer(windowID); |
1442 | 1402 |
1443 /* Free any existing renderer */ | 1403 /* Create a new renderer instance */ |
1444 SDL_DestroyRenderer(windowID); | 1404 window->renderer = SDL_CurrentDisplay.render_drivers[index] |
1445 | 1405 .CreateRenderer(window, flags); |
1446 /* Create a new renderer instance */ | 1406 SDL_SelectRenderer(window->id); |
1447 window->renderer = SDL_CurrentDisplay.render_drivers[index] | 1407 |
1448 .CreateRenderer(window, flags); | 1408 return 0; |
1449 SDL_SelectRenderer(window->id); | |
1450 | |
1451 return 0; | |
1452 } | 1409 } |
1453 | 1410 |
1454 int | 1411 int |
1455 SDL_SelectRenderer(SDL_WindowID windowID) | 1412 SDL_SelectRenderer(SDL_WindowID windowID) |
1456 { | 1413 { |
1457 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1414 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1458 SDL_Renderer *renderer; | 1415 SDL_Renderer *renderer; |
1459 | 1416 |
1460 if (!window || !window->renderer) { | 1417 if (!window || !window->renderer) { |
1461 return -1; | 1418 return -1; |
1462 } | 1419 } |
1463 renderer = window->renderer; | 1420 renderer = window->renderer; |
1464 if (renderer && renderer->ActivateRenderer) { | 1421 if (renderer && renderer->ActivateRenderer) { |
1465 if (renderer->ActivateRenderer(renderer) < 0) { | 1422 if (renderer->ActivateRenderer(renderer) < 0) { |
1466 return -1; | 1423 return -1; |
1467 } | 1424 } |
1468 } | 1425 } |
1469 SDL_CurrentDisplay.current_renderer = renderer; | 1426 SDL_CurrentDisplay.current_renderer = renderer; |
1470 return 0; | 1427 return 0; |
1471 } | 1428 } |
1472 | 1429 |
1473 int | 1430 int |
1474 SDL_GetRendererInfo(SDL_RendererInfo * info) | 1431 SDL_GetRendererInfo(SDL_RendererInfo * info) |
1475 { | 1432 { |
1476 if (!_this) { | 1433 if (!_this) { |
1477 SDL_UninitializedVideo(); | 1434 SDL_UninitializedVideo(); |
1478 return -1; | 1435 return -1; |
1479 } | 1436 } |
1480 | 1437 if (!SDL_CurrentDisplay.current_renderer) { |
1481 if (!SDL_CurrentDisplay.current_renderer) { | 1438 SDL_SetError("There is no current renderer"); |
1482 SDL_SetError("There is no current renderer"); | 1439 return -1; |
1483 return -1; | 1440 } |
1484 } | 1441 *info = SDL_CurrentDisplay.current_renderer->info; |
1485 *info = SDL_CurrentDisplay.current_renderer->info; | 1442 return 0; |
1486 return 0; | |
1487 } | 1443 } |
1488 | 1444 |
1489 SDL_TextureID | 1445 SDL_TextureID |
1490 SDL_CreateTexture(Uint32 format, int access, int w, int h) | 1446 SDL_CreateTexture(Uint32 format, int access, int w, int h) |
1491 { | 1447 { |
1492 int hash; | 1448 int hash; |
1493 SDL_Renderer *renderer; | 1449 SDL_Renderer *renderer; |
1494 SDL_Texture *texture; | 1450 SDL_Texture *texture; |
1495 | 1451 |
1496 if (!_this) { | 1452 if (!_this) { |
1497 SDL_UninitializedVideo(); | 1453 SDL_UninitializedVideo(); |
1498 return 0; | 1454 return 0; |
1499 } | 1455 } |
1500 | 1456 renderer = SDL_CurrentDisplay.current_renderer; |
1501 renderer = SDL_CurrentDisplay.current_renderer; | 1457 if (!renderer || !renderer->CreateTexture) { |
1502 if (!renderer || !renderer->CreateTexture) { | 1458 return 0; |
1503 return 0; | 1459 } |
1504 } | 1460 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); |
1505 | 1461 if (!texture) { |
1506 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); | 1462 SDL_OutOfMemory(); |
1507 if (!texture) { | 1463 return 0; |
1508 SDL_OutOfMemory(); | 1464 } |
1509 return 0; | 1465 texture->id = _this->next_object_id++; |
1510 } | 1466 texture->format = format; |
1511 | 1467 texture->access = access; |
1512 texture->id = _this->next_object_id++; | 1468 texture->w = w; |
1513 texture->format = format; | 1469 texture->h = h; |
1514 texture->access = access; | 1470 texture->r = 255; |
1515 texture->w = w; | 1471 texture->g = 255; |
1516 texture->h = h; | 1472 texture->b = 255; |
1517 texture->r = 255; | 1473 texture->a = 255; |
1518 texture->g = 255; | 1474 texture->renderer = renderer; |
1519 texture->b = 255; | 1475 |
1520 texture->a = 255; | 1476 if (renderer->CreateTexture(renderer, texture) < 0) { |
1521 texture->renderer = renderer; | 1477 if (renderer->DestroyTexture) { |
1522 | 1478 renderer->DestroyTexture(renderer, texture); |
1523 if (renderer->CreateTexture(renderer, texture) < 0) { | 1479 } |
1524 if (renderer->DestroyTexture) { | 1480 SDL_free(texture); |
1525 renderer->DestroyTexture(renderer, texture); | 1481 return 0; |
1526 } | 1482 } |
1527 SDL_free(texture); | 1483 hash = (texture->id % SDL_arraysize(SDL_CurrentDisplay.textures)); |
1528 return 0; | 1484 texture->next = SDL_CurrentDisplay.textures[hash]; |
1529 } | 1485 SDL_CurrentDisplay.textures[hash] = texture; |
1530 | 1486 |
1531 hash = (texture->id % SDL_arraysize(SDL_CurrentDisplay.textures)); | 1487 return texture->id; |
1532 texture->next = SDL_CurrentDisplay.textures[hash]; | |
1533 SDL_CurrentDisplay.textures[hash] = texture; | |
1534 | |
1535 return texture->id; | |
1536 } | 1488 } |
1537 | 1489 |
1538 SDL_TextureID | 1490 SDL_TextureID |
1539 SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) | 1491 SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) |
1540 { | 1492 { |
1541 SDL_TextureID textureID; | 1493 SDL_TextureID textureID; |
1542 SDL_PixelFormat *fmt; | 1494 SDL_PixelFormat *fmt; |
1543 int bpp; | 1495 int bpp; |
1544 Uint32 Rmask, Gmask, Bmask, Amask; | 1496 Uint32 Rmask, Gmask, Bmask, Amask; |
1545 | 1497 |
1546 if (!surface) { | 1498 if (!surface) { |
1547 SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface"); | 1499 SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface"); |
1548 return 0; | 1500 return 0; |
1549 } | 1501 } |
1550 fmt = surface->format; | 1502 fmt = surface->format; |
1551 | 1503 |
1552 if (format) { | 1504 if (format) { |
1553 if (!SDL_PixelFormatEnumToMasks | 1505 if (!SDL_PixelFormatEnumToMasks |
1554 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { | 1506 (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { |
1555 SDL_SetError("Unknown pixel format"); | 1507 SDL_SetError("Unknown pixel format"); |
1556 return 0; | 1508 return 0; |
1557 } | 1509 } |
1558 } else { | 1510 } else { |
1559 if (surface->format->Amask | 1511 if (surface->format->Amask |
1560 || !(surface->map->info.flags & | 1512 || !(surface->map->info.flags & |
1561 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { | 1513 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { |
1562 bpp = fmt->BitsPerPixel; | 1514 bpp = fmt->BitsPerPixel; |
1563 Rmask = fmt->Rmask; | 1515 Rmask = fmt->Rmask; |
1564 Gmask = fmt->Gmask; | 1516 Gmask = fmt->Gmask; |
1565 Bmask = fmt->Bmask; | 1517 Bmask = fmt->Bmask; |
1566 Amask = fmt->Amask; | 1518 Amask = fmt->Amask; |
1567 } else { | 1519 } else { |
1568 /* Need a format with alpha */ | 1520 /* Need a format with alpha */ |
1569 bpp = 32; | 1521 bpp = 32; |
1570 Rmask = 0x00FF0000; | 1522 Rmask = 0x00FF0000; |
1571 Gmask = 0x0000FF00; | 1523 Gmask = 0x0000FF00; |
1572 Bmask = 0x000000FF; | 1524 Bmask = 0x000000FF; |
1573 Amask = 0xFF000000; | 1525 Amask = 0xFF000000; |
1574 } | 1526 } |
1575 format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); | 1527 format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); |
1576 if (!format) { | 1528 if (!format) { |
1577 SDL_SetError("Unknown pixel format"); | 1529 SDL_SetError("Unknown pixel format"); |
1578 return 0; | 1530 return 0; |
1579 } | 1531 } |
1580 } | 1532 } |
1581 | 1533 |
1582 textureID = | 1534 textureID = |
1583 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, | 1535 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, |
1584 surface->h); | 1536 surface->h); |
1585 if (!textureID) { | 1537 if (!textureID) { |
1586 return 0; | 1538 return 0; |
1587 } | 1539 } |
1588 | 1540 if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask |
1589 if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask | 1541 && Bmask == fmt->Bmask && Amask == fmt->Amask) { |
1590 && Bmask == fmt->Bmask && Amask == fmt->Amask) { | 1542 if (SDL_MUSTLOCK(surface)) { |
1591 if (SDL_MUSTLOCK(surface)) { | 1543 if (SDL_LockSurface(surface) < 0) { |
1592 if (SDL_LockSurface(surface) < 0) { | 1544 SDL_DestroyTexture(textureID); |
1593 SDL_DestroyTexture(textureID); | 1545 return 0; |
1594 return 0; | 1546 } |
1595 } | 1547 SDL_UpdateTexture(textureID, NULL, surface->pixels, |
1596 SDL_UpdateTexture(textureID, NULL, surface->pixels, | 1548 surface->pitch); |
1597 surface->pitch); | 1549 SDL_UnlockSurface(surface); |
1598 SDL_UnlockSurface(surface); | 1550 } else { |
1599 } else { | 1551 SDL_UpdateTexture(textureID, NULL, surface->pixels, |
1600 SDL_UpdateTexture(textureID, NULL, surface->pixels, | 1552 surface->pitch); |
1601 surface->pitch); | 1553 } |
1602 } | 1554 } else { |
1603 } else { | 1555 SDL_PixelFormat *dst_fmt; |
1604 SDL_PixelFormat *dst_fmt; | 1556 SDL_Surface *dst = NULL; |
1605 SDL_Surface *dst = NULL; | 1557 |
1606 | 1558 /* Set up a destination surface for the texture update */ |
1607 /* Set up a destination surface for the texture update */ | 1559 dst_fmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask); |
1608 dst_fmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask); | 1560 if (dst_fmt) { |
1609 if (dst_fmt) { | 1561 if (SDL_ISPIXELFORMAT_INDEXED(format)) { |
1610 if (SDL_ISPIXELFORMAT_INDEXED(format)) { | 1562 dst_fmt->palette = |
1611 dst_fmt->palette = | 1563 SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format))); |
1612 SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format))); | 1564 if (dst_fmt->palette) { |
1613 if (dst_fmt->palette) { | 1565 /* |
1614 /* FIXME: Should we try to copy fmt->palette? */ | 1566 * FIXME: Should we try to copy |
1615 SDL_DitherColors(dst_fmt->palette->colors, | 1567 * fmt->palette? |
1616 SDL_BITSPERPIXEL(format)); | 1568 */ |
1617 } | 1569 SDL_DitherColors(dst_fmt->palette->colors, |
1618 } | 1570 SDL_BITSPERPIXEL(format)); |
1619 | 1571 } |
1620 dst = SDL_ConvertSurface(surface, dst_fmt, 0); | 1572 } |
1621 if (dst) { | 1573 dst = SDL_ConvertSurface(surface, dst_fmt, 0); |
1622 SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch); | 1574 if (dst) { |
1623 SDL_FreeSurface(dst); | 1575 SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch); |
1624 } | 1576 SDL_FreeSurface(dst); |
1625 if (dst_fmt->palette) { | 1577 } |
1626 SDL_FreePalette(dst_fmt->palette); | 1578 if (dst_fmt->palette) { |
1627 } | 1579 SDL_FreePalette(dst_fmt->palette); |
1628 SDL_FreeFormat(dst_fmt); | 1580 } |
1629 } | 1581 SDL_FreeFormat(dst_fmt); |
1630 if (!dst) { | 1582 } |
1631 SDL_DestroyTexture(textureID); | 1583 if (!dst) { |
1632 return 0; | 1584 SDL_DestroyTexture(textureID); |
1633 } | 1585 return 0; |
1634 } | 1586 } |
1635 | 1587 } |
1636 if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { | 1588 |
1637 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, | 1589 if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { |
1638 fmt->palette->ncolors); | 1590 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, |
1639 } | 1591 fmt->palette->ncolors); |
1640 | 1592 } |
1641 return textureID; | 1593 return textureID; |
1642 } | 1594 } |
1643 | 1595 |
1644 static __inline__ SDL_Texture * | 1596 static __inline__ SDL_Texture * |
1645 SDL_GetTextureFromID(SDL_TextureID textureID) | 1597 SDL_GetTextureFromID(SDL_TextureID textureID) |
1646 { | 1598 { |
1647 int hash; | 1599 int hash; |
1648 SDL_Texture *texture; | 1600 SDL_Texture *texture; |
1649 | 1601 |
1650 if (!_this) { | 1602 if (!_this) { |
1651 return NULL; | 1603 return NULL; |
1652 } | 1604 } |
1653 | 1605 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures)); |
1654 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures)); | 1606 for (texture = SDL_CurrentDisplay.textures[hash]; texture; |
1655 for (texture = SDL_CurrentDisplay.textures[hash]; texture; | 1607 texture = texture->next) { |
1656 texture = texture->next) { | 1608 if (texture->id == textureID) { |
1657 if (texture->id == textureID) { | 1609 return texture; |
1658 return texture; | 1610 } |
1659 } | 1611 } |
1660 } | 1612 return NULL; |
1661 return NULL; | |
1662 } | 1613 } |
1663 | 1614 |
1664 int | 1615 int |
1665 SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access, | 1616 SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access, |
1666 int *w, int *h) | 1617 int *w, int *h) |
1667 { | 1618 { |
1668 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1619 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1669 | 1620 |
1670 if (!texture) { | 1621 if (!texture) { |
1671 return -1; | 1622 return -1; |
1672 } | 1623 } |
1673 | 1624 if (format) { |
1674 if (format) { | 1625 *format = texture->format; |
1675 *format = texture->format; | 1626 } |
1676 } | 1627 if (access) { |
1677 if (access) { | 1628 *access = texture->access; |
1678 *access = texture->access; | 1629 } |
1679 } | 1630 if (w) { |
1680 if (w) { | 1631 *w = texture->w; |
1681 *w = texture->w; | 1632 } |
1682 } | 1633 if (h) { |
1683 if (h) { | 1634 *h = texture->h; |
1684 *h = texture->h; | 1635 } |
1685 } | 1636 return 0; |
1686 return 0; | |
1687 } | 1637 } |
1688 | 1638 |
1689 int | 1639 int |
1690 SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch) | 1640 SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch) |
1691 { | 1641 { |
1692 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1642 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1693 SDL_Renderer *renderer; | 1643 SDL_Renderer *renderer; |
1694 | 1644 |
1695 if (!texture) { | 1645 if (!texture) { |
1696 return -1; | 1646 return -1; |
1697 } | 1647 } |
1698 | 1648 renderer = texture->renderer; |
1699 renderer = texture->renderer; | 1649 if (!renderer->QueryTexturePixels) { |
1700 if (!renderer->QueryTexturePixels) { | 1650 return -1; |
1701 return -1; | 1651 } |
1702 } | 1652 return renderer->QueryTexturePixels(renderer, texture, pixels, pitch); |
1703 return renderer->QueryTexturePixels(renderer, texture, pixels, pitch); | |
1704 } | 1653 } |
1705 | 1654 |
1706 int | 1655 int |
1707 SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors, | 1656 SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors, |
1708 int firstcolor, int ncolors) | 1657 int firstcolor, int ncolors) |
1709 { | 1658 { |
1710 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1659 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1711 SDL_Renderer *renderer; | 1660 SDL_Renderer *renderer; |
1712 | 1661 |
1713 if (!texture) { | 1662 if (!texture) { |
1714 return -1; | 1663 return -1; |
1715 } | 1664 } |
1716 | 1665 renderer = texture->renderer; |
1717 renderer = texture->renderer; | 1666 if (!renderer->SetTexturePalette) { |
1718 if (!renderer->SetTexturePalette) { | 1667 return -1; |
1719 return -1; | 1668 } |
1720 } | 1669 return renderer->SetTexturePalette(renderer, texture, colors, firstcolor, |
1721 return renderer->SetTexturePalette(renderer, texture, colors, firstcolor, | 1670 ncolors); |
1722 ncolors); | |
1723 } | 1671 } |
1724 | 1672 |
1725 int | 1673 int |
1726 SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, | 1674 SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, |
1727 int firstcolor, int ncolors) | 1675 int firstcolor, int ncolors) |
1728 { | 1676 { |
1729 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1677 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1730 SDL_Renderer *renderer; | 1678 SDL_Renderer *renderer; |
1731 | 1679 |
1732 if (!texture) { | 1680 if (!texture) { |
1733 return -1; | 1681 return -1; |
1734 } | 1682 } |
1735 | 1683 renderer = texture->renderer; |
1736 renderer = texture->renderer; | 1684 if (!renderer->GetTexturePalette) { |
1737 if (!renderer->GetTexturePalette) { | 1685 return -1; |
1738 return -1; | 1686 } |
1739 } | 1687 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor, |
1740 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor, | 1688 ncolors); |
1741 ncolors); | |
1742 } | 1689 } |
1743 | 1690 |
1744 int | 1691 int |
1745 SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b) | 1692 SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b) |
1746 { | 1693 { |
1747 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1694 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1748 SDL_Renderer *renderer; | 1695 SDL_Renderer *renderer; |
1749 | 1696 |
1750 if (!texture) { | 1697 if (!texture) { |
1751 return -1; | 1698 return -1; |
1752 } | 1699 } |
1753 | 1700 renderer = texture->renderer; |
1754 renderer = texture->renderer; | 1701 if (!renderer->SetTextureColorMod) { |
1755 if (!renderer->SetTextureColorMod) { | 1702 return -1; |
1756 return -1; | 1703 } |
1757 } | 1704 if (r < 255 || g < 255 || b < 255) { |
1758 if (r < 255 || g < 255 || b < 255) { | 1705 texture->modMode |= SDL_TEXTUREMODULATE_COLOR; |
1759 texture->modMode |= SDL_TEXTUREMODULATE_COLOR; | 1706 } else { |
1760 } else { | 1707 texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR; |
1761 texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR; | 1708 } |
1762 } | 1709 texture->r = r; |
1763 texture->r = r; | 1710 texture->g = g; |
1764 texture->g = g; | 1711 texture->b = b; |
1765 texture->b = b; | 1712 return renderer->SetTextureColorMod(renderer, texture); |
1766 return renderer->SetTextureColorMod(renderer, texture); | |
1767 } | 1713 } |
1768 | 1714 |
1769 int | 1715 int |
1770 SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g, | 1716 SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g, |
1771 Uint8 * b) | 1717 Uint8 * b) |
1772 { | 1718 { |
1773 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1719 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1774 SDL_Renderer *renderer; | 1720 SDL_Renderer *renderer; |
1775 | 1721 |
1776 if (!texture) { | 1722 if (!texture) { |
1777 return -1; | 1723 return -1; |
1778 } | 1724 } |
1779 | 1725 renderer = texture->renderer; |
1780 renderer = texture->renderer; | 1726 if (r) { |
1781 if (r) { | 1727 *r = texture->r; |
1782 *r = texture->r; | 1728 } |
1783 } | 1729 if (g) { |
1784 if (g) { | 1730 *g = texture->g; |
1785 *g = texture->g; | 1731 } |
1786 } | 1732 if (b) { |
1787 if (b) { | 1733 *b = texture->b; |
1788 *b = texture->b; | 1734 } |
1789 } | 1735 return 0; |
1790 return 0; | |
1791 } | 1736 } |
1792 | 1737 |
1793 int | 1738 int |
1794 SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha) | 1739 SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha) |
1795 { | 1740 { |
1796 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1741 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1797 SDL_Renderer *renderer; | 1742 SDL_Renderer *renderer; |
1798 | 1743 |
1799 if (!texture) { | 1744 if (!texture) { |
1800 return -1; | 1745 return -1; |
1801 } | 1746 } |
1802 | 1747 renderer = texture->renderer; |
1803 renderer = texture->renderer; | 1748 if (!renderer->SetTextureAlphaMod) { |
1804 if (!renderer->SetTextureAlphaMod) { | 1749 return -1; |
1805 return -1; | 1750 } |
1806 } | 1751 if (alpha < 255) { |
1807 if (alpha < 255) { | 1752 texture->modMode |= SDL_TEXTUREMODULATE_ALPHA; |
1808 texture->modMode |= SDL_TEXTUREMODULATE_ALPHA; | 1753 } else { |
1809 } else { | 1754 texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA; |
1810 texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA; | 1755 } |
1811 } | 1756 texture->a = alpha; |
1812 texture->a = alpha; | 1757 return renderer->SetTextureAlphaMod(renderer, texture); |
1813 return renderer->SetTextureAlphaMod(renderer, texture); | |
1814 } | 1758 } |
1815 | 1759 |
1816 int | 1760 int |
1817 SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha) | 1761 SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha) |
1818 { | 1762 { |
1819 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1763 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1820 | 1764 |
1821 if (!texture) { | 1765 if (!texture) { |
1822 return -1; | 1766 return -1; |
1823 } | 1767 } |
1824 | 1768 if (alpha) { |
1825 if (alpha) { | 1769 *alpha = texture->a; |
1826 *alpha = texture->a; | 1770 } |
1827 } | 1771 return 0; |
1828 return 0; | |
1829 } | 1772 } |
1830 | 1773 |
1831 int | 1774 int |
1832 SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode) | 1775 SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode) |
1833 { | 1776 { |
1834 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1777 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1835 SDL_Renderer *renderer; | 1778 SDL_Renderer *renderer; |
1836 | 1779 |
1837 if (!texture) { | 1780 if (!texture) { |
1838 return -1; | 1781 return -1; |
1839 } | 1782 } |
1840 | 1783 renderer = texture->renderer; |
1841 renderer = texture->renderer; | 1784 if (!renderer->SetTextureBlendMode) { |
1842 if (!renderer->SetTextureBlendMode) { | 1785 return -1; |
1843 return -1; | 1786 } |
1844 } | 1787 texture->blendMode = blendMode; |
1845 texture->blendMode = blendMode; | 1788 return renderer->SetTextureBlendMode(renderer, texture); |
1846 return renderer->SetTextureBlendMode(renderer, texture); | |
1847 } | 1789 } |
1848 | 1790 |
1849 int | 1791 int |
1850 SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode) | 1792 SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode) |
1851 { | 1793 { |
1852 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1794 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1853 | 1795 |
1854 if (!texture) { | 1796 if (!texture) { |
1855 return -1; | 1797 return -1; |
1856 } | 1798 } |
1857 | 1799 if (blendMode) { |
1858 if (blendMode) { | 1800 *blendMode = texture->blendMode; |
1859 *blendMode = texture->blendMode; | 1801 } |
1860 } | 1802 return 0; |
1861 return 0; | |
1862 } | 1803 } |
1863 | 1804 |
1864 int | 1805 int |
1865 SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode) | 1806 SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode) |
1866 { | 1807 { |
1867 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1808 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1868 SDL_Renderer *renderer; | 1809 SDL_Renderer *renderer; |
1869 | 1810 |
1870 if (!texture) { | 1811 if (!texture) { |
1871 return -1; | 1812 return -1; |
1872 } | 1813 } |
1873 | 1814 renderer = texture->renderer; |
1874 renderer = texture->renderer; | 1815 if (!renderer->SetTextureScaleMode) { |
1875 if (!renderer->SetTextureScaleMode) { | 1816 return -1; |
1876 return -1; | 1817 } |
1877 } | 1818 texture->scaleMode = scaleMode; |
1878 texture->scaleMode = scaleMode; | 1819 return renderer->SetTextureScaleMode(renderer, texture); |
1879 return renderer->SetTextureScaleMode(renderer, texture); | |
1880 } | 1820 } |
1881 | 1821 |
1882 int | 1822 int |
1883 SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode) | 1823 SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode) |
1884 { | 1824 { |
1885 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1825 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1886 | 1826 |
1887 if (!texture) { | 1827 if (!texture) { |
1888 return -1; | 1828 return -1; |
1889 } | 1829 } |
1890 | 1830 if (scaleMode) { |
1891 if (scaleMode) { | 1831 *scaleMode = texture->scaleMode; |
1892 *scaleMode = texture->scaleMode; | 1832 } |
1893 } | 1833 return 0; |
1894 return 0; | |
1895 } | 1834 } |
1896 | 1835 |
1897 int | 1836 int |
1898 SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect, | 1837 SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect, |
1899 const void *pixels, int pitch) | 1838 const void *pixels, int pitch) |
1900 { | 1839 { |
1901 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1840 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1902 SDL_Renderer *renderer; | 1841 SDL_Renderer *renderer; |
1903 SDL_Rect full_rect; | 1842 SDL_Rect full_rect; |
1904 | 1843 |
1905 if (!texture) { | 1844 if (!texture) { |
1906 return -1; | 1845 return -1; |
1907 } | 1846 } |
1908 | 1847 renderer = texture->renderer; |
1909 renderer = texture->renderer; | 1848 if (!renderer->UpdateTexture) { |
1910 if (!renderer->UpdateTexture) { | 1849 return -1; |
1911 return -1; | 1850 } |
1912 } | 1851 if (!rect) { |
1913 | 1852 full_rect.x = 0; |
1914 if (!rect) { | 1853 full_rect.y = 0; |
1915 full_rect.x = 0; | 1854 full_rect.w = texture->w; |
1916 full_rect.y = 0; | 1855 full_rect.h = texture->h; |
1917 full_rect.w = texture->w; | 1856 rect = &full_rect; |
1918 full_rect.h = texture->h; | 1857 } |
1919 rect = &full_rect; | 1858 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch); |
1920 } | |
1921 | |
1922 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch); | |
1923 } | 1859 } |
1924 | 1860 |
1925 int | 1861 int |
1926 SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty, | 1862 SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty, |
1927 void **pixels, int *pitch) | 1863 void **pixels, int *pitch) |
1928 { | 1864 { |
1929 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1865 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1930 SDL_Renderer *renderer; | 1866 SDL_Renderer *renderer; |
1931 SDL_Rect full_rect; | 1867 SDL_Rect full_rect; |
1932 | 1868 |
1933 if (!texture) { | 1869 if (!texture) { |
1934 return -1; | 1870 return -1; |
1935 } | 1871 } |
1936 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { | 1872 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { |
1937 SDL_SetError("SDL_LockTexture(): texture must be streaming"); | 1873 SDL_SetError("SDL_LockTexture(): texture must be streaming"); |
1938 return -1; | 1874 return -1; |
1939 } | 1875 } |
1940 | 1876 renderer = texture->renderer; |
1941 renderer = texture->renderer; | 1877 if (!renderer->LockTexture) { |
1942 if (!renderer->LockTexture) { | 1878 return -1; |
1943 return -1; | 1879 } |
1944 } | 1880 if (!rect) { |
1945 | 1881 full_rect.x = 0; |
1946 if (!rect) { | 1882 full_rect.y = 0; |
1947 full_rect.x = 0; | 1883 full_rect.w = texture->w; |
1948 full_rect.y = 0; | 1884 full_rect.h = texture->h; |
1949 full_rect.w = texture->w; | 1885 rect = &full_rect; |
1950 full_rect.h = texture->h; | 1886 } |
1951 rect = &full_rect; | 1887 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels, |
1952 } | 1888 pitch); |
1953 | |
1954 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels, | |
1955 pitch); | |
1956 } | 1889 } |
1957 | 1890 |
1958 void | 1891 void |
1959 SDL_UnlockTexture(SDL_TextureID textureID) | 1892 SDL_UnlockTexture(SDL_TextureID textureID) |
1960 { | 1893 { |
1961 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1894 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1962 SDL_Renderer *renderer; | 1895 SDL_Renderer *renderer; |
1963 | 1896 |
1964 if (!texture) { | 1897 if (!texture) { |
1965 return; | 1898 return; |
1966 } | 1899 } |
1967 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { | 1900 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { |
1968 return; | 1901 return; |
1969 } | 1902 } |
1970 | 1903 renderer = texture->renderer; |
1971 renderer = texture->renderer; | 1904 if (!renderer->UnlockTexture) { |
1972 if (!renderer->UnlockTexture) { | 1905 return; |
1973 return; | 1906 } |
1974 } | 1907 renderer->UnlockTexture(renderer, texture); |
1975 renderer->UnlockTexture(renderer, texture); | |
1976 } | 1908 } |
1977 | 1909 |
1978 void | 1910 void |
1979 SDL_DirtyTexture(SDL_TextureID textureID, int numrects, | 1911 SDL_DirtyTexture(SDL_TextureID textureID, int numrects, |
1980 const SDL_Rect * rects) | 1912 const SDL_Rect * rects) |
1981 { | 1913 { |
1982 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1914 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
1983 SDL_Renderer *renderer; | 1915 SDL_Renderer *renderer; |
1984 | 1916 |
1985 if (!texture) { | 1917 if (!texture) { |
1986 return; | 1918 return; |
1987 } | 1919 } |
1988 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { | 1920 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { |
1989 return; | 1921 return; |
1990 } | 1922 } |
1991 | 1923 renderer = texture->renderer; |
1992 renderer = texture->renderer; | 1924 if (!renderer->DirtyTexture) { |
1993 if (!renderer->DirtyTexture) { | 1925 return; |
1994 return; | 1926 } |
1995 } | 1927 renderer->DirtyTexture(renderer, texture, numrects, rects); |
1996 renderer->DirtyTexture(renderer, texture, numrects, rects); | |
1997 } | 1928 } |
1998 | 1929 |
1999 int | 1930 int |
2000 SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect) | 1931 SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect) |
2001 { | 1932 { |
2002 SDL_Renderer *renderer; | 1933 SDL_Renderer *renderer; |
2003 SDL_Window *window; | 1934 SDL_Window *window; |
2004 SDL_Rect real_rect; | 1935 SDL_Rect real_rect; |
2005 | 1936 |
2006 if (!_this) { | 1937 if (!_this) { |
2007 SDL_UninitializedVideo(); | 1938 SDL_UninitializedVideo(); |
2008 return -1; | 1939 return -1; |
2009 } | 1940 } |
2010 | 1941 renderer = SDL_CurrentDisplay.current_renderer; |
2011 renderer = SDL_CurrentDisplay.current_renderer; | 1942 if (!renderer || !renderer->RenderFill) { |
2012 if (!renderer || !renderer->RenderFill) { | 1943 return -1; |
2013 return -1; | 1944 } |
2014 } | 1945 window = SDL_GetWindowFromID(renderer->window); |
2015 | 1946 real_rect.x = 0; |
2016 window = SDL_GetWindowFromID(renderer->window); | 1947 real_rect.y = 0; |
2017 real_rect.x = 0; | 1948 real_rect.w = window->w; |
2018 real_rect.y = 0; | 1949 real_rect.h = window->h; |
2019 real_rect.w = window->w; | 1950 if (rect) { |
2020 real_rect.h = window->h; | 1951 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { |
2021 if (rect) { | 1952 return 0; |
2022 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { | 1953 } |
2023 return 0; | 1954 } |
2024 } | 1955 return renderer->RenderFill(renderer, r, g, b, a, &real_rect); |
2025 } | |
2026 | |
2027 return renderer->RenderFill(renderer, r, g, b, a, &real_rect); | |
2028 } | 1956 } |
2029 | 1957 |
2030 int | 1958 int |
2031 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, | 1959 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, |
2032 const SDL_Rect * dstrect) | 1960 const SDL_Rect * dstrect) |
2033 { | 1961 { |
2034 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | 1962 SDL_Texture *texture = SDL_GetTextureFromID(textureID); |
2035 SDL_Renderer *renderer; | 1963 SDL_Renderer *renderer; |
2036 SDL_Window *window; | 1964 SDL_Window *window; |
2037 SDL_Rect real_srcrect; | 1965 SDL_Rect real_srcrect; |
2038 SDL_Rect real_dstrect; | 1966 SDL_Rect real_dstrect; |
2039 | 1967 |
2040 if (!texture || texture->renderer != SDL_CurrentDisplay.current_renderer) { | 1968 if (!texture || texture->renderer != SDL_CurrentDisplay.current_renderer) { |
2041 return -1; | 1969 return -1; |
2042 } | 1970 } |
2043 | 1971 renderer = SDL_CurrentDisplay.current_renderer; |
2044 renderer = SDL_CurrentDisplay.current_renderer; | 1972 if (!renderer || !renderer->RenderCopy) { |
2045 if (!renderer || !renderer->RenderCopy) { | 1973 return -1; |
2046 return -1; | 1974 } |
2047 } | 1975 window = SDL_GetWindowFromID(renderer->window); |
2048 | 1976 if (srcrect) { |
2049 window = SDL_GetWindowFromID(renderer->window); | 1977 real_srcrect = *srcrect; |
2050 if (srcrect) { | 1978 } else { |
2051 real_srcrect = *srcrect; | 1979 real_srcrect.x = 0; |
2052 } else { | 1980 real_srcrect.y = 0; |
2053 real_srcrect.x = 0; | 1981 real_srcrect.w = texture->w; |
2054 real_srcrect.y = 0; | 1982 real_srcrect.h = texture->h; |
2055 real_srcrect.w = texture->w; | 1983 } |
2056 real_srcrect.h = texture->h; | 1984 if (dstrect) { |
2057 } | 1985 real_dstrect = *dstrect; |
2058 if (dstrect) { | 1986 } else { |
2059 real_dstrect = *dstrect; | 1987 real_dstrect.x = 0; |
2060 } else { | 1988 real_dstrect.y = 0; |
2061 real_dstrect.x = 0; | 1989 real_dstrect.w = window->w; |
2062 real_dstrect.y = 0; | 1990 real_dstrect.h = window->h; |
2063 real_dstrect.w = window->w; | 1991 } |
2064 real_dstrect.h = window->h; | 1992 |
2065 } | 1993 return renderer->RenderCopy(renderer, texture, &real_srcrect, |
2066 | 1994 &real_dstrect); |
2067 return renderer->RenderCopy(renderer, texture, &real_srcrect, | |
2068 &real_dstrect); | |
2069 } | 1995 } |
2070 | 1996 |
2071 void | 1997 void |
2072 SDL_RenderPresent(void) | 1998 SDL_RenderPresent(void) |
2073 { | 1999 { |
2074 SDL_Renderer *renderer; | 2000 SDL_Renderer *renderer; |
2075 | 2001 |
2076 if (!_this) { | 2002 if (!_this) { |
2077 SDL_UninitializedVideo(); | 2003 SDL_UninitializedVideo(); |
2078 return; | 2004 return; |
2079 } | 2005 } |
2080 | 2006 renderer = SDL_CurrentDisplay.current_renderer; |
2081 renderer = SDL_CurrentDisplay.current_renderer; | 2007 if (!renderer || !renderer->RenderPresent) { |
2082 if (!renderer || !renderer->RenderPresent) { | 2008 return; |
2083 return; | 2009 } |
2084 } | 2010 renderer->RenderPresent(renderer); |
2085 renderer->RenderPresent(renderer); | |
2086 } | 2011 } |
2087 | 2012 |
2088 void | 2013 void |
2089 SDL_DestroyTexture(SDL_TextureID textureID) | 2014 SDL_DestroyTexture(SDL_TextureID textureID) |
2090 { | 2015 { |
2091 int hash; | 2016 int hash; |
2092 SDL_Texture *prev, *texture; | 2017 SDL_Texture *prev, *texture; |
2093 SDL_Renderer *renderer; | 2018 SDL_Renderer *renderer; |
2094 | 2019 |
2095 if (!_this) { | 2020 if (!_this) { |
2096 SDL_UninitializedVideo(); | 2021 SDL_UninitializedVideo(); |
2097 return; | 2022 return; |
2098 } | 2023 } |
2099 | 2024 /* Look up the texture in the hash table */ |
2100 /* Look up the texture in the hash table */ | 2025 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures)); |
2101 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures)); | 2026 prev = NULL; |
2102 prev = NULL; | 2027 for (texture = SDL_CurrentDisplay.textures[hash]; texture; |
2103 for (texture = SDL_CurrentDisplay.textures[hash]; texture; | 2028 prev = texture, texture = texture->next) { |
2104 prev = texture, texture = texture->next) { | 2029 if (texture->id == textureID) { |
2105 if (texture->id == textureID) { | 2030 break; |
2106 break; | 2031 } |
2107 } | 2032 } |
2108 } | 2033 if (!texture) { |
2109 if (!texture) { | 2034 return; |
2110 return; | 2035 } |
2111 } | 2036 /* Unlink the texture from the list */ |
2112 | 2037 if (prev) { |
2113 /* Unlink the texture from the list */ | 2038 prev->next = texture->next; |
2114 if (prev) { | 2039 } else { |
2115 prev->next = texture->next; | 2040 SDL_CurrentDisplay.textures[hash] = texture->next; |
2116 } else { | 2041 } |
2117 SDL_CurrentDisplay.textures[hash] = texture->next; | 2042 |
2118 } | 2043 /* Free the texture */ |
2119 | 2044 renderer = texture->renderer; |
2120 /* Free the texture */ | 2045 renderer->DestroyTexture(renderer, texture); |
2121 renderer = texture->renderer; | 2046 SDL_free(texture); |
2122 renderer->DestroyTexture(renderer, texture); | |
2123 SDL_free(texture); | |
2124 } | 2047 } |
2125 | 2048 |
2126 void | 2049 void |
2127 SDL_DestroyRenderer(SDL_WindowID windowID) | 2050 SDL_DestroyRenderer(SDL_WindowID windowID) |
2128 { | 2051 { |
2129 SDL_Window *window = SDL_GetWindowFromID(windowID); | 2052 SDL_Window *window = SDL_GetWindowFromID(windowID); |
2130 SDL_Renderer *renderer; | 2053 SDL_Renderer *renderer; |
2131 int i; | 2054 int i; |
2132 | 2055 |
2133 if (!window) { | 2056 if (!window) { |
2134 return; | 2057 return; |
2135 } | 2058 } |
2136 | 2059 renderer = window->renderer; |
2137 renderer = window->renderer; | 2060 if (!renderer) { |
2138 if (!renderer) { | 2061 return; |
2139 return; | 2062 } |
2140 } | 2063 /* Free existing textures for this renderer */ |
2141 | 2064 for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) { |
2142 /* Free existing textures for this renderer */ | 2065 SDL_Texture *texture; |
2143 for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) { | 2066 SDL_Texture *prev = NULL; |
2144 SDL_Texture *texture; | 2067 SDL_Texture *next; |
2145 SDL_Texture *prev = NULL; | 2068 for (texture = SDL_CurrentDisplay.textures[i]; texture; |
2146 SDL_Texture *next; | 2069 texture = next) { |
2147 for (texture = SDL_CurrentDisplay.textures[i]; texture; | 2070 next = texture->next; |
2148 texture = next) { | 2071 if (texture->renderer == renderer) { |
2149 next = texture->next; | 2072 if (prev) { |
2150 if (texture->renderer == renderer) { | 2073 prev->next = next; |
2151 if (prev) { | 2074 } else { |
2152 prev->next = next; | 2075 SDL_CurrentDisplay.textures[i] = next; |
2153 } else { | 2076 } |
2154 SDL_CurrentDisplay.textures[i] = next; | 2077 renderer->DestroyTexture(renderer, texture); |
2155 } | 2078 SDL_free(texture); |
2156 renderer->DestroyTexture(renderer, texture); | 2079 } else { |
2157 SDL_free(texture); | 2080 prev = texture; |
2158 } else { | 2081 } |
2159 prev = texture; | 2082 } |
2160 } | 2083 } |
2161 } | 2084 |
2162 } | 2085 /* Free the renderer instance */ |
2163 | 2086 renderer->DestroyRenderer(renderer); |
2164 /* Free the renderer instance */ | 2087 |
2165 renderer->DestroyRenderer(renderer); | 2088 /* Clear references */ |
2166 | 2089 window->renderer = NULL; |
2167 /* Clear references */ | 2090 if (SDL_CurrentDisplay.current_renderer == renderer) { |
2168 window->renderer = NULL; | 2091 SDL_CurrentDisplay.current_renderer = NULL; |
2169 if (SDL_CurrentDisplay.current_renderer == renderer) { | 2092 } |
2170 SDL_CurrentDisplay.current_renderer = NULL; | |
2171 } | |
2172 } | 2093 } |
2173 | 2094 |
2174 void | 2095 void |
2175 SDL_VideoQuit(void) | 2096 SDL_VideoQuit(void) |
2176 { | 2097 { |
2177 int i, j; | 2098 int i, j; |
2178 | 2099 |
2179 if (!_this) { | 2100 if (!_this) { |
2180 return; | 2101 return; |
2181 } | 2102 } |
2182 | 2103 /* Halt event processing before doing anything else */ |
2183 /* Halt event processing before doing anything else */ | 2104 SDL_StopEventLoop(); |
2184 SDL_StopEventLoop(); | 2105 |
2185 | 2106 /* Clean up the system video */ |
2186 /* Clean up the system video */ | 2107 for (i = _this->num_displays; i--;) { |
2187 for (i = _this->num_displays; i--;) { | 2108 SDL_VideoDisplay *display = &_this->displays[i]; |
2188 SDL_VideoDisplay *display = &_this->displays[i]; | 2109 for (j = display->num_windows; j--;) { |
2189 for (j = display->num_windows; j--;) { | 2110 SDL_DestroyWindow(display->windows[i].id); |
2190 SDL_DestroyWindow(display->windows[i].id); | 2111 } |
2191 } | 2112 if (display->windows) { |
2192 if (display->windows) { | 2113 SDL_free(display->windows); |
2193 SDL_free(display->windows); | 2114 display->windows = NULL; |
2194 display->windows = NULL; | 2115 } |
2195 } | 2116 display->num_windows = 0; |
2196 display->num_windows = 0; | 2117 if (display->render_drivers) { |
2197 if (display->render_drivers) { | 2118 SDL_free(display->render_drivers); |
2198 SDL_free(display->render_drivers); | 2119 display->render_drivers = NULL; |
2199 display->render_drivers = NULL; | 2120 } |
2200 } | 2121 display->num_render_drivers = 0; |
2201 display->num_render_drivers = 0; | 2122 } |
2202 } | 2123 _this->VideoQuit(_this); |
2203 _this->VideoQuit(_this); | 2124 |
2204 | 2125 for (i = _this->num_displays; i--;) { |
2205 for (i = _this->num_displays; i--;) { | 2126 SDL_VideoDisplay *display = &_this->displays[i]; |
2206 SDL_VideoDisplay *display = &_this->displays[i]; | 2127 for (j = display->num_display_modes; j--;) { |
2207 for (j = display->num_display_modes; j--;) { | 2128 if (display->display_modes[j].driverdata) { |
2208 if (display->display_modes[j].driverdata) { | 2129 SDL_free(display->display_modes[j].driverdata); |
2209 SDL_free(display->display_modes[j].driverdata); | 2130 display->display_modes[j].driverdata = NULL; |
2210 display->display_modes[j].driverdata = NULL; | 2131 } |
2211 } | 2132 } |
2212 } | 2133 if (display->display_modes) { |
2213 if (display->display_modes) { | 2134 SDL_free(display->display_modes); |
2214 SDL_free(display->display_modes); | 2135 display->display_modes = NULL; |
2215 display->display_modes = NULL; | 2136 } |
2216 } | 2137 if (display->desktop_mode.driverdata) { |
2217 if (display->desktop_mode.driverdata) { | 2138 SDL_free(display->desktop_mode.driverdata); |
2218 SDL_free(display->desktop_mode.driverdata); | 2139 display->desktop_mode.driverdata = NULL; |
2219 display->desktop_mode.driverdata = NULL; | 2140 } |
2220 } | 2141 if (display->palette) { |
2221 if (display->palette) { | 2142 SDL_FreePalette(display->palette); |
2222 SDL_FreePalette(display->palette); | 2143 display->palette = NULL; |
2223 display->palette = NULL; | 2144 } |
2224 } | 2145 if (display->gamma) { |
2225 if (display->gamma) { | 2146 SDL_free(display->gamma); |
2226 SDL_free(display->gamma); | 2147 display->gamma = NULL; |
2227 display->gamma = NULL; | 2148 } |
2228 } | 2149 if (display->driverdata) { |
2229 if (display->driverdata) { | 2150 SDL_free(display->driverdata); |
2230 SDL_free(display->driverdata); | 2151 display->driverdata = NULL; |
2231 display->driverdata = NULL; | 2152 } |
2232 } | 2153 } |
2233 } | 2154 if (_this->displays) { |
2234 if (_this->displays) { | 2155 SDL_free(_this->displays); |
2235 SDL_free(_this->displays); | 2156 _this->displays = NULL; |
2236 _this->displays = NULL; | 2157 } |
2237 } | 2158 _this->free(_this); |
2238 _this->free(_this); | 2159 _this = NULL; |
2239 _this = NULL; | |
2240 } | 2160 } |
2241 | 2161 |
2242 int | 2162 int |
2243 SDL_GL_LoadLibrary(const char *path) | 2163 SDL_GL_LoadLibrary(const char *path) |
2244 { | 2164 { |
2245 int retval; | 2165 int retval; |
2246 | 2166 |
2247 if (!_this) { | 2167 if (!_this) { |
2248 SDL_UninitializedVideo(); | 2168 SDL_UninitializedVideo(); |
2249 return -1; | 2169 return -1; |
2250 } | 2170 } |
2251 | 2171 if (_this->GL_LoadLibrary) { |
2252 if (_this->GL_LoadLibrary) { | 2172 retval = _this->GL_LoadLibrary(_this, path); |
2253 retval = _this->GL_LoadLibrary(_this, path); | 2173 } else { |
2254 } else { | 2174 SDL_SetError("No dynamic GL support in video driver"); |
2255 SDL_SetError("No dynamic GL support in video driver"); | 2175 retval = -1; |
2256 retval = -1; | 2176 } |
2257 } | 2177 return (retval); |
2258 return (retval); | 2178 } |
2259 } | 2179 |
2260 | 2180 void * |
2261 void * | |
2262 SDL_GL_GetProcAddress(const char *proc) | 2181 SDL_GL_GetProcAddress(const char *proc) |
2263 { | 2182 { |
2264 void *func; | 2183 void *func; |
2265 | 2184 |
2266 if (!_this) { | 2185 if (!_this) { |
2267 SDL_UninitializedVideo(); | 2186 SDL_UninitializedVideo(); |
2268 return NULL; | 2187 return NULL; |
2269 } | 2188 } |
2270 | 2189 func = NULL; |
2271 func = NULL; | 2190 if (_this->GL_GetProcAddress) { |
2272 if (_this->GL_GetProcAddress) { | 2191 if (_this->gl_config.driver_loaded) { |
2273 if (_this->gl_config.driver_loaded) { | 2192 func = _this->GL_GetProcAddress(_this, proc); |
2274 func = _this->GL_GetProcAddress(_this, proc); | 2193 } else { |
2275 } else { | 2194 SDL_SetError("No GL driver has been loaded"); |
2276 SDL_SetError("No GL driver has been loaded"); | 2195 } |
2277 } | 2196 } else { |
2278 } else { | 2197 SDL_SetError("No dynamic GL support in video driver"); |
2279 SDL_SetError("No dynamic GL support in video driver"); | 2198 } |
2280 } | 2199 return func; |
2281 return func; | |
2282 } | 2200 } |
2283 | 2201 |
2284 SDL_bool | 2202 SDL_bool |
2285 SDL_GL_ExtensionSupported(const char *extension) | 2203 SDL_GL_ExtensionSupported(const char *extension) |
2286 { | 2204 { |
2287 #if SDL_VIDEO_OPENGL | 2205 #if SDL_VIDEO_OPENGL |
2288 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); | 2206 const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); |
2289 const char *extensions; | 2207 const char *extensions; |
2290 const char *start; | 2208 const char *start; |
2291 const char *where, *terminator; | 2209 const char *where, *terminator; |
2292 | 2210 |
2293 /* Extension names should not have spaces. */ | 2211 /* Extension names should not have spaces. */ |
2294 where = SDL_strchr(extension, ' '); | 2212 where = SDL_strchr(extension, ' '); |
2295 if (where || *extension == '\0') { | 2213 if (where || *extension == '\0') { |
2296 return SDL_FALSE; | 2214 return SDL_FALSE; |
2297 } | 2215 } |
2298 | 2216 /* See if there's an environment variable override */ |
2299 /* See if there's an environment variable override */ | 2217 start = SDL_getenv(extension); |
2300 start = SDL_getenv(extension); | 2218 if (start && *start == '0') { |
2301 if (start && *start == '0') { | 2219 return SDL_FALSE; |
2302 return SDL_FALSE; | 2220 } |
2303 } | 2221 /* Lookup the available extensions */ |
2304 | 2222 glGetStringFunc = SDL_GL_GetProcAddress("glGetString"); |
2305 /* Lookup the available extensions */ | 2223 if (glGetStringFunc) { |
2306 glGetStringFunc = SDL_GL_GetProcAddress("glGetString"); | 2224 extensions = (const char *) glGetStringFunc(GL_EXTENSIONS); |
2307 if (glGetStringFunc) { | 2225 } else { |
2308 extensions = (const char *) glGetStringFunc(GL_EXTENSIONS); | 2226 extensions = NULL; |
2309 } else { | 2227 } |
2310 extensions = NULL; | 2228 if (!extensions) { |
2311 } | 2229 return SDL_FALSE; |
2312 if (!extensions) { | 2230 } |
2313 return SDL_FALSE; | 2231 /* |
2314 } | 2232 * It takes a bit of care to be fool-proof about parsing the OpenGL |
2315 | 2233 * extensions string. Don't be fooled by sub-strings, etc. |
2316 /* It takes a bit of care to be fool-proof about parsing the | 2234 */ |
2317 * OpenGL extensions string. Don't be fooled by sub-strings, | 2235 |
2318 * etc. */ | 2236 start = extensions; |
2319 | 2237 |
2320 start = extensions; | 2238 for (;;) { |
2321 | 2239 where = SDL_strstr(start, extension); |
2322 for (;;) { | 2240 if (!where) |
2323 where = SDL_strstr(start, extension); | 2241 break; |
2324 if (!where) | 2242 |
2325 break; | 2243 terminator = where + SDL_strlen(extension); |
2326 | 2244 if (where == start || *(where - 1) == ' ') |
2327 terminator = where + SDL_strlen(extension); | 2245 if (*terminator == ' ' || *terminator == '\0') |
2328 if (where == start || *(where - 1) == ' ') | 2246 return SDL_TRUE; |
2329 if (*terminator == ' ' || *terminator == '\0') | 2247 |
2330 return SDL_TRUE; | 2248 start = terminator; |
2331 | 2249 } |
2332 start = terminator; | 2250 return SDL_FALSE; |
2333 } | |
2334 return SDL_FALSE; | |
2335 #else | 2251 #else |
2336 return SDL_FALSE; | 2252 return SDL_FALSE; |
2337 #endif | 2253 #endif |
2338 } | 2254 } |
2339 | 2255 |
2340 int | 2256 int |
2341 SDL_GL_SetAttribute(SDL_GLattr attr, int value) | 2257 SDL_GL_SetAttribute(SDL_GLattr attr, int value) |
2342 { | 2258 { |
2343 #if SDL_VIDEO_OPENGL | 2259 #if SDL_VIDEO_OPENGL |
2344 int retval; | 2260 int retval; |
2345 | 2261 |
2346 if (!_this) { | 2262 if (!_this) { |
2347 SDL_UninitializedVideo(); | 2263 SDL_UninitializedVideo(); |
2348 return -1; | 2264 return -1; |
2349 } | 2265 } |
2350 | 2266 retval = 0; |
2351 retval = 0; | 2267 switch (attr) { |
2352 switch (attr) { | 2268 case SDL_GL_RED_SIZE: |
2353 case SDL_GL_RED_SIZE: | 2269 _this->gl_config.red_size = value; |
2354 _this->gl_config.red_size = value; | 2270 break; |
2355 break; | 2271 case SDL_GL_GREEN_SIZE: |
2356 case SDL_GL_GREEN_SIZE: | 2272 _this->gl_config.green_size = value; |
2357 _this->gl_config.green_size = value; | 2273 break; |
2358 break; | 2274 case SDL_GL_BLUE_SIZE: |
2359 case SDL_GL_BLUE_SIZE: | 2275 _this->gl_config.blue_size = value; |
2360 _this->gl_config.blue_size = value; | 2276 break; |
2361 break; | 2277 case SDL_GL_ALPHA_SIZE: |
2362 case SDL_GL_ALPHA_SIZE: | 2278 _this->gl_config.alpha_size = value; |
2363 _this->gl_config.alpha_size = value; | 2279 break; |
2364 break; | 2280 case SDL_GL_DOUBLEBUFFER: |
2365 case SDL_GL_DOUBLEBUFFER: | 2281 _this->gl_config.double_buffer = value; |
2366 _this->gl_config.double_buffer = value; | 2282 break; |
2367 break; | 2283 case SDL_GL_BUFFER_SIZE: |
2368 case SDL_GL_BUFFER_SIZE: | 2284 _this->gl_config.buffer_size = value; |
2369 _this->gl_config.buffer_size = value; | 2285 break; |
2370 break; | 2286 case SDL_GL_DEPTH_SIZE: |
2371 case SDL_GL_DEPTH_SIZE: | 2287 _this->gl_config.depth_size = value; |
2372 _this->gl_config.depth_size = value; | 2288 break; |
2373 break; | 2289 case SDL_GL_STENCIL_SIZE: |
2374 case SDL_GL_STENCIL_SIZE: | 2290 _this->gl_config.stencil_size = value; |
2375 _this->gl_config.stencil_size = value; | 2291 break; |
2376 break; | 2292 case SDL_GL_ACCUM_RED_SIZE: |
2377 case SDL_GL_ACCUM_RED_SIZE: | 2293 _this->gl_config.accum_red_size = value; |
2378 _this->gl_config.accum_red_size = value; | 2294 break; |
2379 break; | 2295 case SDL_GL_ACCUM_GREEN_SIZE: |
2380 case SDL_GL_ACCUM_GREEN_SIZE: | 2296 _this->gl_config.accum_green_size = value; |
2381 _this->gl_config.accum_green_size = value; | 2297 break; |
2382 break; | 2298 case SDL_GL_ACCUM_BLUE_SIZE: |
2383 case SDL_GL_ACCUM_BLUE_SIZE: | 2299 _this->gl_config.accum_blue_size = value; |
2384 _this->gl_config.accum_blue_size = value; | 2300 break; |
2385 break; | 2301 case SDL_GL_ACCUM_ALPHA_SIZE: |
2386 case SDL_GL_ACCUM_ALPHA_SIZE: | 2302 _this->gl_config.accum_alpha_size = value; |
2387 _this->gl_config.accum_alpha_size = value; | 2303 break; |
2388 break; | 2304 case SDL_GL_STEREO: |
2389 case SDL_GL_STEREO: | 2305 _this->gl_config.stereo = value; |
2390 _this->gl_config.stereo = value; | 2306 break; |
2391 break; | 2307 case SDL_GL_MULTISAMPLEBUFFERS: |
2392 case SDL_GL_MULTISAMPLEBUFFERS: | 2308 _this->gl_config.multisamplebuffers = value; |
2393 _this->gl_config.multisamplebuffers = value; | 2309 break; |
2394 break; | 2310 case SDL_GL_MULTISAMPLESAMPLES: |
2395 case SDL_GL_MULTISAMPLESAMPLES: | 2311 _this->gl_config.multisamplesamples = value; |
2396 _this->gl_config.multisamplesamples = value; | 2312 break; |
2397 break; | 2313 case SDL_GL_ACCELERATED_VISUAL: |
2398 case SDL_GL_ACCELERATED_VISUAL: | 2314 _this->gl_config.accelerated = value; |
2399 _this->gl_config.accelerated = value; | 2315 break; |
2400 break; | 2316 default: |
2401 default: | 2317 SDL_SetError("Unknown OpenGL attribute"); |
2402 SDL_SetError("Unknown OpenGL attribute"); | 2318 retval = -1; |
2403 retval = -1; | 2319 break; |
2404 break; | 2320 } |
2405 } | 2321 return retval; |
2406 return retval; | |
2407 #else | 2322 #else |
2408 SDL_Unsupported(); | 2323 SDL_Unsupported(); |
2409 return -1; | 2324 return -1; |
2410 #endif /* SDL_VIDEO_OPENGL */ | 2325 #endif /* SDL_VIDEO_OPENGL */ |
2411 } | 2326 } |
2412 | 2327 |
2413 int | 2328 int |
2414 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) | 2329 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) |
2415 { | 2330 { |
2416 #if SDL_VIDEO_OPENGL | 2331 #if SDL_VIDEO_OPENGL |
2417 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); | 2332 void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); |
2418 GLenum attrib = 0; | 2333 GLenum attrib = 0; |
2419 | 2334 |
2420 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv"); | 2335 glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv"); |
2421 if (!glGetIntegervFunc) { | 2336 if (!glGetIntegervFunc) { |
2422 return -1; | 2337 return -1; |
2423 } | 2338 } |
2424 switch (attr) { | 2339 switch (attr) { |
2425 case SDL_GL_RED_SIZE: | 2340 case SDL_GL_RED_SIZE: |
2426 attrib = GL_RED_BITS; | 2341 attrib = GL_RED_BITS; |
2427 break; | 2342 break; |
2428 case SDL_GL_BLUE_SIZE: | 2343 case SDL_GL_BLUE_SIZE: |
2429 attrib = GL_BLUE_BITS; | 2344 attrib = GL_BLUE_BITS; |
2430 break; | 2345 break; |
2431 case SDL_GL_GREEN_SIZE: | 2346 case SDL_GL_GREEN_SIZE: |
2432 attrib = GL_GREEN_BITS; | 2347 attrib = GL_GREEN_BITS; |
2433 break; | 2348 break; |
2434 case SDL_GL_ALPHA_SIZE: | 2349 case SDL_GL_ALPHA_SIZE: |
2435 attrib = GL_ALPHA_BITS; | 2350 attrib = GL_ALPHA_BITS; |
2436 break; | 2351 break; |
2437 case SDL_GL_DOUBLEBUFFER: | 2352 case SDL_GL_DOUBLEBUFFER: |
2438 attrib = GL_DOUBLEBUFFER; | 2353 attrib = GL_DOUBLEBUFFER; |
2439 break; | 2354 break; |
2440 case SDL_GL_DEPTH_SIZE: | 2355 case SDL_GL_DEPTH_SIZE: |
2441 attrib = GL_DEPTH_BITS; | 2356 attrib = GL_DEPTH_BITS; |
2442 break; | 2357 break; |
2443 case SDL_GL_STENCIL_SIZE: | 2358 case SDL_GL_STENCIL_SIZE: |
2444 attrib = GL_STENCIL_BITS; | 2359 attrib = GL_STENCIL_BITS; |
2445 break; | 2360 break; |
2446 case SDL_GL_ACCUM_RED_SIZE: | 2361 case SDL_GL_ACCUM_RED_SIZE: |
2447 attrib = GL_ACCUM_RED_BITS; | 2362 attrib = GL_ACCUM_RED_BITS; |
2448 break; | 2363 break; |
2449 case SDL_GL_ACCUM_GREEN_SIZE: | 2364 case SDL_GL_ACCUM_GREEN_SIZE: |
2450 attrib = GL_ACCUM_GREEN_BITS; | 2365 attrib = GL_ACCUM_GREEN_BITS; |
2451 break; | 2366 break; |
2452 case SDL_GL_ACCUM_BLUE_SIZE: | 2367 case SDL_GL_ACCUM_BLUE_SIZE: |
2453 attrib = GL_ACCUM_BLUE_BITS; | 2368 attrib = GL_ACCUM_BLUE_BITS; |
2454 break; | 2369 break; |
2455 case SDL_GL_ACCUM_ALPHA_SIZE: | 2370 case SDL_GL_ACCUM_ALPHA_SIZE: |
2456 attrib = GL_ACCUM_ALPHA_BITS; | 2371 attrib = GL_ACCUM_ALPHA_BITS; |
2457 break; | 2372 break; |
2458 case SDL_GL_STEREO: | 2373 case SDL_GL_STEREO: |
2459 attrib = GL_STEREO; | 2374 attrib = GL_STEREO; |
2460 break; | 2375 break; |
2461 case SDL_GL_MULTISAMPLEBUFFERS: | 2376 case SDL_GL_MULTISAMPLEBUFFERS: |
2462 attrib = GL_SAMPLE_BUFFERS_ARB; | 2377 attrib = GL_SAMPLE_BUFFERS_ARB; |
2463 break; | 2378 break; |
2464 case SDL_GL_MULTISAMPLESAMPLES: | 2379 case SDL_GL_MULTISAMPLESAMPLES: |
2465 attrib = GL_SAMPLES_ARB; | 2380 attrib = GL_SAMPLES_ARB; |
2466 break; | 2381 break; |
2467 case SDL_GL_BUFFER_SIZE: | 2382 case SDL_GL_BUFFER_SIZE: |
2468 { | 2383 { |
2469 GLint bits = 0; | 2384 GLint bits = 0; |
2470 GLint component; | 2385 GLint component; |
2471 | 2386 |
2472 /* there doesn't seem to be a single flag in OpenGL for this! */ | 2387 /* |
2473 glGetIntegervFunc(GL_RED_BITS, &component); | 2388 * there doesn't seem to be a single flag in OpenGL |
2474 bits += component; | 2389 * for this! |
2475 glGetIntegervFunc(GL_GREEN_BITS, &component); | 2390 */ |
2476 bits += component; | 2391 glGetIntegervFunc(GL_RED_BITS, &component); |
2477 glGetIntegervFunc(GL_BLUE_BITS, &component); | 2392 bits += component; |
2478 bits += component; | 2393 glGetIntegervFunc(GL_GREEN_BITS, &component); |
2479 glGetIntegervFunc(GL_ALPHA_BITS, &component); | 2394 bits += component; |
2480 bits += component; | 2395 glGetIntegervFunc(GL_BLUE_BITS, &component); |
2481 | 2396 bits += component; |
2482 *value = bits; | 2397 glGetIntegervFunc(GL_ALPHA_BITS, &component); |
2483 return 0; | 2398 bits += component; |
2484 } | 2399 |
2485 case SDL_GL_ACCELERATED_VISUAL: | 2400 *value = bits; |
2486 { | 2401 return 0; |
2487 /* FIXME: How do we get this information? */ | 2402 } |
2488 *value = (_this->gl_config.accelerated != 0); | 2403 case SDL_GL_ACCELERATED_VISUAL: |
2489 return 0; | 2404 { |
2490 } | 2405 /* FIXME: How do we get this information? */ |
2491 default: | 2406 *value = (_this->gl_config.accelerated != 0); |
2492 SDL_SetError("Unknown OpenGL attribute"); | 2407 return 0; |
2493 return -1; | 2408 } |
2494 } | 2409 default: |
2495 | 2410 SDL_SetError("Unknown OpenGL attribute"); |
2496 glGetIntegervFunc(attrib, (GLint *) value); | 2411 return -1; |
2497 return 0; | 2412 } |
2413 | |
2414 glGetIntegervFunc(attrib, (GLint *) value); | |
2415 return 0; | |
2498 #else | 2416 #else |
2499 SDL_Unsupported(); | 2417 SDL_Unsupported(); |
2500 return -1; | 2418 return -1; |
2501 #endif /* SDL_VIDEO_OPENGL */ | 2419 #endif /* SDL_VIDEO_OPENGL */ |
2502 } | 2420 } |
2503 | 2421 |
2504 SDL_GLContext | 2422 SDL_GLContext |
2505 SDL_GL_CreateContext(SDL_WindowID windowID) | 2423 SDL_GL_CreateContext(SDL_WindowID windowID) |
2506 { | 2424 { |
2507 SDL_Window *window = SDL_GetWindowFromID(windowID); | 2425 SDL_Window *window = SDL_GetWindowFromID(windowID); |
2508 | 2426 |
2509 if (!window) { | 2427 if (!window) { |
2510 return NULL; | 2428 return NULL; |
2511 } | 2429 } |
2512 if (!(window->flags & SDL_WINDOW_OPENGL)) { | 2430 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
2513 SDL_SetError("The specified window isn't an OpenGL window"); | 2431 SDL_SetError("The specified window isn't an OpenGL window"); |
2514 return NULL; | 2432 return NULL; |
2515 } | 2433 } |
2516 return _this->GL_CreateContext(_this, window); | 2434 return _this->GL_CreateContext(_this, window); |
2517 } | 2435 } |
2518 | 2436 |
2519 int | 2437 int |
2520 SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context) | 2438 SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context) |
2521 { | 2439 { |
2522 SDL_Window *window = SDL_GetWindowFromID(windowID); | 2440 SDL_Window *window = SDL_GetWindowFromID(windowID); |
2523 | 2441 |
2524 if (window && !(window->flags & SDL_WINDOW_OPENGL)) { | 2442 if (window && !(window->flags & SDL_WINDOW_OPENGL)) { |
2525 SDL_SetError("The specified window isn't an OpenGL window"); | 2443 SDL_SetError("The specified window isn't an OpenGL window"); |
2526 return -1; | 2444 return -1; |
2527 } | 2445 } |
2528 if (!context) { | 2446 if (!context) { |
2529 window = NULL; | 2447 window = NULL; |
2530 } | 2448 } |
2531 return _this->GL_MakeCurrent(_this, window, context); | 2449 return _this->GL_MakeCurrent(_this, window, context); |
2532 } | 2450 } |
2533 | 2451 |
2534 int | 2452 int |
2535 SDL_GL_SetSwapInterval(int interval) | 2453 SDL_GL_SetSwapInterval(int interval) |
2536 { | 2454 { |
2537 if (!_this) { | 2455 if (!_this) { |
2538 SDL_UninitializedVideo(); | 2456 SDL_UninitializedVideo(); |
2539 return -1; | 2457 return -1; |
2540 } | 2458 } |
2541 | 2459 if (_this->GL_SetSwapInterval) { |
2542 if (_this->GL_SetSwapInterval) { | 2460 return _this->GL_SetSwapInterval(_this, interval); |
2543 return _this->GL_SetSwapInterval(_this, interval); | 2461 } else { |
2544 } else { | 2462 SDL_SetError("Setting the swap interval is not supported"); |
2545 SDL_SetError("Setting the swap interval is not supported"); | 2463 return -1; |
2546 return -1; | 2464 } |
2547 } | |
2548 } | 2465 } |
2549 | 2466 |
2550 int | 2467 int |
2551 SDL_GL_GetSwapInterval(void) | 2468 SDL_GL_GetSwapInterval(void) |
2552 { | 2469 { |
2553 if (!_this) { | 2470 if (!_this) { |
2554 SDL_UninitializedVideo(); | 2471 SDL_UninitializedVideo(); |
2555 return -1; | 2472 return -1; |
2556 } | 2473 } |
2557 | 2474 if (_this->GL_GetSwapInterval) { |
2558 if (_this->GL_GetSwapInterval) { | 2475 return _this->GL_GetSwapInterval(_this); |
2559 return _this->GL_GetSwapInterval(_this); | 2476 } else { |
2560 } else { | 2477 SDL_SetError("Getting the swap interval is not supported"); |
2561 SDL_SetError("Getting the swap interval is not supported"); | 2478 return -1; |
2562 return -1; | 2479 } |
2563 } | |
2564 } | 2480 } |
2565 | 2481 |
2566 void | 2482 void |
2567 SDL_GL_SwapWindow(SDL_WindowID windowID) | 2483 SDL_GL_SwapWindow(SDL_WindowID windowID) |
2568 { | 2484 { |
2569 SDL_Window *window = SDL_GetWindowFromID(windowID); | 2485 SDL_Window *window = SDL_GetWindowFromID(windowID); |
2570 | 2486 |
2571 if (!window) { | 2487 if (!window) { |
2572 return; | 2488 return; |
2573 } | 2489 } |
2574 if (!(window->flags & SDL_WINDOW_OPENGL)) { | 2490 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
2575 SDL_SetError("The specified window isn't an OpenGL window"); | 2491 SDL_SetError("The specified window isn't an OpenGL window"); |
2576 return; | 2492 return; |
2577 } | 2493 } |
2578 _this->GL_SwapWindow(_this, window); | 2494 _this->GL_SwapWindow(_this, window); |
2579 } | 2495 } |
2580 | 2496 |
2581 void | 2497 void |
2582 SDL_GL_DeleteContext(SDL_GLContext context) | 2498 SDL_GL_DeleteContext(SDL_GLContext context) |
2583 { | 2499 { |
2584 if (!_this || !context) { | 2500 if (!_this || !context) { |
2585 return; | 2501 return; |
2586 } | 2502 } |
2587 _this->GL_MakeCurrent(_this, NULL, NULL); | 2503 _this->GL_MakeCurrent(_this, NULL, NULL); |
2588 _this->GL_DeleteContext(_this, context); | 2504 _this->GL_DeleteContext(_this, context); |
2589 } | 2505 } |
2590 | 2506 |
2591 #if 0 // FIXME | 2507 #if 0 // FIXME |
2592 /* Utility function used by SDL_WM_SetIcon(); | 2508 /* |
2593 * flags & 1 for color key, flags & 2 for alpha channel. */ | 2509 * Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags |
2510 * & 2 for alpha channel. | |
2511 */ | |
2594 static void | 2512 static void |
2595 CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags) | 2513 CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags) |
2596 { | 2514 { |
2597 int x, y; | 2515 int x, y; |
2598 Uint32 colorkey; | 2516 Uint32 colorkey; |
2599 #define SET_MASKBIT(icon, x, y, mask) \ | 2517 #define SET_MASKBIT(icon, x, y, mask) \ |
2600 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) | 2518 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) |
2601 | 2519 |
2602 colorkey = icon->format->colorkey; | 2520 colorkey = icon->format->colorkey; |
2603 switch (icon->format->BytesPerPixel) { | 2521 switch (icon->format->BytesPerPixel) { |
2604 case 1: | 2522 case 1: |
2605 { | 2523 { |
2606 Uint8 *pixels; | 2524 Uint8 *pixels; |
2607 for (y = 0; y < icon->h; ++y) { | 2525 for (y = 0; y < icon->h; ++y) { |
2608 pixels = (Uint8 *) icon->pixels + y * icon->pitch; | 2526 pixels = (Uint8 *) icon->pixels + y * icon->pitch; |
2609 for (x = 0; x < icon->w; ++x) { | 2527 for (x = 0; x < icon->w; ++x) { |
2610 if (*pixels++ == colorkey) { | 2528 if (*pixels++ == colorkey) { |
2611 SET_MASKBIT(icon, x, y, mask); | 2529 SET_MASKBIT(icon, x, y, mask); |
2612 } | 2530 } |
2613 } | 2531 } |
2614 } | 2532 } |
2615 } | 2533 } |
2616 break; | 2534 break; |
2617 | 2535 |
2618 case 2: | 2536 case 2: |
2619 { | 2537 { |
2620 Uint16 *pixels; | 2538 Uint16 *pixels; |
2621 for (y = 0; y < icon->h; ++y) { | 2539 for (y = 0; y < icon->h; ++y) { |
2622 pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2; | 2540 pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2; |
2623 for (x = 0; x < icon->w; ++x) { | 2541 for (x = 0; x < icon->w; ++x) { |
2624 if ((flags & 1) && *pixels == colorkey) { | 2542 if ((flags & 1) && *pixels == colorkey) { |
2625 SET_MASKBIT(icon, x, y, mask); | 2543 SET_MASKBIT(icon, x, y, mask); |
2626 } else if ((flags & 2) | 2544 } else if ((flags & 2) |
2627 && (*pixels & icon->format->Amask) == 0) { | 2545 && (*pixels & icon->format->Amask) == 0) { |
2628 SET_MASKBIT(icon, x, y, mask); | 2546 SET_MASKBIT(icon, x, y, mask); |
2629 } | 2547 } |
2630 pixels++; | 2548 pixels++; |
2631 } | 2549 } |
2632 } | 2550 } |
2633 } | 2551 } |
2634 break; | 2552 break; |
2635 | 2553 |
2636 case 4: | 2554 case 4: |
2637 { | 2555 { |
2638 Uint32 *pixels; | 2556 Uint32 *pixels; |
2639 for (y = 0; y < icon->h; ++y) { | 2557 for (y = 0; y < icon->h; ++y) { |
2640 pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4; | 2558 pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4; |
2641 for (x = 0; x < icon->w; ++x) { | 2559 for (x = 0; x < icon->w; ++x) { |
2642 if ((flags & 1) && *pixels == colorkey) { | 2560 if ((flags & 1) && *pixels == colorkey) { |
2643 SET_MASKBIT(icon, x, y, mask); | 2561 SET_MASKBIT(icon, x, y, mask); |
2644 } else if ((flags & 2) | 2562 } else if ((flags & 2) |
2645 && (*pixels & icon->format->Amask) == 0) { | 2563 && (*pixels & icon->format->Amask) == 0) { |
2646 SET_MASKBIT(icon, x, y, mask); | 2564 SET_MASKBIT(icon, x, y, mask); |
2647 } | 2565 } |
2648 pixels++; | 2566 pixels++; |
2649 } | 2567 } |
2650 } | 2568 } |
2651 } | 2569 } |
2652 break; | 2570 break; |
2653 } | 2571 } |
2654 } | 2572 } |
2655 | 2573 |
2656 /* | 2574 /* |
2657 * Sets the window manager icon for the display window. | 2575 * Sets the window manager icon for the display window. |
2658 */ | 2576 */ |
2659 void | 2577 void |
2660 SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) | 2578 SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) |
2661 { | 2579 { |
2662 if (icon && _this->SetIcon) { | 2580 if (icon && _this->SetIcon) { |
2663 /* Generate a mask if necessary, and create the icon! */ | 2581 /* Generate a mask if necessary, and create the icon! */ |
2664 if (mask == NULL) { | 2582 if (mask == NULL) { |
2665 int mask_len = icon->h * (icon->w + 7) / 8; | 2583 int mask_len = icon->h * (icon->w + 7) / 8; |
2666 int flags = 0; | 2584 int flags = 0; |
2667 mask = (Uint8 *) SDL_malloc(mask_len); | 2585 mask = (Uint8 *) SDL_malloc(mask_len); |
2668 if (mask == NULL) { | 2586 if (mask == NULL) { |
2669 return; | 2587 return; |
2670 } | 2588 } |
2671 SDL_memset(mask, ~0, mask_len); | 2589 SDL_memset(mask, ~0, mask_len); |
2672 if (icon->flags & SDL_SRCCOLORKEY) | 2590 if (icon->flags & SDL_SRCCOLORKEY) |
2673 flags |= 1; | 2591 flags |= 1; |
2674 if (icon->flags & SDL_SRCALPHA) | 2592 if (icon->flags & SDL_SRCALPHA) |
2675 flags |= 2; | 2593 flags |= 2; |
2676 if (flags) { | 2594 if (flags) { |
2677 CreateMaskFromColorKeyOrAlpha(icon, mask, flags); | 2595 CreateMaskFromColorKeyOrAlpha(icon, mask, flags); |
2678 } | 2596 } |
2679 _this->SetIcon(_this, icon, mask); | 2597 _this->SetIcon(_this, icon, mask); |
2680 SDL_free(mask); | 2598 SDL_free(mask); |
2681 } else { | 2599 } else { |
2682 _this->SetIcon(_this, icon, mask); | 2600 _this->SetIcon(_this, icon, mask); |
2683 } | 2601 } |
2684 } | 2602 } |
2685 } | 2603 } |
2686 #endif | 2604 #endif |
2687 | 2605 |
2688 SDL_bool | 2606 SDL_bool |
2689 SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info) | 2607 SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo * info) |
2690 { | 2608 { |
2691 SDL_Window *window = SDL_GetWindowFromID(windowID); | 2609 SDL_Window *window = SDL_GetWindowFromID(windowID); |
2692 | 2610 |
2693 if (!window || !_this->GetWindowWMInfo) { | 2611 if (!window || !_this->GetWindowWMInfo) { |
2694 return SDL_FALSE; | 2612 return SDL_FALSE; |
2695 } | 2613 } |
2696 return (_this->GetWindowWMInfo(_this, window, info)); | 2614 return (_this->GetWindowWMInfo(_this, window, info)); |
2697 } | 2615 } |
2698 | 2616 |
2699 /* vi: set ts=4 sw=4 expandtab: */ | 2617 /* vi: set ts=4 sw=4 expandtab: */ |