comparison src/video/SDL_video.c @ 1725:98a3207ddde8 SDL-1.3

Implemented Win32 video mode support
author Sam Lantinga <slouken@libsdl.org>
date Fri, 07 Jul 2006 08:05:39 +0000
parents 6c63fc2bd986
children 0ef52d56e8bb
comparison
equal deleted inserted replaced
1724:6c63fc2bd986 1725:98a3207ddde8
360 _this->current_display = index; 360 _this->current_display = index;
361 } 361 }
362 return _this->current_display; 362 return _this->current_display;
363 } 363 }
364 364
365 void 365 SDL_bool
366 SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode) 366 SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
367 { 367 {
368 SDL_VideoDisplay *display = &_this->displays[displayIndex]; 368 SDL_VideoDisplay *display = &_this->displays[displayIndex];
369 SDL_DisplayMode *modes; 369 SDL_DisplayMode *modes;
370 int i, nmodes; 370 int i, nmodes;
371 371
372 /* Make sure we don't already have the mode in the list */ 372 /* Make sure we don't already have the mode in the list */
373 modes = display->display_modes; 373 modes = display->display_modes;
374 nmodes = display->num_display_modes; 374 nmodes = display->num_display_modes;
375 for (i = 0; i < nmodes; ++i) { 375 for (i = nmodes; i--;) {
376 if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) { 376 if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
377 return; 377 return SDL_FALSE;
378 } 378 }
379 } 379 }
380 380
381 /* Go ahead and add the new mode */ 381 /* Go ahead and add the new mode */
382 modes = SDL_realloc(modes, (nmodes + 1) * sizeof(*mode)); 382 if (nmodes == display->max_display_modes) {
383 if (modes) { 383 modes =
384 SDL_realloc(modes,
385 (display->max_display_modes + 32) * sizeof(*modes));
386 if (!modes) {
387 return SDL_FALSE;
388 }
384 display->display_modes = modes; 389 display->display_modes = modes;
385 modes[nmodes] = *mode; 390 display->max_display_modes += 32;
386 display->num_display_modes++; 391 }
387 } 392 modes[nmodes] = *mode;
393 display->num_display_modes++;
394
395 return SDL_TRUE;
388 } 396 }
389 397
390 int 398 int
391 SDL_GetNumDisplayModes() 399 SDL_GetNumDisplayModes()
392 { 400 {
499 if (match->refresh_rate) { 507 if (match->refresh_rate) {
500 closest->refresh_rate = match->refresh_rate; 508 closest->refresh_rate = match->refresh_rate;
501 } else { 509 } else {
502 closest->refresh_rate = mode->refresh_rate; 510 closest->refresh_rate = mode->refresh_rate;
503 } 511 }
512 closest->driverdata = match->driverdata;
513
504 /* Pick some reasonable defaults if the app and driver don't care */ 514 /* Pick some reasonable defaults if the app and driver don't care */
505 if (!closest->format) { 515 if (!closest->format) {
506 closest->format = SDL_PixelFormat_RGB888; 516 closest->format = SDL_PixelFormat_RGB888;
507 } 517 }
508 if (!closest->w) { 518 if (!closest->w) {
519 int 529 int
520 SDL_SetDisplayMode(const SDL_DisplayMode * mode) 530 SDL_SetDisplayMode(const SDL_DisplayMode * mode)
521 { 531 {
522 SDL_VideoDisplay *display; 532 SDL_VideoDisplay *display;
523 SDL_DisplayMode display_mode; 533 SDL_DisplayMode display_mode;
524 int ncolors; 534 int i, ncolors;
525 535
526 if (!_this) { 536 if (!_this) {
527 SDL_SetError("Video subsystem has not been initialized"); 537 SDL_SetError("Video subsystem has not been initialized");
528 return -1; 538 return -1;
529 } 539 }
560 (&display_mode, SDL_GetCurrentDisplayMode(), 570 (&display_mode, SDL_GetCurrentDisplayMode(),
561 sizeof(display_mode)) == 0) { 571 sizeof(display_mode)) == 0) {
562 return 0; 572 return 0;
563 } 573 }
564 574
575 /* Actually change the display mode */
576 if (_this->SetDisplayMode(_this, &display_mode) < 0) {
577 return -1;
578 }
579 display->current_mode = display_mode;
580
565 /* Set up a palette, if necessary */ 581 /* Set up a palette, if necessary */
566 if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) { 582 if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
567 ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format)); 583 ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format));
568 } else { 584 } else {
569 ncolors = 0; 585 ncolors = 0;
582 SDL_DitherColors(display->palette->colors, 598 SDL_DitherColors(display->palette->colors,
583 SDL_BITSPERPIXEL(display_mode.format)); 599 SDL_BITSPERPIXEL(display_mode.format));
584 } 600 }
585 } 601 }
586 602
587 return _this->SetDisplayMode(_this, &display_mode); 603 /* Move any fullscreen windows into position */
604 for (i = 0; i < display->num_windows; ++i) {
605 SDL_Window *window = &display->windows[i];
606 if (window->flags & SDL_WINDOW_FULLSCREEN) {
607 SDL_SetWindowPosition(window->id,
608 ((display_mode.w - window->w) / 2),
609 ((display_mode.h - window->h) / 2));
610 }
611 }
612
613 return 0;
588 } 614 }
589 615
590 int 616 int
591 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors) 617 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors)
592 { 618 {
660 } 686 }
661 687
662 SDL_zero(window); 688 SDL_zero(window);
663 window.id = _this->next_object_id++; 689 window.id = _this->next_object_id++;
664 window.title = title ? SDL_strdup(title) : NULL; 690 window.title = title ? SDL_strdup(title) : NULL;
665 window.x = x; 691 if (flags & SDL_WINDOW_FULLSCREEN) {
666 window.y = y; 692 const SDL_DisplayMode *mode = &SDL_CurrentDisplay.current_mode;
693 window.x = (mode->w - w) / 2;
694 window.y = (mode->h - h) / 2;
695 } else {
696 window.x = x;
697 window.y = y;
698 }
667 window.w = w; 699 window.w = w;
668 window.h = h; 700 window.h = h;
669 window.flags = (flags & allowed_flags); 701 window.flags = (flags & allowed_flags);
670 window.display = _this->current_display; 702 window.display = _this->current_display;
671 703
1811 } 1843 }
1812 if (display->windows) { 1844 if (display->windows) {
1813 SDL_free(display->windows); 1845 SDL_free(display->windows);
1814 display->windows = NULL; 1846 display->windows = NULL;
1815 } 1847 }
1848 display->num_windows = 0;
1849 }
1850 _this->VideoQuit(_this);
1851
1852 for (i = _this->num_displays; i--;) {
1853 SDL_VideoDisplay *display = &_this->displays[i];
1854 for (j = display->num_display_modes; j--;) {
1855 if (display->display_modes[j].driverdata) {
1856 SDL_free(display->display_modes[j].driverdata);
1857 display->display_modes[j].driverdata = NULL;
1858 }
1859 }
1860 if (display->display_modes) {
1861 SDL_free(display->display_modes);
1862 display->display_modes = NULL;
1863 }
1864 if (display->desktop_mode.driverdata) {
1865 SDL_free(display->desktop_mode.driverdata);
1866 display->desktop_mode.driverdata = NULL;
1867 }
1816 if (display->palette) { 1868 if (display->palette) {
1817 SDL_FreePalette(display->palette); 1869 SDL_FreePalette(display->palette);
1818 display->palette = NULL; 1870 display->palette = NULL;
1819 } 1871 }
1820 } 1872 }
1821 _this->VideoQuit(_this);
1822 if (_this->displays) { 1873 if (_this->displays) {
1823 SDL_free(_this->displays); 1874 SDL_free(_this->displays);
1875 _this->displays = NULL;
1824 } 1876 }
1825 _this->free(_this); 1877 _this->free(_this);
1826 _this = NULL; 1878 _this = NULL;
1827 } 1879 }
1828 1880