1// Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15#include "OSXUtils.hpp" 16 17#include "common/debug.h" 18 19#import <Cocoa/Cocoa.h> 20 21namespace sw 22{ 23namespace OSX 24{ 25 bool IsValidWindow(EGLNativeWindowType window) 26 { 27 NSObject *object = reinterpret_cast<NSObject*>(window); 28 return window && ([object isKindOfClass:[NSView class]] || [object isKindOfClass:[CALayer class]]); 29 } 30 31 void GetNativeWindowSize(EGLNativeWindowType window, int &width, int &height) 32 { 33 NSObject *object = reinterpret_cast<NSObject*>(window); 34 35 if([object isKindOfClass:[NSView class]]) 36 { 37 NSView *view = reinterpret_cast<NSView*>(object); 38 width = [view convertRectToBacking:[view bounds]].size.width; 39 height = [view convertRectToBacking:[view bounds]].size.height; 40 } 41 else if([object isKindOfClass:[CALayer class]]) 42 { 43 CALayer *layer = reinterpret_cast<CALayer*>(object); 44 width = [layer bounds].size.width * layer.contentsScale; 45 height = [layer bounds].size.height * layer.contentsScale; 46 } 47 else UNREACHABLE(0); 48 } 49} 50} 51