#include "OSXUtils.hpp"

#include "common/debug.h"

#import <Cocoa/Cocoa.h>

namespace sw
{
namespace OSX
{
	bool IsValidWindow(EGLNativeWindowType window)
	{
		NSObject *object = reinterpret_cast<NSObject*>(window);
		return window && ([object isKindOfClass:[NSView class]] || [object isKindOfClass:[CALayer class]]);
	}

	void GetNativeWindowSize(EGLNativeWindowType window, int &width, int &height)
	{
		NSObject *object = reinterpret_cast<NSObject*>(window);

		if([object isKindOfClass:[NSView class]])
		{
			NSView *view = reinterpret_cast<NSView*>(object);
			width = [view bounds].size.width;
			height = [view bounds].size.height;
		}
		else if([object isKindOfClass:[CALayer class]])
		{
			CALayer *layer = reinterpret_cast<CALayer*>(object);
			width = CGRectGetWidth([layer frame]);
			height = CGRectGetHeight([layer frame]);
		}
		else UNREACHABLE(0);
	}
}
}

#include "OSXUtils.hpp"

#include "common/debug.h"

#import <Cocoa/Cocoa.h>

namespace sw
{
namespace OSX
{
	bool IsValidWindow(EGLNativeWindowType window)
	{
		NSObject *object = reinterpret_cast<NSObject*>(window);
		return window && ([object isKindOfClass:[NSView class]] || [object isKindOfClass:[CALayer class]]);
	}

	void GetNativeWindowSize(EGLNativeWindowType window, int &width, int &height)
	{
		NSObject *object = reinterpret_cast<NSObject*>(window);

		if([object isKindOfClass:[NSView class]])
		{
			NSView *view = reinterpret_cast<NSView*>(object);
			width = [view convertRectToBacking:[view bounds]].size.width;
			height = [view convertRectToBacking:[view bounds]].size.height;
		}
		else if([object isKindOfClass:[CALayer class]])
		{
			CALayer *layer = reinterpret_cast<CALayer*>(object);
			width = [layer bounds].size.width * layer.contentsScale;
			height = [layer bounds].size.height * layer.contentsScale;
		}
		else UNREACHABLE(0);
	}
}
}

Fix OSX retina display support.
Fix OSX retina display support.

Change-Id: I712b089c36e9c696c44a8d99a3d21819798a6142
Reviewed-on: https://swiftshader-review.googlesource.com/4430
Reviewed-by: Nicolas Capens <0612353e1fcebbfd4b302d9337447ca0cdfa9122@google.com>
Tested-by: Nicolas Capens <0612353e1fcebbfd4b302d9337447ca0cdfa9122@google.com>
