diff -ru drop/include/SDL_hints.h dev/include/SDL_hints.h --- drop/include/SDL_hints.h 2013-06-27 13:48:28.000000000 -0700 +++ dev/include/SDL_hints.h 2013-06-27 13:48:31.000000000 -0700 @@ -240,6 +240,11 @@ #define SDL_HINT_ALLOW_TOPMOST "SDL_ALLOW_TOPMOST" +/** + * \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac) + */ +#define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_HIGHDPI_DISABLED" + /** * \brief An enumeration of hint priorities diff -ru drop/include/SDL_video.h dev/include/SDL_video.h --- drop/include/SDL_video.h 2013-05-28 14:26:30.000000000 -0700 +++ dev/include/SDL_video.h 2013-05-29 11:39:36.000000000 -0700 @@ -107,7 +107,8 @@ SDL_WINDOW_INPUT_FOCUS = 0x00000200, /**< window has input focus */ SDL_WINDOW_MOUSE_FOCUS = 0x00000400, /**< window has mouse focus */ SDL_WINDOW_FULLSCREEN_DESKTOP = ( SDL_WINDOW_FULLSCREEN | 0x00001000 ), - SDL_WINDOW_FOREIGN = 0x00000800 /**< window not created by SDL */ + SDL_WINDOW_FOREIGN = 0x00000800, /**< window not created by SDL */ + SDL_WINDOW_ALLOW_HIGHDPI = 0x00001000, /**< window should be created in high-DPI mode if supported */ } SDL_WindowFlags; /** @@ -393,10 +394,11 @@ * \param w The width of the window. * \param h The height of the window. * \param flags The flags for the window, a mask of any of the following: - * ::SDL_WINDOW_FULLSCREEN, ::SDL_WINDOW_OPENGL, - * ::SDL_WINDOW_SHOWN, ::SDL_WINDOW_BORDERLESS, - * ::SDL_WINDOW_RESIZABLE, ::SDL_WINDOW_MAXIMIZED, - * ::SDL_WINDOW_MINIMIZED, ::SDL_WINDOW_INPUT_GRABBED. + * ::SDL_WINDOW_FULLSCREEN, ::SDL_WINDOW_OPENGL, + * ::SDL_WINDOW_SHOWN, ::SDL_WINDOW_BORDERLESS, + * ::SDL_WINDOW_RESIZABLE, ::SDL_WINDOW_MAXIMIZED, + * ::SDL_WINDOW_MINIMIZED, ::SDL_WINDOW_INPUT_GRABBED. + * ::SDL_WINDOW_ALLOW_HIGHDPI. * * \return The id of the window created, or zero if window creation failed. * @@ -890,6 +892,23 @@ SDL_GLContext context); /** + * \brief Get the size of a window's underlying drawable (for use with glViewport). + * + * \param w Pointer to variable for storing the width, may be NULL + * \param h Pointer to variable for storing the height, may be NULL + * + * This may differ from SDL_GetWindowSize if we're rendering to a high-DPI + * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a + * platform with high-DPI support (Apple calls this "Retina"), and not disabled + * by the SDL_HINT_VIDEO_HIGHDPI_DISABLED hint. + * + * \sa SDL_GetWindowSize() + * \sa SDL_CreateWindow() + */ +extern DECLSPEC void SDLCALL SDL_GL_GetDrawableSize(SDL_Window * window, int *w, + int *h); + +/** * \brief Set the swap interval for the current OpenGL context. * * \param interval 0 for immediate updates, 1 for updates synchronized with the diff -ru drop/src/render/SDL_render.c dev/src/render/SDL_render.c --- drop/src/render/SDL_render.c 2013-06-27 13:48:28.000000000 -0700 +++ dev/src/render/SDL_render.c 2013-06-27 13:48:27.000000000 -0700 @@ -117,7 +117,12 @@ /* Window was resized, reset viewport */ int w, h; - SDL_GetWindowSize(window, &w, &h); + if (renderer->GetOutputSize) { + renderer->GetOutputSize(renderer, &w, &h); + } else { + SDL_GetWindowSize(renderer->window, &w, &h); + } + if (renderer->target) { renderer->viewport_backup.x = 0; renderer->viewport_backup.y = 0; @@ -325,11 +330,11 @@ if (renderer->target) { return SDL_QueryTexture(renderer->target, NULL, NULL, w, h); + } else if (renderer->GetOutputSize) { + return renderer->GetOutputSize(renderer, w, h); } else if (renderer->window) { SDL_GetWindowSize(renderer->window, w, h); return 0; - } else if (renderer->GetOutputSize) { - return renderer->GetOutputSize(renderer, w, h); } else { /* This should never happen */ SDL_SetError("Renderer doesn't support querying output size"); diff -ru drop/src/render/opengl/SDL_render_gl.c dev/src/render/opengl/SDL_render_gl.c --- drop/src/render/opengl/SDL_render_gl.c 2013-06-27 13:48:28.000000000 -0700 +++ dev/src/render/opengl/SDL_render_gl.c 2013-06-27 13:48:27.000000000 -0700 @@ -47,6 +47,7 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); static void GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event); +static int GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h); static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, @@ -397,6 +398,7 @@ } renderer->WindowEvent = GL_WindowEvent; + renderer->GetOutputSize = GL_GetOutputSize; renderer->CreateTexture = GL_CreateTexture; renderer->UpdateTexture = GL_UpdateTexture; renderer->LockTexture = GL_LockTexture; @@ -537,6 +539,14 @@ } } +static int +GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h) +{ + SDL_GL_GetDrawableSize(renderer->window, w, h); + + return 0; +} + SDL_FORCE_INLINE int power_of_2(int input) { diff -ru drop/src/video/SDL_sysvideo.h dev/src/video/SDL_sysvideo.h --- drop/src/video/SDL_sysvideo.h 2013-05-28 14:26:30.000000000 -0700 +++ dev/src/video/SDL_sysvideo.h 2013-05-29 11:41:42.000000000 -0700 @@ -89,6 +89,7 @@ SDL_Surface *surface; SDL_bool surface_valid; + SDL_bool allow_highdpi; SDL_WindowShaper *shaper; @@ -222,6 +223,7 @@ void (*GL_UnloadLibrary) (_THIS); SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window); int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context); + void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h); int (*GL_SetSwapInterval) (_THIS, int interval); int (*GL_GetSwapInterval) (_THIS); void (*GL_SwapWindow) (_THIS, SDL_Window * window); diff -ru drop/src/video/SDL_video.c dev/src/video/SDL_video.c --- drop/src/video/SDL_video.c 2013-06-27 13:48:28.000000000 -0700 +++ dev/src/video/SDL_video.c 2013-06-27 13:48:27.000000000 -0700 @@ -1183,6 +1183,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) { SDL_Window *window; + const char *hint; if (!_this) { /* Initialize the video system if needed */ @@ -1237,6 +1238,17 @@ window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN); window->brightness = 1.0f; window->next = _this->windows; + + /* Unless the user has specified the high-DPI disabling hint, respect the + * SDL_WINDOW_ALLOW_HIGHDPI flag. + */ + hint = SDL_GetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED); + if (!hint || *hint != '1') { + if ((flags & SDL_WINDOW_ALLOW_HIGHDPI)) { + window->allow_highdpi = SDL_TRUE; + } + } + if (_this->windows) { _this->windows->prev = window; } @@ -2763,6 +2775,17 @@ return retval; } +void SDL_GL_GetDrawableSize(SDL_Window * window, int *w, int *h) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (_this->GL_GetDrawableSize) { + _this->GL_GetDrawableSize(_this, window, w, h); + } else { + SDL_GetWindowSize(window, w, h); + } +} + int SDL_GL_SetSwapInterval(int interval) { diff -ru drop/src/video/cocoa/SDL_cocoaopengl.h dev/src/video/cocoa/SDL_cocoaopengl.h --- drop/src/video/cocoa/SDL_cocoaopengl.h 2013-04-24 14:11:50.000000000 -0700 +++ dev/src/video/cocoa/SDL_cocoaopengl.h 2013-05-29 11:48:06.000000000 -0700 @@ -40,6 +40,8 @@ extern SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window); extern int Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); +extern void Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, + int * w, int * h); extern int Cocoa_GL_SetSwapInterval(_THIS, int interval); extern int Cocoa_GL_GetSwapInterval(_THIS); extern void Cocoa_GL_SwapWindow(_THIS, SDL_Window * window); diff -ru drop/src/video/cocoa/SDL_cocoaopengl.m dev/src/video/cocoa/SDL_cocoaopengl.m --- drop/src/video/cocoa/SDL_cocoaopengl.m 2013-05-13 13:25:48.000000000 -0700 +++ dev/src/video/cocoa/SDL_cocoaopengl.m 2013-05-29 11:44:31.000000000 -0700 @@ -45,6 +45,18 @@ #define kCGLOGLPVersion_3_2_Core 0x3200 #endif +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 +/* New methods for converting to and from backing store pixels, taken from + * AppKite/NSView.h in 10.8 SDK. */ +@interface NSView (Backing) +- (NSPoint)convertPointToBacking:(NSPoint)aPoint; +- (NSPoint)convertPointFromBacking:(NSPoint)aPoint; +- (NSSize)convertSizeToBacking:(NSSize)aSize; +- (NSSize)convertSizeFromBacking:(NSSize)aSize; +- (NSRect)convertRectToBacking:(NSRect)aRect; +- (NSRect)convertRectFromBacking:(NSRect)aRect; +@end +#endif int Cocoa_GL_LoadLibrary(_THIS, const char *path) @@ -236,6 +248,28 @@ return 0; } +void +Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h) +{ + SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; + NSView *contentView = [windata->nswindow contentView]; + NSRect viewport = [contentView bounds]; + + /* This gives us the correct viewport for a Retina-enabled view, only + * supported on 10.7+. */ + if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) { + viewport = [contentView convertRectToBacking:viewport]; + } + + if (w) { + *w = viewport.size.width; + } + + if (h) { + *h = viewport.size.height; + } +} + int Cocoa_GL_SetSwapInterval(_THIS, int interval) { diff -ru drop/src/video/cocoa/SDL_cocoavideo.m dev/src/video/cocoa/SDL_cocoavideo.m --- drop/src/video/cocoa/SDL_cocoavideo.m 2013-05-28 14:26:30.000000000 -0700 +++ dev/src/video/cocoa/SDL_cocoavideo.m 2013-05-29 11:42:23.000000000 -0700 @@ -121,6 +121,7 @@ device->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary; device->GL_CreateContext = Cocoa_GL_CreateContext; device->GL_MakeCurrent = Cocoa_GL_MakeCurrent; + device->GL_GetDrawableSize = Cocoa_GL_GetDrawableSize; device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval; device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval; device->GL_SwapWindow = Cocoa_GL_SwapWindow; diff -ru drop/src/video/cocoa/SDL_cocoawindow.m dev/src/video/cocoa/SDL_cocoawindow.m --- drop/src/video/cocoa/SDL_cocoawindow.m 2013-06-27 13:48:28.000000000 -0700 +++ dev/src/video/cocoa/SDL_cocoawindow.m 2013-06-27 13:48:27.000000000 -0700 @@ -33,6 +33,13 @@ #include "SDL_cocoashape.h" #include "SDL_cocoamouse.h" +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 +/* Taken from AppKit/NSOpenGLView.h in 10.8 SDK. */ +@interface NSView (NSOpenGLSurfaceResolution) +- (BOOL)wantsBestResolutionOpenGLSurface; +- (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag; +@end +#endif static Uint32 s_moveHack; @@ -696,6 +703,11 @@ /* Create a default view for this window */ rect = [nswindow contentRectForFrameRect:[nswindow frame]]; NSView *contentView = [[SDLView alloc] initWithFrame:rect]; + + if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) { + [contentView setWantsBestResolutionOpenGLSurface:window->allow_highdpi]; + } + [nswindow setContentView: contentView]; [contentView release];