1/* 2* Copyright (C) 2011 The Android Open Source Project 3* 4* Licensed under the Apache License, Version 2.0 (the "License"); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an "AS IS" BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15*/ 16#include "NativeSubWindow.h" 17#include <Cocoa/Cocoa.h> 18 19/* 20 * EmuGLView inherit from NSView and override the isOpaque 21 * method to return YES. That prevents drawing of underlying window/view 22 * when the view needs to be redrawn. 23 */ 24@interface EmuGLView : NSView { 25} @end 26 27@implementation EmuGLView 28 29 - (BOOL)isOpaque { 30 return YES; 31 } 32 33@end 34 35 36EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, 37 EGLNativeDisplayType* display_out, 38 int x, int y,int width, int height){ 39 NSWindow *win = (NSWindow *)p_window; 40 if (!win) { 41 return NULL; 42 } 43 44 /* (x,y) assume an upper-left origin, but Cocoa uses a lower-left origin */ 45 NSRect content_rect = [win contentRectForFrameRect:[win frame]]; 46 int cocoa_y = (int)content_rect.size.height - (y + height); 47 NSRect contentRect = NSMakeRect(x, cocoa_y, width, height); 48 49 NSView *glView = [[EmuGLView alloc] initWithFrame:contentRect]; 50 if (glView) { 51 [[win contentView] addSubview:glView]; 52 [win makeKeyAndOrderFront:nil]; 53 } 54 55 return (EGLNativeWindowType)glView; 56} 57 58void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){ 59 if(win){ 60 NSView *glView = (NSView *)win; 61 [glView removeFromSuperview]; 62 [glView release]; 63 } 64} 65