1 | /** @file
|
---|
2 | * VirtualBox OpenGL Cocoa Window System implementation
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2009-2012 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include <OpenGL/OpenGL.h>
|
---|
18 |
|
---|
19 | #include "renderspu.h"
|
---|
20 | #include <iprt/process.h>
|
---|
21 | #include <iprt/string.h>
|
---|
22 | #include <iprt/path.h>
|
---|
23 |
|
---|
24 | GLboolean renderspu_SystemInitVisual(VisualInfo *pVisInfo)
|
---|
25 | {
|
---|
26 | CRASSERT(pVisInfo);
|
---|
27 |
|
---|
28 | /* cocoaGLVisualCreate(&pCtxInfo->context);*/
|
---|
29 |
|
---|
30 | return GL_TRUE;
|
---|
31 | }
|
---|
32 |
|
---|
33 | GLboolean renderspu_SystemCreateContext(VisualInfo *pVisInfo, ContextInfo *pCtxInfo, ContextInfo *pSharedCtxInfo)
|
---|
34 | {
|
---|
35 | CRASSERT(pVisInfo);
|
---|
36 | CRASSERT(pCtxInfo);
|
---|
37 |
|
---|
38 | pCtxInfo->currentWindow = NULL;
|
---|
39 |
|
---|
40 | cocoaGLCtxCreate(&pCtxInfo->context, pVisInfo->visAttribs, pSharedCtxInfo ? pSharedCtxInfo->context : NULL);
|
---|
41 |
|
---|
42 | return GL_TRUE;
|
---|
43 | }
|
---|
44 |
|
---|
45 | void renderspu_SystemDestroyContext(ContextInfo *pCtxInfo)
|
---|
46 | {
|
---|
47 | if(!pCtxInfo)
|
---|
48 | return;
|
---|
49 |
|
---|
50 | if(pCtxInfo->context)
|
---|
51 | {
|
---|
52 | cocoaGLCtxDestroy(pCtxInfo->context);
|
---|
53 | pCtxInfo->context = NULL;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | void renderspuFullscreen(WindowInfo *pWinInfo, GLboolean fFullscreen)
|
---|
58 | {
|
---|
59 | /* Real fullscreen isn't supported by VirtualBox */
|
---|
60 | }
|
---|
61 |
|
---|
62 | GLboolean renderspu_SystemVBoxCreateWindow(VisualInfo *pVisInfo, GLboolean fShowIt, WindowInfo *pWinInfo)
|
---|
63 | {
|
---|
64 | CRASSERT(pVisInfo);
|
---|
65 | CRASSERT(pWinInfo);
|
---|
66 |
|
---|
67 | /* VirtualBox is the only frontend which support 3D right now. */
|
---|
68 | char pszName[256];
|
---|
69 | if (RTProcGetExecutablePath(pszName, sizeof(pszName)))
|
---|
70 | /* Check for VirtualBox and VirtualBoxVM */
|
---|
71 | if (RTStrNICmp(RTPathFilename(pszName), "VirtualBox", 10) != 0)
|
---|
72 | return GL_FALSE;
|
---|
73 |
|
---|
74 | pWinInfo->visual = pVisInfo;
|
---|
75 | pWinInfo->window = NULL;
|
---|
76 | pWinInfo->nativeWindow = NULL;
|
---|
77 | pWinInfo->currentCtx = NULL;
|
---|
78 |
|
---|
79 | #ifdef __LP64__
|
---|
80 | NativeNSViewRef pParentWin = (NativeNSViewRef)render_spu_parent_window_id;
|
---|
81 | #else /* __LP64__ */
|
---|
82 | NativeNSViewRef pParentWin = (NativeNSViewRef)(uint32_t)render_spu_parent_window_id;
|
---|
83 | #endif /* __LP64__ */
|
---|
84 |
|
---|
85 | cocoaViewCreate(&pWinInfo->window, pWinInfo, pParentWin, pVisInfo->visAttribs);
|
---|
86 |
|
---|
87 | if (fShowIt)
|
---|
88 | renderspu_SystemShowWindow(pWinInfo, fShowIt);
|
---|
89 |
|
---|
90 | return GL_TRUE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | void renderspu_SystemReparentWindow(WindowInfo *pWinInfo)
|
---|
94 | {
|
---|
95 | #ifdef __LP64__
|
---|
96 | NativeNSViewRef pParentWin = (NativeNSViewRef)render_spu_parent_window_id;
|
---|
97 | #else /* __LP64__ */
|
---|
98 | NativeNSViewRef pParentWin = (NativeNSViewRef)(uint32_t)render_spu_parent_window_id;
|
---|
99 | #endif /* __LP64__ */
|
---|
100 | cocoaViewReparent(pWinInfo->window, pParentWin);
|
---|
101 | }
|
---|
102 |
|
---|
103 | void renderspu_SystemDestroyWindow(WindowInfo *pWinInfo)
|
---|
104 | {
|
---|
105 | CRASSERT(pWinInfo);
|
---|
106 |
|
---|
107 | cocoaViewDestroy(pWinInfo->window);
|
---|
108 | }
|
---|
109 |
|
---|
110 | void renderspu_SystemWindowPosition(WindowInfo *pWinInfo, GLint x, GLint y)
|
---|
111 | {
|
---|
112 | CRASSERT(pWinInfo);
|
---|
113 |
|
---|
114 | #ifdef __LP64__
|
---|
115 | NativeNSViewRef pParentWin = (NativeNSViewRef)render_spu_parent_window_id;
|
---|
116 | #else /* __LP64__ */
|
---|
117 | NativeNSViewRef pParentWin = (NativeNSViewRef)(uint32_t)render_spu_parent_window_id;
|
---|
118 | #endif /* __LP64__ */
|
---|
119 |
|
---|
120 | /*pParentWin is unused in the call, otherwise it might hold incorrect value if for ex. last reparent call was for
|
---|
121 | a different screen*/
|
---|
122 | cocoaViewSetPosition(pWinInfo->window, pParentWin, x, y);
|
---|
123 | }
|
---|
124 |
|
---|
125 | void renderspu_SystemWindowSize(WindowInfo *pWinInfo, GLint w, GLint h)
|
---|
126 | {
|
---|
127 | CRASSERT(pWinInfo);
|
---|
128 |
|
---|
129 | cocoaViewSetSize(pWinInfo->window, w, h);
|
---|
130 | }
|
---|
131 |
|
---|
132 | void renderspu_SystemGetWindowGeometry(WindowInfo *pWinInfo, GLint *pX, GLint *pY, GLint *pW, GLint *pH)
|
---|
133 | {
|
---|
134 | CRASSERT(pWinInfo);
|
---|
135 |
|
---|
136 | cocoaViewGetGeometry(pWinInfo->window, pX, pY, pW, pH);
|
---|
137 | }
|
---|
138 |
|
---|
139 | void renderspu_SystemGetMaxWindowSize(WindowInfo *pWinInfo, GLint *pW, GLint *pH)
|
---|
140 | {
|
---|
141 | CRASSERT(pWinInfo);
|
---|
142 |
|
---|
143 | *pW = 10000;
|
---|
144 | *pH = 10000;
|
---|
145 | }
|
---|
146 |
|
---|
147 | void renderspu_SystemShowWindow(WindowInfo *pWinInfo, GLboolean fShowIt)
|
---|
148 | {
|
---|
149 | CRASSERT(pWinInfo);
|
---|
150 |
|
---|
151 | cocoaViewShow(pWinInfo->window, fShowIt);
|
---|
152 | }
|
---|
153 |
|
---|
154 | void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry )
|
---|
155 | {
|
---|
156 | cocoaViewPresentComposition(window->window, pCompositor, pChangedEntry);
|
---|
157 | }
|
---|
158 |
|
---|
159 | void renderspu_SystemMakeCurrent(WindowInfo *pWinInfo, GLint nativeWindow, ContextInfo *pCtxInfo)
|
---|
160 | {
|
---|
161 | /* if(pWinInfo->visual != pCtxInfo->visual)*/
|
---|
162 | /* printf ("visual mismatch .....................\n");*/
|
---|
163 |
|
---|
164 | nativeWindow = 0;
|
---|
165 |
|
---|
166 | if (pWinInfo && pCtxInfo)
|
---|
167 | cocoaViewMakeCurrentContext(pWinInfo->window, pCtxInfo->context);
|
---|
168 | else
|
---|
169 | cocoaViewMakeCurrentContext(NULL, NULL);
|
---|
170 | }
|
---|
171 |
|
---|
172 | void renderspu_SystemSwapBuffers(WindowInfo *pWinInfo, GLint flags)
|
---|
173 | {
|
---|
174 | CRASSERT(pWinInfo);
|
---|
175 |
|
---|
176 | cocoaViewDisplay(pWinInfo->window);
|
---|
177 | }
|
---|
178 |
|
---|
179 | void renderspu_SystemWindowVisibleRegion(WindowInfo *pWinInfo, GLint cRects, GLint* paRects)
|
---|
180 | {
|
---|
181 | CRASSERT(pWinInfo);
|
---|
182 |
|
---|
183 | cocoaViewSetVisibleRegion(pWinInfo->window, cRects, paRects);
|
---|
184 | }
|
---|
185 |
|
---|
186 | void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *paRects)
|
---|
187 | {
|
---|
188 | }
|
---|
189 |
|
---|
190 | void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *pWinInfo)
|
---|
191 | {
|
---|
192 | }
|
---|