Skip to content

Commit

Permalink
GLInterface::AGL: refactor some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ligfx committed Apr 16, 2017
1 parent 5298328 commit f48e30f
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions Source/Core/Common/GL/GLInterface/AGL.mm
Expand Up @@ -5,6 +5,45 @@
#include "Common/GL/GLInterface/AGL.h"
#include "Common/Logging/Log.h"

static bool DimensionsWereUpdated(NSView* view, u32* width, u32* height)
{
NSWindow* window = [view window];
NSSize size = [view frame].size;

float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;

if (*width == size.width && *height == size.height)
return false;

*width = size.width;
*height = size.height;

return true;
}

static bool AttachContextToView(NSOpenGLContext* context, NSView* view, u32* width, u32* height)
{
// Enable high-resolution display support.
[view setWantsBestResolutionOpenGLSurface:YES];

NSWindow* window = [view window];
if (window == nil)
{
ERROR_LOG(VIDEO, "failed to create window");
return false;
}

(void)DimensionsWereUpdated(view, width, height);

[window makeFirstResponder:view];
[context setView:view];
[window makeKeyAndOrderFront:nil];

return true;
}

void cInterfaceAGL::Swap()
{
[cocoaCtx flushBuffer];
Expand Down Expand Up @@ -33,36 +72,11 @@
return false;
}

if (window_handle)
{
cocoaWin = reinterpret_cast<NSView*>(window_handle);
NSSize size = [cocoaWin frame].size;

// Enable high-resolution display support.
[cocoaWin setWantsBestResolutionOpenGLSurface:YES];

NSWindow* window = [cocoaWin window];

float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;

// Control window size and picture scaling
s_backbuffer_width = size.width;
s_backbuffer_height = size.height;

if (cocoaWin == nil)
{
ERROR_LOG(VIDEO, "failed to create window");
return false;
}
if (!window_handle)
return true;

[window makeFirstResponder:cocoaWin];
[cocoaCtx setView:cocoaWin];
[window makeKeyAndOrderFront:nil];
}

return true;
cocoaWin = static_cast<NSView*>(window_handle);
return AttachContextToView(cocoaCtx, cocoaWin, &s_backbuffer_width, &s_backbuffer_height);
}

bool cInterfaceAGL::MakeCurrent()
Expand All @@ -87,23 +101,11 @@

void cInterfaceAGL::Update()
{
if (cocoaWin)
{
NSWindow* window = [cocoaWin window];
NSSize size = [cocoaWin frame].size;

float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;

if (s_backbuffer_width == size.width && s_backbuffer_height == size.height)
return;

s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
}
if (!cocoaWin)
return;

[cocoaCtx update];
if (DimensionsWereUpdated(cocoaWin, &s_backbuffer_width, &s_backbuffer_height))
[cocoaCtx update];
}

void cInterfaceAGL::SwapInterval(int interval)
Expand Down

0 comments on commit f48e30f

Please sign in to comment.