src/video/android/SDL_androidvideo.c
changeset 12556 9b2e48b381db
parent 12552 6bc8c73ab0fe
child 12625 e58468e48179
equal deleted inserted replaced
12555:44f55801630b 12556:9b2e48b381db
    57 
    57 
    58 /* Android driver bootstrap functions */
    58 /* Android driver bootstrap functions */
    59 
    59 
    60 
    60 
    61 /* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
    61 /* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
    62 int Android_SurfaceWidth = 0;
    62 int Android_SurfaceWidth           = 0;
    63 int Android_SurfaceHeight = 0;
    63 int Android_SurfaceHeight          = 0;
    64 int Android_DeviceWidth = 0;
    64 static int Android_DeviceWidth     = 0;
    65 int Android_DeviceHeight = 0;
    65 static int Android_DeviceHeight    = 0;
    66 static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
    66 static Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
    67 static int Android_ScreenRate = 0;
    67 static int Android_ScreenRate      = 0;
    68 
    68 SDL_sem *Android_PauseSem          = NULL;
    69 SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
    69 SDL_sem *Android_ResumeSem         = NULL;
    70 SDL_mutex *Android_ActivityMutex = NULL;
    70 SDL_mutex *Android_ActivityMutex   = NULL;
    71 
    71 
    72 static int
    72 static int
    73 Android_Available(void)
    73 Android_Available(void)
    74 {
    74 {
    75     return 1;
    75     return 1;
   176     SDL_DisplayMode  mode;
   176     SDL_DisplayMode  mode;
   177 
   177 
   178     videodata->isPaused  = SDL_FALSE;
   178     videodata->isPaused  = SDL_FALSE;
   179     videodata->isPausing = SDL_FALSE;
   179     videodata->isPausing = SDL_FALSE;
   180 
   180 
   181     mode.format = Android_ScreenFormat;
   181     mode.format          = Android_ScreenFormat;
   182     mode.w = Android_DeviceWidth;
   182     mode.w               = Android_DeviceWidth;
   183     mode.h = Android_DeviceHeight;
   183     mode.h               = Android_DeviceHeight;
   184     mode.refresh_rate = Android_ScreenRate;
   184     mode.refresh_rate    = Android_ScreenRate;
   185     mode.driverdata = NULL;
   185     mode.driverdata      = NULL;
       
   186 
   186     if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   187     if (SDL_AddBasicVideoDisplay(&mode) < 0) {
   187         return -1;
   188         return -1;
   188     }
   189     }
   189 
   190 
   190     SDL_AddDisplayMode(&_this->displays[0], &mode);
   191     SDL_AddDisplayMode(&_this->displays[0], &mode);
   211 {
   212 {
   212     return Android_JNI_GetDisplayDPI(ddpi, hdpi, vdpi);
   213     return Android_JNI_GetDisplayDPI(ddpi, hdpi, vdpi);
   213 }
   214 }
   214 
   215 
   215 void
   216 void
   216 Android_SetScreenResolution(SDL_Window *window, int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
   217 Android_SetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, Uint32 format, float rate)
   217 {
   218 {
   218     SDL_VideoDevice *device;
   219     Android_SurfaceWidth  = surfaceWidth;
   219     SDL_VideoDisplay *display;
       
   220     Android_SurfaceWidth = surfaceWidth;
       
   221     Android_SurfaceHeight = surfaceHeight;
   220     Android_SurfaceHeight = surfaceHeight;
   222     Android_DeviceWidth = deviceWidth;
   221     Android_DeviceWidth   = deviceWidth;
   223     Android_DeviceHeight = deviceHeight;
   222     Android_DeviceHeight  = deviceHeight;
   224     Android_ScreenFormat = format;
   223     Android_ScreenFormat  = format;
   225     Android_ScreenRate = (int)rate;
   224     Android_ScreenRate    = (int)rate;
   226 
   225 }
       
   226 
       
   227 void Android_SendResize(SDL_Window *window)
       
   228 {
   227     /*
   229     /*
   228       Update the resolution of the desktop mode, so that the window
   230       Update the resolution of the desktop mode, so that the window
   229       can be properly resized. The screen resolution change can for
   231       can be properly resized. The screen resolution change can for
   230       example happen when the Activity enters or exits immersive mode,
   232       example happen when the Activity enters or exits immersive mode,
   231       which can happen after VideoInit().
   233       which can happen after VideoInit().
   232     */
   234     */
   233     device = SDL_GetVideoDevice();
   235     SDL_VideoDevice *device = SDL_GetVideoDevice();
   234     if (device && device->num_displays > 0)
   236     if (device && device->num_displays > 0)
   235     {
   237     {
   236         display = &device->displays[0];
   238         SDL_VideoDisplay *display          = &device->displays[0];
   237         display->desktop_mode.format = Android_ScreenFormat;
   239         display->desktop_mode.format       = Android_ScreenFormat;
   238         display->desktop_mode.w = Android_DeviceWidth;
   240         display->desktop_mode.w            = Android_DeviceWidth;
   239         display->desktop_mode.h = Android_DeviceHeight;
   241         display->desktop_mode.h            = Android_DeviceHeight;
   240         display->desktop_mode.refresh_rate  = Android_ScreenRate;
   242         display->desktop_mode.refresh_rate = Android_ScreenRate;
   241     }
   243     }
   242 
   244 
   243     if (window) {
   245     if (window) {
   244         /* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
   246         /* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
   245          * will fall back to the old mode */
   247          * will fall back to the old mode */
   246         display = SDL_GetDisplayForWindow(window);
   248         SDL_VideoDisplay *display              = SDL_GetDisplayForWindow(window);
   247 
   249         display->display_modes[0].format       = Android_ScreenFormat;
   248         display->display_modes[0].format = format;
   250         display->display_modes[0].w            = Android_DeviceWidth;
   249         display->display_modes[0].w = Android_DeviceWidth;
   251         display->display_modes[0].h            = Android_DeviceHeight;
   250         display->display_modes[0].h = Android_DeviceHeight;
   252         display->display_modes[0].refresh_rate = Android_ScreenRate;
   251         display->display_modes[0].refresh_rate = (int)rate;
   253         display->current_mode                  = display->display_modes[0];
   252         display->current_mode = display->display_modes[0];
   254 
   253 
   255         SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, Android_SurfaceWidth, Android_SurfaceHeight);
   254         SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, surfaceWidth, surfaceHeight);
       
   255     }
   256     }
   256 }
   257 }
   257 
   258 
   258 #endif /* SDL_VIDEO_DRIVER_ANDROID */
   259 #endif /* SDL_VIDEO_DRIVER_ANDROID */
   259 
   260