src/video/raspberry/SDL_rpivideo.c
changeset 11694 2ce56475ad57
parent 11444 38f181f81476
child 11811 5d94cb6b24d3
     1.1 --- a/src/video/raspberry/SDL_rpivideo.c	Mon Nov 06 15:29:24 2017 -0500
     1.2 +++ b/src/video/raspberry/SDL_rpivideo.c	Tue Nov 07 09:10:32 2017 -0800
     1.3 @@ -214,6 +214,16 @@
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +static void
     1.8 +RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
     1.9 +{
    1.10 +   SDL_WindowData *wdata = ((SDL_WindowData *) data);
    1.11 +
    1.12 +   SDL_LockMutex(wdata->vsync_cond_mutex);
    1.13 +   SDL_CondSignal(wdata->vsync_cond);
    1.14 +   SDL_UnlockMutex(wdata->vsync_cond_mutex);
    1.15 +}
    1.16 +
    1.17  int
    1.18  RPI_CreateWindow(_THIS, SDL_Window * window)
    1.19  {
    1.20 @@ -289,9 +299,18 @@
    1.21          return SDL_SetError("Could not create GLES window surface");
    1.22      }
    1.23  
    1.24 +    /* Start generating vsync callbacks if necesary */
    1.25 +    wdata->double_buffer = SDL_FALSE;
    1.26 +    if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) {
    1.27 +        wdata->vsync_cond = SDL_CreateCond();
    1.28 +        wdata->vsync_cond_mutex = SDL_CreateMutex();
    1.29 +        wdata->double_buffer = SDL_TRUE;
    1.30 +        vc_dispmanx_vsync_callback(displaydata->dispman_display, RPI_vsync_callback, (void*)wdata);
    1.31 +    }
    1.32 +
    1.33      /* Setup driver data for this window */
    1.34      window->driverdata = wdata;
    1.35 -    
    1.36 +
    1.37      /* One window, it always has focus */
    1.38      SDL_SetMouseFocus(window);
    1.39      SDL_SetKeyboardFocus(window);
    1.40 @@ -304,7 +323,22 @@
    1.41  RPI_DestroyWindow(_THIS, SDL_Window * window)
    1.42  {
    1.43      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.44 +    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    1.45 +    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
    1.46 +
    1.47      if(data) {
    1.48 +	if (data->double_buffer) {
    1.49 +	    /* Wait for vsync, and then stop vsync callbacks and destroy related stuff, if needed */
    1.50 +	    SDL_LockMutex(data->vsync_cond_mutex);
    1.51 +	    SDL_CondWait(data->vsync_cond, data->vsync_cond_mutex);
    1.52 +	    SDL_UnlockMutex(data->vsync_cond_mutex);
    1.53 +
    1.54 +	    vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL);
    1.55 +
    1.56 +	    SDL_DestroyCond(data->vsync_cond);
    1.57 +	    SDL_DestroyMutex(data->vsync_cond_mutex);
    1.58 +	}
    1.59 +
    1.60  #if SDL_VIDEO_OPENGL_EGL
    1.61          if (data->egl_surface != EGL_NO_SURFACE) {
    1.62              SDL_EGL_DestroySurface(_this, data->egl_surface);