VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_cocoa.c@ 48521

Last change on this file since 48521 was 48291, checked in by vboxsync, 11 years ago

crOpenGL: fix OSX win8.1 rendering

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
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
24GLboolean renderspu_SystemInitVisual(VisualInfo *pVisInfo)
25{
26 CRASSERT(pVisInfo);
27
28/* cocoaGLVisualCreate(&pCtxInfo->context);*/
29
30 return GL_TRUE;
31}
32
33GLboolean 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
45void 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
57void renderspuFullscreen(WindowInfo *pWinInfo, GLboolean fFullscreen)
58{
59 /* Real fullscreen isn't supported by VirtualBox */
60}
61
62GLboolean 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
93void 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
103void renderspu_SystemDestroyWindow(WindowInfo *pWinInfo)
104{
105 CRASSERT(pWinInfo);
106
107 cocoaViewDestroy(pWinInfo->window);
108}
109
110void 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
125void renderspu_SystemWindowSize(WindowInfo *pWinInfo, GLint w, GLint h)
126{
127 CRASSERT(pWinInfo);
128
129 cocoaViewSetSize(pWinInfo->window, w, h);
130}
131
132void 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
139void renderspu_SystemGetMaxWindowSize(WindowInfo *pWinInfo, GLint *pW, GLint *pH)
140{
141 CRASSERT(pWinInfo);
142
143 *pW = 10000;
144 *pH = 10000;
145}
146
147void renderspu_SystemShowWindow(WindowInfo *pWinInfo, GLboolean fShowIt)
148{
149 CRASSERT(pWinInfo);
150
151 cocoaViewShow(pWinInfo->window, fShowIt);
152}
153
154void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry )
155{
156 cocoaViewPresentComposition(window->window, pChangedEntry);
157}
158
159void 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
172void renderspu_SystemSwapBuffers(WindowInfo *pWinInfo, GLint flags)
173{
174 CRASSERT(pWinInfo);
175
176 cocoaViewDisplay(pWinInfo->window);
177}
178
179void renderspu_SystemWindowVisibleRegion(WindowInfo *pWinInfo, GLint cRects, const GLint* paRects)
180{
181 CRASSERT(pWinInfo);
182
183 cocoaViewSetVisibleRegion(pWinInfo->window, cRects, paRects);
184}
185
186void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *pWinInfo)
187{
188}
189
190int renderspu_SystemInit()
191{
192 return VINF_SUCCESS;
193}
194
195int renderspu_SystemTerm()
196{
197 CrGlslTerm(&render_spu.GlobalShaders);
198 return VINF_SUCCESS;
199}
200
201typedef struct CR_RENDER_CTX_INFO
202{
203 ContextInfo * pContext;
204 WindowInfo * pWindow;
205} CR_RENDER_CTX_INFO;
206
207void renderspuCtxInfoInitCurrent(CR_RENDER_CTX_INFO *pInfo)
208{
209 GET_CONTEXT(pCurCtx);
210 pInfo->pContext = pCurCtx;
211 pInfo->pWindow = pCurCtx->currentWindow;
212}
213
214void renderspuCtxInfoRestoreCurrent(CR_RENDER_CTX_INFO *pInfo)
215{
216 GET_CONTEXT(pCurCtx);
217 if (pCurCtx == pInfo->pContext && (!pCurCtx || pCurCtx->currentWindow == pInfo->pWindow))
218 return;
219 renderspuPerformMakeCurrent(pInfo->pWindow, 0, pInfo->pContext);
220}
221
222GLboolean renderspuCtxSetCurrentWithAnyWindow(ContextInfo * pContext, CR_RENDER_CTX_INFO *pInfo)
223{
224 WindowInfo * window;
225 renderspuCtxInfoInitCurrent(pInfo);
226
227 if (pInfo->pContext == pContext)
228 return GL_TRUE;
229
230 window = pContext->currentWindow;
231 if (!window)
232 {
233 window = renderspuGetDummyWindow(pContext->BltInfo.Base.visualBits);
234 if (!window)
235 {
236 crWarning("renderspuGetDummyWindow failed");
237 return GL_FALSE;
238 }
239 }
240
241 Assert(window);
242
243 renderspuPerformMakeCurrent(window, 0, pContext);
244 return GL_TRUE;
245}
246
247void renderspu_SystemDefaultSharedContextChanged(ContextInfo *fromContext, ContextInfo *toContext)
248{
249 CRASSERT(fromContext != toContext);
250
251 if (!CrGlslIsInited(&render_spu.GlobalShaders))
252 {
253 CrGlslInit(&render_spu.GlobalShaders, render_spu.blitterDispatch);
254 }
255
256 if (fromContext)
257 {
258 if (CrGlslNeedsCleanup(&render_spu.GlobalShaders))
259 {
260 CR_RENDER_CTX_INFO Info;
261 if (renderspuCtxSetCurrentWithAnyWindow(fromContext, &Info))
262 {
263 CrGlslCleanup(&render_spu.GlobalShaders);
264 renderspuCtxInfoRestoreCurrent(&Info);
265 }
266 else
267 crWarning("renderspuCtxSetCurrentWithAnyWindow failed!");
268 }
269 }
270 else
271 {
272 CRASSERT(!CrGlslNeedsCleanup(&render_spu.GlobalShaders));
273 }
274
275 CRASSERT(!CrGlslNeedsCleanup(&render_spu.GlobalShaders));
276
277 if (toContext)
278 {
279 CR_RENDER_CTX_INFO Info;
280 if (renderspuCtxSetCurrentWithAnyWindow(toContext, &Info))
281 {
282 int rc = CrGlslProgGenAllNoAlpha(&render_spu.GlobalShaders);
283 if (!RT_SUCCESS(rc))
284 crWarning("CrGlslProgGenAllNoAlpha failed, rc %d", rc);
285
286 renderspuCtxInfoRestoreCurrent(&Info);
287 }
288 else
289 crWarning("renderspuCtxSetCurrentWithAnyWindow failed!");
290 }
291}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette