[KMS/DRM] Move surface size info to window driverdata, for coherency.
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 781b796..f860815 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -823,7 +823,7 @@
 {
     SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
     SDL_WindowData *windata = (SDL_WindowData *)window->driverdata;
-    SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+
     uint32_t surface_fmt = GBM_FORMAT_ARGB8888;
     uint32_t surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
 
@@ -845,7 +845,7 @@
     }
 
     windata->gs = KMSDRM_gbm_surface_create(viddata->gbm_dev,
-                      dispdata->surface_w, dispdata->surface_h, surface_fmt, surface_flags);
+                      windata->surface_w, windata->surface_h, surface_fmt, surface_flags);
 
     if (!windata->gs) {
         return SDL_SetError("Could not create GBM surface");
@@ -1020,14 +1020,11 @@
         return SDL_SetError("Mode doesn't have an associated index");
     }
 
-    /* Take note of the new mode to be set, and leave the modeset pending. */
+    /* Take note of the new mode to be set, and leave the CRTC modeset pending
+       so it's done in SwapWindow. */
     dispdata->mode = conn->modes[modedata->mode_index];
     dispdata->modeset_pending = SDL_TRUE; 
 
-    /* Set the new surface size. */
-    dispdata->surface_w = dispdata->mode.hdisplay; 
-    dispdata->surface_h = dispdata->mode.vdisplay; 
-
     for (i = 0; i < viddata->num_windows; i++) {
         SDL_Window *window = viddata->windows[i];
 
@@ -1193,16 +1190,17 @@
         /* Try to find a matching video mode for the window, with fallback to the
             original mode if not available, and configure that mode into the CRTC. */
 	if (mode) {
-	    dispdata->surface_w = window->w;
-	    dispdata->surface_h = window->h;
+	    windata->surface_w = window->w;
+	    windata->surface_h = window->h;
 	    dispdata->mode = *mode;
 	}
 	else {
-	    dispdata->surface_w = dispdata->original_mode.hdisplay;
-	    dispdata->surface_h = dispdata->original_mode.vdisplay;
+	    windata->surface_w = dispdata->original_mode.hdisplay;
+	    windata->surface_h = dispdata->original_mode.vdisplay;
 	    dispdata->mode = dispdata->original_mode;
 	}
 
+        /* Take note to do the modesettng on the CRTC in SwapWindow. */
 	dispdata->modeset_pending = SDL_TRUE;
 
         /* Create the window surfaces with the size we have just chosen.
@@ -1239,7 +1237,7 @@
     /* Tell app about the size we have determined for the window,
        so SDL pre-scales to that size for us. */
     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED,
-        dispdata->surface_w, dispdata->surface_h);
+        windata->surface_w, windata->surface_h);
 
     /***********************************************************/
     /* Tell SDL that the mouse has entered the window using an */
@@ -1266,8 +1264,8 @@
 /*****************************************************************************/
 void
 KMSDRM_ReconfigureWindow( _THIS, SDL_Window * window) {
-
     SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
 
     if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) ==
 			 SDL_WINDOW_FULLSCREEN_DESKTOP)
@@ -1275,8 +1273,8 @@
 	/* Update the current mode to the desktop mode,
 	   take note of pending mode configuration to the CRTC,
 	   and recreate the GBM surface with the same size as the size. */
-	dispdata->surface_w = dispdata->original_mode.hdisplay;
-	dispdata->surface_h = dispdata->original_mode.vdisplay;
+	windata->surface_w = dispdata->original_mode.hdisplay;
+	windata->surface_h = dispdata->original_mode.vdisplay;
 	dispdata->mode = dispdata->original_mode;
     }
     else
@@ -1288,16 +1286,16 @@
 	if (mode) {
             /* If matching mode found, recreate the GBM surface with the size
                of that mode and configure it on the CRTC. */
-	    dispdata->surface_w = window->windowed.w;
-	    dispdata->surface_h = window->windowed.h;
+	    windata->surface_w = window->windowed.w;
+	    windata->surface_h = window->windowed.h;
 	    dispdata->mode = *mode;
 	}
 	else {
             /* If not matching mode found, recreate the GBM surfaces with the
                size of the mode that was originally configured on the CRTC,
                and setup that mode on the CRTC. */
-	    dispdata->surface_w = dispdata->original_mode.hdisplay;
-	    dispdata->surface_h = dispdata->original_mode.vdisplay;
+	    windata->surface_w = dispdata->original_mode.hdisplay;
+	    windata->surface_h = dispdata->original_mode.vdisplay;
 	    dispdata->mode = dispdata->original_mode;
         }
     }
@@ -1310,7 +1308,7 @@
     /* Tell app about the size we have determined for the window,
        so SDL pre-scales to that size for us. */
     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED,
-    dispdata->surface_w, dispdata->surface_h);
+    windata->surface_w, windata->surface_h);
 }
 
 int
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h
index 74af9f0..d089e10 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -78,9 +78,6 @@
     SDL_bool set_default_cursor_pending;
     SDL_bool modeset_pending;
 
-    uint32_t surface_w;
-    uint32_t surface_h;
-
 } SDL_DisplayData;
 
 typedef struct SDL_WindowData
@@ -99,6 +96,12 @@
 
     EGLSurface egl_surface;
 
+    /* The size we chose for the GBM surface. REMEMBER that the CRTC must always have
+       a mode with the same size configured before trying to flip to a buffer of that
+       surface or drmModePageFlip() will return -28. */
+    uint32_t surface_w;
+    uint32_t surface_h;
+
 } SDL_WindowData;
 
 typedef struct KMSDRM_FBInfo