Cocoa Port: Bring back NSOpenGLContext for Macs running macOS 10.7 Lion or earlier.

Also do some misc. backwards compatibility fixes.
This commit is contained in:
rogerman 2017-01-11 17:56:21 -08:00
parent 07a68dbb7a
commit 3af5423387
5 changed files with 98 additions and 23 deletions

View File

@ -40,6 +40,7 @@ class OGLVideoOutput;
InputManager *inputManager;
CocoaDSDisplayVideo *cdsVideoOutput;
CALayer *localLayer;
NSOpenGLContext *localOGLContext;
}
@property (retain) InputManager *inputManager;

View File

@ -27,7 +27,11 @@
#import "cocoa_util.h"
#include "MacOGLDisplayView.h"
/*
#if defined(MAC_OS_X_VERSION_10_11) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11)
#include "MacMetalDisplayView.h"
#endif
*/
#include <Carbon/Carbon.h>
#if defined(__ppc__) || defined(__ppc64__)
@ -1599,26 +1603,46 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
return self;
}
#if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
if ([self respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)])
{
[self setWantsBestResolutionOpenGLSurface:YES];
}
#endif
inputManager = nil;
cdsVideoOutput = nil;
/*#if defined(MAC_OS_X_VERSION_10_11) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11)
if (IsOSXVersionSupported(10, 11, 0))
{
localLayer = [[DisplayViewMetalLayer alloc] init];
}
else
#endif*/
{
localLayer = [[DisplayViewOpenGLLayer alloc] init];
MacOGLDisplayView *macOGLCDV = (MacOGLDisplayView *)[(id<DisplayViewCALayer>)localLayer clientDisplay3DView];
if (IsOSXVersionSupported(10, 8, 0))
{
localOGLContext = nil;
macOGLCDV->SetRenderToCALayer(true);
[self setLayer:localLayer];
[self setWantsLayer:YES];
#if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
if ([self respondsToSelector:@selector(setLayerContentsRedrawPolicy:)])
{
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawNever];
}
#endif
}
else
{
localOGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:macOGLCDV->GetContext()];
macOGLCDV->SetRenderToCALayer(false);
}
}
ClientDisplay3DView *cdv = [(id<DisplayViewCALayer>)localLayer clientDisplay3DView];
NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"SourceSansPro-Bold" ofType:@"otf"];
cdv->SetHUDFontUsingPath([fontPath cStringUsingEncoding:NSUTF8StringEncoding]);
[self setLayer:localLayer];
[self setWantsLayer:YES];
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawNever];
return self;
}
@ -1628,6 +1652,12 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
[self setCdsVideoOutput:nil];
[self setLayer:nil];
if (localOGLContext != nil)
{
[localOGLContext clearDrawable];
[localOGLContext release];
}
[localLayer release];
[super dealloc];
@ -1876,6 +1906,16 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
#pragma mark NSView Methods
- (void)lockFocus
{
[super lockFocus];
if ( (localOGLContext != nil) && ([localOGLContext view] != self) )
{
[localOGLContext setView:self];
}
}
- (BOOL)isOpaque
{
return YES;
@ -1886,6 +1926,7 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
return NO;
}
#if defined(MAC_OS_X_VERSION_10_8) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8)
- (BOOL)wantsUpdateLayer
{
return YES;
@ -1896,6 +1937,7 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
ClientDisplay3DView *cdv = [(id<DisplayViewCALayer>)localLayer clientDisplay3DView];
cdv->UpdateView();
}
#endif
- (void)drawRect:(NSRect)dirtyRect
{
@ -1910,16 +1952,22 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
if (rect.size.width != oldFrame.size.width || rect.size.height != oldFrame.size.height)
{
if (localOGLContext != nil)
{
[localOGLContext update];
}
DisplayWindowController *windowController = (DisplayWindowController *)[[self window] delegate];
ClientDisplayViewProperties &props = [windowController localViewProperties];
NSRect newViewportRect = rect;
#if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
const NSRect newViewportRect = [self convertRectToBacking:rect];
#else
const NSRect newViewportRect = rect;
if ([self respondsToSelector:@selector(convertRectToBacking:)])
{
newViewportRect = [self convertRectToBacking:rect];
}
#endif
ClientDisplayViewProperties &props = [windowController localViewProperties];
// Calculate the view scale for the given client size.
double checkWidth = props.normalWidth;
double checkHeight = props.normalHeight;

View File

@ -44,6 +44,7 @@ class MacOGLDisplayView : public OGLVideoOutput, public DisplayViewCALayerInterf
protected:
CGLPixelFormatObj _pixelFormat;
CGLContextObj _context;
bool _willRenderToCALayer;
void _FrameRenderAndFlush();
@ -56,6 +57,9 @@ public:
CGLPixelFormatObj GetPixelFormat() const;
CGLContextObj GetContext() const;
bool GetRenderToCALayer() const;
void SetRenderToCALayer(const bool renderToLayer);
virtual void SetHUDFontUsingPath(const char *filePath);
virtual void SetVideoBuffers(const uint32_t colorFormat,

View File

@ -152,6 +152,8 @@ MacOGLDisplayView::MacOGLDisplayView()
}
CGLSetCurrentContext(prevContext);
_willRenderToCALayer = false;
}
void MacOGLDisplayView::Init()
@ -163,9 +165,17 @@ void MacOGLDisplayView::Init()
}
void MacOGLDisplayView::_FrameRenderAndFlush()
{
if (this->_willRenderToCALayer)
{
this->CALayerDisplay();
}
else
{
this->FrameRender();
CGLFlushDrawable(this->_context);
}
}
CGLPixelFormatObj MacOGLDisplayView::GetPixelFormat() const
{
@ -177,6 +187,16 @@ CGLContextObj MacOGLDisplayView::GetContext() const
return this->_context;
}
bool MacOGLDisplayView::GetRenderToCALayer() const
{
return this->_willRenderToCALayer;
}
void MacOGLDisplayView::SetRenderToCALayer(const bool renderToLayer)
{
this->_willRenderToCALayer = renderToLayer;
}
void MacOGLDisplayView::SetHUDFontUsingPath(const char *filePath)
{
CGLLockContext(this->_context);

View File

@ -1,6 +1,6 @@
/*
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012-2015 DeSmuME Team
Copyright (C) 2012-2017 DeSmuME Team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -98,10 +98,12 @@
CGLContextObj prevContext = CGLGetCurrentContext();
CGLSetCurrentContext(cglDisplayContext);
NSRect newViewportRect = frameRect;
#if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
const NSRect newViewportRect = [self convertRectToBacking:frameRect];
#else
const NSRect newViewportRect = frameRect;
if ([self respondsToSelector:@selector(convertRectToBacking:)])
{
newViewportRect = [self convertRectToBacking:frameRect];
}
#endif
OGLContextInfo *contextInfo = NULL;