src/video/raspberry/SDL_rpivideo.c
changeset 12615 6f0eb21dd7d1
parent 12503 806492103856
equal deleted inserted replaced
12614:8c5251cbf63c 12615:6f0eb21dd7d1
   152     "RPI Video Driver",
   152     "RPI Video Driver",
   153     RPI_Available,
   153     RPI_Available,
   154     RPI_Create
   154     RPI_Create
   155 };
   155 };
   156 
   156 
       
   157 
   157 /*****************************************************************************/
   158 /*****************************************************************************/
   158 /* SDL Video and Display initialization/handling functions                   */
   159 /* SDL Video and Display initialization/handling functions                   */
   159 /*****************************************************************************/
   160 /*****************************************************************************/
   160 int
   161 
   161 RPI_VideoInit(_THIS)
   162 static void
   162 {
   163 AddDispManXDisplay(const int display_id)
       
   164 {
       
   165     DISPMANX_MODEINFO_T modeinfo;
       
   166     DISPMANX_DISPLAY_HANDLE_T handle;
   163     SDL_VideoDisplay display;
   167     SDL_VideoDisplay display;
   164     SDL_DisplayMode current_mode;
   168     SDL_DisplayMode current_mode;
   165     SDL_DisplayData *data;
   169     SDL_DisplayData *data;
   166     uint32_t w,h;
   170 
   167 
   171     handle = vc_dispmanx_display_open(display_id);
   168     /* Initialize BCM Host */
   172     if (!handle) {
   169     bcm_host_init();
   173         return;  /* this display isn't available */
   170 
   174     }
       
   175 
       
   176     if (vc_dispmanx_display_get_info(handle, &modeinfo) < 0) {
       
   177         vc_dispmanx_display_close(handle);
       
   178         return;
       
   179     }
       
   180 
       
   181     /* RPI_GetRefreshRate() doesn't distinguish between displays. I'm not sure the hardware distinguishes either */
   171     SDL_zero(current_mode);
   182     SDL_zero(current_mode);
   172 
   183     current_mode.w = modeinfo.width;
   173     if (graphics_get_display_size( 0, &w, &h) < 0) {
   184     current_mode.h = modeinfo.height;
   174         return -1;
       
   175     }
       
   176 
       
   177     current_mode.w = w;
       
   178     current_mode.h = h;
       
   179     current_mode.refresh_rate = RPI_GetRefreshRate();
   185     current_mode.refresh_rate = RPI_GetRefreshRate();
   180     /* 32 bpp for default */
   186     /* 32 bpp for default */
   181     current_mode.format = SDL_PIXELFORMAT_ABGR8888;
   187     current_mode.format = SDL_PIXELFORMAT_ABGR8888;
   182 
   188 
   183     current_mode.driverdata = NULL;
   189     current_mode.driverdata = NULL;
   187     display.current_mode = current_mode;
   193     display.current_mode = current_mode;
   188 
   194 
   189     /* Allocate display internal data */
   195     /* Allocate display internal data */
   190     data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
   196     data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
   191     if (data == NULL) {
   197     if (data == NULL) {
   192         return SDL_OutOfMemory();
   198         vc_dispmanx_display_close(handle);
   193     }
   199         return;  /* oh well */
   194 
   200     }
   195     data->dispman_display = vc_dispmanx_display_open( 0 /* LCD */);
   201 
       
   202     data->dispman_display = handle;
   196 
   203 
   197     display.driverdata = data;
   204     display.driverdata = data;
   198 
   205 
   199     SDL_AddVideoDisplay(&display);
   206     SDL_AddVideoDisplay(&display);
       
   207 }
       
   208 
       
   209 int
       
   210 RPI_VideoInit(_THIS)
       
   211 {
       
   212     /* Initialize BCM Host */
       
   213     bcm_host_init();
       
   214 
       
   215     AddDispManXDisplay(DISPMANX_ID_MAIN_LCD);  /* your default display */
       
   216     AddDispManXDisplay(DISPMANX_ID_FORCE_OTHER);  /* an "other" display...maybe DSI-connected screen while HDMI is your main */
   200 
   217 
   201 #ifdef SDL_INPUT_LINUXEV    
   218 #ifdef SDL_INPUT_LINUXEV    
   202     if (SDL_EVDEV_Init() < 0) {
   219     if (SDL_EVDEV_Init() < 0) {
   203         return -1;
   220         return -1;
   204     }
   221     }