Cocoa Port: Fix some bugs with HUD font loading and HUD rendering on Retina displays.

This commit is contained in:
rogerman 2017-01-15 21:45:26 -08:00
parent 6756f41bdb
commit 25c0232673
7 changed files with 61 additions and 28 deletions

View File

@ -174,15 +174,15 @@ double ClientDisplayView::GetScaleFactor() const
void ClientDisplayView::SetScaleFactor(const double scaleFactor)
{
const bool willChangeScaleFactor = (this->_scaleFactor != scaleFactor);
this->_scaleFactor = scaleFactor;
const bool willChangeScaleFactor = (this->_scaleFactor != scaleFactor);
if (willChangeScaleFactor)
{
this->_glyphTileSize = (double)HUD_TEXTBOX_BASEGLYPHSIZE * scaleFactor;
this->_glyphSize = (double)this->_glyphTileSize * 0.75;
this->SetHUDFontUsingPath(this->_lastFontFilePath);
this->LoadHUDFont();
}
}
@ -321,9 +321,19 @@ void ClientDisplayView::SetPixelScaler(const VideoFilterTypeID filterID)
}
// HUD appearance
void ClientDisplayView::SetHUDFontUsingPath(const char *filePath)
const char* ClientDisplayView::GetHUDFontPath() const
{
if (filePath == NULL)
return this->_lastFontFilePath;
}
void ClientDisplayView::SetHUDFontPath(const char *filePath)
{
this->_lastFontFilePath = filePath;
}
void ClientDisplayView::LoadHUDFont()
{
if (this->_lastFontFilePath == NULL)
{
return;
}
@ -331,22 +341,21 @@ void ClientDisplayView::SetHUDFontUsingPath(const char *filePath)
FT_Face fontFace;
FT_Error error = FT_Err_Ok;
error = FT_New_Face(this->_ftLibrary, filePath, 0, &fontFace);
error = FT_New_Face(this->_ftLibrary, this->_lastFontFilePath, 0, &fontFace);
if (error == FT_Err_Unknown_File_Format)
{
printf("ClientDisplayView: FreeType failed to load font face because it is in an unknown format from:\n%s\n", filePath);
printf("ClientDisplayView: FreeType failed to load font face because it is in an unknown format from:\n%s\n", this->_lastFontFilePath);
return;
}
else if (error)
{
printf("ClientDisplayView: FreeType failed to load font face with an unknown error from:\n%s\n", filePath);
printf("ClientDisplayView: FreeType failed to load font face with an unknown error from:\n%s\n", this->_lastFontFilePath);
return;
}
this->CopyHUDFont(fontFace, this->_glyphSize, this->_glyphTileSize, this->_glyphInfo);
FT_Done_Face(fontFace);
this->_lastFontFilePath = filePath;
}
void ClientDisplayView::CopyHUDFont(const FT_Face &fontFace, const size_t glyphSize, const size_t glyphTileSize, GlyphInfo *glyphInfo)
@ -445,6 +454,17 @@ void ClientDisplayView::SetHUDShowRTC(const bool visibleState)
this->_SetHUDShowInfoItem(this->_showRTC, visibleState);
}
// NDS GPU Interface
void ClientDisplayView::FrameProcessGPU()
{
// Do nothing. This is implementation dependent.
}
void ClientDisplayView::FrameProcessHUD()
{
// Do nothing. This is implementation dependent.
}
// Touch screen input handling
void ClientDisplayView::GetNDSPoint(const int inputID, const bool isInitialTouchPress,
const double clientX, const double clientY,
@ -908,6 +928,8 @@ void ClientDisplay3DView::SetHUDVertices(float viewportWidth, float viewportHeig
textBoxScale = HUD_TEXTBOX_BASE_SCALE * HUD_TEXTBOX_MIN_SCALE;
}
textBoxScale /= this->_scaleFactor;
float boxOffset = 8.0f * HUD_TEXTBOX_BASE_SCALE * this->_hudObjectScale;
if (boxOffset < 1.0f)
{

View File

@ -182,7 +182,9 @@ public:
virtual void SetPixelScaler(const VideoFilterTypeID filterID);
// HUD appearance
virtual void SetHUDFontUsingPath(const char *filePath);
const char* GetHUDFontPath() const;
void SetHUDFontPath(const char *filePath);
virtual void LoadHUDFont();
virtual void CopyHUDFont(const FT_Face &fontFace, const size_t glyphSize, const size_t glyphTileSize, GlyphInfo *glyphInfo);
virtual void SetHUDInfo(const NDSFrameInfo &frameInfo);
@ -207,8 +209,8 @@ public:
// NDS GPU interface
virtual void FrameLoadGPU(bool isMainSizeNative, bool isTouchSizeNative) = 0;
virtual void FrameProcessGPU() = 0;
virtual void FrameProcessHUD() = 0;
virtual void FrameProcessGPU();
virtual void FrameProcessHUD();
virtual void FrameRender() = 0;
virtual void FrameFinish() = 0;
@ -261,7 +263,7 @@ public:
const void *nativeBuffer0,
const void *nativeBuffer1,
const void *customBuffer0, const size_t customWidth0, const size_t customHeight0,
const void *customBuffer1, const size_t customWidth1, const size_t customHeight1) = 0;
const void *customBuffer1, const size_t customWidth1, const size_t customHeight1);
void SetHUDVertices(float viewportWidth, float viewportHeight, float *vtxBufferPtr);
void SetHUDTextureCoordinates(float *texCoordBufferPtr);

View File

@ -6407,7 +6407,7 @@ void OGLHUDLayer::RenderOGL()
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
// Next, draw each character inside the box.
const GLfloat textBoxScale = (GLfloat)HUD_TEXTBOX_BASE_SCALE * this->_output->GetHUDObjectScale();
const GLfloat textBoxScale = (GLfloat)HUD_TEXTBOX_BASE_SCALE * this->_output->GetHUDObjectScale() / this->_output->GetScaleFactor();
if (textBoxScale >= (2.0/3.0))
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

View File

@ -95,7 +95,7 @@ class OGLVideoOutput;
BOOL _isMinSizeNormal;
NSUInteger _statusBarHeight;
BOOL _isUpdatingDisplayScaleValueOnly;
BOOL _useMavericksFullScreen;
BOOL _canUseMavericksFullScreen;
BOOL _masterStatusBarState;
NSRect _masterWindowFrame;
double _masterWindowScale;

View File

@ -116,7 +116,7 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
_isMinSizeNormal = YES;
_statusBarHeight = WINDOW_STATUS_BAR_HEIGHT;
_isUpdatingDisplayScaleValueOnly = NO;
_useMavericksFullScreen = IsOSXVersionSupported(10, 9, 0);
_canUseMavericksFullScreen = IsOSXVersionSupported(10, 9, 0);
_masterWindowScale = 1.0;
_masterWindowFrame = NSMakeRect(0.0, 0.0, _localViewProps.clientWidth, _localViewProps.clientHeight + _localViewProps.gapDistance);
_masterStatusBarState = NO;
@ -538,17 +538,17 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
- (BOOL) masterStatusBarState
{
return (![self isFullScreen] || !_useMavericksFullScreen) ? [self isShowingStatusBar] : _masterStatusBarState;
return (![self isFullScreen] || !_canUseMavericksFullScreen) ? [self isShowingStatusBar] : _masterStatusBarState;
}
- (NSRect) masterWindowFrame
{
return (![self isFullScreen] || !_useMavericksFullScreen) ? [masterWindow frame] : _masterWindowFrame;
return (![self isFullScreen] || !_canUseMavericksFullScreen) ? [masterWindow frame] : _masterWindowFrame;
}
- (double) masterWindowScale
{
return (![self isFullScreen] || !_useMavericksFullScreen) ? [self displayScale] : _masterWindowScale;
return (![self isFullScreen] || !_canUseMavericksFullScreen) ? [self displayScale] : _masterWindowScale;
}
- (NSRect) updateViewProperties
@ -698,7 +698,7 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
- (void) respondToScreenChange:(NSNotification *)aNotification
{
if (_useMavericksFullScreen)
if (_canUseMavericksFullScreen)
{
return;
}
@ -839,7 +839,7 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
- (IBAction) toggleFullScreenDisplay:(id)sender
{
#if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
if (_useMavericksFullScreen)
if (_canUseMavericksFullScreen)
{
[masterWindow toggleFullScreen:nil];
}
@ -1286,7 +1286,20 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
// Set up the video output thread.
CocoaDSDisplayVideo *newDisplayOutput = [[CocoaDSDisplayVideo alloc] init];
[newDisplayOutput setClientDisplayView:[view clientDisplay3DView]];
[newDisplayOutput setScaleFactor:scaleFactor];
ClientDisplayView *cdv = [newDisplayOutput clientDisplayView];
NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"SourceSansPro-Bold" ofType:@"otf"];
cdv->SetHUDFontPath([fontPath cStringUsingEncoding:NSUTF8StringEncoding]);
if (scaleFactor != 1.0f)
{
[newDisplayOutput setScaleFactor:scaleFactor];
}
else
{
cdv->LoadHUDFont();
}
[newDisplayOutput resetVideoBuffers];
[self setCdsVideoOutput:newDisplayOutput];
[view setCdsVideoOutput:newDisplayOutput];
@ -1645,10 +1658,6 @@ static std::unordered_map<NSScreen *, DisplayWindowController *> _screenMap; //
}
}
ClientDisplay3DView *cdv = [(id<DisplayViewCALayer>)localLayer clientDisplay3DView];
NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"SourceSansPro-Bold" ofType:@"otf"];
cdv->SetHUDFontUsingPath([fontPath cStringUsingEncoding:NSUTF8StringEncoding]);
return self;
}

View File

@ -60,7 +60,7 @@ public:
bool GetRenderToCALayer() const;
void SetRenderToCALayer(const bool renderToLayer);
virtual void SetHUDFontUsingPath(const char *filePath);
virtual void LoadHUDFont();
virtual void SetVideoBuffers(const uint32_t colorFormat,
const void *videoBufferHead,

View File

@ -197,11 +197,11 @@ void MacOGLDisplayView::SetRenderToCALayer(const bool renderToLayer)
this->_willRenderToCALayer = renderToLayer;
}
void MacOGLDisplayView::SetHUDFontUsingPath(const char *filePath)
void MacOGLDisplayView::LoadHUDFont()
{
CGLLockContext(this->_context);
CGLSetCurrentContext(this->_context);
this->OGLVideoOutput::SetHUDFontUsingPath(filePath);
this->OGLVideoOutput::LoadHUDFont();
CGLUnlockContext(this->_context);
}