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 36 EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, 37 EGLNativeDisplayType* display_out, 38 int x, int y,int width, int height){ 39 NSRect contentRect = NSMakeRect(x, y, width, height); 40 NSView *glView = [[EmuGLView alloc] initWithFrame:contentRect]; 41 if (glView) { 42 NSWindow *win = (NSWindow *)p_window; 43 [[win contentView] addSubview:glView]; 44 [win makeKeyAndOrderFront:nil]; 45 } 46 47 return (EGLNativeWindowType)glView; 48 } 49 50 void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){ 51 if(win){ 52 NSView *glView = (NSView *)win; 53 [glView removeFromSuperview]; 54 [glView release]; 55 } 56 } 57