src/video/raspberry/SDL_rpivideo.c
changeset 11694 2ce56475ad57
parent 11444 38f181f81476
child 11811 5d94cb6b24d3
equal deleted inserted replaced
11693:4c8bd26f1aab 11694:2ce56475ad57
   212 RPI_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
   212 RPI_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
   213 {
   213 {
   214     return 0;
   214     return 0;
   215 }
   215 }
   216 
   216 
       
   217 static void
       
   218 RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
       
   219 {
       
   220    SDL_WindowData *wdata = ((SDL_WindowData *) data);
       
   221 
       
   222    SDL_LockMutex(wdata->vsync_cond_mutex);
       
   223    SDL_CondSignal(wdata->vsync_cond);
       
   224    SDL_UnlockMutex(wdata->vsync_cond_mutex);
       
   225 }
       
   226 
   217 int
   227 int
   218 RPI_CreateWindow(_THIS, SDL_Window * window)
   228 RPI_CreateWindow(_THIS, SDL_Window * window)
   219 {
   229 {
   220     SDL_WindowData *wdata;
   230     SDL_WindowData *wdata;
   221     SDL_VideoDisplay *display;
   231     SDL_VideoDisplay *display;
   287 
   297 
   288     if (wdata->egl_surface == EGL_NO_SURFACE) {
   298     if (wdata->egl_surface == EGL_NO_SURFACE) {
   289         return SDL_SetError("Could not create GLES window surface");
   299         return SDL_SetError("Could not create GLES window surface");
   290     }
   300     }
   291 
   301 
       
   302     /* Start generating vsync callbacks if necesary */
       
   303     wdata->double_buffer = SDL_FALSE;
       
   304     if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) {
       
   305         wdata->vsync_cond = SDL_CreateCond();
       
   306         wdata->vsync_cond_mutex = SDL_CreateMutex();
       
   307         wdata->double_buffer = SDL_TRUE;
       
   308         vc_dispmanx_vsync_callback(displaydata->dispman_display, RPI_vsync_callback, (void*)wdata);
       
   309     }
       
   310 
   292     /* Setup driver data for this window */
   311     /* Setup driver data for this window */
   293     window->driverdata = wdata;
   312     window->driverdata = wdata;
   294     
   313 
   295     /* One window, it always has focus */
   314     /* One window, it always has focus */
   296     SDL_SetMouseFocus(window);
   315     SDL_SetMouseFocus(window);
   297     SDL_SetKeyboardFocus(window);
   316     SDL_SetKeyboardFocus(window);
   298 
   317 
   299     /* Window has been successfully created */
   318     /* Window has been successfully created */
   302 
   321 
   303 void
   322 void
   304 RPI_DestroyWindow(_THIS, SDL_Window * window)
   323 RPI_DestroyWindow(_THIS, SDL_Window * window)
   305 {
   324 {
   306     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   325     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
       
   326     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
       
   327     SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
       
   328 
   307     if(data) {
   329     if(data) {
       
   330 	if (data->double_buffer) {
       
   331 	    /* Wait for vsync, and then stop vsync callbacks and destroy related stuff, if needed */
       
   332 	    SDL_LockMutex(data->vsync_cond_mutex);
       
   333 	    SDL_CondWait(data->vsync_cond, data->vsync_cond_mutex);
       
   334 	    SDL_UnlockMutex(data->vsync_cond_mutex);
       
   335 
       
   336 	    vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL);
       
   337 
       
   338 	    SDL_DestroyCond(data->vsync_cond);
       
   339 	    SDL_DestroyMutex(data->vsync_cond_mutex);
       
   340 	}
       
   341 
   308 #if SDL_VIDEO_OPENGL_EGL
   342 #if SDL_VIDEO_OPENGL_EGL
   309         if (data->egl_surface != EGL_NO_SURFACE) {
   343         if (data->egl_surface != EGL_NO_SURFACE) {
   310             SDL_EGL_DestroySurface(_this, data->egl_surface);
   344             SDL_EGL_DestroySurface(_this, data->egl_surface);
   311         }
   345         }
   312 #endif
   346 #endif