Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Much improved multi-display support for iPad.
Browse files Browse the repository at this point in the history
Fixes most issues and limitations, I think.
  • Loading branch information
icculus committed May 2, 2010
1 parent 5609d04 commit c644da5
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 78 deletions.
5 changes: 0 additions & 5 deletions src/video/uikit/SDL_uikitappdelegate.h
Expand Up @@ -25,13 +25,8 @@

/* *INDENT-OFF* */
@interface SDLUIKitDelegate:NSObject<UIApplicationDelegate> {
SDL_Window *window;
UIWindow *uiwindow;
}

@property (readwrite, assign) SDL_Window *window;
@property (readwrite, retain) UIWindow *uiwindow;

+(SDLUIKitDelegate *)sharedAppDelegate;

@end
Expand Down
50 changes: 34 additions & 16 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -20,6 +20,8 @@
slouken@libsdl.org
*/

#import "../SDL_sysvideo.h"

#import "SDL_uikitappdelegate.h"
#import "SDL_uikitopenglview.h"
#import "SDL_events_c.h"
Expand Down Expand Up @@ -55,9 +57,6 @@ int main(int argc, char **argv) {

@implementation SDLUIKitDelegate

@synthesize window;
@synthesize uiwindow;

/* convenience method */
+(SDLUIKitDelegate *)sharedAppDelegate {
/* the delegate is set in UIApplicationMain(), which is garaunteed to be called before this method */
Expand All @@ -66,8 +65,6 @@ +(SDLUIKitDelegate *)sharedAppDelegate {

- (id)init {
self = [super init];
window = NULL;
uiwindow = nil;
return self;
}

Expand Down Expand Up @@ -106,21 +103,42 @@ - (void)applicationWillTerminate:(UIApplication *)application {

- (void) applicationWillResignActive:(UIApplication*)application
{
// NSLog(@"%@", NSStringFromSelector(_cmd));
SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
//NSLog(@"%@", NSStringFromSelector(_cmd));

// Send every window on every screen a MINIMIZED event.
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
return;
}

int i;
for (i = 0; i < _this->num_displays; i++) {
const SDL_VideoDisplay *display = &_this->displays[i];
SDL_Window *window;
for (window = display->windows; window != nil; window = window->next) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
}
}
}

- (void) applicationDidBecomeActive:(UIApplication*)application
{
// NSLog(@"%@", NSStringFromSelector(_cmd));
SDL_SendWindowEvent(self.window, SDL_WINDOWEVENT_RESTORED, 0, 0);
}



-(void)dealloc {
[uiwindow release];
[super dealloc];
//NSLog(@"%@", NSStringFromSelector(_cmd));

// Send every window on every screen a RESTORED event.
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (!_this) {
return;
}

int i;
for (i = 0; i < _this->num_displays; i++) {
const SDL_VideoDisplay *display = &_this->displays[i];
SDL_Window *window;
for (window = display->windows; window != nil; window = window->next) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
}
}
}

@end
12 changes: 6 additions & 6 deletions src/video/uikit/SDL_uikitopengles.m
Expand Up @@ -99,13 +99,13 @@ void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)

SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
{

SDL_uikitopenglview *view;
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
UIScreen *uiscreen = (UIScreen *) window->display->driverdata;
UIWindow *uiwindow = data->uiwindow;

SDL_WindowData *data = (SDL_WindowData *)window->driverdata;

/* construct our view, passing in SDL's OpenGL configuration data */
view = [[SDL_uikitopenglview alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] \
/* construct our view, passing in SDL's OpenGL configuration data */
view = [[SDL_uikitopenglview alloc] initWithFrame: [uiwindow bounds] \
retainBacking: _this->gl_config.retained_backing \
rBits: _this->gl_config.red_size \
gBits: _this->gl_config.green_size \
Expand All @@ -116,7 +116,7 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
data->view = view;

/* add the view to our window */
[data->uiwindow addSubview: view ];
[uiwindow addSubview: view ];

/* Don't worry, the window retained the view */
[view release];
Expand Down
4 changes: 4 additions & 0 deletions src/video/uikit/SDL_uikitvideo.h
Expand Up @@ -26,6 +26,10 @@

#include "../SDL_sysvideo.h"

#include <UIKit/UIKit.h>

extern BOOL SDL_UIKit_supports_multiple_displays;

#endif /* _SDL_uikitvideo_h */

/* vi: set ts=4 sw=4 expandtab: */
44 changes: 22 additions & 22 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -49,7 +49,7 @@ static int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display,
SDL_DisplayMode * mode);
static void UIKit_VideoQuit(_THIS);

static BOOL supports_multiple_displays = NO;
BOOL SDL_UIKit_supports_multiple_displays = NO;

/* DUMMY driver bootstrap functions */

Expand Down Expand Up @@ -124,14 +124,14 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
static void
UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
const UIScreen *screen = (UIScreen *) display->driverdata;
UIScreen *uiscreen = (UIScreen *) display->driverdata;
SDL_DisplayMode mode;
SDL_zero(mode);

// availableModes showed up in 3.2 (the iPad and later). We should only
// land here for at least that version of the OS.
if (!supports_multiple_displays) {
const CGRect rect = [screen bounds];
if (!SDL_UIKit_supports_multiple_displays) {
const CGRect rect = [uiscreen bounds];
mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.w = (int) rect.size.width;
mode.h = (int) rect.size.height;
Expand All @@ -141,7 +141,7 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
return;
}

const NSArray *modes = [screen availableModes];
const NSArray *modes = [uiscreen availableModes];
const NSUInteger mode_count = [modes count];
NSUInteger i;
for (i = 0; i < mode_count; i++) {
Expand All @@ -159,11 +159,10 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)


static void
UIKit_AddDisplay(UIScreen *screen, int w, int h)
UIKit_AddDisplay(UIScreen *uiscreen, int w, int h)
{
SDL_VideoDisplay display;
SDL_DisplayMode mode;

SDL_zero(mode);
mode.format = SDL_PIXELFORMAT_ABGR8888;
mode.w = w;
Expand All @@ -173,8 +172,9 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
SDL_zero(display);
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = screen;
[screen retain];

[uiscreen retain];
display.driverdata = uiscreen;
SDL_AddVideoDisplay(&display);
}

Expand All @@ -187,25 +187,25 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
NSString *reqSysVer = @"3.2";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
supports_multiple_displays = YES;
SDL_UIKit_supports_multiple_displays = YES;

// If this is iPhoneOS < 3.2, all devices are one screen, 320x480 pixels.
// The iPad added both a larger main screen and the ability to use
// external displays.
if (!supports_multiple_displays) {
if (!SDL_UIKit_supports_multiple_displays) {
// Just give 'em the whole main screen.
UIScreen *screen = [UIScreen mainScreen];
const CGRect rect = [screen bounds];
UIKit_AddDisplay(screen, (int)rect.size.width, (int)rect.size.height);
UIScreen *uiscreen = [UIScreen mainScreen];
const CGRect rect = [uiscreen bounds];
UIKit_AddDisplay(uiscreen, (int)rect.size.width, (int)rect.size.height);
} else {
const NSArray *screens = [UIScreen screens];
const NSUInteger screen_count = [screens count];
NSUInteger i;
for (i = 0; i < screen_count; i++) {
// the main screen is the first element in the array.
UIScreen *screen = (UIScreen *) [screens objectAtIndex:i];
const CGSize size = [[screen currentMode] size];
UIKit_AddDisplay(screen, (int) size.width, (int) size.height);
UIScreen *uiscreen = (UIScreen *) [screens objectAtIndex:i];
const CGSize size = [[uiscreen currentMode] size];
UIKit_AddDisplay(uiscreen, (int) size.width, (int) size.height);
}
}

Expand All @@ -216,13 +216,13 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
static int
UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
UIScreen *screen = (UIScreen *) display->driverdata;
if (!supports_multiple_displays) {
UIScreen *uiscreen = (UIScreen *) display->driverdata;
if (!SDL_UIKit_supports_multiple_displays) {
// Not on at least iPhoneOS 3.2 (versions prior to iPad).
SDL_assert(mode->driverdata == NULL);
} else {
UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
[screen setCurrentMode:uimode];
[uiscreen setCurrentMode:uimode];
}

return 0;
Expand All @@ -235,8 +235,8 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
int i, j;
for (i = 0; i < _this->num_displays; i++) {
SDL_VideoDisplay *display = &_this->displays[i];
UIScreen *screen = (UIScreen *) display->driverdata;
[((UIScreen *) display->driverdata) release];
UIScreen *uiscreen = (UIScreen *) display->driverdata;
[uiscreen release];
display->driverdata = NULL;
for (j = 0; j < display->num_display_modes; j++) {
SDL_DisplayMode *mode = &display->display_modes[j];
Expand Down
1 change: 0 additions & 1 deletion src/video/uikit/SDL_uikitwindow.h
Expand Up @@ -36,7 +36,6 @@ extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);

struct SDL_WindowData
{
SDL_Window *window;
UIWindow *uiwindow;
SDL_uikitopenglview *view;
};
Expand Down

0 comments on commit c644da5

Please sign in to comment.