• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
35EGLNativeWindowType createSubWindow(FBNativeWindowType p_window,
36                                    int x,
37                                    int y,
38                                    int width,
39                                    int height,
40                                    SubWindowRepaintCallback repaint_callback,
41                                    void* repaint_callback_param,
42                                    int hideWindow) {
43    NSWindow* win = (NSWindow *)p_window;
44    if (!win) {
45        return NULL;
46    }
47
48    /* (x,y) assume an upper-left origin, but Cocoa uses a lower-left origin */
49    NSRect content_rect = [win contentRectForFrameRect:[win frame]];
50    int cocoa_y = (int)content_rect.size.height - (y + height);
51    NSRect contentRect = NSMakeRect(x, cocoa_y, width, height);
52
53    NSView *glView = [[EmuGLView alloc] initWithFrame:contentRect];
54    if (glView) {
55        [glView setWantsBestResolutionOpenGLSurface:YES];
56        [[win contentView] addSubview:glView];
57        [win makeKeyAndOrderFront:nil];
58        if (hideWindow) {
59            [glView setHidden:YES];
60        }
61    }
62
63    return (EGLNativeWindowType)glView;
64}
65
66void destroySubWindow(EGLNativeWindowType win) {
67    if(win){
68        NSView *glView = (NSView *)win;
69        [glView removeFromSuperview];
70        [glView release];
71    }
72}
73
74int moveSubWindow(FBNativeWindowType p_parent_window,
75                  EGLNativeWindowType p_sub_window,
76                  int x,
77                  int y,
78                  int width,
79                  int height) {
80    NSWindow *win = (NSWindow *)p_parent_window;
81    if (!win) {
82        return 0;
83    }
84
85    NSView *glView = (NSView *)p_sub_window;
86    if (!glView) {
87        return 0;
88    }
89
90    /* The view must be removed from the hierarchy to be properly resized */
91    [glView removeFromSuperview];
92
93    /* (x,y) assume an upper-left origin, but Cocoa uses a lower-left origin */
94    NSRect content_rect = [win contentRectForFrameRect:[win frame]];
95    int cocoa_y = (int)content_rect.size.height - (y + height);
96    NSRect newFrame = NSMakeRect(x, cocoa_y, width, height);
97    [glView setFrame:newFrame];
98
99    /* Re-add the sub-window to the view hierarchy */
100    [[win contentView] addSubview:glView];
101
102    return 1;
103}
104