comparison src/video/SDL_video.c @ 3695:f6a8be3fefa0

Added magic to detect already freed or otherwise invalid windows and textures.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 24 Jan 2010 20:21:51 +0000
parents b0a707f589a6
children f7b03b6838cb
comparison
equal deleted inserted replaced
3694:b0a707f589a6 3695:f6a8be3fefa0
103 NULL 103 NULL
104 }; 104 };
105 105
106 static SDL_VideoDevice *_this = NULL; 106 static SDL_VideoDevice *_this = NULL;
107 107
108 #define CHECK_WINDOW_MAGIC(window, retval) \
109 if (!_this) { \
110 SDL_UninitializedVideo(); \
111 return retval; \
112 } \
113 if (!window || window->magic != &_this->window_magic) { \
114 SDL_SetError("Invalid window"); \
115 return retval; \
116 }
117
118 #define CHECK_TEXTURE_MAGIC(texture, retval) \
119 if (!_this) { \
120 SDL_UninitializedVideo(); \
121 return retval; \
122 } \
123 if (!texture || texture->magic != &_this->texture_magic) { \
124 SDL_SetError("Invalid texture"); \
125 return retval; \
126 }
127
108 /* Various local functions */ 128 /* Various local functions */
109 static void SDL_UpdateWindowGrab(SDL_Window * window); 129 static void SDL_UpdateWindowGrab(SDL_Window * window);
110 130
111 static int 131 static int
112 cmpmodes(const void *A, const void *B) 132 cmpmodes(const void *A, const void *B)
708 } 728 }
709 729
710 int 730 int
711 SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode) 731 SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
712 { 732 {
713 if (!window) { 733 CHECK_WINDOW_MAGIC(window, -1);
714 return -1;
715 }
716 734
717 if (mode) { 735 if (mode) {
718 window->fullscreen_mode = *mode; 736 window->fullscreen_mode = *mode;
719 } else { 737 } else {
720 SDL_zero(window->fullscreen_mode); 738 SDL_zero(window->fullscreen_mode);
725 int 743 int
726 SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) 744 SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
727 { 745 {
728 SDL_DisplayMode fullscreen_mode; 746 SDL_DisplayMode fullscreen_mode;
729 747
730 if (!window) { 748 CHECK_WINDOW_MAGIC(window, -1);
731 return -1;
732 }
733 749
734 fullscreen_mode = window->fullscreen_mode; 750 fullscreen_mode = window->fullscreen_mode;
735 if (!fullscreen_mode.w) { 751 if (!fullscreen_mode.w) {
736 fullscreen_mode.w = window->w; 752 fullscreen_mode.w = window->w;
737 } 753 }
895 } 911 }
896 SDL_GL_LoadLibrary(NULL); 912 SDL_GL_LoadLibrary(NULL);
897 } 913 }
898 display = SDL_CurrentDisplay; 914 display = SDL_CurrentDisplay;
899 window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); 915 window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
916 window->magic = &_this->window_magic;
900 window->id = _this->next_object_id++; 917 window->id = _this->next_object_id++;
901 window->x = x; 918 window->x = x;
902 window->y = y; 919 window->y = y;
903 window->w = w; 920 window->w = w;
904 window->h = h; 921 window->h = h;
942 SDL_UninitializedVideo(); 959 SDL_UninitializedVideo();
943 return NULL; 960 return NULL;
944 } 961 }
945 display = SDL_CurrentDisplay; 962 display = SDL_CurrentDisplay;
946 window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); 963 window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
964 window->magic = &_this->window_magic;
947 window->id = _this->next_object_id++; 965 window->id = _this->next_object_id++;
948 window->flags = SDL_WINDOW_FOREIGN; 966 window->flags = SDL_WINDOW_FOREIGN;
949 window->display = display; 967 window->display = display;
950 window->next = display->windows; 968 window->next = display->windows;
951 if (display->windows) { 969 if (display->windows) {
1045 } 1063 }
1046 1064
1047 Uint32 1065 Uint32
1048 SDL_GetWindowID(SDL_Window * window) 1066 SDL_GetWindowID(SDL_Window * window)
1049 { 1067 {
1050 if (!window) { 1068 CHECK_WINDOW_MAGIC(window, 0);
1051 return 0; 1069
1052 }
1053 return window->id; 1070 return window->id;
1054 } 1071 }
1055 1072
1056 SDL_Window * 1073 SDL_Window *
1057 SDL_GetWindowFromID(Uint32 id) 1074 SDL_GetWindowFromID(Uint32 id)
1075 } 1092 }
1076 1093
1077 Uint32 1094 Uint32
1078 SDL_GetWindowFlags(SDL_Window * window) 1095 SDL_GetWindowFlags(SDL_Window * window)
1079 { 1096 {
1080 if (!window) { 1097 CHECK_WINDOW_MAGIC(window, 0);
1081 return 0; 1098
1082 }
1083 return window->flags; 1099 return window->flags;
1084 } 1100 }
1085 1101
1086 void 1102 void
1087 SDL_SetWindowTitle(SDL_Window * window, const char *title) 1103 SDL_SetWindowTitle(SDL_Window * window, const char *title)
1088 { 1104 {
1089 if (!window || title == window->title) { 1105 CHECK_WINDOW_MAGIC(window, );
1106
1107 if (title == window->title) {
1090 return; 1108 return;
1091 } 1109 }
1092 if (window->title) { 1110 if (window->title) {
1093 SDL_free(window->title); 1111 SDL_free(window->title);
1094 } 1112 }
1104 } 1122 }
1105 1123
1106 const char * 1124 const char *
1107 SDL_GetWindowTitle(SDL_Window * window) 1125 SDL_GetWindowTitle(SDL_Window * window)
1108 { 1126 {
1109 if (!window) { 1127 CHECK_WINDOW_MAGIC(window, NULL);
1110 return NULL; 1128
1111 }
1112 return window->title; 1129 return window->title;
1113 } 1130 }
1114 1131
1115 void 1132 void
1116 SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon) 1133 SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
1117 { 1134 {
1118 if (!window) { 1135 CHECK_WINDOW_MAGIC(window, );
1119 return; 1136
1120 }
1121 if (_this->SetWindowIcon) { 1137 if (_this->SetWindowIcon) {
1122 _this->SetWindowIcon(_this, window, icon); 1138 _this->SetWindowIcon(_this, window, icon);
1123 } 1139 }
1124 } 1140 }
1125 1141
1126 void 1142 void
1127 SDL_SetWindowData(SDL_Window * window, void *userdata) 1143 SDL_SetWindowData(SDL_Window * window, void *userdata)
1128 { 1144 {
1129 if (!window) { 1145 CHECK_WINDOW_MAGIC(window, );
1130 return; 1146
1131 }
1132 window->userdata = userdata; 1147 window->userdata = userdata;
1133 } 1148 }
1134 1149
1135 void * 1150 void *
1136 SDL_GetWindowData(SDL_Window * window) 1151 SDL_GetWindowData(SDL_Window * window)
1137 { 1152 {
1138 if (!window) { 1153 CHECK_WINDOW_MAGIC(window, NULL);
1139 return NULL; 1154
1140 }
1141 return window->userdata; 1155 return window->userdata;
1142 } 1156 }
1143 1157
1144 void 1158 void
1145 SDL_SetWindowPosition(SDL_Window * window, int x, int y) 1159 SDL_SetWindowPosition(SDL_Window * window, int x, int y)
1146 { 1160 {
1147 if (!window) { 1161 CHECK_WINDOW_MAGIC(window, );
1148 return; 1162
1149 }
1150 if (x != SDL_WINDOWPOS_UNDEFINED) { 1163 if (x != SDL_WINDOWPOS_UNDEFINED) {
1151 window->x = x; 1164 window->x = x;
1152 } 1165 }
1153 if (y != SDL_WINDOWPOS_UNDEFINED) { 1166 if (y != SDL_WINDOWPOS_UNDEFINED) {
1154 window->y = y; 1167 window->y = y;
1160 } 1173 }
1161 1174
1162 void 1175 void
1163 SDL_GetWindowPosition(SDL_Window * window, int *x, int *y) 1176 SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
1164 { 1177 {
1165 if (!window) { 1178 CHECK_WINDOW_MAGIC(window, );
1166 return; 1179
1167 }
1168 if (x) { 1180 if (x) {
1169 *x = window->x; 1181 *x = window->x;
1170 } 1182 }
1171 if (y) { 1183 if (y) {
1172 *y = window->y; 1184 *y = window->y;
1174 } 1186 }
1175 1187
1176 void 1188 void
1177 SDL_SetWindowSize(SDL_Window * window, int w, int h) 1189 SDL_SetWindowSize(SDL_Window * window, int w, int h)
1178 { 1190 {
1179 if (!window) { 1191 CHECK_WINDOW_MAGIC(window, );
1180 return; 1192
1181 }
1182 window->w = w; 1193 window->w = w;
1183 window->h = h; 1194 window->h = h;
1184 1195
1185 if (_this->SetWindowSize) { 1196 if (_this->SetWindowSize) {
1186 _this->SetWindowSize(_this, window); 1197 _this->SetWindowSize(_this, window);
1209 } 1220 }
1210 1221
1211 void 1222 void
1212 SDL_ShowWindow(SDL_Window * window) 1223 SDL_ShowWindow(SDL_Window * window)
1213 { 1224 {
1214 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { 1225 CHECK_WINDOW_MAGIC(window, );
1226
1227 if (window->flags & SDL_WINDOW_SHOWN) {
1215 return; 1228 return;
1216 } 1229 }
1217 1230
1218 if (_this->ShowWindow) { 1231 if (_this->ShowWindow) {
1219 _this->ShowWindow(_this, window); 1232 _this->ShowWindow(_this, window);
1222 } 1235 }
1223 1236
1224 void 1237 void
1225 SDL_HideWindow(SDL_Window * window) 1238 SDL_HideWindow(SDL_Window * window)
1226 { 1239 {
1227 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { 1240 CHECK_WINDOW_MAGIC(window, );
1241
1242 if (!(window->flags & SDL_WINDOW_SHOWN)) {
1228 return; 1243 return;
1229 } 1244 }
1230 1245
1231 if (_this->HideWindow) { 1246 if (_this->HideWindow) {
1232 _this->HideWindow(_this, window); 1247 _this->HideWindow(_this, window);
1235 } 1250 }
1236 1251
1237 void 1252 void
1238 SDL_RaiseWindow(SDL_Window * window) 1253 SDL_RaiseWindow(SDL_Window * window)
1239 { 1254 {
1240 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { 1255 CHECK_WINDOW_MAGIC(window, );
1256
1257 if (!(window->flags & SDL_WINDOW_SHOWN)) {
1241 return; 1258 return;
1242 } 1259 }
1243 if (_this->RaiseWindow) { 1260 if (_this->RaiseWindow) {
1244 _this->RaiseWindow(_this, window); 1261 _this->RaiseWindow(_this, window);
1245 } else { 1262 } else {
1249 } 1266 }
1250 1267
1251 void 1268 void
1252 SDL_MaximizeWindow(SDL_Window * window) 1269 SDL_MaximizeWindow(SDL_Window * window)
1253 { 1270 {
1254 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { 1271 CHECK_WINDOW_MAGIC(window, );
1272
1273 if (window->flags & SDL_WINDOW_MAXIMIZED) {
1255 return; 1274 return;
1256 } 1275 }
1257 1276
1258 if (_this->MaximizeWindow) { 1277 if (_this->MaximizeWindow) {
1259 _this->MaximizeWindow(_this, window); 1278 _this->MaximizeWindow(_this, window);
1262 } 1281 }
1263 1282
1264 void 1283 void
1265 SDL_MinimizeWindow(SDL_Window * window) 1284 SDL_MinimizeWindow(SDL_Window * window)
1266 { 1285 {
1267 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { 1286 CHECK_WINDOW_MAGIC(window, );
1287
1288 if (window->flags & SDL_WINDOW_MINIMIZED) {
1268 return; 1289 return;
1269 } 1290 }
1270 1291
1271 if (_this->MinimizeWindow) { 1292 if (_this->MinimizeWindow) {
1272 _this->MinimizeWindow(_this, window); 1293 _this->MinimizeWindow(_this, window);
1275 } 1296 }
1276 1297
1277 void 1298 void
1278 SDL_RestoreWindow(SDL_Window * window) 1299 SDL_RestoreWindow(SDL_Window * window)
1279 { 1300 {
1280 if (!window 1301 CHECK_WINDOW_MAGIC(window, );
1281 || !(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { 1302
1303 if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
1282 return; 1304 return;
1283 } 1305 }
1284 1306
1285 if (_this->RestoreWindow) { 1307 if (_this->RestoreWindow) {
1286 _this->RestoreWindow(_this, window); 1308 _this->RestoreWindow(_this, window);
1289 } 1311 }
1290 1312
1291 int 1313 int
1292 SDL_SetWindowFullscreen(SDL_Window * window, int fullscreen) 1314 SDL_SetWindowFullscreen(SDL_Window * window, int fullscreen)
1293 { 1315 {
1294 if (!window) { 1316 CHECK_WINDOW_MAGIC(window, -1);
1295 return -1; 1317
1296 }
1297 if (fullscreen) { 1318 if (fullscreen) {
1298 fullscreen = SDL_WINDOW_FULLSCREEN; 1319 fullscreen = SDL_WINDOW_FULLSCREEN;
1299 } 1320 }
1300 if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) { 1321 if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
1301 return 0; 1322 return 0;
1313 } 1334 }
1314 1335
1315 void 1336 void
1316 SDL_SetWindowGrab(SDL_Window * window, int mode) 1337 SDL_SetWindowGrab(SDL_Window * window, int mode)
1317 { 1338 {
1318 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { 1339 CHECK_WINDOW_MAGIC(window, );
1340
1341 if ((!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
1319 return; 1342 return;
1320 } 1343 }
1321 if (mode) { 1344 if (mode) {
1322 window->flags |= SDL_WINDOW_INPUT_GRABBED; 1345 window->flags |= SDL_WINDOW_INPUT_GRABBED;
1323 } else { 1346 } else {
1335 } 1358 }
1336 1359
1337 int 1360 int
1338 SDL_GetWindowGrab(SDL_Window * window) 1361 SDL_GetWindowGrab(SDL_Window * window)
1339 { 1362 {
1340 if (!window) { 1363 CHECK_WINDOW_MAGIC(window, 0);
1341 return 0; 1364
1342 }
1343 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); 1365 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
1344 } 1366 }
1345 1367
1346 void 1368 void
1347 SDL_OnWindowShown(SDL_Window * window) 1369 SDL_OnWindowShown(SDL_Window * window)
1434 void 1456 void
1435 SDL_DestroyWindow(SDL_Window * window) 1457 SDL_DestroyWindow(SDL_Window * window)
1436 { 1458 {
1437 SDL_VideoDisplay *display; 1459 SDL_VideoDisplay *display;
1438 1460
1439 if (!_this || !window || !window->id) { 1461 CHECK_WINDOW_MAGIC(window, );
1440 SDL_SetError("Invalid window"); 1462 window->magic = NULL;
1441 return;
1442 }
1443 1463
1444 if (window->title) { 1464 if (window->title) {
1445 SDL_free(window->title); 1465 SDL_free(window->title);
1446 } 1466 }
1447 if (window->renderer) { 1467 if (window->renderer) {
1466 if (window->prev) { 1486 if (window->prev) {
1467 window->prev->next = window->next; 1487 window->prev->next = window->next;
1468 } else { 1488 } else {
1469 display->windows = window->next; 1489 display->windows = window->next;
1470 } 1490 }
1471
1472 /* Clear the ID so we know it was destroyed */
1473 window->id = 0;
1474 1491
1475 SDL_free(window); 1492 SDL_free(window);
1476 } 1493 }
1477 1494
1478 void 1495 void
1517 } 1534 }
1518 1535
1519 int 1536 int
1520 SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) 1537 SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
1521 { 1538 {
1522 if (!window) { 1539 CHECK_WINDOW_MAGIC(window, -1);
1523 SDL_SetError("Invalid window");
1524 return -1;
1525 }
1526 1540
1527 /* Free any existing renderer */ 1541 /* Free any existing renderer */
1528 SDL_DestroyRenderer(window); 1542 SDL_DestroyRenderer(window);
1529 1543
1530 if (index < 0) { 1544 if (index < 0) {
1594 int 1608 int
1595 SDL_SelectRenderer(SDL_Window * window) 1609 SDL_SelectRenderer(SDL_Window * window)
1596 { 1610 {
1597 SDL_Renderer *renderer; 1611 SDL_Renderer *renderer;
1598 1612
1599 if (!window) { 1613 CHECK_WINDOW_MAGIC(window, -1);
1600 SDL_SetError("Invalid window"); 1614
1601 return -1;
1602 }
1603 renderer = window->renderer; 1615 renderer = window->renderer;
1604 if (!renderer) { 1616 if (!renderer) {
1605 SDL_SetError("Use SDL_CreateRenderer() to create a renderer"); 1617 SDL_SetError("Use SDL_CreateRenderer() to create a renderer");
1606 return -1; 1618 return -1;
1607 } 1619 }
1642 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); 1654 texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
1643 if (!texture) { 1655 if (!texture) {
1644 SDL_OutOfMemory(); 1656 SDL_OutOfMemory();
1645 return 0; 1657 return 0;
1646 } 1658 }
1659 texture->magic = &_this->texture_magic;
1647 texture->format = format; 1660 texture->format = format;
1648 texture->access = access; 1661 texture->access = access;
1649 texture->w = w; 1662 texture->w = w;
1650 texture->h = h; 1663 texture->h = h;
1651 texture->r = 255; 1664 texture->r = 255;
1970 1983
1971 int 1984 int
1972 SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access, 1985 SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access,
1973 int *w, int *h) 1986 int *w, int *h)
1974 { 1987 {
1975 if (!texture) { 1988 CHECK_TEXTURE_MAGIC(texture, -1);
1976 return -1; 1989
1977 }
1978 if (format) { 1990 if (format) {
1979 *format = texture->format; 1991 *format = texture->format;
1980 } 1992 }
1981 if (access) { 1993 if (access) {
1982 *access = texture->access; 1994 *access = texture->access;
1993 int 2005 int
1994 SDL_QueryTexturePixels(SDL_Texture * texture, void **pixels, int *pitch) 2006 SDL_QueryTexturePixels(SDL_Texture * texture, void **pixels, int *pitch)
1995 { 2007 {
1996 SDL_Renderer *renderer; 2008 SDL_Renderer *renderer;
1997 2009
1998 if (!texture) { 2010 CHECK_TEXTURE_MAGIC(texture, -1);
1999 return -1; 2011
2000 }
2001 renderer = texture->renderer; 2012 renderer = texture->renderer;
2002 if (!renderer->QueryTexturePixels) { 2013 if (!renderer->QueryTexturePixels) {
2003 SDL_Unsupported(); 2014 SDL_Unsupported();
2004 return -1; 2015 return -1;
2005 } 2016 }
2010 SDL_SetTexturePalette(SDL_Texture * texture, const SDL_Color * colors, 2021 SDL_SetTexturePalette(SDL_Texture * texture, const SDL_Color * colors,
2011 int firstcolor, int ncolors) 2022 int firstcolor, int ncolors)
2012 { 2023 {
2013 SDL_Renderer *renderer; 2024 SDL_Renderer *renderer;
2014 2025
2015 if (!texture) { 2026 CHECK_TEXTURE_MAGIC(texture, -1);
2016 return -1; 2027
2017 }
2018 renderer = texture->renderer; 2028 renderer = texture->renderer;
2019 if (!renderer->SetTexturePalette) { 2029 if (!renderer->SetTexturePalette) {
2020 SDL_Unsupported(); 2030 SDL_Unsupported();
2021 return -1; 2031 return -1;
2022 } 2032 }
2028 SDL_GetTexturePalette(SDL_Texture * texture, SDL_Color * colors, 2038 SDL_GetTexturePalette(SDL_Texture * texture, SDL_Color * colors,
2029 int firstcolor, int ncolors) 2039 int firstcolor, int ncolors)
2030 { 2040 {
2031 SDL_Renderer *renderer; 2041 SDL_Renderer *renderer;
2032 2042
2033 if (!texture) { 2043 CHECK_TEXTURE_MAGIC(texture, -1);
2034 return -1; 2044
2035 }
2036 renderer = texture->renderer; 2045 renderer = texture->renderer;
2037 if (!renderer->GetTexturePalette) { 2046 if (!renderer->GetTexturePalette) {
2038 SDL_Unsupported(); 2047 SDL_Unsupported();
2039 return -1; 2048 return -1;
2040 } 2049 }
2045 int 2054 int
2046 SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b) 2055 SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b)
2047 { 2056 {
2048 SDL_Renderer *renderer; 2057 SDL_Renderer *renderer;
2049 2058
2050 if (!texture) { 2059 CHECK_TEXTURE_MAGIC(texture, -1);
2051 return -1; 2060
2052 }
2053 renderer = texture->renderer; 2061 renderer = texture->renderer;
2054 if (!renderer->SetTextureColorMod) { 2062 if (!renderer->SetTextureColorMod) {
2055 SDL_Unsupported(); 2063 SDL_Unsupported();
2056 return -1; 2064 return -1;
2057 } 2065 }
2070 SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g, 2078 SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g,
2071 Uint8 * b) 2079 Uint8 * b)
2072 { 2080 {
2073 SDL_Renderer *renderer; 2081 SDL_Renderer *renderer;
2074 2082
2075 if (!texture) { 2083 CHECK_TEXTURE_MAGIC(texture, -1);
2076 return -1; 2084
2077 }
2078 renderer = texture->renderer; 2085 renderer = texture->renderer;
2079 if (r) { 2086 if (r) {
2080 *r = texture->r; 2087 *r = texture->r;
2081 } 2088 }
2082 if (g) { 2089 if (g) {
2091 int 2098 int
2092 SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha) 2099 SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha)
2093 { 2100 {
2094 SDL_Renderer *renderer; 2101 SDL_Renderer *renderer;
2095 2102
2096 if (!texture) { 2103 CHECK_TEXTURE_MAGIC(texture, -1);
2097 return -1; 2104
2098 }
2099 renderer = texture->renderer; 2105 renderer = texture->renderer;
2100 if (!renderer->SetTextureAlphaMod) { 2106 if (!renderer->SetTextureAlphaMod) {
2101 SDL_Unsupported(); 2107 SDL_Unsupported();
2102 return -1; 2108 return -1;
2103 } 2109 }
2111 } 2117 }
2112 2118
2113 int 2119 int
2114 SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha) 2120 SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha)
2115 { 2121 {
2116 if (!texture) { 2122 CHECK_TEXTURE_MAGIC(texture, -1);
2117 return -1; 2123
2118 }
2119 if (alpha) { 2124 if (alpha) {
2120 *alpha = texture->a; 2125 *alpha = texture->a;
2121 } 2126 }
2122 return 0; 2127 return 0;
2123 } 2128 }
2125 int 2130 int
2126 SDL_SetTextureBlendMode(SDL_Texture * texture, int blendMode) 2131 SDL_SetTextureBlendMode(SDL_Texture * texture, int blendMode)
2127 { 2132 {
2128 SDL_Renderer *renderer; 2133 SDL_Renderer *renderer;
2129 2134
2130 if (!texture) { 2135 CHECK_TEXTURE_MAGIC(texture, -1);
2131 return -1; 2136
2132 }
2133 renderer = texture->renderer; 2137 renderer = texture->renderer;
2134 if (!renderer->SetTextureBlendMode) { 2138 if (!renderer->SetTextureBlendMode) {
2135 SDL_Unsupported(); 2139 SDL_Unsupported();
2136 return -1; 2140 return -1;
2137 } 2141 }
2140 } 2144 }
2141 2145
2142 int 2146 int
2143 SDL_GetTextureBlendMode(SDL_Texture * texture, int *blendMode) 2147 SDL_GetTextureBlendMode(SDL_Texture * texture, int *blendMode)
2144 { 2148 {
2145 if (!texture) { 2149 CHECK_TEXTURE_MAGIC(texture, -1);
2146 return -1; 2150
2147 }
2148 if (blendMode) { 2151 if (blendMode) {
2149 *blendMode = texture->blendMode; 2152 *blendMode = texture->blendMode;
2150 } 2153 }
2151 return 0; 2154 return 0;
2152 } 2155 }
2154 int 2157 int
2155 SDL_SetTextureScaleMode(SDL_Texture * texture, int scaleMode) 2158 SDL_SetTextureScaleMode(SDL_Texture * texture, int scaleMode)
2156 { 2159 {
2157 SDL_Renderer *renderer; 2160 SDL_Renderer *renderer;
2158 2161
2159 if (!texture) { 2162 CHECK_TEXTURE_MAGIC(texture, -1);
2160 return -1; 2163
2161 }
2162 renderer = texture->renderer; 2164 renderer = texture->renderer;
2163 if (!renderer->SetTextureScaleMode) { 2165 if (!renderer->SetTextureScaleMode) {
2164 SDL_Unsupported(); 2166 SDL_Unsupported();
2165 return -1; 2167 return -1;
2166 } 2168 }
2169 } 2171 }
2170 2172
2171 int 2173 int
2172 SDL_GetTextureScaleMode(SDL_Texture * texture, int *scaleMode) 2174 SDL_GetTextureScaleMode(SDL_Texture * texture, int *scaleMode)
2173 { 2175 {
2174 if (!texture) { 2176 CHECK_TEXTURE_MAGIC(texture, -1);
2175 return -1; 2177
2176 }
2177 if (scaleMode) { 2178 if (scaleMode) {
2178 *scaleMode = texture->scaleMode; 2179 *scaleMode = texture->scaleMode;
2179 } 2180 }
2180 return 0; 2181 return 0;
2181 } 2182 }
2185 const void *pixels, int pitch) 2186 const void *pixels, int pitch)
2186 { 2187 {
2187 SDL_Renderer *renderer; 2188 SDL_Renderer *renderer;
2188 SDL_Rect full_rect; 2189 SDL_Rect full_rect;
2189 2190
2190 if (!texture) { 2191 CHECK_TEXTURE_MAGIC(texture, -1);
2191 return -1; 2192
2192 }
2193 renderer = texture->renderer; 2193 renderer = texture->renderer;
2194 if (!renderer->UpdateTexture) { 2194 if (!renderer->UpdateTexture) {
2195 SDL_Unsupported(); 2195 SDL_Unsupported();
2196 return -1; 2196 return -1;
2197 } 2197 }
2210 void **pixels, int *pitch) 2210 void **pixels, int *pitch)
2211 { 2211 {
2212 SDL_Renderer *renderer; 2212 SDL_Renderer *renderer;
2213 SDL_Rect full_rect; 2213 SDL_Rect full_rect;
2214 2214
2215 if (!texture) { 2215 CHECK_TEXTURE_MAGIC(texture, -1);
2216 return -1; 2216
2217 }
2218 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { 2217 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2219 SDL_SetError("SDL_LockTexture(): texture must be streaming"); 2218 SDL_SetError("SDL_LockTexture(): texture must be streaming");
2220 return -1; 2219 return -1;
2221 } 2220 }
2222 renderer = texture->renderer; 2221 renderer = texture->renderer;
2238 void 2237 void
2239 SDL_UnlockTexture(SDL_Texture * texture) 2238 SDL_UnlockTexture(SDL_Texture * texture)
2240 { 2239 {
2241 SDL_Renderer *renderer; 2240 SDL_Renderer *renderer;
2242 2241
2243 if (!texture) { 2242 CHECK_TEXTURE_MAGIC(texture, );
2244 return; 2243
2245 }
2246 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { 2244 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2247 return; 2245 return;
2248 } 2246 }
2249 renderer = texture->renderer; 2247 renderer = texture->renderer;
2250 if (!renderer->UnlockTexture) { 2248 if (!renderer->UnlockTexture) {
2257 SDL_DirtyTexture(SDL_Texture * texture, int numrects, 2255 SDL_DirtyTexture(SDL_Texture * texture, int numrects,
2258 const SDL_Rect * rects) 2256 const SDL_Rect * rects)
2259 { 2257 {
2260 SDL_Renderer *renderer; 2258 SDL_Renderer *renderer;
2261 2259
2262 if (!texture) { 2260 CHECK_TEXTURE_MAGIC(texture, );
2263 return; 2261
2264 }
2265 if (texture->access != SDL_TEXTUREACCESS_STREAMING) { 2262 if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
2266 return; 2263 return;
2267 } 2264 }
2268 renderer = texture->renderer; 2265 renderer = texture->renderer;
2269 if (!renderer->DirtyTexture) { 2266 if (!renderer->DirtyTexture) {
2542 SDL_Renderer *renderer; 2539 SDL_Renderer *renderer;
2543 SDL_Window *window; 2540 SDL_Window *window;
2544 SDL_Rect real_srcrect; 2541 SDL_Rect real_srcrect;
2545 SDL_Rect real_dstrect; 2542 SDL_Rect real_dstrect;
2546 2543
2544 CHECK_TEXTURE_MAGIC(texture, -1);
2545
2547 renderer = SDL_GetCurrentRenderer(SDL_TRUE); 2546 renderer = SDL_GetCurrentRenderer(SDL_TRUE);
2548 if (!renderer) { 2547 if (!renderer) {
2549 return -1;
2550 }
2551 if (!texture) {
2552 SDL_SetError("Texture not found");
2553 return -1; 2548 return -1;
2554 } 2549 }
2555 if (texture->renderer != renderer) { 2550 if (texture->renderer != renderer) {
2556 SDL_SetError("Texture was not created with this renderer"); 2551 SDL_SetError("Texture was not created with this renderer");
2557 return -1; 2552 return -1;
2702 void 2697 void
2703 SDL_DestroyTexture(SDL_Texture * texture) 2698 SDL_DestroyTexture(SDL_Texture * texture)
2704 { 2699 {
2705 SDL_Renderer *renderer; 2700 SDL_Renderer *renderer;
2706 2701
2707 if (!texture || !texture->renderer) { 2702 CHECK_TEXTURE_MAGIC(texture, );
2708 SDL_SetError("Invalid texture"); 2703 texture->magic = NULL;
2709 return;
2710 }
2711 2704
2712 renderer = texture->renderer; 2705 renderer = texture->renderer;
2713 if (texture->next) { 2706 if (texture->next) {
2714 texture->next->prev = texture->prev; 2707 texture->next->prev = texture->prev;
2715 } 2708 }
2716 if (texture->prev) { 2709 if (texture->prev) {
2717 texture->prev->next = texture->next; 2710 texture->prev->next = texture->next;
2718 } else { 2711 } else {
2719 renderer->textures = texture->next; 2712 renderer->textures = texture->next;
2720 } 2713 }
2721 texture->renderer = NULL;
2722 2714
2723 renderer->DestroyTexture(renderer, texture); 2715 renderer->DestroyTexture(renderer, texture);
2724 SDL_free(texture); 2716 SDL_free(texture);
2725 } 2717 }
2726 2718
2727 void 2719 void
2728 SDL_DestroyRenderer(SDL_Window * window) 2720 SDL_DestroyRenderer(SDL_Window * window)
2729 { 2721 {
2730 SDL_Renderer *renderer; 2722 SDL_Renderer *renderer;
2731 2723
2732 if (!window) { 2724 CHECK_WINDOW_MAGIC(window, );
2733 return; 2725
2734 }
2735 renderer = window->renderer; 2726 renderer = window->renderer;
2736 if (!renderer) { 2727 if (!renderer) {
2737 return; 2728 return;
2738 } 2729 }
2739 2730
3213 } 3204 }
3214 3205
3215 SDL_GLContext 3206 SDL_GLContext
3216 SDL_GL_CreateContext(SDL_Window * window) 3207 SDL_GL_CreateContext(SDL_Window * window)
3217 { 3208 {
3218 if (!window) { 3209 CHECK_WINDOW_MAGIC(window, NULL);
3219 return NULL; 3210
3220 }
3221 if (!(window->flags & SDL_WINDOW_OPENGL)) { 3211 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3222 SDL_SetError("The specified window isn't an OpenGL window"); 3212 SDL_SetError("The specified window isn't an OpenGL window");
3223 return NULL; 3213 return NULL;
3224 } 3214 }
3225 return _this->GL_CreateContext(_this, window); 3215 return _this->GL_CreateContext(_this, window);
3226 } 3216 }
3227 3217
3228 int 3218 int
3229 SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context) 3219 SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context)
3230 { 3220 {
3231 if (window && !(window->flags & SDL_WINDOW_OPENGL)) { 3221 CHECK_WINDOW_MAGIC(window, -1);
3222
3223 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3232 SDL_SetError("The specified window isn't an OpenGL window"); 3224 SDL_SetError("The specified window isn't an OpenGL window");
3233 return -1; 3225 return -1;
3234 } 3226 }
3235 if (!context) { 3227 if (!context) {
3236 window = NULL; 3228 window = NULL;
3269 } 3261 }
3270 3262
3271 void 3263 void
3272 SDL_GL_SwapWindow(SDL_Window * window) 3264 SDL_GL_SwapWindow(SDL_Window * window)
3273 { 3265 {
3274 if (!window) { 3266 CHECK_WINDOW_MAGIC(window, );
3275 return; 3267
3276 }
3277 if (!(window->flags & SDL_WINDOW_OPENGL)) { 3268 if (!(window->flags & SDL_WINDOW_OPENGL)) {
3278 SDL_SetError("The specified window isn't an OpenGL window"); 3269 SDL_SetError("The specified window isn't an OpenGL window");
3279 return; 3270 return;
3280 } 3271 }
3281 _this->GL_SwapWindow(_this, window); 3272 _this->GL_SwapWindow(_this, window);
3391 #endif 3382 #endif
3392 3383
3393 SDL_bool 3384 SDL_bool
3394 SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info) 3385 SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info)
3395 { 3386 {
3396 if (!window || !_this->GetWindowWMInfo) { 3387 CHECK_WINDOW_MAGIC(window, SDL_FALSE);
3388
3389 if (!_this->GetWindowWMInfo) {
3397 return SDL_FALSE; 3390 return SDL_FALSE;
3398 } 3391 }
3399 return (_this->GetWindowWMInfo(_this, window, info)); 3392 return (_this->GetWindowWMInfo(_this, window, info));
3400 } 3393 }
3401 3394