src/video/SDL_video.c
changeset 3685 64ce267332c6
parent 3683 4c5ab6841fdc
child 3686 d87db9cf6a31
     1.1 --- a/src/video/SDL_video.c	Thu Jan 21 05:49:41 2010 +0000
     1.2 +++ b/src/video/SDL_video.c	Thu Jan 21 06:21:52 2010 +0000
     1.3 @@ -443,7 +443,7 @@
     1.4  SDL_GetNumDisplayModes()
     1.5  {
     1.6      if (_this) {
     1.7 -        return SDL_GetNumDisplayModesForDisplay(&SDL_CurrentDisplay);
     1.8 +        return SDL_GetNumDisplayModesForDisplay(SDL_CurrentDisplay);
     1.9      }
    1.10      return 0;
    1.11  }
    1.12 @@ -465,7 +465,7 @@
    1.13  int
    1.14  SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
    1.15  {
    1.16 -    return SDL_GetDisplayModeForDisplay(&SDL_CurrentDisplay, index, mode);
    1.17 +    return SDL_GetDisplayModeForDisplay(SDL_CurrentDisplay, index, mode);
    1.18  }
    1.19  
    1.20  int
    1.21 @@ -484,7 +484,7 @@
    1.22          SDL_UninitializedVideo();
    1.23          return -1;
    1.24      }
    1.25 -    return SDL_GetDesktopDisplayModeForDisplay(&SDL_CurrentDisplay, mode);
    1.26 +    return SDL_GetDesktopDisplayModeForDisplay(SDL_CurrentDisplay, mode);
    1.27  }
    1.28  
    1.29  int
    1.30 @@ -503,7 +503,7 @@
    1.31          SDL_UninitializedVideo();
    1.32          return -1;
    1.33      }
    1.34 -    return SDL_GetCurrentDisplayModeForDisplay(&SDL_CurrentDisplay, mode);
    1.35 +    return SDL_GetCurrentDisplayModeForDisplay(SDL_CurrentDisplay, mode);
    1.36  }
    1.37  
    1.38  SDL_DisplayMode *
    1.39 @@ -621,7 +621,7 @@
    1.40          SDL_UninitializedVideo();
    1.41          return NULL;
    1.42      }
    1.43 -    return SDL_GetClosestDisplayModeForDisplay(&SDL_CurrentDisplay, mode, closest);
    1.44 +    return SDL_GetClosestDisplayModeForDisplay(SDL_CurrentDisplay, mode, closest);
    1.45  }
    1.46  
    1.47  int
    1.48 @@ -702,14 +702,12 @@
    1.49          SDL_UninitializedVideo();
    1.50          return -1;
    1.51      }
    1.52 -    return SDL_SetDisplayModeForDisplay(&SDL_CurrentDisplay, mode);
    1.53 +    return SDL_SetDisplayModeForDisplay(SDL_CurrentDisplay, mode);
    1.54  }
    1.55  
    1.56  int
    1.57 -SDL_SetWindowDisplayMode(SDL_WindowID windowID, const SDL_DisplayMode * mode)
    1.58 +SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
    1.59  {
    1.60 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
    1.61 -
    1.62      if (!window) {
    1.63          return -1;
    1.64      }
    1.65 @@ -723,9 +721,8 @@
    1.66  }
    1.67  
    1.68  int
    1.69 -SDL_GetWindowDisplayMode(SDL_WindowID windowID, SDL_DisplayMode * mode)
    1.70 +SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
    1.71  {
    1.72 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
    1.73      SDL_DisplayMode fullscreen_mode;
    1.74  
    1.75      if (!window) {
    1.76 @@ -740,7 +737,7 @@
    1.77          fullscreen_mode.h = window->h;
    1.78      }
    1.79  
    1.80 -    if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayFromWindow(window),
    1.81 +    if (!SDL_GetClosestDisplayModeForDisplay(window->display,
    1.82                                               &fullscreen_mode,
    1.83                                               &fullscreen_mode)) {
    1.84          SDL_SetError("Couldn't find display mode match");
    1.85 @@ -756,7 +753,7 @@
    1.86  static void
    1.87  SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
    1.88  {
    1.89 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
    1.90 +    SDL_VideoDisplay *display = window->display;
    1.91      int i;
    1.92  
    1.93      /* See if we're already processing a window */
    1.94 @@ -772,13 +769,13 @@
    1.95          if (attempt) {
    1.96              /* We just gained some state, try to gain all states */
    1.97              if (window->flags & SDL_WINDOW_MINIMIZED) {
    1.98 -                SDL_RestoreWindow(window->id);
    1.99 +                SDL_RestoreWindow(window);
   1.100              } else {
   1.101 -                SDL_RaiseWindow(window->id);
   1.102 +                SDL_RaiseWindow(window);
   1.103              }
   1.104          } else {
   1.105              /* We just lost some state, try to release all states */
   1.106 -            SDL_MinimizeWindow(window->id);
   1.107 +            SDL_MinimizeWindow(window);
   1.108          }
   1.109      }
   1.110  
   1.111 @@ -787,7 +784,7 @@
   1.112          for (i = 0; i < display->num_windows; ++i) {
   1.113              SDL_Window *other = &display->windows[i];
   1.114              if (other != window && FULLSCREEN_VISIBLE(other)) {
   1.115 -                SDL_MinimizeWindow(other->id);
   1.116 +                SDL_MinimizeWindow(other);
   1.117              }
   1.118          }
   1.119      }
   1.120 @@ -799,7 +796,7 @@
   1.121          window = &display->windows[i];
   1.122          if (FULLSCREEN_VISIBLE(window)) {
   1.123              SDL_DisplayMode fullscreen_mode;
   1.124 -            if (SDL_GetWindowDisplayMode(window->id, &fullscreen_mode) == 0) {
   1.125 +            if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
   1.126                  SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
   1.127                  display->fullscreen_window = window;
   1.128                  return;
   1.129 @@ -840,7 +837,7 @@
   1.130          SDL_UninitializedVideo();
   1.131          return -1;
   1.132      }
   1.133 -    return SDL_SetPaletteForDisplay(&SDL_CurrentDisplay, colors, firstcolor, ncolors);
   1.134 +    return SDL_SetPaletteForDisplay(SDL_CurrentDisplay, colors, firstcolor, ncolors);
   1.135  }
   1.136  
   1.137  int
   1.138 @@ -869,10 +866,10 @@
   1.139          SDL_UninitializedVideo();
   1.140          return -1;
   1.141      }
   1.142 -    return SDL_GetPaletteForDisplay(&SDL_CurrentDisplay, colors, firstcolor, ncolors);
   1.143 +    return SDL_GetPaletteForDisplay(SDL_CurrentDisplay, colors, firstcolor, ncolors);
   1.144  }
   1.145  
   1.146 -SDL_WindowID
   1.147 +SDL_Window *
   1.148  SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
   1.149  {
   1.150      const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN |
   1.151 @@ -881,112 +878,79 @@
   1.152                                    SDL_WINDOW_RESIZABLE |
   1.153                                    SDL_WINDOW_INPUT_GRABBED);
   1.154      SDL_VideoDisplay *display;
   1.155 -    SDL_Window window;
   1.156 -    int num_windows;
   1.157 -    SDL_Window *windows;
   1.158 +    SDL_Window *window;
   1.159  
   1.160      if (!_this) {
   1.161          /* Initialize the video system if needed */
   1.162          if (SDL_VideoInit(NULL, 0) < 0) {
   1.163 -            return 0;
   1.164 +            return NULL;
   1.165          }
   1.166      }
   1.167      if (flags & SDL_WINDOW_OPENGL) {
   1.168          if (!_this->GL_CreateContext) {
   1.169              SDL_SetError("No OpenGL support in video driver");
   1.170 -            return 0;
   1.171 +            return NULL;
   1.172          }
   1.173          SDL_GL_LoadLibrary(NULL);
   1.174      }
   1.175 -    SDL_zero(window);
   1.176 -    window.id = _this->next_object_id++;
   1.177 -    window.x = x;
   1.178 -    window.y = y;
   1.179 -    window.w = w;
   1.180 -    window.h = h;
   1.181 -    window.flags = (flags & allowed_flags);
   1.182 -    window.display = _this->current_display;
   1.183 -
   1.184 -    if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
   1.185 -        if (flags & SDL_WINDOW_OPENGL) {
   1.186 -            SDL_GL_UnloadLibrary();
   1.187 -        }
   1.188 -        return 0;
   1.189 -    }
   1.190 -    display = &SDL_CurrentDisplay;
   1.191 -    num_windows = display->num_windows;
   1.192 -    windows =
   1.193 -        SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
   1.194 -    if (!windows) {
   1.195 -        if (_this->DestroyWindow) {
   1.196 -            _this->DestroyWindow(_this, &window);
   1.197 -        }
   1.198 -        if (flags & SDL_WINDOW_OPENGL) {
   1.199 -            SDL_GL_UnloadLibrary();
   1.200 -        }
   1.201 -        return 0;
   1.202 -    }
   1.203 -    windows[num_windows] = window;
   1.204 -    display->windows = windows;
   1.205 -    display->num_windows++;
   1.206 +    display = SDL_CurrentDisplay;
   1.207 +    window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
   1.208 +    window->id = _this->next_object_id++;
   1.209 +    window->x = x;
   1.210 +    window->y = y;
   1.211 +    window->w = w;
   1.212 +    window->h = h;
   1.213 +    window->flags = (flags & allowed_flags);
   1.214 +    window->display = display;
   1.215 +    window->next = display->windows;
   1.216 +    display->windows = window;
   1.217 +
   1.218 +    if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
   1.219 +        SDL_DestroyWindow(window);
   1.220 +        return NULL;
   1.221 +    }
   1.222  
   1.223      if (title) {
   1.224 -        SDL_SetWindowTitle(window.id, title);
   1.225 +        SDL_SetWindowTitle(window, title);
   1.226      }
   1.227      if (flags & SDL_WINDOW_MAXIMIZED) {
   1.228 -        SDL_MaximizeWindow(window.id);
   1.229 +        SDL_MaximizeWindow(window);
   1.230      }
   1.231      if (flags & SDL_WINDOW_MINIMIZED) {
   1.232 -        SDL_MinimizeWindow(window.id);
   1.233 +        SDL_MinimizeWindow(window);
   1.234      }
   1.235      if (flags & SDL_WINDOW_SHOWN) {
   1.236 -        SDL_ShowWindow(window.id);
   1.237 -    }
   1.238 -    SDL_UpdateWindowGrab(&window);
   1.239 -
   1.240 -    return window.id;
   1.241 +        SDL_ShowWindow(window);
   1.242 +    }
   1.243 +    SDL_UpdateWindowGrab(window);
   1.244 +
   1.245 +    return window;
   1.246  }
   1.247  
   1.248 -SDL_WindowID
   1.249 +SDL_Window *
   1.250  SDL_CreateWindowFrom(const void *data)
   1.251  {
   1.252      SDL_VideoDisplay *display;
   1.253 -    SDL_Window window;
   1.254 -    int num_windows;
   1.255 -    SDL_Window *windows;
   1.256 +    SDL_Window *window;
   1.257  
   1.258      if (!_this) {
   1.259          SDL_UninitializedVideo();
   1.260 -        return (0);
   1.261 -    }
   1.262 -    SDL_zero(window);
   1.263 -    window.id = _this->next_object_id++;
   1.264 -    window.display = _this->current_display;
   1.265 -    window.flags = SDL_WINDOW_FOREIGN;
   1.266 +        return NULL;
   1.267 +    }
   1.268 +    display = SDL_CurrentDisplay;
   1.269 +    window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
   1.270 +    window->id = _this->next_object_id++;
   1.271 +    window->flags = SDL_WINDOW_FOREIGN;
   1.272 +    window->display = display;
   1.273 +    window->next = display->windows;
   1.274 +    display->windows = window;
   1.275  
   1.276      if (!_this->CreateWindowFrom ||
   1.277 -        _this->CreateWindowFrom(_this, &window, data) < 0) {
   1.278 -        return 0;
   1.279 -    }
   1.280 -    /* FIXME: Find out what display this window is actually on... */
   1.281 -    display = &SDL_CurrentDisplay;
   1.282 -    num_windows = display->num_windows;
   1.283 -    windows =
   1.284 -        SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows));
   1.285 -    if (!windows) {
   1.286 -        if (_this->DestroyWindow) {
   1.287 -            _this->DestroyWindow(_this, &window);
   1.288 -        }
   1.289 -        if (window.title) {
   1.290 -            SDL_free(window.title);
   1.291 -        }
   1.292 -        return 0;
   1.293 -    }
   1.294 -    windows[num_windows] = window;
   1.295 -    display->windows = windows;
   1.296 -    display->num_windows++;
   1.297 -
   1.298 -    return window.id;
   1.299 +        _this->CreateWindowFrom(_this, window, data) < 0) {
   1.300 +        SDL_DestroyWindow(window);
   1.301 +        return NULL;
   1.302 +    }
   1.303 +    return window;
   1.304  }
   1.305  
   1.306  int
   1.307 @@ -1036,70 +1000,23 @@
   1.308      }
   1.309  
   1.310      if (title) {
   1.311 -        SDL_SetWindowTitle(window->id, title);
   1.312 +        SDL_SetWindowTitle(window, title);
   1.313          SDL_free(title);
   1.314      }
   1.315      if (flags & SDL_WINDOW_MAXIMIZED) {
   1.316 -        SDL_MaximizeWindow(window->id);
   1.317 +        SDL_MaximizeWindow(window);
   1.318      }
   1.319      if (flags & SDL_WINDOW_MINIMIZED) {
   1.320 -        SDL_MinimizeWindow(window->id);
   1.321 +        SDL_MinimizeWindow(window);
   1.322      }
   1.323      if (flags & SDL_WINDOW_SHOWN) {
   1.324 -        SDL_ShowWindow(window->id);
   1.325 +        SDL_ShowWindow(window);
   1.326      }
   1.327      SDL_UpdateWindowGrab(window);
   1.328  
   1.329      return 0;
   1.330  }
   1.331  
   1.332 -SDL_Window *
   1.333 -SDL_GetWindowFromID(SDL_WindowID windowID)
   1.334 -{
   1.335 -    int i, j;
   1.336 -
   1.337 -    if (!_this) {
   1.338 -        SDL_UninitializedVideo();
   1.339 -        return NULL;
   1.340 -    }
   1.341 -    if (windowID) {
   1.342 -        for (i = 0; i < _this->num_displays; ++i) {
   1.343 -            SDL_VideoDisplay *display = &_this->displays[i];
   1.344 -            for (j = 0; j < display->num_windows; ++j) {
   1.345 -                SDL_Window *window = &display->windows[j];
   1.346 -                if (window->id == windowID) {
   1.347 -                    return window;
   1.348 -                }
   1.349 -            }
   1.350 -        }
   1.351 -    } else {
   1.352 -        /* Just return the first active window */
   1.353 -        for (i = 0; i < _this->num_displays; ++i) {
   1.354 -            SDL_VideoDisplay *display = &_this->displays[i];
   1.355 -            for (j = 0; j < display->num_windows; ++j) {
   1.356 -                SDL_Window *window = &display->windows[j];
   1.357 -                return window;
   1.358 -            }
   1.359 -        }
   1.360 -    }
   1.361 -    /* Couldn't find the window with the requested ID */
   1.362 -    SDL_SetError("Invalid window ID");
   1.363 -    return NULL;
   1.364 -}
   1.365 -
   1.366 -SDL_VideoDisplay *
   1.367 -SDL_GetDisplayFromWindow(SDL_Window * window)
   1.368 -{
   1.369 -    if (!_this) {
   1.370 -        SDL_UninitializedVideo();
   1.371 -        return NULL;
   1.372 -    }
   1.373 -    if (!window) {
   1.374 -        return NULL;
   1.375 -    }
   1.376 -    return &_this->displays[window->display];
   1.377 -}
   1.378 -
   1.379  static __inline__ SDL_Renderer *
   1.380  SDL_GetCurrentRenderer(SDL_bool create)
   1.381  {
   1.382 @@ -1120,21 +1037,47 @@
   1.383  }
   1.384  
   1.385  Uint32
   1.386 -SDL_GetWindowFlags(SDL_WindowID windowID)
   1.387 +SDL_GetWindowID(SDL_Window * window)
   1.388  {
   1.389 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.390 -
   1.391      if (!window) {
   1.392          return 0;
   1.393      }
   1.394 +    return window->id;
   1.395 +}
   1.396 +
   1.397 +SDL_Window *
   1.398 +SDL_GetWindowFromID(Uint32 id)
   1.399 +{
   1.400 +    SDL_Window *window;
   1.401 +    int i;
   1.402 +
   1.403 +    if (!_this) {
   1.404 +        return NULL;
   1.405 +    }
   1.406 +    /* FIXME: Should we keep a separate hash table for these? */
   1.407 +    for (i = _this->num_displays; i--;) {
   1.408 +        SDL_VideoDisplay *display = &_this->displays[i];
   1.409 +        for (window = display->windows; window; window = window->next) {
   1.410 +            if (window->id == id) {
   1.411 +                return window;
   1.412 +            }
   1.413 +        }
   1.414 +    }
   1.415 +    return NULL;
   1.416 +}
   1.417 +
   1.418 +Uint32
   1.419 +SDL_GetWindowFlags(SDL_Window * window)
   1.420 +{
   1.421 +    if (!window) {
   1.422 +        return 0;
   1.423 +    }
   1.424      return window->flags;
   1.425  }
   1.426  
   1.427  void
   1.428 -SDL_SetWindowTitle(SDL_WindowID windowID, const char *title)
   1.429 +SDL_SetWindowTitle(SDL_Window * window, const char *title)
   1.430  {
   1.431 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.432 -
   1.433      if (!window || title == window->title) {
   1.434          return;
   1.435      }
   1.436 @@ -1153,10 +1096,8 @@
   1.437  }
   1.438  
   1.439  const char *
   1.440 -SDL_GetWindowTitle(SDL_WindowID windowID)
   1.441 +SDL_GetWindowTitle(SDL_Window * window)
   1.442  {
   1.443 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.444 -
   1.445      if (!window) {
   1.446          return NULL;
   1.447      }
   1.448 @@ -1164,10 +1105,8 @@
   1.449  }
   1.450  
   1.451  void
   1.452 -SDL_SetWindowIcon(SDL_WindowID windowID, SDL_Surface * icon)
   1.453 +SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
   1.454  {
   1.455 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.456 -
   1.457      if (!window) {
   1.458          return;
   1.459      }
   1.460 @@ -1177,10 +1116,8 @@
   1.461  }
   1.462  
   1.463  void
   1.464 -SDL_SetWindowData(SDL_WindowID windowID, void *userdata)
   1.465 +SDL_SetWindowData(SDL_Window * window, void *userdata)
   1.466  {
   1.467 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.468 -
   1.469      if (!window) {
   1.470          return;
   1.471      }
   1.472 @@ -1188,10 +1125,8 @@
   1.473  }
   1.474  
   1.475  void *
   1.476 -SDL_GetWindowData(SDL_WindowID windowID)
   1.477 +SDL_GetWindowData(SDL_Window * window)
   1.478  {
   1.479 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.480 -
   1.481      if (!window) {
   1.482          return NULL;
   1.483      }
   1.484 @@ -1199,11 +1134,8 @@
   1.485  }
   1.486  
   1.487  void
   1.488 -SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y)
   1.489 +SDL_SetWindowPosition(SDL_Window * window, int x, int y)
   1.490  {
   1.491 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.492 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.493 -
   1.494      if (!window) {
   1.495          return;
   1.496      }
   1.497 @@ -1216,14 +1148,12 @@
   1.498      if (_this->SetWindowPosition) {
   1.499          _this->SetWindowPosition(_this, window);
   1.500      }
   1.501 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, x, y);
   1.502 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
   1.503  }
   1.504  
   1.505  void
   1.506 -SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y)
   1.507 +SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
   1.508  {
   1.509 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.510 -
   1.511      if (!window) {
   1.512          return;
   1.513      }
   1.514 @@ -1236,10 +1166,8 @@
   1.515  }
   1.516  
   1.517  void
   1.518 -SDL_SetWindowSize(SDL_WindowID windowID, int w, int h)
   1.519 +SDL_SetWindowSize(SDL_Window * window, int w, int h)
   1.520  {
   1.521 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.522 -
   1.523      if (!window) {
   1.524          return;
   1.525      }
   1.526 @@ -1253,10 +1181,8 @@
   1.527  }
   1.528  
   1.529  void
   1.530 -SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h)
   1.531 +SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
   1.532  {
   1.533 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.534 -
   1.535      if (window) {
   1.536          if (w) {
   1.537              *w = window->w;
   1.538 @@ -1275,10 +1201,8 @@
   1.539  }
   1.540  
   1.541  void
   1.542 -SDL_ShowWindow(SDL_WindowID windowID)
   1.543 +SDL_ShowWindow(SDL_Window * window)
   1.544  {
   1.545 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.546 -
   1.547      if (!window || (window->flags & SDL_WINDOW_SHOWN)) {
   1.548          return;
   1.549      }
   1.550 @@ -1286,14 +1210,12 @@
   1.551      if (_this->ShowWindow) {
   1.552          _this->ShowWindow(_this, window);
   1.553      }
   1.554 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
   1.555 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
   1.556  }
   1.557  
   1.558  void
   1.559 -SDL_HideWindow(SDL_WindowID windowID)
   1.560 +SDL_HideWindow(SDL_Window * window)
   1.561  {
   1.562 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.563 -
   1.564      if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
   1.565          return;
   1.566      }
   1.567 @@ -1301,14 +1223,12 @@
   1.568      if (_this->HideWindow) {
   1.569          _this->HideWindow(_this, window);
   1.570      }
   1.571 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   1.572 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
   1.573  }
   1.574  
   1.575  void
   1.576 -SDL_RaiseWindow(SDL_WindowID windowID)
   1.577 +SDL_RaiseWindow(SDL_Window * window)
   1.578  {
   1.579 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.580 -
   1.581      if (!window || !(window->flags & SDL_WINDOW_SHOWN)) {
   1.582          return;
   1.583      }
   1.584 @@ -1316,15 +1236,13 @@
   1.585          _this->RaiseWindow(_this, window);
   1.586      } else {
   1.587          /* FIXME: What we really want is a way to request focus */
   1.588 -        SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
   1.589 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
   1.590      }
   1.591  }
   1.592  
   1.593  void
   1.594 -SDL_MaximizeWindow(SDL_WindowID windowID)
   1.595 +SDL_MaximizeWindow(SDL_Window * window)
   1.596  {
   1.597 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.598 -
   1.599      if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) {
   1.600          return;
   1.601      }
   1.602 @@ -1332,14 +1250,12 @@
   1.603      if (_this->MaximizeWindow) {
   1.604          _this->MaximizeWindow(_this, window);
   1.605      }
   1.606 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   1.607 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   1.608  }
   1.609  
   1.610  void
   1.611 -SDL_MinimizeWindow(SDL_WindowID windowID)
   1.612 +SDL_MinimizeWindow(SDL_Window * window)
   1.613  {
   1.614 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.615 -
   1.616      if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) {
   1.617          return;
   1.618      }
   1.619 @@ -1347,14 +1263,12 @@
   1.620      if (_this->MinimizeWindow) {
   1.621          _this->MinimizeWindow(_this, window);
   1.622      }
   1.623 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   1.624 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
   1.625  }
   1.626  
   1.627  void
   1.628 -SDL_RestoreWindow(SDL_WindowID windowID)
   1.629 +SDL_RestoreWindow(SDL_Window * window)
   1.630  {
   1.631 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.632 -
   1.633      if (!window
   1.634          || !(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
   1.635          return;
   1.636 @@ -1363,14 +1277,12 @@
   1.637      if (_this->RestoreWindow) {
   1.638          _this->RestoreWindow(_this, window);
   1.639      }
   1.640 -    SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
   1.641 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
   1.642  }
   1.643  
   1.644  int
   1.645 -SDL_SetWindowFullscreen(SDL_WindowID windowID, int fullscreen)
   1.646 +SDL_SetWindowFullscreen(SDL_Window * window, int fullscreen)
   1.647  {
   1.648 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.649 -
   1.650      if (!window) {
   1.651          return -1;
   1.652      }
   1.653 @@ -1393,10 +1305,8 @@
   1.654  }
   1.655  
   1.656  void
   1.657 -SDL_SetWindowGrab(SDL_WindowID windowID, int mode)
   1.658 +SDL_SetWindowGrab(SDL_Window * window, int mode)
   1.659  {
   1.660 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.661 -
   1.662      if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
   1.663          return;
   1.664      }
   1.665 @@ -1417,10 +1327,8 @@
   1.666  }
   1.667  
   1.668  int
   1.669 -SDL_GetWindowGrab(SDL_WindowID windowID)
   1.670 +SDL_GetWindowGrab(SDL_Window * window)
   1.671  {
   1.672 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.673 -
   1.674      if (!window) {
   1.675          return 0;
   1.676      }
   1.677 @@ -1430,7 +1338,7 @@
   1.678  void
   1.679  SDL_OnWindowShown(SDL_Window * window)
   1.680  {
   1.681 -    SDL_RaiseWindow(window->id);
   1.682 +    SDL_RaiseWindow(window);
   1.683      SDL_UpdateFullscreenMode(window, SDL_TRUE);
   1.684  }
   1.685  
   1.686 @@ -1459,14 +1367,14 @@
   1.687  void
   1.688  SDL_OnWindowRestored(SDL_Window * window)
   1.689  {
   1.690 -    SDL_RaiseWindow(window->id);
   1.691 +    SDL_RaiseWindow(window);
   1.692      SDL_UpdateFullscreenMode(window, SDL_TRUE);
   1.693  }
   1.694  
   1.695  void
   1.696  SDL_OnWindowFocusGained(SDL_Window * window)
   1.697  {
   1.698 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.699 +    SDL_VideoDisplay *display = window->display;
   1.700  
   1.701      if (display->gamma && _this->SetDisplayGammaRamp) {
   1.702          _this->SetDisplayGammaRamp(_this, display, display->gamma);
   1.703 @@ -1480,12 +1388,12 @@
   1.704  void
   1.705  SDL_OnWindowFocusLost(SDL_Window * window)
   1.706  {
   1.707 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   1.708 +    SDL_VideoDisplay *display = window->display;
   1.709  
   1.710      /* If we're fullscreen on a single-head system and lose focus, minimize */
   1.711      if ((window->flags & SDL_WINDOW_FULLSCREEN) &&
   1.712          _this->num_displays == 1) {
   1.713 -        SDL_MinimizeWindow(window->id);
   1.714 +        SDL_MinimizeWindow(window);
   1.715      }
   1.716  
   1.717      if (display->gamma && _this->SetDisplayGammaRamp) {
   1.718 @@ -1497,69 +1405,63 @@
   1.719      }
   1.720  }
   1.721  
   1.722 -SDL_WindowID
   1.723 +SDL_Window *
   1.724  SDL_GetFocusWindow(void)
   1.725  {
   1.726      SDL_VideoDisplay *display;
   1.727 -    int i;
   1.728 +    SDL_Window *window;
   1.729  
   1.730      if (!_this) {
   1.731 -        return 0;
   1.732 -    }
   1.733 -    display = &SDL_CurrentDisplay;
   1.734 -    for (i = 0; i < display->num_windows; ++i) {
   1.735 -        SDL_Window *window = &display->windows[i];
   1.736 -
   1.737 +        return NULL;
   1.738 +    }
   1.739 +    display = SDL_CurrentDisplay;
   1.740 +    for (window = display->windows; window; window = window->next) {
   1.741          if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
   1.742 -            return window->id;
   1.743 +            return window;
   1.744          }
   1.745      }
   1.746 -    return 0;
   1.747 +    return NULL;
   1.748  }
   1.749  
   1.750  void
   1.751 -SDL_DestroyWindow(SDL_WindowID windowID)
   1.752 +SDL_DestroyWindow(SDL_Window * window)
   1.753  {
   1.754 -    int i, j;
   1.755 -
   1.756 -    if (!_this) {
   1.757 +    SDL_VideoDisplay *display;
   1.758 +
   1.759 +    if (!_this || !window || !window->id) {
   1.760 +        SDL_SetError("Invalid window");
   1.761          return;
   1.762      }
   1.763  
   1.764 -    for (i = 0; i < _this->num_displays; ++i) {
   1.765 -        SDL_VideoDisplay *display = &_this->displays[i];
   1.766 -        for (j = 0; j < display->num_windows; ++j) {
   1.767 -            SDL_Window *window = &display->windows[j];
   1.768 -            if (window->id != windowID) {
   1.769 -                continue;
   1.770 -            }
   1.771 -            if (window->title) {
   1.772 -                SDL_free(window->title);
   1.773 -                window->title = NULL;
   1.774 -            }
   1.775 -            if (window->renderer) {
   1.776 -                SDL_DestroyRenderer(window->id);
   1.777 -                window->renderer = NULL;
   1.778 -            }
   1.779 -
   1.780 -            /* Restore video mode, etc. */
   1.781 -            SDL_UpdateFullscreenMode(window, SDL_FALSE);
   1.782 -
   1.783 -            if (_this->DestroyWindow) {
   1.784 -                _this->DestroyWindow(_this, window);
   1.785 -            }
   1.786 -            if (window->flags & SDL_WINDOW_OPENGL) {
   1.787 -                SDL_GL_UnloadLibrary();
   1.788 -            }
   1.789 -            if (j != display->num_windows - 1) {
   1.790 -                SDL_memcpy(&display->windows[i],
   1.791 -                           &display->windows[i + 1],
   1.792 -                           (display->num_windows - i - 1) * sizeof(*window));
   1.793 -            }
   1.794 -            --display->num_windows;
   1.795 -            return;
   1.796 -        }
   1.797 -    }
   1.798 +    if (window->title) {
   1.799 +        SDL_free(window->title);
   1.800 +    }
   1.801 +    if (window->renderer) {
   1.802 +        SDL_DestroyRenderer(window);
   1.803 +    }
   1.804 +
   1.805 +    /* Restore video mode, etc. */
   1.806 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   1.807 +
   1.808 +    if (_this->DestroyWindow) {
   1.809 +        _this->DestroyWindow(_this, window);
   1.810 +    }
   1.811 +    if (window->flags & SDL_WINDOW_OPENGL) {
   1.812 +        SDL_GL_UnloadLibrary();
   1.813 +    }
   1.814 +
   1.815 +    /* Unlink the window from the list */
   1.816 +    display = window->display;
   1.817 +    if (window->prev) {
   1.818 +        window->prev->next = window->next;
   1.819 +    } else {
   1.820 +        display->windows = window->next;
   1.821 +    }
   1.822 +
   1.823 +    /* Clear the ID so we know it was destroyed */
   1.824 +    window->id = 0;
   1.825 +
   1.826 +    SDL_free(window);
   1.827  }
   1.828  
   1.829  void
   1.830 @@ -1582,7 +1484,7 @@
   1.831  SDL_GetNumRenderDrivers(void)
   1.832  {
   1.833      if (_this) {
   1.834 -        return SDL_CurrentDisplay.num_render_drivers;
   1.835 +        return SDL_CurrentDisplay->num_render_drivers;
   1.836      }
   1.837      return 0;
   1.838  }
   1.839 @@ -1599,22 +1501,20 @@
   1.840                       SDL_GetNumRenderDrivers() - 1);
   1.841          return -1;
   1.842      }
   1.843 -    *info = SDL_CurrentDisplay.render_drivers[index].info;
   1.844 +    *info = SDL_CurrentDisplay->render_drivers[index].info;
   1.845      return 0;
   1.846  }
   1.847  
   1.848  int
   1.849 -SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags)
   1.850 +SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
   1.851  {
   1.852 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.853 -
   1.854      if (!window) {
   1.855 -        SDL_SetError("Invalid window ID");
   1.856 +        SDL_SetError("Invalid window");
   1.857          return -1;
   1.858      }
   1.859  
   1.860      /* Free any existing renderer */
   1.861 -    SDL_DestroyRenderer(windowID);
   1.862 +    SDL_DestroyRenderer(window);
   1.863  
   1.864      if (index < 0) {
   1.865          char *override = SDL_getenv("SDL_VIDEO_RENDERER");
   1.866 @@ -1633,7 +1533,7 @@
   1.867          if (override) {
   1.868              for (index = 0; index < n; ++index) {
   1.869                  SDL_RenderDriver *driver =
   1.870 -                    &SDL_CurrentDisplay.render_drivers[index];
   1.871 +                    &SDL_CurrentDisplay->render_drivers[index];
   1.872  
   1.873                  if (SDL_strcasecmp(override, driver->info.name) == 0) {
   1.874                      /* Create a new renderer instance */
   1.875 @@ -1644,7 +1544,7 @@
   1.876          } else {
   1.877              for (index = 0; index < n; ++index) {
   1.878                  SDL_RenderDriver *driver =
   1.879 -                    &SDL_CurrentDisplay.render_drivers[index];
   1.880 +                    &SDL_CurrentDisplay->render_drivers[index];
   1.881  
   1.882                  if ((driver->info.flags & flags) == flags) {
   1.883                      /* Create a new renderer instance */
   1.884 @@ -1667,7 +1567,7 @@
   1.885              return -1;
   1.886          }
   1.887          /* Create a new renderer instance */
   1.888 -        window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
   1.889 +        window->renderer = SDL_CurrentDisplay->render_drivers[index].CreateRenderer(window, flags);
   1.890      }
   1.891  
   1.892      if (window->renderer == NULL) {
   1.893 @@ -1675,19 +1575,18 @@
   1.894          return -1;
   1.895      }
   1.896  
   1.897 -    SDL_SelectRenderer(window->id);
   1.898 +    SDL_SelectRenderer(window);
   1.899  
   1.900      return 0;
   1.901  }
   1.902  
   1.903  int
   1.904 -SDL_SelectRenderer(SDL_WindowID windowID)
   1.905 +SDL_SelectRenderer(SDL_Window * window)
   1.906  {
   1.907 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.908      SDL_Renderer *renderer;
   1.909  
   1.910      if (!window) {
   1.911 -        SDL_SetError("Invalid window ID");
   1.912 +        SDL_SetError("Invalid window");
   1.913          return -1;
   1.914      }
   1.915      renderer = window->renderer;
   1.916 @@ -1700,7 +1599,7 @@
   1.917              return -1;
   1.918          }
   1.919      }
   1.920 -    SDL_CurrentDisplay.current_renderer = renderer;
   1.921 +    SDL_CurrentDisplay->current_renderer = renderer;
   1.922      return 0;
   1.923  }
   1.924  
   1.925 @@ -1715,10 +1614,9 @@
   1.926      return 0;
   1.927  }
   1.928  
   1.929 -SDL_TextureID
   1.930 +SDL_Texture *
   1.931  SDL_CreateTexture(Uint32 format, int access, int w, int h)
   1.932  {
   1.933 -    int hash;
   1.934      SDL_Renderer *renderer;
   1.935      SDL_Texture *texture;
   1.936  
   1.937 @@ -1735,7 +1633,6 @@
   1.938          SDL_OutOfMemory();
   1.939          return 0;
   1.940      }
   1.941 -    texture->id = _this->next_object_id++;
   1.942      texture->format = format;
   1.943      texture->access = access;
   1.944      texture->w = w;
   1.945 @@ -1745,25 +1642,20 @@
   1.946      texture->b = 255;
   1.947      texture->a = 255;
   1.948      texture->renderer = renderer;
   1.949 +    texture->next = renderer->textures;
   1.950 +    renderer->textures = texture;
   1.951  
   1.952      if (renderer->CreateTexture(renderer, texture) < 0) {
   1.953 -        if (renderer->DestroyTexture) {
   1.954 -            renderer->DestroyTexture(renderer, texture);
   1.955 -        }
   1.956 -        SDL_free(texture);
   1.957 +        SDL_DestroyTexture(texture);
   1.958          return 0;
   1.959      }
   1.960 -    hash = (texture->id % SDL_arraysize(SDL_CurrentDisplay.textures));
   1.961 -    texture->next = SDL_CurrentDisplay.textures[hash];
   1.962 -    SDL_CurrentDisplay.textures[hash] = texture;
   1.963 -
   1.964 -    return texture->id;
   1.965 +    return texture;
   1.966  }
   1.967  
   1.968 -SDL_TextureID
   1.969 +SDL_Texture *
   1.970  SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
   1.971  {
   1.972 -    SDL_TextureID textureID;
   1.973 +    SDL_Texture *texture;
   1.974      Uint32 requested_format = format;
   1.975      SDL_PixelFormat *fmt;
   1.976      SDL_Renderer *renderer;
   1.977 @@ -1980,29 +1872,29 @@
   1.978          }
   1.979      }
   1.980  
   1.981 -    textureID =
   1.982 +    texture =
   1.983          SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
   1.984                            surface->h);
   1.985 -    if (!textureID && !requested_format) {
   1.986 +    if (!texture && !requested_format) {
   1.987          SDL_DisplayMode desktop_mode;
   1.988          SDL_GetDesktopDisplayMode(&desktop_mode);
   1.989          format = desktop_mode.format;
   1.990 -        textureID =
   1.991 +        texture =
   1.992              SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
   1.993                                surface->h);
   1.994      }
   1.995 -    if (!textureID) {
   1.996 +    if (!texture) {
   1.997          return 0;
   1.998      }
   1.999      if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask
  1.1000          && Bmask == fmt->Bmask && Amask == fmt->Amask) {
  1.1001          if (SDL_MUSTLOCK(surface)) {
  1.1002              SDL_LockSurface(surface);
  1.1003 -            SDL_UpdateTexture(textureID, NULL, surface->pixels,
  1.1004 +            SDL_UpdateTexture(texture, NULL, surface->pixels,
  1.1005                                surface->pitch);
  1.1006              SDL_UnlockSurface(surface);
  1.1007          } else {
  1.1008 -            SDL_UpdateTexture(textureID, NULL, surface->pixels,
  1.1009 +            SDL_UpdateTexture(texture, NULL, surface->pixels,
  1.1010                                surface->pitch);
  1.1011          }
  1.1012      } else {
  1.1013 @@ -2025,14 +1917,14 @@
  1.1014          }
  1.1015          dst = SDL_ConvertSurface(surface, &dst_fmt, 0);
  1.1016          if (dst) {
  1.1017 -            SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
  1.1018 +            SDL_UpdateTexture(texture, NULL, dst->pixels, dst->pitch);
  1.1019              SDL_FreeSurface(dst);
  1.1020          }
  1.1021          if (dst_fmt.palette) {
  1.1022              SDL_FreePalette(dst_fmt.palette);
  1.1023          }
  1.1024          if (!dst) {
  1.1025 -            SDL_DestroyTexture(textureID);
  1.1026 +            SDL_DestroyTexture(texture);
  1.1027              return 0;
  1.1028          }
  1.1029      }
  1.1030 @@ -2043,50 +1935,29 @@
  1.1031          int scaleMode;
  1.1032  
  1.1033          SDL_GetSurfaceColorMod(surface, &r, &g, &b);
  1.1034 -        SDL_SetTextureColorMod(textureID, r, g, b);
  1.1035 +        SDL_SetTextureColorMod(texture, r, g, b);
  1.1036  
  1.1037          SDL_GetSurfaceAlphaMod(surface, &a);
  1.1038 -        SDL_SetTextureAlphaMod(textureID, a);
  1.1039 +        SDL_SetTextureAlphaMod(texture, a);
  1.1040  
  1.1041          SDL_GetSurfaceBlendMode(surface, &blendMode);
  1.1042 -        SDL_SetTextureBlendMode(textureID, blendMode);
  1.1043 +        SDL_SetTextureBlendMode(texture, blendMode);
  1.1044  
  1.1045          SDL_GetSurfaceScaleMode(surface, &scaleMode);
  1.1046 -        SDL_SetTextureScaleMode(textureID, scaleMode);
  1.1047 +        SDL_SetTextureScaleMode(texture, scaleMode);
  1.1048      }
  1.1049  
  1.1050      if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) {
  1.1051 -        SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
  1.1052 +        SDL_SetTexturePalette(texture, fmt->palette->colors, 0,
  1.1053                                fmt->palette->ncolors);
  1.1054      }
  1.1055 -    return textureID;
  1.1056 +    return texture;
  1.1057  }
  1.1058  
  1.1059 -static __inline__ SDL_Texture *
  1.1060 -SDL_GetTextureFromID(SDL_TextureID textureID)
  1.1061 -{
  1.1062 -    int hash;
  1.1063 -    SDL_Texture *texture;
  1.1064 -
  1.1065 -    if (!_this) {
  1.1066 -        return NULL;
  1.1067 -    }
  1.1068 -    hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
  1.1069 -    for (texture = SDL_CurrentDisplay.textures[hash]; texture;
  1.1070 -         texture = texture->next) {
  1.1071 -        if (texture->id == textureID) {
  1.1072 -            return texture;
  1.1073 -        }
  1.1074 -    }
  1.1075 -    return NULL;
  1.1076 -}
  1.1077 -
  1.1078  int
  1.1079 -SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access,
  1.1080 +SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access,
  1.1081                   int *w, int *h)
  1.1082  {
  1.1083 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1084 -
  1.1085      if (!texture) {
  1.1086          return -1;
  1.1087      }
  1.1088 @@ -2106,9 +1977,8 @@
  1.1089  }
  1.1090  
  1.1091  int
  1.1092 -SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch)
  1.1093 +SDL_QueryTexturePixels(SDL_Texture * texture, void **pixels, int *pitch)
  1.1094  {
  1.1095 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1096      SDL_Renderer *renderer;
  1.1097  
  1.1098      if (!texture) {
  1.1099 @@ -2123,10 +1993,9 @@
  1.1100  }
  1.1101  
  1.1102  int
  1.1103 -SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors,
  1.1104 +SDL_SetTexturePalette(SDL_Texture * texture, const SDL_Color * colors,
  1.1105                        int firstcolor, int ncolors)
  1.1106  {
  1.1107 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1108      SDL_Renderer *renderer;
  1.1109  
  1.1110      if (!texture) {
  1.1111 @@ -2142,10 +2011,9 @@
  1.1112  }
  1.1113  
  1.1114  int
  1.1115 -SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
  1.1116 +SDL_GetTexturePalette(SDL_Texture * texture, SDL_Color * colors,
  1.1117                        int firstcolor, int ncolors)
  1.1118  {
  1.1119 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1120      SDL_Renderer *renderer;
  1.1121  
  1.1122      if (!texture) {
  1.1123 @@ -2161,9 +2029,8 @@
  1.1124  }
  1.1125  
  1.1126  int
  1.1127 -SDL_SetTextureColorMod(SDL_TextureID textureID, Uint8 r, Uint8 g, Uint8 b)
  1.1128 +SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b)
  1.1129  {
  1.1130 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1131      SDL_Renderer *renderer;
  1.1132  
  1.1133      if (!texture) {
  1.1134 @@ -2186,10 +2053,9 @@
  1.1135  }
  1.1136  
  1.1137  int
  1.1138 -SDL_GetTextureColorMod(SDL_TextureID textureID, Uint8 * r, Uint8 * g,
  1.1139 +SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g,
  1.1140                         Uint8 * b)
  1.1141  {
  1.1142 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1143      SDL_Renderer *renderer;
  1.1144  
  1.1145      if (!texture) {
  1.1146 @@ -2209,9 +2075,8 @@
  1.1147  }
  1.1148  
  1.1149  int
  1.1150 -SDL_SetTextureAlphaMod(SDL_TextureID textureID, Uint8 alpha)
  1.1151 +SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha)
  1.1152  {
  1.1153 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1154      SDL_Renderer *renderer;
  1.1155  
  1.1156      if (!texture) {
  1.1157 @@ -2232,10 +2097,8 @@
  1.1158  }
  1.1159  
  1.1160  int
  1.1161 -SDL_GetTextureAlphaMod(SDL_TextureID textureID, Uint8 * alpha)
  1.1162 +SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha)
  1.1163  {
  1.1164 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1165 -
  1.1166      if (!texture) {
  1.1167          return -1;
  1.1168      }
  1.1169 @@ -2246,9 +2109,8 @@
  1.1170  }
  1.1171  
  1.1172  int
  1.1173 -SDL_SetTextureBlendMode(SDL_TextureID textureID, int blendMode)
  1.1174 +SDL_SetTextureBlendMode(SDL_Texture * texture, int blendMode)
  1.1175  {
  1.1176 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1177      SDL_Renderer *renderer;
  1.1178  
  1.1179      if (!texture) {
  1.1180 @@ -2264,10 +2126,8 @@
  1.1181  }
  1.1182  
  1.1183  int
  1.1184 -SDL_GetTextureBlendMode(SDL_TextureID textureID, int *blendMode)
  1.1185 +SDL_GetTextureBlendMode(SDL_Texture * texture, int *blendMode)
  1.1186  {
  1.1187 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1188 -
  1.1189      if (!texture) {
  1.1190          return -1;
  1.1191      }
  1.1192 @@ -2278,9 +2138,8 @@
  1.1193  }
  1.1194  
  1.1195  int
  1.1196 -SDL_SetTextureScaleMode(SDL_TextureID textureID, int scaleMode)
  1.1197 +SDL_SetTextureScaleMode(SDL_Texture * texture, int scaleMode)
  1.1198  {
  1.1199 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1200      SDL_Renderer *renderer;
  1.1201  
  1.1202      if (!texture) {
  1.1203 @@ -2296,10 +2155,8 @@
  1.1204  }
  1.1205  
  1.1206  int
  1.1207 -SDL_GetTextureScaleMode(SDL_TextureID textureID, int *scaleMode)
  1.1208 +SDL_GetTextureScaleMode(SDL_Texture * texture, int *scaleMode)
  1.1209  {
  1.1210 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1211 -
  1.1212      if (!texture) {
  1.1213          return -1;
  1.1214      }
  1.1215 @@ -2310,10 +2167,9 @@
  1.1216  }
  1.1217  
  1.1218  int
  1.1219 -SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect,
  1.1220 +SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
  1.1221                    const void *pixels, int pitch)
  1.1222  {
  1.1223 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1224      SDL_Renderer *renderer;
  1.1225      SDL_Rect full_rect;
  1.1226  
  1.1227 @@ -2336,10 +2192,9 @@
  1.1228  }
  1.1229  
  1.1230  int
  1.1231 -SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty,
  1.1232 +SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, int markDirty,
  1.1233                  void **pixels, int *pitch)
  1.1234  {
  1.1235 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1236      SDL_Renderer *renderer;
  1.1237      SDL_Rect full_rect;
  1.1238  
  1.1239 @@ -2367,9 +2222,8 @@
  1.1240  }
  1.1241  
  1.1242  void
  1.1243 -SDL_UnlockTexture(SDL_TextureID textureID)
  1.1244 +SDL_UnlockTexture(SDL_Texture * texture)
  1.1245  {
  1.1246 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1247      SDL_Renderer *renderer;
  1.1248  
  1.1249      if (!texture) {
  1.1250 @@ -2386,10 +2240,9 @@
  1.1251  }
  1.1252  
  1.1253  void
  1.1254 -SDL_DirtyTexture(SDL_TextureID textureID, int numrects,
  1.1255 +SDL_DirtyTexture(SDL_Texture * texture, int numrects,
  1.1256                   const SDL_Rect * rects)
  1.1257  {
  1.1258 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1259      SDL_Renderer *renderer;
  1.1260  
  1.1261      if (!texture) {
  1.1262 @@ -2607,11 +2460,10 @@
  1.1263      /* Check for NULL rect, which means fill entire window */
  1.1264      for (i = 0; i < count; ++i) {
  1.1265          if (rects[i] == NULL) {
  1.1266 -            SDL_Window *window;
  1.1267 +            SDL_Window *window = renderer->window;
  1.1268              SDL_Rect full_rect;
  1.1269              const SDL_Rect *rect;
  1.1270  
  1.1271 -            window = SDL_GetWindowFromID(renderer->window);
  1.1272              full_rect.x = 0;
  1.1273              full_rect.y = 0;
  1.1274              full_rect.w = window->w;
  1.1275 @@ -2654,11 +2506,10 @@
  1.1276      /* Check for NULL rect, which means fill entire window */
  1.1277      for (i = 0; i < count; ++i) {
  1.1278          if (rects[i] == NULL) {
  1.1279 -            SDL_Window *window;
  1.1280 +            SDL_Window *window = renderer->window;
  1.1281              SDL_Rect full_rect;
  1.1282              const SDL_Rect *rect;
  1.1283  
  1.1284 -            window = SDL_GetWindowFromID(renderer->window);
  1.1285              full_rect.x = 0;
  1.1286              full_rect.y = 0;
  1.1287              full_rect.w = window->w;
  1.1288 @@ -2671,10 +2522,9 @@
  1.1289  }
  1.1290  
  1.1291  int
  1.1292 -SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
  1.1293 +SDL_RenderCopy(SDL_Texture * texture, const SDL_Rect * srcrect,
  1.1294                 const SDL_Rect * dstrect)
  1.1295  {
  1.1296 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  1.1297      SDL_Renderer *renderer;
  1.1298      SDL_Window *window;
  1.1299      SDL_Rect real_srcrect;
  1.1300 @@ -2696,7 +2546,7 @@
  1.1301          SDL_Unsupported();
  1.1302          return -1;
  1.1303      }
  1.1304 -    window = SDL_GetWindowFromID(renderer->window);
  1.1305 +    window = renderer->window;
  1.1306  
  1.1307      real_srcrect.x = 0;
  1.1308      real_srcrect.y = 0;
  1.1309 @@ -2751,10 +2601,10 @@
  1.1310          SDL_Unsupported();
  1.1311          return -1;
  1.1312      }
  1.1313 -    window = SDL_GetWindowFromID(renderer->window);
  1.1314 +    window = renderer->window;
  1.1315  
  1.1316      if (!format) {
  1.1317 -        format = SDL_GetDisplayFromWindow(window)->current_mode.format;
  1.1318 +        format = window->display->current_mode.format;
  1.1319      }
  1.1320  
  1.1321      real_rect.x = 0;
  1.1322 @@ -2769,7 +2619,7 @@
  1.1323              pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
  1.1324          }
  1.1325          if (real_rect.x > rect->x) {
  1.1326 -            Uint32 format = SDL_CurrentDisplay.current_mode.format;
  1.1327 +            Uint32 format = SDL_CurrentDisplay->current_mode.format;
  1.1328              int bpp = SDL_BYTESPERPIXEL(format);
  1.1329              pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
  1.1330          }
  1.1331 @@ -2795,10 +2645,10 @@
  1.1332          SDL_Unsupported();
  1.1333          return -1;
  1.1334      }
  1.1335 -    window = SDL_GetWindowFromID(renderer->window);
  1.1336 +    window = renderer->window;
  1.1337  
  1.1338      if (!format) {
  1.1339 -        format = SDL_GetDisplayFromWindow(window)->current_mode.format;
  1.1340 +        format = window->display->current_mode.format;
  1.1341      }
  1.1342  
  1.1343      real_rect.x = 0;
  1.1344 @@ -2813,7 +2663,7 @@
  1.1345              pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y);
  1.1346          }
  1.1347          if (real_rect.x > rect->x) {
  1.1348 -            Uint32 format = SDL_CurrentDisplay.current_mode.format;
  1.1349 +            Uint32 format = SDL_CurrentDisplay->current_mode.format;
  1.1350              int bpp = SDL_BYTESPERPIXEL(format);
  1.1351              pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
  1.1352          }
  1.1353 @@ -2836,45 +2686,30 @@
  1.1354  }
  1.1355  
  1.1356  void
  1.1357 -SDL_DestroyTexture(SDL_TextureID textureID)
  1.1358 +SDL_DestroyTexture(SDL_Texture * texture)
  1.1359  {
  1.1360 -    int hash;
  1.1361 -    SDL_Texture *prev, *texture;
  1.1362      SDL_Renderer *renderer;
  1.1363  
  1.1364 -    if (!_this) {
  1.1365 -        SDL_UninitializedVideo();
  1.1366 +    if (!texture || !texture->renderer) {
  1.1367 +        SDL_SetError("Invalid texture");
  1.1368          return;
  1.1369      }
  1.1370 -    /* Look up the texture in the hash table */
  1.1371 -    hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
  1.1372 -    prev = NULL;
  1.1373 -    for (texture = SDL_CurrentDisplay.textures[hash]; texture;
  1.1374 -         prev = texture, texture = texture->next) {
  1.1375 -        if (texture->id == textureID) {
  1.1376 -            break;
  1.1377 -        }
  1.1378 -    }
  1.1379 -    if (!texture) {
  1.1380 -        return;
  1.1381 -    }
  1.1382 -    /* Unlink the texture from the list */
  1.1383 -    if (prev) {
  1.1384 -        prev->next = texture->next;
  1.1385 +
  1.1386 +    renderer = texture->renderer;
  1.1387 +    if (texture->prev) {
  1.1388 +        texture->prev->next = texture->next;
  1.1389      } else {
  1.1390 -        SDL_CurrentDisplay.textures[hash] = texture->next;
  1.1391 -    }
  1.1392 -
  1.1393 -    /* Free the texture */
  1.1394 -    renderer = texture->renderer;
  1.1395 +        renderer->textures = texture->next;
  1.1396 +    }
  1.1397 +    texture->renderer = NULL;
  1.1398 +
  1.1399      renderer->DestroyTexture(renderer, texture);
  1.1400      SDL_free(texture);
  1.1401  }
  1.1402  
  1.1403  void
  1.1404 -SDL_DestroyRenderer(SDL_WindowID windowID)
  1.1405 +SDL_DestroyRenderer(SDL_Window * window)
  1.1406  {
  1.1407 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
  1.1408      SDL_Renderer *renderer;
  1.1409      int i;
  1.1410  
  1.1411 @@ -2885,26 +2720,10 @@
  1.1412      if (!renderer) {
  1.1413          return;
  1.1414      }
  1.1415 +
  1.1416      /* Free existing textures for this renderer */
  1.1417 -    for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) {
  1.1418 -        SDL_Texture *texture;
  1.1419 -        SDL_Texture *prev = NULL;
  1.1420 -        SDL_Texture *next;
  1.1421 -        for (texture = SDL_CurrentDisplay.textures[i]; texture;
  1.1422 -             texture = next) {
  1.1423 -            next = texture->next;
  1.1424 -            if (texture->renderer == renderer) {
  1.1425 -                if (prev) {
  1.1426 -                    prev->next = next;
  1.1427 -                } else {
  1.1428 -                    SDL_CurrentDisplay.textures[i] = next;
  1.1429 -                }
  1.1430 -                renderer->DestroyTexture(renderer, texture);
  1.1431 -                SDL_free(texture);
  1.1432 -            } else {
  1.1433 -                prev = texture;
  1.1434 -            }
  1.1435 -        }
  1.1436 +    while (renderer->textures) {
  1.1437 +        SDL_DestroyTexture(renderer->textures);
  1.1438      }
  1.1439  
  1.1440      /* Free the renderer instance */
  1.1441 @@ -2912,8 +2731,8 @@
  1.1442  
  1.1443      /* Clear references */
  1.1444      window->renderer = NULL;
  1.1445 -    if (SDL_CurrentDisplay.current_renderer == renderer) {
  1.1446 -        SDL_CurrentDisplay.current_renderer = NULL;
  1.1447 +    if (SDL_CurrentDisplay->current_renderer == renderer) {
  1.1448 +        SDL_CurrentDisplay->current_renderer = NULL;
  1.1449      }
  1.1450  }
  1.1451  
  1.1452 @@ -2971,14 +2790,9 @@
  1.1453      /* Clean up the system video */
  1.1454      for (i = _this->num_displays; i--;) {
  1.1455          SDL_VideoDisplay *display = &_this->displays[i];
  1.1456 -        for (j = display->num_windows; j--;) {
  1.1457 -            SDL_DestroyWindow(display->windows[i].id);
  1.1458 +        while (display->windows) {
  1.1459 +            SDL_DestroyWindow(display->windows);
  1.1460          }
  1.1461 -        if (display->windows) {
  1.1462 -            SDL_free(display->windows);
  1.1463 -            display->windows = NULL;
  1.1464 -        }
  1.1465 -        display->num_windows = 0;
  1.1466          if (display->render_drivers) {
  1.1467              SDL_free(display->render_drivers);
  1.1468              display->render_drivers = NULL;
  1.1469 @@ -3383,10 +3197,8 @@
  1.1470  }
  1.1471  
  1.1472  SDL_GLContext
  1.1473 -SDL_GL_CreateContext(SDL_WindowID windowID)
  1.1474 +SDL_GL_CreateContext(SDL_Window * window)
  1.1475  {
  1.1476 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
  1.1477 -
  1.1478      if (!window) {
  1.1479          return NULL;
  1.1480      }
  1.1481 @@ -3398,10 +3210,8 @@
  1.1482  }
  1.1483  
  1.1484  int
  1.1485 -SDL_GL_MakeCurrent(SDL_WindowID windowID, SDL_GLContext context)
  1.1486 +SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context)
  1.1487  {
  1.1488 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
  1.1489 -
  1.1490      if (window && !(window->flags & SDL_WINDOW_OPENGL)) {
  1.1491          SDL_SetError("The specified window isn't an OpenGL window");
  1.1492          return -1;
  1.1493 @@ -3443,10 +3253,8 @@
  1.1494  }
  1.1495  
  1.1496  void
  1.1497 -SDL_GL_SwapWindow(SDL_WindowID windowID)
  1.1498 +SDL_GL_SwapWindow(SDL_Window * window)
  1.1499  {
  1.1500 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
  1.1501 -
  1.1502      if (!window) {
  1.1503          return;
  1.1504      }
  1.1505 @@ -3567,10 +3375,8 @@
  1.1506  #endif
  1.1507  
  1.1508  SDL_bool
  1.1509 -SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info)
  1.1510 +SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info)
  1.1511  {
  1.1512 -    SDL_Window *window = SDL_GetWindowFromID(windowID);
  1.1513 -
  1.1514      if (!window || !_this->GetWindowWMInfo) {
  1.1515          return SDL_FALSE;
  1.1516      }