Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 3685:64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 21 Jan 2010 06:21:52 +0000 |
parents | 4c5ab6841fdc |
children | d87db9cf6a31 |
comparison
equal
deleted
inserted
replaced
3684:cc564f08884f | 3685:64ce267332c6 |
---|---|
441 | 441 |
442 int | 442 int |
443 SDL_GetNumDisplayModes() | 443 SDL_GetNumDisplayModes() |
444 { | 444 { |
445 if (_this) { | 445 if (_this) { |
446 return SDL_GetNumDisplayModesForDisplay(&SDL_CurrentDisplay); | 446 return SDL_GetNumDisplayModesForDisplay(SDL_CurrentDisplay); |
447 } | 447 } |
448 return 0; | 448 return 0; |
449 } | 449 } |
450 | 450 |
451 int | 451 int |
463 } | 463 } |
464 | 464 |
465 int | 465 int |
466 SDL_GetDisplayMode(int index, SDL_DisplayMode * mode) | 466 SDL_GetDisplayMode(int index, SDL_DisplayMode * mode) |
467 { | 467 { |
468 return SDL_GetDisplayModeForDisplay(&SDL_CurrentDisplay, index, mode); | 468 return SDL_GetDisplayModeForDisplay(SDL_CurrentDisplay, index, mode); |
469 } | 469 } |
470 | 470 |
471 int | 471 int |
472 SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode) | 472 SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode) |
473 { | 473 { |
482 { | 482 { |
483 if (!_this) { | 483 if (!_this) { |
484 SDL_UninitializedVideo(); | 484 SDL_UninitializedVideo(); |
485 return -1; | 485 return -1; |
486 } | 486 } |
487 return SDL_GetDesktopDisplayModeForDisplay(&SDL_CurrentDisplay, mode); | 487 return SDL_GetDesktopDisplayModeForDisplay(SDL_CurrentDisplay, mode); |
488 } | 488 } |
489 | 489 |
490 int | 490 int |
491 SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode) | 491 SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode) |
492 { | 492 { |
501 { | 501 { |
502 if (!_this) { | 502 if (!_this) { |
503 SDL_UninitializedVideo(); | 503 SDL_UninitializedVideo(); |
504 return -1; | 504 return -1; |
505 } | 505 } |
506 return SDL_GetCurrentDisplayModeForDisplay(&SDL_CurrentDisplay, mode); | 506 return SDL_GetCurrentDisplayModeForDisplay(SDL_CurrentDisplay, mode); |
507 } | 507 } |
508 | 508 |
509 SDL_DisplayMode * | 509 SDL_DisplayMode * |
510 SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, | 510 SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, |
511 const SDL_DisplayMode * mode, | 511 const SDL_DisplayMode * mode, |
619 { | 619 { |
620 if (!_this) { | 620 if (!_this) { |
621 SDL_UninitializedVideo(); | 621 SDL_UninitializedVideo(); |
622 return NULL; | 622 return NULL; |
623 } | 623 } |
624 return SDL_GetClosestDisplayModeForDisplay(&SDL_CurrentDisplay, mode, closest); | 624 return SDL_GetClosestDisplayModeForDisplay(SDL_CurrentDisplay, mode, closest); |
625 } | 625 } |
626 | 626 |
627 int | 627 int |
628 SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) | 628 SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) |
629 { | 629 { |
700 { | 700 { |
701 if (!_this) { | 701 if (!_this) { |
702 SDL_UninitializedVideo(); | 702 SDL_UninitializedVideo(); |
703 return -1; | 703 return -1; |
704 } | 704 } |
705 return SDL_SetDisplayModeForDisplay(&SDL_CurrentDisplay, mode); | 705 return SDL_SetDisplayModeForDisplay(SDL_CurrentDisplay, mode); |
706 } | 706 } |
707 | 707 |
708 int | 708 int |
709 SDL_SetWindowDisplayMode(SDL_WindowID windowID, const SDL_DisplayMode * mode) | 709 SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode) |
710 { | 710 { |
711 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
712 | |
713 if (!window) { | 711 if (!window) { |
714 return -1; | 712 return -1; |
715 } | 713 } |
716 | 714 |
717 if (mode) { | 715 if (mode) { |
721 } | 719 } |
722 return 0; | 720 return 0; |
723 } | 721 } |
724 | 722 |
725 int | 723 int |
726 SDL_GetWindowDisplayMode(SDL_WindowID windowID, SDL_DisplayMode * mode) | 724 SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) |
727 { | 725 { |
728 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
729 SDL_DisplayMode fullscreen_mode; | 726 SDL_DisplayMode fullscreen_mode; |
730 | 727 |
731 if (!window) { | 728 if (!window) { |
732 return -1; | 729 return -1; |
733 } | 730 } |
738 } | 735 } |
739 if (!fullscreen_mode.h) { | 736 if (!fullscreen_mode.h) { |
740 fullscreen_mode.h = window->h; | 737 fullscreen_mode.h = window->h; |
741 } | 738 } |
742 | 739 |
743 if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayFromWindow(window), | 740 if (!SDL_GetClosestDisplayModeForDisplay(window->display, |
744 &fullscreen_mode, | 741 &fullscreen_mode, |
745 &fullscreen_mode)) { | 742 &fullscreen_mode)) { |
746 SDL_SetError("Couldn't find display mode match"); | 743 SDL_SetError("Couldn't find display mode match"); |
747 return -1; | 744 return -1; |
748 } | 745 } |
754 } | 751 } |
755 | 752 |
756 static void | 753 static void |
757 SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt) | 754 SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt) |
758 { | 755 { |
759 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 756 SDL_VideoDisplay *display = window->display; |
760 int i; | 757 int i; |
761 | 758 |
762 /* See if we're already processing a window */ | 759 /* See if we're already processing a window */ |
763 if (display->updating_fullscreen) { | 760 if (display->updating_fullscreen) { |
764 return; | 761 return; |
770 if ((window->flags & SDL_WINDOW_FULLSCREEN) && | 767 if ((window->flags & SDL_WINDOW_FULLSCREEN) && |
771 (window->flags & SDL_WINDOW_SHOWN)) { | 768 (window->flags & SDL_WINDOW_SHOWN)) { |
772 if (attempt) { | 769 if (attempt) { |
773 /* We just gained some state, try to gain all states */ | 770 /* We just gained some state, try to gain all states */ |
774 if (window->flags & SDL_WINDOW_MINIMIZED) { | 771 if (window->flags & SDL_WINDOW_MINIMIZED) { |
775 SDL_RestoreWindow(window->id); | 772 SDL_RestoreWindow(window); |
776 } else { | 773 } else { |
777 SDL_RaiseWindow(window->id); | 774 SDL_RaiseWindow(window); |
778 } | 775 } |
779 } else { | 776 } else { |
780 /* We just lost some state, try to release all states */ | 777 /* We just lost some state, try to release all states */ |
781 SDL_MinimizeWindow(window->id); | 778 SDL_MinimizeWindow(window); |
782 } | 779 } |
783 } | 780 } |
784 | 781 |
785 if (FULLSCREEN_VISIBLE(window)) { | 782 if (FULLSCREEN_VISIBLE(window)) { |
786 /* Hide any other fullscreen windows */ | 783 /* Hide any other fullscreen windows */ |
787 for (i = 0; i < display->num_windows; ++i) { | 784 for (i = 0; i < display->num_windows; ++i) { |
788 SDL_Window *other = &display->windows[i]; | 785 SDL_Window *other = &display->windows[i]; |
789 if (other != window && FULLSCREEN_VISIBLE(other)) { | 786 if (other != window && FULLSCREEN_VISIBLE(other)) { |
790 SDL_MinimizeWindow(other->id); | 787 SDL_MinimizeWindow(other); |
791 } | 788 } |
792 } | 789 } |
793 } | 790 } |
794 | 791 |
795 display->updating_fullscreen = SDL_FALSE; | 792 display->updating_fullscreen = SDL_FALSE; |
797 /* See if there are any fullscreen windows */ | 794 /* See if there are any fullscreen windows */ |
798 for (i = 0; i < display->num_windows; ++i) { | 795 for (i = 0; i < display->num_windows; ++i) { |
799 window = &display->windows[i]; | 796 window = &display->windows[i]; |
800 if (FULLSCREEN_VISIBLE(window)) { | 797 if (FULLSCREEN_VISIBLE(window)) { |
801 SDL_DisplayMode fullscreen_mode; | 798 SDL_DisplayMode fullscreen_mode; |
802 if (SDL_GetWindowDisplayMode(window->id, &fullscreen_mode) == 0) { | 799 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { |
803 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode); | 800 SDL_SetDisplayModeForDisplay(display, &fullscreen_mode); |
804 display->fullscreen_window = window; | 801 display->fullscreen_window = window; |
805 return; | 802 return; |
806 } | 803 } |
807 } | 804 } |
838 { | 835 { |
839 if (!_this) { | 836 if (!_this) { |
840 SDL_UninitializedVideo(); | 837 SDL_UninitializedVideo(); |
841 return -1; | 838 return -1; |
842 } | 839 } |
843 return SDL_SetPaletteForDisplay(&SDL_CurrentDisplay, colors, firstcolor, ncolors); | 840 return SDL_SetPaletteForDisplay(SDL_CurrentDisplay, colors, firstcolor, ncolors); |
844 } | 841 } |
845 | 842 |
846 int | 843 int |
847 SDL_GetPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors) | 844 SDL_GetPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors) |
848 { | 845 { |
867 { | 864 { |
868 if (!_this) { | 865 if (!_this) { |
869 SDL_UninitializedVideo(); | 866 SDL_UninitializedVideo(); |
870 return -1; | 867 return -1; |
871 } | 868 } |
872 return SDL_GetPaletteForDisplay(&SDL_CurrentDisplay, colors, firstcolor, ncolors); | 869 return SDL_GetPaletteForDisplay(SDL_CurrentDisplay, colors, firstcolor, ncolors); |
873 } | 870 } |
874 | 871 |
875 SDL_WindowID | 872 SDL_Window * |
876 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) | 873 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) |
877 { | 874 { |
878 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | | 875 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | |
879 SDL_WINDOW_OPENGL | | 876 SDL_WINDOW_OPENGL | |
880 SDL_WINDOW_BORDERLESS | | 877 SDL_WINDOW_BORDERLESS | |
881 SDL_WINDOW_RESIZABLE | | 878 SDL_WINDOW_RESIZABLE | |
882 SDL_WINDOW_INPUT_GRABBED); | 879 SDL_WINDOW_INPUT_GRABBED); |
883 SDL_VideoDisplay *display; | 880 SDL_VideoDisplay *display; |
884 SDL_Window window; | 881 SDL_Window *window; |
885 int num_windows; | |
886 SDL_Window *windows; | |
887 | 882 |
888 if (!_this) { | 883 if (!_this) { |
889 /* Initialize the video system if needed */ | 884 /* Initialize the video system if needed */ |
890 if (SDL_VideoInit(NULL, 0) < 0) { | 885 if (SDL_VideoInit(NULL, 0) < 0) { |
891 return 0; | 886 return NULL; |
892 } | 887 } |
893 } | 888 } |
894 if (flags & SDL_WINDOW_OPENGL) { | 889 if (flags & SDL_WINDOW_OPENGL) { |
895 if (!_this->GL_CreateContext) { | 890 if (!_this->GL_CreateContext) { |
896 SDL_SetError("No OpenGL support in video driver"); | 891 SDL_SetError("No OpenGL support in video driver"); |
897 return 0; | 892 return NULL; |
898 } | 893 } |
899 SDL_GL_LoadLibrary(NULL); | 894 SDL_GL_LoadLibrary(NULL); |
900 } | 895 } |
901 SDL_zero(window); | 896 display = SDL_CurrentDisplay; |
902 window.id = _this->next_object_id++; | 897 window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); |
903 window.x = x; | 898 window->id = _this->next_object_id++; |
904 window.y = y; | 899 window->x = x; |
905 window.w = w; | 900 window->y = y; |
906 window.h = h; | 901 window->w = w; |
907 window.flags = (flags & allowed_flags); | 902 window->h = h; |
908 window.display = _this->current_display; | 903 window->flags = (flags & allowed_flags); |
909 | 904 window->display = display; |
910 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { | 905 window->next = display->windows; |
911 if (flags & SDL_WINDOW_OPENGL) { | 906 display->windows = window; |
912 SDL_GL_UnloadLibrary(); | 907 |
913 } | 908 if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) { |
914 return 0; | 909 SDL_DestroyWindow(window); |
915 } | 910 return NULL; |
916 display = &SDL_CurrentDisplay; | 911 } |
917 num_windows = display->num_windows; | |
918 windows = | |
919 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); | |
920 if (!windows) { | |
921 if (_this->DestroyWindow) { | |
922 _this->DestroyWindow(_this, &window); | |
923 } | |
924 if (flags & SDL_WINDOW_OPENGL) { | |
925 SDL_GL_UnloadLibrary(); | |
926 } | |
927 return 0; | |
928 } | |
929 windows[num_windows] = window; | |
930 display->windows = windows; | |
931 display->num_windows++; | |
932 | 912 |
933 if (title) { | 913 if (title) { |
934 SDL_SetWindowTitle(window.id, title); | 914 SDL_SetWindowTitle(window, title); |
935 } | 915 } |
936 if (flags & SDL_WINDOW_MAXIMIZED) { | 916 if (flags & SDL_WINDOW_MAXIMIZED) { |
937 SDL_MaximizeWindow(window.id); | 917 SDL_MaximizeWindow(window); |
938 } | 918 } |
939 if (flags & SDL_WINDOW_MINIMIZED) { | 919 if (flags & SDL_WINDOW_MINIMIZED) { |
940 SDL_MinimizeWindow(window.id); | 920 SDL_MinimizeWindow(window); |
941 } | 921 } |
942 if (flags & SDL_WINDOW_SHOWN) { | 922 if (flags & SDL_WINDOW_SHOWN) { |
943 SDL_ShowWindow(window.id); | 923 SDL_ShowWindow(window); |
944 } | 924 } |
945 SDL_UpdateWindowGrab(&window); | 925 SDL_UpdateWindowGrab(window); |
946 | 926 |
947 return window.id; | 927 return window; |
948 } | 928 } |
949 | 929 |
950 SDL_WindowID | 930 SDL_Window * |
951 SDL_CreateWindowFrom(const void *data) | 931 SDL_CreateWindowFrom(const void *data) |
952 { | 932 { |
953 SDL_VideoDisplay *display; | 933 SDL_VideoDisplay *display; |
954 SDL_Window window; | 934 SDL_Window *window; |
955 int num_windows; | |
956 SDL_Window *windows; | |
957 | 935 |
958 if (!_this) { | 936 if (!_this) { |
959 SDL_UninitializedVideo(); | 937 SDL_UninitializedVideo(); |
960 return (0); | 938 return NULL; |
961 } | 939 } |
962 SDL_zero(window); | 940 display = SDL_CurrentDisplay; |
963 window.id = _this->next_object_id++; | 941 window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); |
964 window.display = _this->current_display; | 942 window->id = _this->next_object_id++; |
965 window.flags = SDL_WINDOW_FOREIGN; | 943 window->flags = SDL_WINDOW_FOREIGN; |
944 window->display = display; | |
945 window->next = display->windows; | |
946 display->windows = window; | |
966 | 947 |
967 if (!_this->CreateWindowFrom || | 948 if (!_this->CreateWindowFrom || |
968 _this->CreateWindowFrom(_this, &window, data) < 0) { | 949 _this->CreateWindowFrom(_this, window, data) < 0) { |
969 return 0; | 950 SDL_DestroyWindow(window); |
970 } | 951 return NULL; |
971 /* FIXME: Find out what display this window is actually on... */ | 952 } |
972 display = &SDL_CurrentDisplay; | 953 return window; |
973 num_windows = display->num_windows; | |
974 windows = | |
975 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); | |
976 if (!windows) { | |
977 if (_this->DestroyWindow) { | |
978 _this->DestroyWindow(_this, &window); | |
979 } | |
980 if (window.title) { | |
981 SDL_free(window.title); | |
982 } | |
983 return 0; | |
984 } | |
985 windows[num_windows] = window; | |
986 display->windows = windows; | |
987 display->num_windows++; | |
988 | |
989 return window.id; | |
990 } | 954 } |
991 | 955 |
992 int | 956 int |
993 SDL_RecreateWindow(SDL_Window * window, Uint32 flags) | 957 SDL_RecreateWindow(SDL_Window * window, Uint32 flags) |
994 { | 958 { |
1034 return -1; | 998 return -1; |
1035 } | 999 } |
1036 } | 1000 } |
1037 | 1001 |
1038 if (title) { | 1002 if (title) { |
1039 SDL_SetWindowTitle(window->id, title); | 1003 SDL_SetWindowTitle(window, title); |
1040 SDL_free(title); | 1004 SDL_free(title); |
1041 } | 1005 } |
1042 if (flags & SDL_WINDOW_MAXIMIZED) { | 1006 if (flags & SDL_WINDOW_MAXIMIZED) { |
1043 SDL_MaximizeWindow(window->id); | 1007 SDL_MaximizeWindow(window); |
1044 } | 1008 } |
1045 if (flags & SDL_WINDOW_MINIMIZED) { | 1009 if (flags & SDL_WINDOW_MINIMIZED) { |
1046 SDL_MinimizeWindow(window->id); | 1010 SDL_MinimizeWindow(window); |
1047 } | 1011 } |
1048 if (flags & SDL_WINDOW_SHOWN) { | 1012 if (flags & SDL_WINDOW_SHOWN) { |
1049 SDL_ShowWindow(window->id); | 1013 SDL_ShowWindow(window); |
1050 } | 1014 } |
1051 SDL_UpdateWindowGrab(window); | 1015 SDL_UpdateWindowGrab(window); |
1052 | 1016 |
1053 return 0; | 1017 return 0; |
1054 } | |
1055 | |
1056 SDL_Window * | |
1057 SDL_GetWindowFromID(SDL_WindowID windowID) | |
1058 { | |
1059 int i, j; | |
1060 | |
1061 if (!_this) { | |
1062 SDL_UninitializedVideo(); | |
1063 return NULL; | |
1064 } | |
1065 if (windowID) { | |
1066 for (i = 0; i < _this->num_displays; ++i) { | |
1067 SDL_VideoDisplay *display = &_this->displays[i]; | |
1068 for (j = 0; j < display->num_windows; ++j) { | |
1069 SDL_Window *window = &display->windows[j]; | |
1070 if (window->id == windowID) { | |
1071 return window; | |
1072 } | |
1073 } | |
1074 } | |
1075 } else { | |
1076 /* Just return the first active window */ | |
1077 for (i = 0; i < _this->num_displays; ++i) { | |
1078 SDL_VideoDisplay *display = &_this->displays[i]; | |
1079 for (j = 0; j < display->num_windows; ++j) { | |
1080 SDL_Window *window = &display->windows[j]; | |
1081 return window; | |
1082 } | |
1083 } | |
1084 } | |
1085 /* Couldn't find the window with the requested ID */ | |
1086 SDL_SetError("Invalid window ID"); | |
1087 return NULL; | |
1088 } | |
1089 | |
1090 SDL_VideoDisplay * | |
1091 SDL_GetDisplayFromWindow(SDL_Window * window) | |
1092 { | |
1093 if (!_this) { | |
1094 SDL_UninitializedVideo(); | |
1095 return NULL; | |
1096 } | |
1097 if (!window) { | |
1098 return NULL; | |
1099 } | |
1100 return &_this->displays[window->display]; | |
1101 } | 1018 } |
1102 | 1019 |
1103 static __inline__ SDL_Renderer * | 1020 static __inline__ SDL_Renderer * |
1104 SDL_GetCurrentRenderer(SDL_bool create) | 1021 SDL_GetCurrentRenderer(SDL_bool create) |
1105 { | 1022 { |
1118 } | 1035 } |
1119 return SDL_CurrentRenderer; | 1036 return SDL_CurrentRenderer; |
1120 } | 1037 } |
1121 | 1038 |
1122 Uint32 | 1039 Uint32 |
1123 SDL_GetWindowFlags(SDL_WindowID windowID) | 1040 SDL_GetWindowID(SDL_Window * window) |
1124 { | 1041 { |
1125 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1126 | |
1127 if (!window) { | 1042 if (!window) { |
1128 return 0; | 1043 return 0; |
1129 } | 1044 } |
1045 return window->id; | |
1046 } | |
1047 | |
1048 SDL_Window * | |
1049 SDL_GetWindowFromID(Uint32 id) | |
1050 { | |
1051 SDL_Window *window; | |
1052 int i; | |
1053 | |
1054 if (!_this) { | |
1055 return NULL; | |
1056 } | |
1057 /* FIXME: Should we keep a separate hash table for these? */ | |
1058 for (i = _this->num_displays; i--;) { | |
1059 SDL_VideoDisplay *display = &_this->displays[i]; | |
1060 for (window = display->windows; window; window = window->next) { | |
1061 if (window->id == id) { | |
1062 return window; | |
1063 } | |
1064 } | |
1065 } | |
1066 return NULL; | |
1067 } | |
1068 | |
1069 Uint32 | |
1070 SDL_GetWindowFlags(SDL_Window * window) | |
1071 { | |
1072 if (!window) { | |
1073 return 0; | |
1074 } | |
1130 return window->flags; | 1075 return window->flags; |
1131 } | 1076 } |
1132 | 1077 |
1133 void | 1078 void |
1134 SDL_SetWindowTitle(SDL_WindowID windowID, const char *title) | 1079 SDL_SetWindowTitle(SDL_Window * window, const char *title) |
1135 { | 1080 { |
1136 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1137 | |
1138 if (!window || title == window->title) { | 1081 if (!window || title == window->title) { |
1139 return; | 1082 return; |
1140 } | 1083 } |
1141 if (window->title) { | 1084 if (window->title) { |
1142 SDL_free(window->title); | 1085 SDL_free(window->title); |
1151 _this->SetWindowTitle(_this, window); | 1094 _this->SetWindowTitle(_this, window); |
1152 } | 1095 } |
1153 } | 1096 } |
1154 | 1097 |
1155 const char * | 1098 const char * |
1156 SDL_GetWindowTitle(SDL_WindowID windowID) | 1099 SDL_GetWindowTitle(SDL_Window * window) |
1157 { | 1100 { |
1158 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1159 | |
1160 if (!window) { | 1101 if (!window) { |
1161 return NULL; | 1102 return NULL; |
1162 } | 1103 } |
1163 return window->title; | 1104 return window->title; |
1164 } | 1105 } |
1165 | 1106 |
1166 void | 1107 void |
1167 SDL_SetWindowIcon(SDL_WindowID windowID, SDL_Surface * icon) | 1108 SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon) |
1168 { | 1109 { |
1169 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1170 | |
1171 if (!window) { | 1110 if (!window) { |
1172 return; | 1111 return; |
1173 } | 1112 } |
1174 if (_this->SetWindowIcon) { | 1113 if (_this->SetWindowIcon) { |
1175 _this->SetWindowIcon(_this, window, icon); | 1114 _this->SetWindowIcon(_this, window, icon); |
1176 } | 1115 } |
1177 } | 1116 } |
1178 | 1117 |
1179 void | 1118 void |
1180 SDL_SetWindowData(SDL_WindowID windowID, void *userdata) | 1119 SDL_SetWindowData(SDL_Window * window, void *userdata) |
1181 { | 1120 { |
1182 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1183 | |
1184 if (!window) { | 1121 if (!window) { |
1185 return; | 1122 return; |
1186 } | 1123 } |
1187 window->userdata = userdata; | 1124 window->userdata = userdata; |
1188 } | 1125 } |
1189 | 1126 |
1190 void * | 1127 void * |
1191 SDL_GetWindowData(SDL_WindowID windowID) | 1128 SDL_GetWindowData(SDL_Window * window) |
1192 { | 1129 { |
1193 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1194 | |
1195 if (!window) { | 1130 if (!window) { |
1196 return NULL; | 1131 return NULL; |
1197 } | 1132 } |
1198 return window->userdata; | 1133 return window->userdata; |
1199 } | 1134 } |
1200 | 1135 |
1201 void | 1136 void |
1202 SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y) | 1137 SDL_SetWindowPosition(SDL_Window * window, int x, int y) |
1203 { | 1138 { |
1204 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1205 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | |
1206 | |
1207 if (!window) { | 1139 if (!window) { |
1208 return; | 1140 return; |
1209 } | 1141 } |
1210 if (x != SDL_WINDOWPOS_UNDEFINED) { | 1142 if (x != SDL_WINDOWPOS_UNDEFINED) { |
1211 window->x = x; | 1143 window->x = x; |
1214 window->y = y; | 1146 window->y = y; |
1215 } | 1147 } |
1216 if (_this->SetWindowPosition) { | 1148 if (_this->SetWindowPosition) { |
1217 _this->SetWindowPosition(_this, window); | 1149 _this->SetWindowPosition(_this, window); |
1218 } | 1150 } |
1219 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, x, y); | 1151 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y); |
1220 } | 1152 } |
1221 | 1153 |
1222 void | 1154 void |
1223 SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y) | 1155 SDL_GetWindowPosition(SDL_Window * window, int *x, int *y) |
1224 { | 1156 { |
1225 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1226 | |
1227 if (!window) { | 1157 if (!window) { |
1228 return; | 1158 return; |
1229 } | 1159 } |
1230 if (x) { | 1160 if (x) { |
1231 *x = window->x; | 1161 *x = window->x; |
1234 *y = window->y; | 1164 *y = window->y; |
1235 } | 1165 } |
1236 } | 1166 } |
1237 | 1167 |
1238 void | 1168 void |
1239 SDL_SetWindowSize(SDL_WindowID windowID, int w, int h) | 1169 SDL_SetWindowSize(SDL_Window * window, int w, int h) |
1240 { | 1170 { |
1241 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1242 | |
1243 if (!window) { | 1171 if (!window) { |
1244 return; | 1172 return; |
1245 } | 1173 } |
1246 window->w = w; | 1174 window->w = w; |
1247 window->h = h; | 1175 window->h = h; |
1251 } | 1179 } |
1252 SDL_OnWindowResized(window); | 1180 SDL_OnWindowResized(window); |
1253 } | 1181 } |
1254 | 1182 |
1255 void | 1183 void |
1256 SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h) | 1184 SDL_GetWindowSize(SDL_Window * window, int *w, int *h) |
1257 { | 1185 { |
1258 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1259 | |
1260 if (window) { | 1186 if (window) { |
1261 if (w) { | 1187 if (w) { |
1262 *w = window->w; | 1188 *w = window->w; |
1263 } | 1189 } |
1264 if (h) { | 1190 if (h) { |
1273 } | 1199 } |
1274 } | 1200 } |
1275 } | 1201 } |
1276 | 1202 |
1277 void | 1203 void |
1278 SDL_ShowWindow(SDL_WindowID windowID) | 1204 SDL_ShowWindow(SDL_Window * window) |
1279 { | 1205 { |
1280 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1281 | |
1282 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { | 1206 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { |
1283 return; | 1207 return; |
1284 } | 1208 } |
1285 | 1209 |
1286 if (_this->ShowWindow) { | 1210 if (_this->ShowWindow) { |
1287 _this->ShowWindow(_this, window); | 1211 _this->ShowWindow(_this, window); |
1288 } | 1212 } |
1289 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0); | 1213 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0); |
1290 } | 1214 } |
1291 | 1215 |
1292 void | 1216 void |
1293 SDL_HideWindow(SDL_WindowID windowID) | 1217 SDL_HideWindow(SDL_Window * window) |
1294 { | 1218 { |
1295 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1296 | |
1297 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { | 1219 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { |
1298 return; | 1220 return; |
1299 } | 1221 } |
1300 | 1222 |
1301 if (_this->HideWindow) { | 1223 if (_this->HideWindow) { |
1302 _this->HideWindow(_this, window); | 1224 _this->HideWindow(_this, window); |
1303 } | 1225 } |
1304 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0); | 1226 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0); |
1305 } | 1227 } |
1306 | 1228 |
1307 void | 1229 void |
1308 SDL_RaiseWindow(SDL_WindowID windowID) | 1230 SDL_RaiseWindow(SDL_Window * window) |
1309 { | 1231 { |
1310 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1311 | |
1312 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { | 1232 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { |
1313 return; | 1233 return; |
1314 } | 1234 } |
1315 if (_this->RaiseWindow) { | 1235 if (_this->RaiseWindow) { |
1316 _this->RaiseWindow(_this, window); | 1236 _this->RaiseWindow(_this, window); |
1317 } else { | 1237 } else { |
1318 /* FIXME: What we really want is a way to request focus */ | 1238 /* FIXME: What we really want is a way to request focus */ |
1319 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); | 1239 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); |
1320 } | 1240 } |
1321 } | 1241 } |
1322 | 1242 |
1323 void | 1243 void |
1324 SDL_MaximizeWindow(SDL_WindowID windowID) | 1244 SDL_MaximizeWindow(SDL_Window * window) |
1325 { | 1245 { |
1326 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1327 | |
1328 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { | 1246 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { |
1329 return; | 1247 return; |
1330 } | 1248 } |
1331 | 1249 |
1332 if (_this->MaximizeWindow) { | 1250 if (_this->MaximizeWindow) { |
1333 _this->MaximizeWindow(_this, window); | 1251 _this->MaximizeWindow(_this, window); |
1334 } | 1252 } |
1335 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); | 1253 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); |
1336 } | 1254 } |
1337 | 1255 |
1338 void | 1256 void |
1339 SDL_MinimizeWindow(SDL_WindowID windowID) | 1257 SDL_MinimizeWindow(SDL_Window * window) |
1340 { | 1258 { |
1341 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1342 | |
1343 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { | 1259 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { |
1344 return; | 1260 return; |
1345 } | 1261 } |
1346 | 1262 |
1347 if (_this->MinimizeWindow) { | 1263 if (_this->MinimizeWindow) { |
1348 _this->MinimizeWindow(_this, window); | 1264 _this->MinimizeWindow(_this, window); |
1349 } | 1265 } |
1350 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0); | 1266 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
1351 } | 1267 } |
1352 | 1268 |
1353 void | 1269 void |
1354 SDL_RestoreWindow(SDL_WindowID windowID) | 1270 SDL_RestoreWindow(SDL_Window * window) |
1355 { | 1271 { |
1356 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1357 | |
1358 if (!window | 1272 if (!window |
1359 || !(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { | 1273 || !(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { |
1360 return; | 1274 return; |
1361 } | 1275 } |
1362 | 1276 |
1363 if (_this->RestoreWindow) { | 1277 if (_this->RestoreWindow) { |
1364 _this->RestoreWindow(_this, window); | 1278 _this->RestoreWindow(_this, window); |
1365 } | 1279 } |
1366 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0); | 1280 SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); |
1367 } | 1281 } |
1368 | 1282 |
1369 int | 1283 int |
1370 SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen) | 1284 SDL_SetWindowFullscreen(SDL_Window * window, int fullscreen) |
1371 { | 1285 { |
1372 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1373 | |
1374 if (!window) { | 1286 if (!window) { |
1375 return -1; | 1287 return -1; |
1376 } | 1288 } |
1377 if (fullscreen) { | 1289 if (fullscreen) { |
1378 fullscreen = SDL_WINDOW_FULLSCREEN; | 1290 fullscreen = SDL_WINDOW_FULLSCREEN; |
1391 } | 1303 } |
1392 return 0; | 1304 return 0; |
1393 } | 1305 } |
1394 | 1306 |
1395 void | 1307 void |
1396 SDL_SetWindowGrab(SDL_WindowID windowID, int mode) | 1308 SDL_SetWindowGrab(SDL_Window * window, int mode) |
1397 { | 1309 { |
1398 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1399 | |
1400 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { | 1310 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { |
1401 return; | 1311 return; |
1402 } | 1312 } |
1403 if (mode) { | 1313 if (mode) { |
1404 window->flags |= SDL_WINDOW_INPUT_GRABBED; | 1314 window->flags |= SDL_WINDOW_INPUT_GRABBED; |
1415 _this->SetWindowGrab(_this, window); | 1325 _this->SetWindowGrab(_this, window); |
1416 } | 1326 } |
1417 } | 1327 } |
1418 | 1328 |
1419 int | 1329 int |
1420 SDL_GetWindowGrab(SDL_WindowID windowID) | 1330 SDL_GetWindowGrab(SDL_Window * window) |
1421 { | 1331 { |
1422 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1423 | |
1424 if (!window) { | 1332 if (!window) { |
1425 return 0; | 1333 return 0; |
1426 } | 1334 } |
1427 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); | 1335 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); |
1428 } | 1336 } |
1429 | 1337 |
1430 void | 1338 void |
1431 SDL_OnWindowShown(SDL_Window * window) | 1339 SDL_OnWindowShown(SDL_Window * window) |
1432 { | 1340 { |
1433 SDL_RaiseWindow(window->id); | 1341 SDL_RaiseWindow(window); |
1434 SDL_UpdateFullscreenMode(window, SDL_TRUE); | 1342 SDL_UpdateFullscreenMode(window, SDL_TRUE); |
1435 } | 1343 } |
1436 | 1344 |
1437 void | 1345 void |
1438 SDL_OnWindowHidden(SDL_Window * window) | 1346 SDL_OnWindowHidden(SDL_Window * window) |
1457 } | 1365 } |
1458 | 1366 |
1459 void | 1367 void |
1460 SDL_OnWindowRestored(SDL_Window * window) | 1368 SDL_OnWindowRestored(SDL_Window * window) |
1461 { | 1369 { |
1462 SDL_RaiseWindow(window->id); | 1370 SDL_RaiseWindow(window); |
1463 SDL_UpdateFullscreenMode(window, SDL_TRUE); | 1371 SDL_UpdateFullscreenMode(window, SDL_TRUE); |
1464 } | 1372 } |
1465 | 1373 |
1466 void | 1374 void |
1467 SDL_OnWindowFocusGained(SDL_Window * window) | 1375 SDL_OnWindowFocusGained(SDL_Window * window) |
1468 { | 1376 { |
1469 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 1377 SDL_VideoDisplay *display = window->display; |
1470 | 1378 |
1471 if (display->gamma && _this->SetDisplayGammaRamp) { | 1379 if (display->gamma && _this->SetDisplayGammaRamp) { |
1472 _this->SetDisplayGammaRamp(_this, display, display->gamma); | 1380 _this->SetDisplayGammaRamp(_this, display, display->gamma); |
1473 } | 1381 } |
1474 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) | 1382 if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) |
1478 } | 1386 } |
1479 | 1387 |
1480 void | 1388 void |
1481 SDL_OnWindowFocusLost(SDL_Window * window) | 1389 SDL_OnWindowFocusLost(SDL_Window * window) |
1482 { | 1390 { |
1483 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | 1391 SDL_VideoDisplay *display = window->display; |
1484 | 1392 |
1485 /* If we're fullscreen on a single-head system and lose focus, minimize */ | 1393 /* If we're fullscreen on a single-head system and lose focus, minimize */ |
1486 if ((window->flags & SDL_WINDOW_FULLSCREEN) && | 1394 if ((window->flags & SDL_WINDOW_FULLSCREEN) && |
1487 _this->num_displays == 1) { | 1395 _this->num_displays == 1) { |
1488 SDL_MinimizeWindow(window->id); | 1396 SDL_MinimizeWindow(window); |
1489 } | 1397 } |
1490 | 1398 |
1491 if (display->gamma && _this->SetDisplayGammaRamp) { | 1399 if (display->gamma && _this->SetDisplayGammaRamp) { |
1492 _this->SetDisplayGammaRamp(_this, display, display->saved_gamma); | 1400 _this->SetDisplayGammaRamp(_this, display, display->saved_gamma); |
1493 } | 1401 } |
1495 && _this->SetWindowGrab) { | 1403 && _this->SetWindowGrab) { |
1496 _this->SetWindowGrab(_this, window); | 1404 _this->SetWindowGrab(_this, window); |
1497 } | 1405 } |
1498 } | 1406 } |
1499 | 1407 |
1500 SDL_WindowID | 1408 SDL_Window * |
1501 SDL_GetFocusWindow(void) | 1409 SDL_GetFocusWindow(void) |
1502 { | 1410 { |
1503 SDL_VideoDisplay *display; | 1411 SDL_VideoDisplay *display; |
1504 int i; | 1412 SDL_Window *window; |
1505 | 1413 |
1506 if (!_this) { | 1414 if (!_this) { |
1507 return 0; | 1415 return NULL; |
1508 } | 1416 } |
1509 display = &SDL_CurrentDisplay; | 1417 display = SDL_CurrentDisplay; |
1510 for (i = 0; i < display->num_windows; ++i) { | 1418 for (window = display->windows; window; window = window->next) { |
1511 SDL_Window *window = &display->windows[i]; | |
1512 | |
1513 if (window->flags & SDL_WINDOW_INPUT_FOCUS) { | 1419 if (window->flags & SDL_WINDOW_INPUT_FOCUS) { |
1514 return window->id; | 1420 return window; |
1515 } | 1421 } |
1516 } | 1422 } |
1517 return 0; | 1423 return NULL; |
1518 } | 1424 } |
1519 | 1425 |
1520 void | 1426 void |
1521 SDL_DestroyWindow(SDL_WindowID windowID) | 1427 SDL_DestroyWindow(SDL_Window * window) |
1522 { | 1428 { |
1523 int i, j; | 1429 SDL_VideoDisplay *display; |
1524 | 1430 |
1525 if (!_this) { | 1431 if (!_this || !window || !window->id) { |
1432 SDL_SetError("Invalid window"); | |
1526 return; | 1433 return; |
1527 } | 1434 } |
1528 | 1435 |
1529 for (i = 0; i < _this->num_displays; ++i) { | 1436 if (window->title) { |
1530 SDL_VideoDisplay *display = &_this->displays[i]; | 1437 SDL_free(window->title); |
1531 for (j = 0; j < display->num_windows; ++j) { | 1438 } |
1532 SDL_Window *window = &display->windows[j]; | 1439 if (window->renderer) { |
1533 if (window->id != windowID) { | 1440 SDL_DestroyRenderer(window); |
1534 continue; | 1441 } |
1535 } | 1442 |
1536 if (window->title) { | 1443 /* Restore video mode, etc. */ |
1537 SDL_free(window->title); | 1444 SDL_UpdateFullscreenMode(window, SDL_FALSE); |
1538 window->title = NULL; | 1445 |
1539 } | 1446 if (_this->DestroyWindow) { |
1540 if (window->renderer) { | 1447 _this->DestroyWindow(_this, window); |
1541 SDL_DestroyRenderer(window->id); | 1448 } |
1542 window->renderer = NULL; | 1449 if (window->flags & SDL_WINDOW_OPENGL) { |
1543 } | 1450 SDL_GL_UnloadLibrary(); |
1544 | 1451 } |
1545 /* Restore video mode, etc. */ | 1452 |
1546 SDL_UpdateFullscreenMode(window, SDL_FALSE); | 1453 /* Unlink the window from the list */ |
1547 | 1454 display = window->display; |
1548 if (_this->DestroyWindow) { | 1455 if (window->prev) { |
1549 _this->DestroyWindow(_this, window); | 1456 window->prev->next = window->next; |
1550 } | 1457 } else { |
1551 if (window->flags & SDL_WINDOW_OPENGL) { | 1458 display->windows = window->next; |
1552 SDL_GL_UnloadLibrary(); | 1459 } |
1553 } | 1460 |
1554 if (j != display->num_windows - 1) { | 1461 /* Clear the ID so we know it was destroyed */ |
1555 SDL_memcpy(&display->windows[i], | 1462 window->id = 0; |
1556 &display->windows[i + 1], | 1463 |
1557 (display->num_windows - i - 1) * sizeof(*window)); | 1464 SDL_free(window); |
1558 } | |
1559 --display->num_windows; | |
1560 return; | |
1561 } | |
1562 } | |
1563 } | 1465 } |
1564 | 1466 |
1565 void | 1467 void |
1566 SDL_AddRenderDriver(SDL_VideoDisplay * display, const SDL_RenderDriver * driver) | 1468 SDL_AddRenderDriver(SDL_VideoDisplay * display, const SDL_RenderDriver * driver) |
1567 { | 1469 { |
1580 | 1482 |
1581 int | 1483 int |
1582 SDL_GetNumRenderDrivers(void) | 1484 SDL_GetNumRenderDrivers(void) |
1583 { | 1485 { |
1584 if (_this) { | 1486 if (_this) { |
1585 return SDL_CurrentDisplay.num_render_drivers; | 1487 return SDL_CurrentDisplay->num_render_drivers; |
1586 } | 1488 } |
1587 return 0; | 1489 return 0; |
1588 } | 1490 } |
1589 | 1491 |
1590 int | 1492 int |
1597 if (index < 0 || index >= SDL_GetNumRenderDrivers()) { | 1499 if (index < 0 || index >= SDL_GetNumRenderDrivers()) { |
1598 SDL_SetError("index must be in the range of 0 - %d", | 1500 SDL_SetError("index must be in the range of 0 - %d", |
1599 SDL_GetNumRenderDrivers() - 1); | 1501 SDL_GetNumRenderDrivers() - 1); |
1600 return -1; | 1502 return -1; |
1601 } | 1503 } |
1602 *info = SDL_CurrentDisplay.render_drivers[index].info; | 1504 *info = SDL_CurrentDisplay->render_drivers[index].info; |
1603 return 0; | 1505 return 0; |
1604 } | 1506 } |
1605 | 1507 |
1606 int | 1508 int |
1607 SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags) | 1509 SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) |
1608 { | 1510 { |
1609 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1610 | |
1611 if (!window) { | 1511 if (!window) { |
1612 SDL_SetError("Invalid window ID"); | 1512 SDL_SetError("Invalid window"); |
1613 return -1; | 1513 return -1; |
1614 } | 1514 } |
1615 | 1515 |
1616 /* Free any existing renderer */ | 1516 /* Free any existing renderer */ |
1617 SDL_DestroyRenderer(windowID); | 1517 SDL_DestroyRenderer(window); |
1618 | 1518 |
1619 if (index < 0) { | 1519 if (index < 0) { |
1620 char *override = SDL_getenv("SDL_VIDEO_RENDERER"); | 1520 char *override = SDL_getenv("SDL_VIDEO_RENDERER"); |
1621 int n = SDL_GetNumRenderDrivers(); | 1521 int n = SDL_GetNumRenderDrivers(); |
1622 | 1522 |
1631 } | 1531 } |
1632 #endif /* SDL_VIDEO_RENDER_OGL_ES */ | 1532 #endif /* SDL_VIDEO_RENDER_OGL_ES */ |
1633 if (override) { | 1533 if (override) { |
1634 for (index = 0; index < n; ++index) { | 1534 for (index = 0; index < n; ++index) { |
1635 SDL_RenderDriver *driver = | 1535 SDL_RenderDriver *driver = |
1636 &SDL_CurrentDisplay.render_drivers[index]; | 1536 &SDL_CurrentDisplay->render_drivers[index]; |
1637 | 1537 |
1638 if (SDL_strcasecmp(override, driver->info.name) == 0) { | 1538 if (SDL_strcasecmp(override, driver->info.name) == 0) { |
1639 /* Create a new renderer instance */ | 1539 /* Create a new renderer instance */ |
1640 window->renderer = driver->CreateRenderer(window, flags); | 1540 window->renderer = driver->CreateRenderer(window, flags); |
1641 break; | 1541 break; |
1642 } | 1542 } |
1643 } | 1543 } |
1644 } else { | 1544 } else { |
1645 for (index = 0; index < n; ++index) { | 1545 for (index = 0; index < n; ++index) { |
1646 SDL_RenderDriver *driver = | 1546 SDL_RenderDriver *driver = |
1647 &SDL_CurrentDisplay.render_drivers[index]; | 1547 &SDL_CurrentDisplay->render_drivers[index]; |
1648 | 1548 |
1649 if ((driver->info.flags & flags) == flags) { | 1549 if ((driver->info.flags & flags) == flags) { |
1650 /* Create a new renderer instance */ | 1550 /* Create a new renderer instance */ |
1651 window->renderer = driver->CreateRenderer(window, flags); | 1551 window->renderer = driver->CreateRenderer(window, flags); |
1652 if (window->renderer) { | 1552 if (window->renderer) { |
1665 SDL_SetError("index must be -1 or in the range of 0 - %d", | 1565 SDL_SetError("index must be -1 or in the range of 0 - %d", |
1666 SDL_GetNumRenderDrivers() - 1); | 1566 SDL_GetNumRenderDrivers() - 1); |
1667 return -1; | 1567 return -1; |
1668 } | 1568 } |
1669 /* Create a new renderer instance */ | 1569 /* Create a new renderer instance */ |
1670 window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags); | 1570 window->renderer = SDL_CurrentDisplay->render_drivers[index].CreateRenderer(window, flags); |
1671 } | 1571 } |
1672 | 1572 |
1673 if (window->renderer == NULL) { | 1573 if (window->renderer == NULL) { |
1674 /* Assuming renderer set its error */ | 1574 /* Assuming renderer set its error */ |
1675 return -1; | 1575 return -1; |
1676 } | 1576 } |
1677 | 1577 |
1678 SDL_SelectRenderer(window->id); | 1578 SDL_SelectRenderer(window); |
1679 | 1579 |
1680 return 0; | 1580 return 0; |
1681 } | 1581 } |
1682 | 1582 |
1683 int | 1583 int |
1684 SDL_SelectRenderer(SDL_WindowID windowID) | 1584 SDL_SelectRenderer(SDL_Window * window) |
1685 { | 1585 { |
1686 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
1687 SDL_Renderer *renderer; | 1586 SDL_Renderer *renderer; |
1688 | 1587 |
1689 if (!window) { | 1588 if (!window) { |
1690 SDL_SetError("Invalid window ID"); | 1589 SDL_SetError("Invalid window"); |
1691 return -1; | 1590 return -1; |
1692 } | 1591 } |
1693 renderer = window->renderer; | 1592 renderer = window->renderer; |
1694 if (!renderer) { | 1593 if (!renderer) { |
1695 SDL_SetError("Use SDL_CreateRenderer() to create a renderer"); | 1594 SDL_SetError("Use SDL_CreateRenderer() to create a renderer"); |
1698 if (renderer->ActivateRenderer) { | 1597 if (renderer->ActivateRenderer) { |
1699 if (renderer->ActivateRenderer(renderer) < 0) { | 1598 if (renderer->ActivateRenderer(renderer) < 0) { |
1700 return -1; | 1599 return -1; |
1701 } | 1600 } |
1702 } | 1601 } |
1703 SDL_CurrentDisplay.current_renderer = renderer; | 1602 SDL_CurrentDisplay->current_renderer = renderer; |
1704 return 0; | 1603 return 0; |
1705 } | 1604 } |
1706 | 1605 |
1707 int | 1606 int |
1708 SDL_GetRendererInfo(SDL_RendererInfo * info) | 1607 SDL_GetRendererInfo(SDL_RendererInfo * info) |
1713 } | 1612 } |
1714 *info = renderer->info; | 1613 *info = renderer->info; |
1715 return 0; | 1614 return 0; |
1716 } | 1615 } |
1717 | 1616 |
1718 SDL_TextureID | 1617 SDL_Texture * |
1719 SDL_CreateTexture(Uint32 format, int access, int w, int h) | 1618 SDL_CreateTexture(Uint32 format, int access, int w, int h) |
1720 { | 1619 { |
1721 int hash; | |
1722 SDL_Renderer *renderer; | 1620 SDL_Renderer *renderer; |
1723 SDL_Texture *texture; | 1621 SDL_Texture *texture; |
1724 | 1622 |
1725 renderer = SDL_GetCurrentRenderer(SDL_TRUE); | 1623 renderer = SDL_GetCurrentRenderer(SDL_TRUE); |
1726 if (!renderer) { | 1624 if (!renderer) { |
1733 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); | 1631 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); |
1734 if (!texture) { | 1632 if (!texture) { |
1735 SDL_OutOfMemory(); | 1633 SDL_OutOfMemory(); |
1736 return 0; | 1634 return 0; |
1737 } | 1635 } |
1738 texture->id = _this->next_object_id++; | |
1739 texture->format = format; | 1636 texture->format = format; |
1740 texture->access = access; | 1637 texture->access = access; |
1741 texture->w = w; | 1638 texture->w = w; |
1742 texture->h = h; | 1639 texture->h = h; |
1743 texture->r = 255; | 1640 texture->r = 255; |
1744 texture->g = 255; | 1641 texture->g = 255; |
1745 texture->b = 255; | 1642 texture->b = 255; |
1746 texture->a = 255; | 1643 texture->a = 255; |
1747 texture->renderer = renderer; | 1644 texture->renderer = renderer; |
1645 texture->next = renderer->textures; | |
1646 renderer->textures = texture; | |
1748 | 1647 |
1749 if (renderer->CreateTexture(renderer, texture) < 0) { | 1648 if (renderer->CreateTexture(renderer, texture) < 0) { |
1750 if (renderer->DestroyTexture) { | 1649 SDL_DestroyTexture(texture); |
1751 renderer->DestroyTexture(renderer, texture); | |
1752 } | |
1753 SDL_free(texture); | |
1754 return 0; | 1650 return 0; |
1755 } | 1651 } |
1756 hash = (texture->id % SDL_arraysize(SDL_CurrentDisplay.textures)); | 1652 return texture; |
1757 texture->next = SDL_CurrentDisplay.textures[hash]; | 1653 } |
1758 SDL_CurrentDisplay.textures[hash] = texture; | 1654 |
1759 | 1655 SDL_Texture * |
1760 return texture->id; | |
1761 } | |
1762 | |
1763 SDL_TextureID | |
1764 SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) | 1656 SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) |
1765 { | 1657 { |
1766 SDL_TextureID textureID; | 1658 SDL_Texture *texture; |
1767 Uint32 requested_format = format; | 1659 Uint32 requested_format = format; |
1768 SDL_PixelFormat *fmt; | 1660 SDL_PixelFormat *fmt; |
1769 SDL_Renderer *renderer; | 1661 SDL_Renderer *renderer; |
1770 int bpp; | 1662 int bpp; |
1771 Uint32 Rmask, Gmask, Bmask, Amask; | 1663 Uint32 Rmask, Gmask, Bmask, Amask; |
1978 SDL_SetError("Unknown pixel format"); | 1870 SDL_SetError("Unknown pixel format"); |
1979 return 0; | 1871 return 0; |
1980 } | 1872 } |
1981 } | 1873 } |
1982 | 1874 |
1983 textureID = | 1875 texture = |
1984 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, | 1876 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, |
1985 surface->h); | 1877 surface->h); |
1986 if (!textureID && !requested_format) { | 1878 if (!texture && !requested_format) { |
1987 SDL_DisplayMode desktop_mode; | 1879 SDL_DisplayMode desktop_mode; |
1988 SDL_GetDesktopDisplayMode(&desktop_mode); | 1880 SDL_GetDesktopDisplayMode(&desktop_mode); |
1989 format = desktop_mode.format; | 1881 format = desktop_mode.format; |
1990 textureID = | 1882 texture = |
1991 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, | 1883 SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, |
1992 surface->h); | 1884 surface->h); |
1993 } | 1885 } |
1994 if (!textureID) { | 1886 if (!texture) { |
1995 return 0; | 1887 return 0; |
1996 } | 1888 } |
1997 if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask | 1889 if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask |
1998 && Bmask == fmt->Bmask && Amask == fmt->Amask) { | 1890 && Bmask == fmt->Bmask && Amask == fmt->Amask) { |
1999 if (SDL_MUSTLOCK(surface)) { | 1891 if (SDL_MUSTLOCK(surface)) { |
2000 SDL_LockSurface(surface); | 1892 SDL_LockSurface(surface); |
2001 SDL_UpdateTexture(textureID, NULL, surface->pixels, | 1893 SDL_UpdateTexture(texture, NULL, surface->pixels, |
2002 surface->pitch); | 1894 surface->pitch); |
2003 SDL_UnlockSurface(surface); | 1895 SDL_UnlockSurface(surface); |
2004 } else { | 1896 } else { |
2005 SDL_UpdateTexture(textureID, NULL, surface->pixels, | 1897 SDL_UpdateTexture(texture, NULL, surface->pixels, |
2006 surface->pitch); | 1898 surface->pitch); |
2007 } | 1899 } |
2008 } else { | 1900 } else { |
2009 SDL_PixelFormat dst_fmt; | 1901 SDL_PixelFormat dst_fmt; |
2010 SDL_Surface *dst = NULL; | 1902 SDL_Surface *dst = NULL; |
2023 SDL_BITSPERPIXEL(format)); | 1915 SDL_BITSPERPIXEL(format)); |
2024 } | 1916 } |
2025 } | 1917 } |
2026 dst = SDL_ConvertSurface(surface, &dst_fmt, 0); | 1918 dst = SDL_ConvertSurface(surface, &dst_fmt, 0); |
2027 if (dst) { | 1919 if (dst) { |
2028 SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch); | 1920 SDL_UpdateTexture(texture, NULL, dst->pixels, dst->pitch); |
2029 SDL_FreeSurface(dst); | 1921 SDL_FreeSurface(dst); |
2030 } | 1922 } |
2031 if (dst_fmt.palette) { | 1923 if (dst_fmt.palette) { |
2032 SDL_FreePalette(dst_fmt.palette); | 1924 SDL_FreePalette(dst_fmt.palette); |
2033 } | 1925 } |
2034 if (!dst) { | 1926 if (!dst) { |
2035 SDL_DestroyTexture(textureID); | 1927 SDL_DestroyTexture(texture); |
2036 return 0; | 1928 return 0; |
2037 } | 1929 } |
2038 } | 1930 } |
2039 | 1931 |
2040 { | 1932 { |
2041 Uint8 r, g, b, a; | 1933 Uint8 r, g, b, a; |
2042 int blendMode; | 1934 int blendMode; |
2043 int scaleMode; | 1935 int scaleMode; |
2044 | 1936 |
2045 SDL_GetSurfaceColorMod(surface, &r, &g, &b); | 1937 SDL_GetSurfaceColorMod(surface, &r, &g, &b); |
2046 SDL_SetTextureColorMod(textureID, r, g, b); | 1938 SDL_SetTextureColorMod(texture, r, g, b); |
2047 | 1939 |
2048 SDL_GetSurfaceAlphaMod(surface, &a); | 1940 SDL_GetSurfaceAlphaMod(surface, &a); |
2049 SDL_SetTextureAlphaMod(textureID, a); | 1941 SDL_SetTextureAlphaMod(texture, a); |
2050 | 1942 |
2051 SDL_GetSurfaceBlendMode(surface, &blendMode); | 1943 SDL_GetSurfaceBlendMode(surface, &blendMode); |
2052 SDL_SetTextureBlendMode(textureID, blendMode); | 1944 SDL_SetTextureBlendMode(texture, blendMode); |
2053 | 1945 |
2054 SDL_GetSurfaceScaleMode(surface, &scaleMode); | 1946 SDL_GetSurfaceScaleMode(surface, &scaleMode); |
2055 SDL_SetTextureScaleMode(textureID, scaleMode); | 1947 SDL_SetTextureScaleMode(texture, scaleMode); |
2056 } | 1948 } |
2057 | 1949 |
2058 if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { | 1950 if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { |
2059 SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, | 1951 SDL_SetTexturePalette(texture, fmt->palette->colors, 0, |
2060 fmt->palette->ncolors); | 1952 fmt->palette->ncolors); |
2061 } | 1953 } |
2062 return textureID; | 1954 return texture; |
2063 } | 1955 } |
2064 | 1956 |
2065 static __inline__ SDL_Texture * | 1957 int |
2066 SDL_GetTextureFromID(SDL_TextureID textureID) | 1958 SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access, |
2067 { | |
2068 int hash; | |
2069 SDL_Texture *texture; | |
2070 | |
2071 if (!_this) { | |
2072 return NULL; | |
2073 } | |
2074 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures)); | |
2075 for (texture = SDL_CurrentDisplay.textures[hash]; texture; | |
2076 texture = texture->next) { | |
2077 if (texture->id == textureID) { | |
2078 return texture; | |
2079 } | |
2080 } | |
2081 return NULL; | |
2082 } | |
2083 | |
2084 int | |
2085 SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access, | |
2086 int *w, int *h) | 1959 int *w, int *h) |
2087 { | 1960 { |
2088 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2089 | |
2090 if (!texture) { | 1961 if (!texture) { |
2091 return -1; | 1962 return -1; |
2092 } | 1963 } |
2093 if (format) { | 1964 if (format) { |
2094 *format = texture->format; | 1965 *format = texture->format; |
2104 } | 1975 } |
2105 return 0; | 1976 return 0; |
2106 } | 1977 } |
2107 | 1978 |
2108 int | 1979 int |
2109 SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch) | 1980 SDL_QueryTexturePixels(SDL_Texture * texture, void **pixels, int *pitch) |
2110 { | 1981 { |
2111 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2112 SDL_Renderer *renderer; | 1982 SDL_Renderer *renderer; |
2113 | 1983 |
2114 if (!texture) { | 1984 if (!texture) { |
2115 return -1; | 1985 return -1; |
2116 } | 1986 } |
2121 } | 1991 } |
2122 return renderer->QueryTexturePixels(renderer, texture, pixels, pitch); | 1992 return renderer->QueryTexturePixels(renderer, texture, pixels, pitch); |
2123 } | 1993 } |
2124 | 1994 |
2125 int | 1995 int |
2126 SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors, | 1996 SDL_SetTexturePalette(SDL_Texture * texture, const SDL_Color * colors, |
2127 int firstcolor, int ncolors) | 1997 int firstcolor, int ncolors) |
2128 { | 1998 { |
2129 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2130 SDL_Renderer *renderer; | 1999 SDL_Renderer *renderer; |
2131 | 2000 |
2132 if (!texture) { | 2001 if (!texture) { |
2133 return -1; | 2002 return -1; |
2134 } | 2003 } |
2140 return renderer->SetTexturePalette(renderer, texture, colors, firstcolor, | 2009 return renderer->SetTexturePalette(renderer, texture, colors, firstcolor, |
2141 ncolors); | 2010 ncolors); |
2142 } | 2011 } |
2143 | 2012 |
2144 int | 2013 int |
2145 SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, | 2014 SDL_GetTexturePalette(SDL_Texture * texture, SDL_Color * colors, |
2146 int firstcolor, int ncolors) | 2015 int firstcolor, int ncolors) |
2147 { | 2016 { |
2148 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2149 SDL_Renderer *renderer; | 2017 SDL_Renderer *renderer; |
2150 | 2018 |
2151 if (!texture) { | 2019 if (!texture) { |
2152 return -1; | 2020 return -1; |
2153 } | 2021 } |
2159 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor, | 2027 return renderer->GetTexturePalette(renderer, texture, colors, firstcolor, |
2160 ncolors); | 2028 ncolors); |
2161 } | 2029 } |
2162 | 2030 |
2163 int | 2031 int |
2164 SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b) | 2032 SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b) |
2165 { | 2033 { |
2166 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2167 SDL_Renderer *renderer; | 2034 SDL_Renderer *renderer; |
2168 | 2035 |
2169 if (!texture) { | 2036 if (!texture) { |
2170 return -1; | 2037 return -1; |
2171 } | 2038 } |
2184 texture->b = b; | 2051 texture->b = b; |
2185 return renderer->SetTextureColorMod(renderer, texture); | 2052 return renderer->SetTextureColorMod(renderer, texture); |
2186 } | 2053 } |
2187 | 2054 |
2188 int | 2055 int |
2189 SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g, | 2056 SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g, |
2190 Uint8 * b) | 2057 Uint8 * b) |
2191 { | 2058 { |
2192 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2193 SDL_Renderer *renderer; | 2059 SDL_Renderer *renderer; |
2194 | 2060 |
2195 if (!texture) { | 2061 if (!texture) { |
2196 return -1; | 2062 return -1; |
2197 } | 2063 } |
2207 } | 2073 } |
2208 return 0; | 2074 return 0; |
2209 } | 2075 } |
2210 | 2076 |
2211 int | 2077 int |
2212 SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha) | 2078 SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha) |
2213 { | 2079 { |
2214 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2215 SDL_Renderer *renderer; | 2080 SDL_Renderer *renderer; |
2216 | 2081 |
2217 if (!texture) { | 2082 if (!texture) { |
2218 return -1; | 2083 return -1; |
2219 } | 2084 } |
2230 texture->a = alpha; | 2095 texture->a = alpha; |
2231 return renderer->SetTextureAlphaMod(renderer, texture); | 2096 return renderer->SetTextureAlphaMod(renderer, texture); |
2232 } | 2097 } |
2233 | 2098 |
2234 int | 2099 int |
2235 SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha) | 2100 SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha) |
2236 { | 2101 { |
2237 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2238 | |
2239 if (!texture) { | 2102 if (!texture) { |
2240 return -1; | 2103 return -1; |
2241 } | 2104 } |
2242 if (alpha) { | 2105 if (alpha) { |
2243 *alpha = texture->a; | 2106 *alpha = texture->a; |
2244 } | 2107 } |
2245 return 0; | 2108 return 0; |
2246 } | 2109 } |
2247 | 2110 |
2248 int | 2111 int |
2249 SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode) | 2112 SDL_SetTextureBlendMode(SDL_Texture * texture, int blendMode) |
2250 { | 2113 { |
2251 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2252 SDL_Renderer *renderer; | 2114 SDL_Renderer *renderer; |
2253 | 2115 |
2254 if (!texture) { | 2116 if (!texture) { |
2255 return -1; | 2117 return -1; |
2256 } | 2118 } |
2262 texture->blendMode = blendMode; | 2124 texture->blendMode = blendMode; |
2263 return renderer->SetTextureBlendMode(renderer, texture); | 2125 return renderer->SetTextureBlendMode(renderer, texture); |
2264 } | 2126 } |
2265 | 2127 |
2266 int | 2128 int |
2267 SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode) | 2129 SDL_GetTextureBlendMode(SDL_Texture * texture, int *blendMode) |
2268 { | 2130 { |
2269 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2270 | |
2271 if (!texture) { | 2131 if (!texture) { |
2272 return -1; | 2132 return -1; |
2273 } | 2133 } |
2274 if (blendMode) { | 2134 if (blendMode) { |
2275 *blendMode = texture->blendMode; | 2135 *blendMode = texture->blendMode; |
2276 } | 2136 } |
2277 return 0; | 2137 return 0; |
2278 } | 2138 } |
2279 | 2139 |
2280 int | 2140 int |
2281 SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode) | 2141 SDL_SetTextureScaleMode(SDL_Texture * texture, int scaleMode) |
2282 { | 2142 { |
2283 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2284 SDL_Renderer *renderer; | 2143 SDL_Renderer *renderer; |
2285 | 2144 |
2286 if (!texture) { | 2145 if (!texture) { |
2287 return -1; | 2146 return -1; |
2288 } | 2147 } |
2294 texture->scaleMode = scaleMode; | 2153 texture->scaleMode = scaleMode; |
2295 return renderer->SetTextureScaleMode(renderer, texture); | 2154 return renderer->SetTextureScaleMode(renderer, texture); |
2296 } | 2155 } |
2297 | 2156 |
2298 int | 2157 int |
2299 SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode) | 2158 SDL_GetTextureScaleMode(SDL_Texture * texture, int *scaleMode) |
2300 { | 2159 { |
2301 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2302 | |
2303 if (!texture) { | 2160 if (!texture) { |
2304 return -1; | 2161 return -1; |
2305 } | 2162 } |
2306 if (scaleMode) { | 2163 if (scaleMode) { |
2307 *scaleMode = texture->scaleMode; | 2164 *scaleMode = texture->scaleMode; |
2308 } | 2165 } |
2309 return 0; | 2166 return 0; |
2310 } | 2167 } |
2311 | 2168 |
2312 int | 2169 int |
2313 SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect, | 2170 SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect, |
2314 const void *pixels, int pitch) | 2171 const void *pixels, int pitch) |
2315 { | 2172 { |
2316 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2317 SDL_Renderer *renderer; | 2173 SDL_Renderer *renderer; |
2318 SDL_Rect full_rect; | 2174 SDL_Rect full_rect; |
2319 | 2175 |
2320 if (!texture) { | 2176 if (!texture) { |
2321 return -1; | 2177 return -1; |
2334 } | 2190 } |
2335 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch); | 2191 return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch); |
2336 } | 2192 } |
2337 | 2193 |
2338 int | 2194 int |
2339 SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty, | 2195 SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, int markDirty, |
2340 void **pixels, int *pitch) | 2196 void **pixels, int *pitch) |
2341 { | 2197 { |
2342 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2343 SDL_Renderer *renderer; | 2198 SDL_Renderer *renderer; |
2344 SDL_Rect full_rect; | 2199 SDL_Rect full_rect; |
2345 | 2200 |
2346 if (!texture) { | 2201 if (!texture) { |
2347 return -1; | 2202 return -1; |
2365 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels, | 2220 return renderer->LockTexture(renderer, texture, rect, markDirty, pixels, |
2366 pitch); | 2221 pitch); |
2367 } | 2222 } |
2368 | 2223 |
2369 void | 2224 void |
2370 SDL_UnlockTexture(SDL_TextureID textureID) | 2225 SDL_UnlockTexture(SDL_Texture * texture) |
2371 { | 2226 { |
2372 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2373 SDL_Renderer *renderer; | 2227 SDL_Renderer *renderer; |
2374 | 2228 |
2375 if (!texture) { | 2229 if (!texture) { |
2376 return; | 2230 return; |
2377 } | 2231 } |
2384 } | 2238 } |
2385 renderer->UnlockTexture(renderer, texture); | 2239 renderer->UnlockTexture(renderer, texture); |
2386 } | 2240 } |
2387 | 2241 |
2388 void | 2242 void |
2389 SDL_DirtyTexture(SDL_TextureID textureID, int numrects, | 2243 SDL_DirtyTexture(SDL_Texture * texture, int numrects, |
2390 const SDL_Rect * rects) | 2244 const SDL_Rect * rects) |
2391 { | 2245 { |
2392 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2393 SDL_Renderer *renderer; | 2246 SDL_Renderer *renderer; |
2394 | 2247 |
2395 if (!texture) { | 2248 if (!texture) { |
2396 return; | 2249 return; |
2397 } | 2250 } |
2605 return 0; | 2458 return 0; |
2606 } | 2459 } |
2607 /* Check for NULL rect, which means fill entire window */ | 2460 /* Check for NULL rect, which means fill entire window */ |
2608 for (i = 0; i < count; ++i) { | 2461 for (i = 0; i < count; ++i) { |
2609 if (rects[i] == NULL) { | 2462 if (rects[i] == NULL) { |
2610 SDL_Window *window; | 2463 SDL_Window *window = renderer->window; |
2611 SDL_Rect full_rect; | 2464 SDL_Rect full_rect; |
2612 const SDL_Rect *rect; | 2465 const SDL_Rect *rect; |
2613 | 2466 |
2614 window = SDL_GetWindowFromID(renderer->window); | |
2615 full_rect.x = 0; | 2467 full_rect.x = 0; |
2616 full_rect.y = 0; | 2468 full_rect.y = 0; |
2617 full_rect.w = window->w; | 2469 full_rect.w = window->w; |
2618 full_rect.h = window->h; | 2470 full_rect.h = window->h; |
2619 rect = &full_rect; | 2471 rect = &full_rect; |
2652 return 0; | 2504 return 0; |
2653 } | 2505 } |
2654 /* Check for NULL rect, which means fill entire window */ | 2506 /* Check for NULL rect, which means fill entire window */ |
2655 for (i = 0; i < count; ++i) { | 2507 for (i = 0; i < count; ++i) { |
2656 if (rects[i] == NULL) { | 2508 if (rects[i] == NULL) { |
2657 SDL_Window *window; | 2509 SDL_Window *window = renderer->window; |
2658 SDL_Rect full_rect; | 2510 SDL_Rect full_rect; |
2659 const SDL_Rect *rect; | 2511 const SDL_Rect *rect; |
2660 | 2512 |
2661 window = SDL_GetWindowFromID(renderer->window); | |
2662 full_rect.x = 0; | 2513 full_rect.x = 0; |
2663 full_rect.y = 0; | 2514 full_rect.y = 0; |
2664 full_rect.w = window->w; | 2515 full_rect.w = window->w; |
2665 full_rect.h = window->h; | 2516 full_rect.h = window->h; |
2666 rect = &full_rect; | 2517 rect = &full_rect; |
2669 } | 2520 } |
2670 return renderer->RenderFillRects(renderer, rects, count); | 2521 return renderer->RenderFillRects(renderer, rects, count); |
2671 } | 2522 } |
2672 | 2523 |
2673 int | 2524 int |
2674 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, | 2525 SDL_RenderCopy(SDL_Texture * texture, const SDL_Rect * srcrect, |
2675 const SDL_Rect * dstrect) | 2526 const SDL_Rect * dstrect) |
2676 { | 2527 { |
2677 SDL_Texture *texture = SDL_GetTextureFromID(textureID); | |
2678 SDL_Renderer *renderer; | 2528 SDL_Renderer *renderer; |
2679 SDL_Window *window; | 2529 SDL_Window *window; |
2680 SDL_Rect real_srcrect; | 2530 SDL_Rect real_srcrect; |
2681 SDL_Rect real_dstrect; | 2531 SDL_Rect real_dstrect; |
2682 | 2532 |
2694 } | 2544 } |
2695 if (!renderer->RenderCopy) { | 2545 if (!renderer->RenderCopy) { |
2696 SDL_Unsupported(); | 2546 SDL_Unsupported(); |
2697 return -1; | 2547 return -1; |
2698 } | 2548 } |
2699 window = SDL_GetWindowFromID(renderer->window); | 2549 window = renderer->window; |
2700 | 2550 |
2701 real_srcrect.x = 0; | 2551 real_srcrect.x = 0; |
2702 real_srcrect.y = 0; | 2552 real_srcrect.y = 0; |
2703 real_srcrect.w = texture->w; | 2553 real_srcrect.w = texture->w; |
2704 real_srcrect.h = texture->h; | 2554 real_srcrect.h = texture->h; |
2749 } | 2599 } |
2750 if (!renderer->RenderReadPixels) { | 2600 if (!renderer->RenderReadPixels) { |
2751 SDL_Unsupported(); | 2601 SDL_Unsupported(); |
2752 return -1; | 2602 return -1; |
2753 } | 2603 } |
2754 window = SDL_GetWindowFromID(renderer->window); | 2604 window = renderer->window; |
2755 | 2605 |
2756 if (!format) { | 2606 if (!format) { |
2757 format = SDL_GetDisplayFromWindow(window)->current_mode.format; | 2607 format = window->display->current_mode.format; |
2758 } | 2608 } |
2759 | 2609 |
2760 real_rect.x = 0; | 2610 real_rect.x = 0; |
2761 real_rect.y = 0; | 2611 real_rect.y = 0; |
2762 real_rect.w = window->w; | 2612 real_rect.w = window->w; |
2767 } | 2617 } |
2768 if (real_rect.y > rect->y) { | 2618 if (real_rect.y > rect->y) { |
2769 pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y); | 2619 pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y); |
2770 } | 2620 } |
2771 if (real_rect.x > rect->x) { | 2621 if (real_rect.x > rect->x) { |
2772 Uint32 format = SDL_CurrentDisplay.current_mode.format; | 2622 Uint32 format = SDL_CurrentDisplay->current_mode.format; |
2773 int bpp = SDL_BYTESPERPIXEL(format); | 2623 int bpp = SDL_BYTESPERPIXEL(format); |
2774 pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x); | 2624 pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x); |
2775 } | 2625 } |
2776 } | 2626 } |
2777 | 2627 |
2793 } | 2643 } |
2794 if (!renderer->RenderWritePixels) { | 2644 if (!renderer->RenderWritePixels) { |
2795 SDL_Unsupported(); | 2645 SDL_Unsupported(); |
2796 return -1; | 2646 return -1; |
2797 } | 2647 } |
2798 window = SDL_GetWindowFromID(renderer->window); | 2648 window = renderer->window; |
2799 | 2649 |
2800 if (!format) { | 2650 if (!format) { |
2801 format = SDL_GetDisplayFromWindow(window)->current_mode.format; | 2651 format = window->display->current_mode.format; |
2802 } | 2652 } |
2803 | 2653 |
2804 real_rect.x = 0; | 2654 real_rect.x = 0; |
2805 real_rect.y = 0; | 2655 real_rect.y = 0; |
2806 real_rect.w = window->w; | 2656 real_rect.w = window->w; |
2811 } | 2661 } |
2812 if (real_rect.y > rect->y) { | 2662 if (real_rect.y > rect->y) { |
2813 pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y); | 2663 pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y); |
2814 } | 2664 } |
2815 if (real_rect.x > rect->x) { | 2665 if (real_rect.x > rect->x) { |
2816 Uint32 format = SDL_CurrentDisplay.current_mode.format; | 2666 Uint32 format = SDL_CurrentDisplay->current_mode.format; |
2817 int bpp = SDL_BYTESPERPIXEL(format); | 2667 int bpp = SDL_BYTESPERPIXEL(format); |
2818 pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x); | 2668 pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x); |
2819 } | 2669 } |
2820 } | 2670 } |
2821 | 2671 |
2834 } | 2684 } |
2835 renderer->RenderPresent(renderer); | 2685 renderer->RenderPresent(renderer); |
2836 } | 2686 } |
2837 | 2687 |
2838 void | 2688 void |
2839 SDL_DestroyTexture(SDL_TextureID textureID) | 2689 SDL_DestroyTexture(SDL_Texture * texture) |
2840 { | 2690 { |
2841 int hash; | |
2842 SDL_Texture *prev, *texture; | |
2843 SDL_Renderer *renderer; | 2691 SDL_Renderer *renderer; |
2844 | 2692 |
2845 if (!_this) { | 2693 if (!texture || !texture->renderer) { |
2846 SDL_UninitializedVideo(); | 2694 SDL_SetError("Invalid texture"); |
2847 return; | 2695 return; |
2848 } | 2696 } |
2849 /* Look up the texture in the hash table */ | 2697 |
2850 hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures)); | 2698 renderer = texture->renderer; |
2851 prev = NULL; | 2699 if (texture->prev) { |
2852 for (texture = SDL_CurrentDisplay.textures[hash]; texture; | 2700 texture->prev->next = texture->next; |
2853 prev = texture, texture = texture->next) { | |
2854 if (texture->id == textureID) { | |
2855 break; | |
2856 } | |
2857 } | |
2858 if (!texture) { | |
2859 return; | |
2860 } | |
2861 /* Unlink the texture from the list */ | |
2862 if (prev) { | |
2863 prev->next = texture->next; | |
2864 } else { | 2701 } else { |
2865 SDL_CurrentDisplay.textures[hash] = texture->next; | 2702 renderer->textures = texture->next; |
2866 } | 2703 } |
2867 | 2704 texture->renderer = NULL; |
2868 /* Free the texture */ | 2705 |
2869 renderer = texture->renderer; | |
2870 renderer->DestroyTexture(renderer, texture); | 2706 renderer->DestroyTexture(renderer, texture); |
2871 SDL_free(texture); | 2707 SDL_free(texture); |
2872 } | 2708 } |
2873 | 2709 |
2874 void | 2710 void |
2875 SDL_DestroyRenderer(SDL_WindowID windowID) | 2711 SDL_DestroyRenderer(SDL_Window * window) |
2876 { | 2712 { |
2877 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
2878 SDL_Renderer *renderer; | 2713 SDL_Renderer *renderer; |
2879 int i; | 2714 int i; |
2880 | 2715 |
2881 if (!window) { | 2716 if (!window) { |
2882 return; | 2717 return; |
2883 } | 2718 } |
2884 renderer = window->renderer; | 2719 renderer = window->renderer; |
2885 if (!renderer) { | 2720 if (!renderer) { |
2886 return; | 2721 return; |
2887 } | 2722 } |
2723 | |
2888 /* Free existing textures for this renderer */ | 2724 /* Free existing textures for this renderer */ |
2889 for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) { | 2725 while (renderer->textures) { |
2890 SDL_Texture *texture; | 2726 SDL_DestroyTexture(renderer->textures); |
2891 SDL_Texture *prev = NULL; | |
2892 SDL_Texture *next; | |
2893 for (texture = SDL_CurrentDisplay.textures[i]; texture; | |
2894 texture = next) { | |
2895 next = texture->next; | |
2896 if (texture->renderer == renderer) { | |
2897 if (prev) { | |
2898 prev->next = next; | |
2899 } else { | |
2900 SDL_CurrentDisplay.textures[i] = next; | |
2901 } | |
2902 renderer->DestroyTexture(renderer, texture); | |
2903 SDL_free(texture); | |
2904 } else { | |
2905 prev = texture; | |
2906 } | |
2907 } | |
2908 } | 2727 } |
2909 | 2728 |
2910 /* Free the renderer instance */ | 2729 /* Free the renderer instance */ |
2911 renderer->DestroyRenderer(renderer); | 2730 renderer->DestroyRenderer(renderer); |
2912 | 2731 |
2913 /* Clear references */ | 2732 /* Clear references */ |
2914 window->renderer = NULL; | 2733 window->renderer = NULL; |
2915 if (SDL_CurrentDisplay.current_renderer == renderer) { | 2734 if (SDL_CurrentDisplay->current_renderer == renderer) { |
2916 SDL_CurrentDisplay.current_renderer = NULL; | 2735 SDL_CurrentDisplay->current_renderer = NULL; |
2917 } | 2736 } |
2918 } | 2737 } |
2919 | 2738 |
2920 SDL_bool | 2739 SDL_bool |
2921 SDL_IsScreenSaverEnabled() | 2740 SDL_IsScreenSaverEnabled() |
2969 SDL_EnableScreenSaver(); | 2788 SDL_EnableScreenSaver(); |
2970 | 2789 |
2971 /* Clean up the system video */ | 2790 /* Clean up the system video */ |
2972 for (i = _this->num_displays; i--;) { | 2791 for (i = _this->num_displays; i--;) { |
2973 SDL_VideoDisplay *display = &_this->displays[i]; | 2792 SDL_VideoDisplay *display = &_this->displays[i]; |
2974 for (j = display->num_windows; j--;) { | 2793 while (display->windows) { |
2975 SDL_DestroyWindow(display->windows[i].id); | 2794 SDL_DestroyWindow(display->windows); |
2976 } | 2795 } |
2977 if (display->windows) { | |
2978 SDL_free(display->windows); | |
2979 display->windows = NULL; | |
2980 } | |
2981 display->num_windows = 0; | |
2982 if (display->render_drivers) { | 2796 if (display->render_drivers) { |
2983 SDL_free(display->render_drivers); | 2797 SDL_free(display->render_drivers); |
2984 display->render_drivers = NULL; | 2798 display->render_drivers = NULL; |
2985 } | 2799 } |
2986 display->num_render_drivers = 0; | 2800 display->num_render_drivers = 0; |
3381 return -1; | 3195 return -1; |
3382 #endif /* SDL_VIDEO_OPENGL */ | 3196 #endif /* SDL_VIDEO_OPENGL */ |
3383 } | 3197 } |
3384 | 3198 |
3385 SDL_GLContext | 3199 SDL_GLContext |
3386 SDL_GL_CreateContext(SDL_WindowID windowID) | 3200 SDL_GL_CreateContext(SDL_Window * window) |
3387 { | 3201 { |
3388 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
3389 | |
3390 if (!window) { | 3202 if (!window) { |
3391 return NULL; | 3203 return NULL; |
3392 } | 3204 } |
3393 if (!(window->flags & SDL_WINDOW_OPENGL)) { | 3205 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
3394 SDL_SetError("The specified window isn't an OpenGL window"); | 3206 SDL_SetError("The specified window isn't an OpenGL window"); |
3396 } | 3208 } |
3397 return _this->GL_CreateContext(_this, window); | 3209 return _this->GL_CreateContext(_this, window); |
3398 } | 3210 } |
3399 | 3211 |
3400 int | 3212 int |
3401 SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context) | 3213 SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context) |
3402 { | 3214 { |
3403 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
3404 | |
3405 if (window && !(window->flags & SDL_WINDOW_OPENGL)) { | 3215 if (window && !(window->flags & SDL_WINDOW_OPENGL)) { |
3406 SDL_SetError("The specified window isn't an OpenGL window"); | 3216 SDL_SetError("The specified window isn't an OpenGL window"); |
3407 return -1; | 3217 return -1; |
3408 } | 3218 } |
3409 if (!context) { | 3219 if (!context) { |
3441 return -1; | 3251 return -1; |
3442 } | 3252 } |
3443 } | 3253 } |
3444 | 3254 |
3445 void | 3255 void |
3446 SDL_GL_SwapWindow(SDL_WindowID windowID) | 3256 SDL_GL_SwapWindow(SDL_Window * window) |
3447 { | 3257 { |
3448 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
3449 | |
3450 if (!window) { | 3258 if (!window) { |
3451 return; | 3259 return; |
3452 } | 3260 } |
3453 if (!(window->flags & SDL_WINDOW_OPENGL)) { | 3261 if (!(window->flags & SDL_WINDOW_OPENGL)) { |
3454 SDL_SetError("The specified window isn't an OpenGL window"); | 3262 SDL_SetError("The specified window isn't an OpenGL window"); |
3565 } | 3373 } |
3566 } | 3374 } |
3567 #endif | 3375 #endif |
3568 | 3376 |
3569 SDL_bool | 3377 SDL_bool |
3570 SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info) | 3378 SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info) |
3571 { | 3379 { |
3572 SDL_Window *window = SDL_GetWindowFromID(windowID); | |
3573 | |
3574 if (!window || !_this->GetWindowWMInfo) { | 3380 if (!window || !_this->GetWindowWMInfo) { |
3575 return SDL_FALSE; | 3381 return SDL_FALSE; |
3576 } | 3382 } |
3577 return (_this->GetWindowWMInfo(_this, window, info)); | 3383 return (_this->GetWindowWMInfo(_this, window, info)); |
3578 } | 3384 } |