src/render/SDL_render.c
changeset 5528 15c9c03a80cc
parent 5464 bec064e902cf
child 5535 96594ac5fd1a
--- a/src/render/SDL_render.c	Sun Apr 03 18:33:32 2011 -0500
+++ b/src/render/SDL_render.c	Mon Apr 04 09:29:13 2011 -0700
@@ -30,6 +30,8 @@
 #include "software/SDL_render_sw_c.h"
 
 
+#define SDL_WINDOWRENDERDATA    "_SDL_WindowRenderData"
+
 #define CHECK_RENDERER_MAGIC(renderer, retval) \
     if (!renderer || renderer->magic != &renderer_magic) { \
         SDL_SetError("Invalid renderer"); \
@@ -123,6 +125,16 @@
     int n = SDL_GetNumRenderDrivers();
     const char *hint;
 
+    if (!window) {
+        SDL_SetError("Invalid window");
+        return NULL;
+    }
+
+    if (SDL_GetRenderer(window)) {
+        SDL_SetError("Renderer already associated with window");
+        return NULL;
+    }
+
     hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
     if (hint) {
         if (*hint == '0') {
@@ -178,6 +190,8 @@
         renderer->magic = &renderer_magic;
         renderer->window = window;
 
+        SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
+
         SDL_RenderSetViewport(renderer, NULL);
 
         SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
@@ -208,6 +222,12 @@
 #endif /* !SDL_RENDER_DISABLED */
 }
 
+SDL_Renderer *
+SDL_GetRenderer(SDL_Window * window)
+{
+    return (SDL_Renderer *)SDL_GetWindowData(window, SDL_WINDOWRENDERDATA);
+}
+
 int
 SDL_GetRendererInfo(SDL_Renderer * renderer, SDL_RendererInfo * info)
 {
@@ -1149,6 +1169,8 @@
         SDL_DestroyTexture(renderer->textures);
     }
 
+    SDL_SetWindowData(renderer->window, SDL_WINDOWRENDERDATA, NULL);
+
     /* It's no longer magical... */
     renderer->magic = NULL;