| | |
| | | /* This should only be called on the thread on which a user is using the context. */ |
| | | - (void)updateIfNeeded |
| | | { |
| | | int value = SDL_AtomicSet(&self->dirty, 0); |
| | | const int value = SDL_AtomicSet(&self->dirty, 0); |
| | | if (value > 0) { |
| | | /* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */ |
| | | [super update]; |
| | | [self explicitUpdate]; |
| | | } |
| | | } |
| | | |
| | |
| | | SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata; |
| | | NSView *contentview = windowdata->sdlContentView; |
| | | |
| | | /* This should never be nil since sdlContentView is only nil if the |
| | | window was created via SDL_CreateWindowFrom, and SDL doesn't allow |
| | | OpenGL contexts to be created in that case. However, it doesn't hurt |
| | | to check. */ |
| | | if (contentview == nil) { |
| | | /* Prefer to access the cached content view above instead of this, |
| | | since as of Xcode 11 + SDK 10.15, [window contentView] causes |
| | | Apple's Main Thread Checker to output a warning. */ |
| | | contentview = [windowdata->nswindow contentView]; |
| | | } |
| | | |
| | | /* Now sign up for scheduled updates for the new window. */ |
| | | NSMutableArray *contexts = windowdata->nscontexts; |
| | | @synchronized (contexts) { |
| | |
| | | } |
| | | |
| | | if ([self view] != contentview) { |
| | | [self setView:contentview]; |
| | | if ([NSThread isMainThread]) { |
| | | [self setView:contentview]; |
| | | } else { |
| | | dispatch_sync(dispatch_get_main_queue(), ^{ [self setView:contentview]; }); |
| | | } |
| | | if (self == [NSOpenGLContext currentContext]) { |
| | | [self update]; |
| | | [self explicitUpdate]; |
| | | } else { |
| | | [self scheduleUpdate]; |
| | | } |
| | |
| | | } else { |
| | | [self clearDrawable]; |
| | | if (self == [NSOpenGLContext currentContext]) { |
| | | [self update]; |
| | | [self explicitUpdate]; |
| | | } else { |
| | | [self scheduleUpdate]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | - (SDL_Window*)window |
| | | { |
| | | return self->window; |
| | | } |
| | | |
| | | - (void)explicitUpdate |
| | | { |
| | | if ([NSThread isMainThread]) { |
| | | [super update]; |
| | | } else { |
| | | dispatch_sync(dispatch_get_main_queue(), ^{ [super update]; }); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | if (context) { |
| | | SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context; |
| | | [nscontext setWindow:window]; |
| | | [nscontext updateIfNeeded]; |
| | | if ([nscontext window] != window) { |
| | | [nscontext setWindow:window]; |
| | | [nscontext updateIfNeeded]; |
| | | } |
| | | [nscontext makeCurrentContext]; |
| | | } else { |
| | | [NSOpenGLContext clearCurrentContext]; |
| | |
| | | Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h) |
| | | { |
| | | SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; |
| | | NSView *contentView = [windata->nswindow contentView]; |
| | | NSView *contentView = windata->sdlContentView; |
| | | NSRect viewport = [contentView bounds]; |
| | | |
| | | if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { |