add in High DPI support (aka Retina)
- based on Jørgen's patch with a few bug fixes
This commit is contained in:
parent
a449178caa
commit
3a11d95444
12 changed files with 134 additions and 11 deletions
|
@ -224,6 +224,7 @@ struct SDL_VideoDevice
|
|||
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);
|
||||
|
|
|
@ -1187,6 +1187,7 @@ SDL_Window *
|
|||
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 */
|
||||
|
@ -1245,6 +1246,17 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
|
|||
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->flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
}
|
||||
}
|
||||
|
||||
if (_this->windows) {
|
||||
_this->windows->prev = window;
|
||||
}
|
||||
|
@ -2813,6 +2825,17 @@ SDL_GL_GetCurrentContext(void)
|
|||
return (SDL_GLContext)SDL_TLSGet(_this->current_glctx_tls);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -54,6 +54,8 @@ extern void Cocoa_GL_UnloadLibrary(_THIS);
|
|||
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);
|
||||
|
|
|
@ -35,6 +35,18 @@
|
|||
|
||||
#define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
|
||||
|
||||
#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
|
||||
|
||||
#ifndef kCGLPFAOpenGLProfile
|
||||
#define kCGLPFAOpenGLProfile 99
|
||||
|
@ -294,6 +306,28 @@ Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -119,6 +119,7 @@ Cocoa_CreateDevice(int devindex)
|
|||
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;
|
||||
|
|
|
@ -34,6 +34,13 @@
|
|||
#include "SDL_cocoamouse.h"
|
||||
#include "SDL_cocoaopengl.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;
|
||||
|
||||
|
@ -739,6 +746,13 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
|||
/* Create a default view for this window */
|
||||
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
NSView *contentView = [[SDLView alloc] initWithFrame:rect];
|
||||
|
||||
if ((window->flags & SDL_WINDOW_ALLOW_HIGHDPI) > 0) {
|
||||
if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
|
||||
[contentView setWantsBestResolutionOpenGLSurface:YES];
|
||||
}
|
||||
}
|
||||
|
||||
[nswindow setContentView: contentView];
|
||||
[contentView release];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue