comparison src/video/SDL_video.c @ 5249:762e40fb8e28

Be explicit about what display you're querying. The default display is 0.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 10 Feb 2011 12:14:37 -0800
parents 3a8a452b49f0
children 58265e606e4e
comparison
equal deleted inserted replaced
5248:3a8a452b49f0 5249:762e40fb8e28
94 if (!window || window->magic != &_this->window_magic) { \ 94 if (!window || window->magic != &_this->window_magic) { \
95 SDL_SetError("Invalid window"); \ 95 SDL_SetError("Invalid window"); \
96 return retval; \ 96 return retval; \
97 } 97 }
98 98
99 #define CHECK_DISPLAY_INDEX(displayIndex, retval) \
100 if (!_this) { \
101 SDL_UninitializedVideo(); \
102 return retval; \
103 } \
104 if (displayIndex < 0 || displayIndex >= _this->num_displays) { \
105 SDL_SetError("displayIndex must be in the range 0 - %d", \
106 _this->num_displays - 1); \
107 return retval; \
108 }
109
99 /* Various local functions */ 110 /* Various local functions */
100 static void SDL_UpdateWindowGrab(SDL_Window * window); 111 static void SDL_UpdateWindowGrab(SDL_Window * window);
101 112
102 /* Support for framebuffer emulation using an accelerated renderer */ 113 /* Support for framebuffer emulation using an accelerated renderer */
103 114
579 } 590 }
580 return _this->num_displays; 591 return _this->num_displays;
581 } 592 }
582 593
583 int 594 int
584 SDL_GetDisplayBounds(int index, SDL_Rect * rect) 595 SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
585 { 596 {
586 if (!_this) { 597 CHECK_DISPLAY_INDEX(displayIndex, -1);
587 SDL_UninitializedVideo(); 598
588 return -1;
589 }
590 if (index < 0 || index >= _this->num_displays) {
591 SDL_SetError("index must be in the range 0 - %d",
592 _this->num_displays - 1);
593 return -1;
594 }
595 if (rect) { 599 if (rect) {
596 SDL_VideoDisplay *display = &_this->displays[index]; 600 SDL_VideoDisplay *display = &_this->displays[displayIndex];
597 601
598 if (_this->GetDisplayBounds) { 602 if (_this->GetDisplayBounds) {
599 if (_this->GetDisplayBounds(_this, display, rect) < 0) { 603 if (_this->GetDisplayBounds(_this, display, rect) < 0) {
600 return -1; 604 return -1;
601 } 605 }
602 } else { 606 } else {
603 /* Assume that the displays are left to right */ 607 /* Assume that the displays are left to right */
604 if (index == 0) { 608 if (displayIndex == 0) {
605 rect->x = 0; 609 rect->x = 0;
606 rect->y = 0; 610 rect->y = 0;
607 } else { 611 } else {
608 SDL_GetDisplayBounds(index-1, rect); 612 SDL_GetDisplayBounds(displayIndex-1, rect);
609 rect->x += rect->w; 613 rect->x += rect->w;
610 } 614 }
611 rect->w = display->desktop_mode.w; 615 rect->w = display->desktop_mode.w;
612 rect->h = display->desktop_mode.h; 616 rect->h = display->desktop_mode.h;
613 } 617 }
614 } 618 }
615 return 0; 619 return 0;
616 }
617
618 int
619 SDL_SelectVideoDisplay(int index)
620 {
621 if (!_this) {
622 SDL_UninitializedVideo();
623 return (-1);
624 }
625 if (index < 0 || index >= _this->num_displays) {
626 SDL_SetError("index must be in the range 0 - %d",
627 _this->num_displays - 1);
628 return -1;
629 }
630 _this->current_display = index;
631 return 0;
632 }
633
634 int
635 SDL_GetCurrentVideoDisplay(void)
636 {
637 if (!_this) {
638 SDL_UninitializedVideo();
639 return (-1);
640 }
641 return _this->current_display;
642 } 620 }
643 621
644 SDL_bool 622 SDL_bool
645 SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) 623 SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
646 { 624 {
675 sizeof(SDL_DisplayMode), cmpmodes); 653 sizeof(SDL_DisplayMode), cmpmodes);
676 654
677 return SDL_TRUE; 655 return SDL_TRUE;
678 } 656 }
679 657
680 int 658 static int
681 SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display) 659 SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
682 { 660 {
683 if (!display->num_display_modes && _this->GetDisplayModes) { 661 if (!display->num_display_modes && _this->GetDisplayModes) {
684 _this->GetDisplayModes(_this, display); 662 _this->GetDisplayModes(_this, display);
685 SDL_qsort(display->display_modes, display->num_display_modes, 663 SDL_qsort(display->display_modes, display->num_display_modes,
687 } 665 }
688 return display->num_display_modes; 666 return display->num_display_modes;
689 } 667 }
690 668
691 int 669 int
692 SDL_GetNumDisplayModes() 670 SDL_GetNumDisplayModes(int displayIndex)
693 { 671 {
694 if (_this) { 672 CHECK_DISPLAY_INDEX(displayIndex, -1);
695 return SDL_GetNumDisplayModesForDisplay(SDL_CurrentDisplay); 673
696 } 674 return SDL_GetNumDisplayModesForDisplay(&_this->displays[displayIndex]);
697 return 0;
698 } 675 }
699 676
700 int 677 int
701 SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode) 678 SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode)
702 { 679 {
680 SDL_VideoDisplay *display;
681
682 CHECK_DISPLAY_INDEX(displayIndex, -1);
683
684 display = &_this->displays[displayIndex];
703 if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) { 685 if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) {
704 SDL_SetError("index must be in the range of 0 - %d", 686 SDL_SetError("index must be in the range of 0 - %d",
705 SDL_GetNumDisplayModesForDisplay(display) - 1); 687 SDL_GetNumDisplayModesForDisplay(display) - 1);
706 return -1; 688 return -1;
707 } 689 }
710 } 692 }
711 return 0; 693 return 0;
712 } 694 }
713 695
714 int 696 int
715 SDL_GetDisplayMode(int index, SDL_DisplayMode * mode) 697 SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode)
716 { 698 {
717 return SDL_GetDisplayModeForDisplay(SDL_CurrentDisplay, index, mode); 699 SDL_VideoDisplay *display;
718 } 700
719 701 CHECK_DISPLAY_INDEX(displayIndex, -1);
720 int 702
721 SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode) 703 display = &_this->displays[displayIndex];
722 {
723 if (mode) { 704 if (mode) {
724 *mode = display->desktop_mode; 705 *mode = display->desktop_mode;
725 } 706 }
726 return 0; 707 return 0;
727 } 708 }
728 709
729 int 710 int
730 SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode) 711 SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode)
731 { 712 {
732 if (!_this) { 713 SDL_VideoDisplay *display;
733 SDL_UninitializedVideo(); 714
734 return -1; 715 CHECK_DISPLAY_INDEX(displayIndex, -1);
735 } 716
736 return SDL_GetDesktopDisplayModeForDisplay(SDL_CurrentDisplay, mode); 717 display = &_this->displays[displayIndex];
737 }
738
739 int
740 SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode)
741 {
742 if (mode) { 718 if (mode) {
743 *mode = display->current_mode; 719 *mode = display->current_mode;
744 } 720 }
745 return 0; 721 return 0;
746 } 722 }
747 723
748 int 724 static SDL_DisplayMode *
749 SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
750 {
751 if (!_this) {
752 SDL_UninitializedVideo();
753 return -1;
754 }
755 return SDL_GetCurrentDisplayModeForDisplay(SDL_CurrentDisplay, mode);
756 }
757
758 SDL_DisplayMode *
759 SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, 725 SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
760 const SDL_DisplayMode * mode, 726 const SDL_DisplayMode * mode,
761 SDL_DisplayMode * closest) 727 SDL_DisplayMode * closest)
762 { 728 {
763 Uint32 target_format; 729 Uint32 target_format;
861 } 827 }
862 return NULL; 828 return NULL;
863 } 829 }
864 830
865 SDL_DisplayMode * 831 SDL_DisplayMode *
866 SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode, 832 SDL_GetClosestDisplayMode(int displayIndex,
833 const SDL_DisplayMode * mode,
867 SDL_DisplayMode * closest) 834 SDL_DisplayMode * closest)
868 { 835 {
869 if (!_this) { 836 SDL_VideoDisplay *display;
870 SDL_UninitializedVideo(); 837
871 return NULL; 838 CHECK_DISPLAY_INDEX(displayIndex, NULL);
872 } 839
873 return SDL_GetClosestDisplayModeForDisplay(SDL_CurrentDisplay, mode, closest); 840 display = &_this->displays[displayIndex];
841 return SDL_GetClosestDisplayModeForDisplay(display, mode, closest);
874 } 842 }
875 843
876 int 844 int
877 SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) 845 SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
878 { 846 {
905 } else { 873 } else {
906 display_mode = display->desktop_mode; 874 display_mode = display->desktop_mode;
907 } 875 }
908 876
909 /* See if there's anything left to do */ 877 /* See if there's anything left to do */
910 SDL_GetCurrentDisplayModeForDisplay(display, &current_mode); 878 current_mode = display->current_mode;
911 if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) { 879 if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) {
912 return 0; 880 return 0;
913 } 881 }
914 882
915 /* Actually change the display mode */ 883 /* Actually change the display mode */
1052 SDL_SetError("No OpenGL support in video driver"); 1020 SDL_SetError("No OpenGL support in video driver");
1053 return NULL; 1021 return NULL;
1054 } 1022 }
1055 SDL_GL_LoadLibrary(NULL); 1023 SDL_GL_LoadLibrary(NULL);
1056 } 1024 }
1057 display = SDL_CurrentDisplay; 1025 display = &_this->displays[0]; /* FIXME */
1058 window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); 1026 window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
1059 window->magic = &_this->window_magic; 1027 window->magic = &_this->window_magic;
1060 window->id = _this->next_object_id++; 1028 window->id = _this->next_object_id++;
1061 window->x = x; 1029 window->x = x;
1062 window->y = y; 1030 window->y = y;
1100 1068
1101 if (!_this) { 1069 if (!_this) {
1102 SDL_UninitializedVideo(); 1070 SDL_UninitializedVideo();
1103 return NULL; 1071 return NULL;
1104 } 1072 }
1105 display = SDL_CurrentDisplay; 1073 display = &_this->displays[0]; /* FIXME */
1106 window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); 1074 window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
1107 window->magic = &_this->window_magic; 1075 window->magic = &_this->window_magic;
1108 window->id = _this->next_object_id++; 1076 window->id = _this->next_object_id++;
1109 window->flags = SDL_WINDOW_FOREIGN; 1077 window->flags = SDL_WINDOW_FOREIGN;
1110 window->display = display; 1078 window->display = display;
1674 SDL_Window *window; 1642 SDL_Window *window;
1675 1643
1676 if (!_this) { 1644 if (!_this) {
1677 return NULL; 1645 return NULL;
1678 } 1646 }
1679 display = SDL_CurrentDisplay; 1647 display = &_this->displays[0]; /* FIXME */
1680 for (window = display->windows; window; window = window->next) { 1648 for (window = display->windows; window; window = window->next) {
1681 if (window->flags & SDL_WINDOW_INPUT_FOCUS) { 1649 if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
1682 return window; 1650 return window;
1683 } 1651 }
1684 } 1652 }