1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <Carbon/Carbon.h>
|
---|
8 | #include <AGL/agl.h>
|
---|
9 | #include <OpenGL/OpenGL.h>
|
---|
10 |
|
---|
11 | #include <iprt/time.h>
|
---|
12 | #include <iprt/assert.h>
|
---|
13 | #include <iprt/semaphore.h>
|
---|
14 |
|
---|
15 | #include <stdio.h>
|
---|
16 |
|
---|
17 | #include "cr_environment.h"
|
---|
18 | #include "cr_error.h"
|
---|
19 | #include "cr_string.h"
|
---|
20 | #include "cr_mem.h"
|
---|
21 | #include "renderspu.h"
|
---|
22 |
|
---|
23 | #ifdef __LP64__ /** @todo port to 64-bit darwin. */
|
---|
24 | # define renderspuSetWindowContext(w, c) \
|
---|
25 | AssertFailed()
|
---|
26 | # define renderspuGetWindowContext(w) \
|
---|
27 | ( (ContextInfo *) GetWRefCon( ((w)->nativeWindow ? (w)->nativeWindow : (w)->window) ) )
|
---|
28 | #else
|
---|
29 | # define renderspuSetWindowContext(w, c) \
|
---|
30 | ( SetWRefCon( (w), (unsigned long) (c) ) )
|
---|
31 | # define renderspuGetWindowContext(w) \
|
---|
32 | ( (ContextInfo *) GetWRefCon( ((w)->nativeWindow ? (w)->nativeWindow : (w)->window) ) )
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | /* Debug macros */
|
---|
36 | #ifdef DEBUG_poetzsch
|
---|
37 | #define DEBUG_MSG_POETZSCH(text) \
|
---|
38 | printf text
|
---|
39 | #else
|
---|
40 | #define DEBUG_MSG_POETZSCH(text) \
|
---|
41 | do {} while (0)
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | #define DEBUG_MSG_RESULT(result, text) \
|
---|
45 | crDebug(text" (%d; %s:%d)", (int)(result), __FILE__, __LINE__)
|
---|
46 |
|
---|
47 | #define CHECK_CARBON_RC(result, text) \
|
---|
48 | if((result) != noErr) \
|
---|
49 | DEBUG_MSG_RESULT(result, text);
|
---|
50 |
|
---|
51 | #define CHECK_CARBON_RC_RETURN(result, text, ret) \
|
---|
52 | if((result) != noErr) \
|
---|
53 | { \
|
---|
54 | DEBUG_MSG_RESULT(result, text); \
|
---|
55 | return ret; \
|
---|
56 | }
|
---|
57 |
|
---|
58 | #define CHECK_CARBON_RC_RETURN_VOID(result, text) \
|
---|
59 | CHECK_CARBON_RC_RETURN(result, text,)
|
---|
60 |
|
---|
61 | #define CHECK_AGL_RC(result, text) \
|
---|
62 | if(!(result)) \
|
---|
63 | { \
|
---|
64 | GLenum error = render_spu.ws.aglGetError(); \
|
---|
65 | DEBUG_MSG_RESULT(result, text); \
|
---|
66 | }
|
---|
67 |
|
---|
68 | static void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *window);
|
---|
69 | static void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *pRects);
|
---|
70 |
|
---|
71 | /* In some case (like compiz which doesn't provide us with clipping regions) we
|
---|
72 | * have to make sure that *all* open OpenGL windows are clipped to the main
|
---|
73 | * application window. This is done here when called from the event handler
|
---|
74 | * which monitor bounding changes of the main window. */
|
---|
75 | static void crClipRootHelper(unsigned long key, void *data1, void *data2)
|
---|
76 | {
|
---|
77 | /* The window with id zero is the base window, which isn't displayed at
|
---|
78 | * all. So ignore it. */
|
---|
79 | if (key > 0)
|
---|
80 | {
|
---|
81 | /* Fetch the actually window info & the user data */
|
---|
82 | WindowInfo *pWin = (WindowInfo *) data1;
|
---|
83 | /* We need to assign the context with this window */
|
---|
84 | ContextInfo *context = renderspuGetWindowContext(pWin);
|
---|
85 | if (context &&
|
---|
86 | context->context)
|
---|
87 | {
|
---|
88 | RTSemFastMutexRequest(render_spu.syncMutex);
|
---|
89 | GLboolean result = render_spu.ws.aglSetCurrentContext(context->context);
|
---|
90 | CHECK_AGL_RC (result, "Render SPU (crClipRootHelper): SetCurrentContext Failed");
|
---|
91 | if (result)
|
---|
92 | {
|
---|
93 | result = render_spu.ws.aglUpdateContext(context->context);
|
---|
94 | CHECK_AGL_RC (result, "Render SPU (crClipRootHelper): UpdateContext Failed");
|
---|
95 | /* Update the clipping region */
|
---|
96 | renderspu_SystemWindowApplyVisibleRegion(pWin);
|
---|
97 | }
|
---|
98 | RTSemFastMutexRelease(render_spu.syncMutex);
|
---|
99 | /* Make sure that the position is updated relative to the Qt main
|
---|
100 | * view */
|
---|
101 | renderspu_SystemWindowPosition(pWin, pWin->x, pWin->y);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | /* Window event handler */
|
---|
107 | pascal OSStatus
|
---|
108 | windowEvtHndlr(EventHandlerCallRef myHandler, EventRef event, void* userData)
|
---|
109 | {
|
---|
110 | WindowRef window = NULL;
|
---|
111 | OSStatus eventResult = eventNotHandledErr;
|
---|
112 | UInt32 class = GetEventClass (event);
|
---|
113 | UInt32 kind = GetEventKind (event);
|
---|
114 |
|
---|
115 | /* If we aren't initialized or even deinitialized already (as on VM
|
---|
116 | * shutdown) do nothing. */
|
---|
117 | if (!render_spu.fInit)
|
---|
118 | return eventNotHandledErr;
|
---|
119 |
|
---|
120 | /* Fetch the sender of the event */
|
---|
121 | GetEventParameter(event, kEventParamDirectObject, typeWindowRef,
|
---|
122 | NULL, sizeof(WindowRef), NULL, &window);
|
---|
123 | switch (class)
|
---|
124 | {
|
---|
125 | case kEventClassVBox:
|
---|
126 | {
|
---|
127 | switch (kind)
|
---|
128 | {
|
---|
129 | case kEventVBoxUpdateContext:
|
---|
130 | {
|
---|
131 | #ifndef __LP64__ /** @todo port to 64-bit darwin! Need to check if this event is generated or not (it probably isn't). */
|
---|
132 | WindowInfo *wi1;
|
---|
133 | GetEventParameter(event, kEventParamUserData, typeVoidPtr,
|
---|
134 | NULL, sizeof(wi1), NULL, &wi1);
|
---|
135 | ContextInfo *context = renderspuGetWindowContext(wi1);
|
---|
136 | if (context &&
|
---|
137 | context->context)
|
---|
138 | {
|
---|
139 | AGLContext tmpContext = render_spu.ws.aglGetCurrentContext();
|
---|
140 | DEBUG_MSG_POETZSCH (("kEventVBoxUpdateContext %x %x\n", wi1, context->context));
|
---|
141 | RTSemFastMutexRequest(render_spu.syncMutex);
|
---|
142 | GLboolean result = render_spu.ws.aglSetCurrentContext(context->context);
|
---|
143 | if (result)
|
---|
144 | {
|
---|
145 | result = render_spu.ws.aglUpdateContext(context->context);
|
---|
146 | CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): UpdateContext Failed");
|
---|
147 | renderspu_SystemWindowApplyVisibleRegion(wi1);
|
---|
148 | /* Reapply the last active context */
|
---|
149 | if (tmpContext)
|
---|
150 | {
|
---|
151 | result = render_spu.ws.aglSetCurrentContext(tmpContext);
|
---|
152 | CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): SetCurrentContext Failed");
|
---|
153 | if (result)
|
---|
154 | {
|
---|
155 | result = render_spu.ws.aglUpdateContext(tmpContext);
|
---|
156 | CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): UpdateContext Failed");
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|
160 | RTSemFastMutexRelease(render_spu.syncMutex);
|
---|
161 | }
|
---|
162 | eventResult = noErr;
|
---|
163 | #endif
|
---|
164 | break;
|
---|
165 | }
|
---|
166 | case kEventVBoxBoundsChanged:
|
---|
167 | {
|
---|
168 | #ifndef __LP64__ /** @todo port to 64-bit darwin! Need to check if this event is generated or not (it probably isn't). */
|
---|
169 | HIPoint p;
|
---|
170 | GetEventParameter(event, kEventParamOrigin, typeHIPoint,
|
---|
171 | NULL, sizeof(p), NULL, &p);
|
---|
172 | HISize s;
|
---|
173 | GetEventParameter(event, kEventParamDimensions, typeHISize,
|
---|
174 | NULL, sizeof(s), NULL, &s);
|
---|
175 | HIRect r = CGRectMake (0, 0, s.width, s.height);
|
---|
176 | DEBUG_MSG_POETZSCH (("kEventVBoxBoundsChanged %f %f %f %f\n", p.x, p.y, s.width, s.height));
|
---|
177 | GLint l[4] = { 0,
|
---|
178 | 0,
|
---|
179 | r.size.width,
|
---|
180 | r.size.height };
|
---|
181 | /* Update the root window clip region */
|
---|
182 | renderspu_SystemSetRootVisibleRegion(1, l);
|
---|
183 | /* Temporary save the current active context */
|
---|
184 | AGLContext tmpContext = render_spu.ws.aglGetCurrentContext();
|
---|
185 | crHashtableWalk(render_spu.windowTable, crClipRootHelper, NULL);
|
---|
186 | /* Reapply the last active context */
|
---|
187 | if (tmpContext)
|
---|
188 | {
|
---|
189 | RTSemFastMutexRequest(render_spu.syncMutex);
|
---|
190 | GLboolean result = render_spu.ws.aglSetCurrentContext(tmpContext);
|
---|
191 | CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): SetCurrentContext Failed");
|
---|
192 | /* Doesn't work with DirectX; Anyway doesn't */
|
---|
193 | /* if (result)*/
|
---|
194 | /* {*/
|
---|
195 | /* result = render_spu.ws.aglUpdateContext(tmpContext);*/
|
---|
196 | /* CHECK_AGL_RC (result, "Render SPU (windowEvtHndlr): UpdateContext Failed");*/
|
---|
197 | /* }*/
|
---|
198 | RTSemFastMutexRelease(render_spu.syncMutex);
|
---|
199 | }
|
---|
200 | eventResult = noErr;
|
---|
201 | #endif
|
---|
202 | break;
|
---|
203 | }
|
---|
204 | };
|
---|
205 | break;
|
---|
206 | }
|
---|
207 | break;
|
---|
208 | };
|
---|
209 |
|
---|
210 | return eventResult;
|
---|
211 | }
|
---|
212 |
|
---|
213 | GLboolean
|
---|
214 | renderspu_SystemInitVisual(VisualInfo *visual)
|
---|
215 | {
|
---|
216 | if(visual->visAttribs & CR_PBUFFER_BIT)
|
---|
217 | crWarning("Render SPU (renderspu_SystemInitVisual): PBuffers not support on Darwin/AGL yet.");
|
---|
218 |
|
---|
219 | return GL_TRUE;
|
---|
220 | }
|
---|
221 |
|
---|
222 | GLboolean
|
---|
223 | renderspuChoosePixelFormat(ContextInfo *context, AGLPixelFormat *pix)
|
---|
224 | {
|
---|
225 | GLbitfield visAttribs = context->visual->visAttribs;
|
---|
226 | GLint attribs[32];
|
---|
227 | GLint ind = 0;
|
---|
228 |
|
---|
229 | #define ATTR_ADD(s) ( attribs[ind++] = (s) )
|
---|
230 | #define ATTR_ADDV(s,v) ( ATTR_ADD((s)), ATTR_ADD((v)) )
|
---|
231 |
|
---|
232 | CRASSERT(render_spu.ws.aglChoosePixelFormat);
|
---|
233 |
|
---|
234 | ATTR_ADD(AGL_RGBA);
|
---|
235 | /* ATTR_ADDV(AGL_RED_SIZE, 1);
|
---|
236 | ATTR_ADDV(AGL_GREEN_SIZE, 1);
|
---|
237 | ATTR_ADDV(AGL_BLUE_SIZE, 1); */
|
---|
238 |
|
---|
239 | /* if( render_spu.fullscreen )*/
|
---|
240 | /* ATTR_ADD(AGL_FULLSCREEN);*/
|
---|
241 |
|
---|
242 | if( visAttribs & CR_ALPHA_BIT )
|
---|
243 | ATTR_ADDV(AGL_ALPHA_SIZE, 1);
|
---|
244 |
|
---|
245 | if( visAttribs & CR_DOUBLE_BIT )
|
---|
246 | ATTR_ADD(AGL_DOUBLEBUFFER);
|
---|
247 |
|
---|
248 | if( visAttribs & CR_STEREO_BIT )
|
---|
249 | ATTR_ADD(AGL_STEREO);
|
---|
250 |
|
---|
251 | if( visAttribs & CR_DEPTH_BIT )
|
---|
252 | ATTR_ADDV(AGL_DEPTH_SIZE, 1);
|
---|
253 |
|
---|
254 | if( visAttribs & CR_STENCIL_BIT )
|
---|
255 | ATTR_ADDV(AGL_STENCIL_SIZE, 1);
|
---|
256 |
|
---|
257 | if( visAttribs & CR_ACCUM_BIT ) {
|
---|
258 | ATTR_ADDV(AGL_ACCUM_RED_SIZE, 1);
|
---|
259 | ATTR_ADDV(AGL_ACCUM_GREEN_SIZE, 1);
|
---|
260 | ATTR_ADDV(AGL_ACCUM_BLUE_SIZE, 1);
|
---|
261 | if( visAttribs & CR_ALPHA_BIT )
|
---|
262 | ATTR_ADDV(AGL_ACCUM_ALPHA_SIZE, 1);
|
---|
263 | }
|
---|
264 |
|
---|
265 | if( visAttribs & CR_MULTISAMPLE_BIT ) {
|
---|
266 | ATTR_ADDV(AGL_SAMPLE_BUFFERS_ARB, 1);
|
---|
267 | ATTR_ADDV(AGL_SAMPLES_ARB, 4);
|
---|
268 | }
|
---|
269 |
|
---|
270 | if( visAttribs & CR_OVERLAY_BIT )
|
---|
271 | ATTR_ADDV(AGL_LEVEL, 1);
|
---|
272 |
|
---|
273 | ATTR_ADD(AGL_NONE);
|
---|
274 |
|
---|
275 | *pix = render_spu.ws.aglChoosePixelFormat( NULL, 0, attribs );
|
---|
276 |
|
---|
277 | return (*pix != NULL);
|
---|
278 | }
|
---|
279 |
|
---|
280 | void
|
---|
281 | renderspuDestroyPixelFormat(ContextInfo *context, AGLPixelFormat *pix)
|
---|
282 | {
|
---|
283 | render_spu.ws.aglDestroyPixelFormat( *pix );
|
---|
284 | *pix = NULL;
|
---|
285 | }
|
---|
286 |
|
---|
287 | GLboolean
|
---|
288 | renderspu_SystemCreateContext(VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext)
|
---|
289 | {
|
---|
290 | AGLPixelFormat pix;
|
---|
291 |
|
---|
292 | (void) sharedContext;
|
---|
293 | CRASSERT(visual);
|
---|
294 | CRASSERT(context);
|
---|
295 |
|
---|
296 | context->visual = visual;
|
---|
297 |
|
---|
298 | if( !renderspuChoosePixelFormat(context, &pix) ) {
|
---|
299 | crError( "Render SPU (renderspu_SystemCreateContext): Unable to create pixel format" );
|
---|
300 | return GL_FALSE;
|
---|
301 | }
|
---|
302 |
|
---|
303 | context->context = render_spu.ws.aglCreateContext( pix, NULL );
|
---|
304 | renderspuDestroyPixelFormat( context, &pix );
|
---|
305 |
|
---|
306 | if( !context->context ) {
|
---|
307 | crError( "Render SPU (renderspu_SystemCreateContext): Could not create rendering context" );
|
---|
308 | return GL_FALSE;
|
---|
309 | }
|
---|
310 |
|
---|
311 | return GL_TRUE;
|
---|
312 | }
|
---|
313 |
|
---|
314 | void
|
---|
315 | renderspu_SystemDestroyContext(ContextInfo *context)
|
---|
316 | {
|
---|
317 | if(!context)
|
---|
318 | return;
|
---|
319 |
|
---|
320 | render_spu.ws.aglSetDrawable(context->context, NULL);
|
---|
321 | render_spu.ws.aglSetCurrentContext(NULL);
|
---|
322 | if(context->context)
|
---|
323 | {
|
---|
324 | render_spu.ws.aglDestroyContext(context->context);
|
---|
325 | context->context = NULL;
|
---|
326 | }
|
---|
327 |
|
---|
328 | context->visual = NULL;
|
---|
329 | }
|
---|
330 |
|
---|
331 | void
|
---|
332 | renderspuFullscreen(WindowInfo *window, GLboolean fullscreen)
|
---|
333 | {
|
---|
334 | /* Real fullscreen isn't supported by VirtualBox */
|
---|
335 | }
|
---|
336 |
|
---|
337 | GLboolean
|
---|
338 | renderspuWindowAttachContext(WindowInfo *wi, WindowRef window,
|
---|
339 | ContextInfo *context)
|
---|
340 | {
|
---|
341 | GLboolean result;
|
---|
342 |
|
---|
343 | if(!context || !wi)
|
---|
344 | return render_spu.ws.aglSetCurrentContext( NULL );
|
---|
345 |
|
---|
346 | /* DEBUG_MSG_POETZSCH (("WindowAttachContext %d\n", wi->BltInfo.Base.id));*/
|
---|
347 |
|
---|
348 | /* Flush old context first */
|
---|
349 | if (context->currentWindow->window != window)
|
---|
350 | render_spu.self.Flush();
|
---|
351 | /* If the window buffer name is uninitialized we have to create a new
|
---|
352 | * dummy context. */
|
---|
353 | if (wi->bufferName == -1)
|
---|
354 | {
|
---|
355 | DEBUG_MSG_POETZSCH (("WindowAttachContext: create context %d\n", wi->BltInfo.Base.id));
|
---|
356 | /* Use the same visual bits as those in the context structure */
|
---|
357 | AGLPixelFormat pix;
|
---|
358 | if( !renderspuChoosePixelFormat(context, &pix) )
|
---|
359 | {
|
---|
360 | crError( "Render SPU (renderspuWindowAttachContext): Unable to create pixel format" );
|
---|
361 | return GL_FALSE;
|
---|
362 | }
|
---|
363 | /* Create the dummy context */
|
---|
364 | wi->dummyContext = render_spu.ws.aglCreateContext( pix, NULL );
|
---|
365 | renderspuDestroyPixelFormat( context, &pix );
|
---|
366 | if( !wi->dummyContext )
|
---|
367 | {
|
---|
368 | crError( "Render SPU (renderspuWindowAttachContext): Could not create rendering context" );
|
---|
369 | return GL_FALSE;
|
---|
370 | }
|
---|
371 | AGLDrawable drawable;
|
---|
372 | #ifdef __LP64__ /** @todo port to 64-bit darwin. */
|
---|
373 | drawable = NULL;
|
---|
374 | #else
|
---|
375 | drawable = (AGLDrawable) GetWindowPort(window);
|
---|
376 | #endif
|
---|
377 | /* New global buffer name */
|
---|
378 | wi->bufferName = render_spu.currentBufferName++;
|
---|
379 | /* Set the new buffer name to the dummy context. This enable the
|
---|
380 | * sharing of the same hardware buffer afterwards. */
|
---|
381 | result = render_spu.ws.aglSetInteger(wi->dummyContext, AGL_BUFFER_NAME, &wi->bufferName);
|
---|
382 | CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): SetInteger Failed");
|
---|
383 | /* Assign the dummy context to the window */
|
---|
384 | result = render_spu.ws.aglSetDrawable(wi->dummyContext, drawable);
|
---|
385 | CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): SetDrawable Failed");
|
---|
386 | }
|
---|
387 |
|
---|
388 | AGLDrawable oldDrawable;
|
---|
389 | AGLDrawable newDrawable;
|
---|
390 |
|
---|
391 | oldDrawable = render_spu.ws.aglGetDrawable(context->context);
|
---|
392 | #ifdef __LP64__ /** @todo port to 64-bit darwin. */
|
---|
393 | newDrawable = oldDrawable;
|
---|
394 | #else
|
---|
395 | newDrawable = (AGLDrawable) GetWindowPort(window);
|
---|
396 | #endif
|
---|
397 | RTSemFastMutexRequest(render_spu.syncMutex);
|
---|
398 | /* Only switch the context if the drawable has changed */
|
---|
399 | if (oldDrawable != newDrawable)
|
---|
400 | {
|
---|
401 | /* Reset the current context */
|
---|
402 | result = render_spu.ws.aglSetDrawable(context->context, NULL);
|
---|
403 | CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): SetDrawable Failed");
|
---|
404 | /* Set the buffer name of the dummy context to the current context
|
---|
405 | * also. After that both share the same hardware buffer. */
|
---|
406 | render_spu.ws.aglSetInteger (context->context, AGL_BUFFER_NAME, &wi->bufferName);
|
---|
407 | CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): SetInteger Failed");
|
---|
408 | /* Set the new drawable */
|
---|
409 | #ifdef __LP64__ /** @todo port to 64-bit darwin. */
|
---|
410 | result = -1;
|
---|
411 | #else
|
---|
412 | result = render_spu.ws.aglSetDrawable(context->context, newDrawable);
|
---|
413 | #endif
|
---|
414 | CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): SetDrawable Failed");
|
---|
415 | renderspuSetWindowContext(window, context);
|
---|
416 | }
|
---|
417 | result = render_spu.ws.aglSetCurrentContext(context->context);
|
---|
418 | CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): SetCurrentContext Failed");
|
---|
419 | result = render_spu.ws.aglUpdateContext(context->context);
|
---|
420 | CHECK_AGL_RC (result, "Render SPU (renderspuWindowAttachContext): UpdateContext Failed");
|
---|
421 | RTSemFastMutexRelease(render_spu.syncMutex);
|
---|
422 |
|
---|
423 | return result;
|
---|
424 | }
|
---|
425 |
|
---|
426 | GLboolean
|
---|
427 | renderspu_SystemCreateWindow(VisualInfo *visual, GLboolean showIt,
|
---|
428 | WindowInfo *window)
|
---|
429 | {
|
---|
430 | return GL_TRUE;
|
---|
431 | }
|
---|
432 |
|
---|
433 | void renderspu_SystemReparentWindow(WindowInfo *)
|
---|
434 | {
|
---|
435 | /* stub only */
|
---|
436 | }
|
---|
437 |
|
---|
438 | void
|
---|
439 | renderspu_SystemDestroyWindow(WindowInfo *window)
|
---|
440 | {
|
---|
441 | CRASSERT(window);
|
---|
442 | CRASSERT(window->visual);
|
---|
443 |
|
---|
444 | if(!window->nativeWindow)
|
---|
445 | {
|
---|
446 | EventRef evt;
|
---|
447 | OSStatus status = CreateEvent(NULL, kEventClassVBox, kEventVBoxDisposeWindow, 0, kEventAttributeNone, &evt);
|
---|
448 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemDestroyWindow): CreateEvent Failed");
|
---|
449 | status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof (window->window), &window->window);
|
---|
450 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemDestroyWindow): SetEventParameter Failed");
|
---|
451 | status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
|
---|
452 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemDestroyWindow): PostEventToQueue Failed");
|
---|
453 | }
|
---|
454 |
|
---|
455 | /* Delete the dummy context */
|
---|
456 | if(window->dummyContext)
|
---|
457 | {
|
---|
458 | render_spu.ws.aglSetDrawable(window->dummyContext, NULL);
|
---|
459 | render_spu.ws.aglDestroyContext(window->dummyContext);
|
---|
460 | window->dummyContext = NULL;
|
---|
461 | }
|
---|
462 |
|
---|
463 | /* Reset some values */
|
---|
464 | window->bufferName = -1;
|
---|
465 | window->visual = NULL;
|
---|
466 | window->window = NULL;
|
---|
467 |
|
---|
468 | if (window->hVisibleRegion)
|
---|
469 | {
|
---|
470 | DisposeRgn(window->hVisibleRegion);
|
---|
471 | window->hVisibleRegion = 0;
|
---|
472 | }
|
---|
473 | }
|
---|
474 |
|
---|
475 | void
|
---|
476 | renderspu_SystemWindowPosition(WindowInfo *window,
|
---|
477 | GLint x, GLint y)
|
---|
478 | {
|
---|
479 | CRASSERT(window);
|
---|
480 | CRASSERT(window->window);
|
---|
481 |
|
---|
482 | OSStatus status = noErr;
|
---|
483 | /* Send a event to the main thread, cause some function of Carbon aren't
|
---|
484 | * thread safe */
|
---|
485 | EventRef evt;
|
---|
486 | status = CreateEvent(NULL, kEventClassVBox, kEventVBoxMoveWindow, 0, kEventAttributeNone, &evt);
|
---|
487 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): CreateEvent Failed");
|
---|
488 | status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof(window->window), &window->window);
|
---|
489 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed");
|
---|
490 | HIPoint p = CGPointMake (x, y);
|
---|
491 | status = SetEventParameter(evt, kEventParamOrigin, typeHIPoint, sizeof (p), &p);
|
---|
492 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed");
|
---|
493 | status = SetEventParameter(evt, kEventParamUserData, typeVoidPtr, sizeof (window), &window);
|
---|
494 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): SetEventParameter Failed");
|
---|
495 | status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
|
---|
496 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowPosition): PostEventToQueue Failed");
|
---|
497 |
|
---|
498 | /* save the new pos */
|
---|
499 | window->x = x;
|
---|
500 | window->y = y;
|
---|
501 | }
|
---|
502 |
|
---|
503 | void
|
---|
504 | renderspu_SystemWindowSize(WindowInfo *window, GLint w, GLint h)
|
---|
505 | {
|
---|
506 | CRASSERT(window);
|
---|
507 | CRASSERT(window->window);
|
---|
508 |
|
---|
509 | OSStatus status = noErr;
|
---|
510 | /* Send a event to the main thread, cause some function of Carbon aren't
|
---|
511 | * thread safe */
|
---|
512 | EventRef evt;
|
---|
513 | status = CreateEvent(NULL, kEventClassVBox, kEventVBoxResizeWindow, 0, kEventAttributeNone, &evt);
|
---|
514 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): CreateEvent Failed ");
|
---|
515 | status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof(window->window), &window->window);
|
---|
516 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SetEventParameter Failed");
|
---|
517 | HISize s = CGSizeMake (w, h);
|
---|
518 | status = SetEventParameter(evt, kEventParamDimensions, typeHISize, sizeof (s), &s);
|
---|
519 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SetEventParameter Failed");
|
---|
520 | status = SetEventParameter(evt, kEventParamUserData, typeVoidPtr, sizeof (window), &window);
|
---|
521 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SetEventParameter Failed");
|
---|
522 | status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
|
---|
523 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowSize): SendEventToEventTarget Failed");
|
---|
524 |
|
---|
525 | DEBUG_MSG_POETZSCH (("Size %d visible %d\n", window->BltInfo.Base.id, IsWindowVisible (window->window)));
|
---|
526 | /* save the new size */
|
---|
527 | window->BltInfo.width = w;
|
---|
528 | window->BltInfo.height = h;
|
---|
529 | }
|
---|
530 |
|
---|
531 | void
|
---|
532 | renderspu_SystemGetWindowGeometry(WindowInfo *window,
|
---|
533 | GLint *x, GLint *y,
|
---|
534 | GLint *w, GLint *h)
|
---|
535 | {
|
---|
536 | CRASSERT(window);
|
---|
537 | CRASSERT(window->window);
|
---|
538 |
|
---|
539 | OSStatus status = noErr;
|
---|
540 | Rect r;
|
---|
541 | status = GetWindowBounds(window->window, kWindowStructureRgn, &r);
|
---|
542 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemGetWindowGeometry): GetWindowBounds Failed");
|
---|
543 |
|
---|
544 | *x = (int) r.left;
|
---|
545 | *y = (int) r.top;
|
---|
546 | *w = (int) (r.right - r.left);
|
---|
547 | *h = (int) (r.bottom - r.top);
|
---|
548 | }
|
---|
549 |
|
---|
550 | void
|
---|
551 | renderspu_SystemGetMaxWindowSize(WindowInfo *window,
|
---|
552 | GLint *w, GLint *h)
|
---|
553 | {
|
---|
554 | CRASSERT(window);
|
---|
555 | CRASSERT(window->window);
|
---|
556 |
|
---|
557 | OSStatus status = noErr;
|
---|
558 | HISize s;
|
---|
559 | #ifdef __LP64__ /** @todo port to 64-bit darwin. */
|
---|
560 | status = -1;
|
---|
561 | #else
|
---|
562 | status = GetWindowResizeLimits (window->window, NULL, &s);
|
---|
563 | #endif
|
---|
564 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemGetMaxWindowSize): GetWindowResizeLimits Failed");
|
---|
565 |
|
---|
566 | *w = s.width;
|
---|
567 | *h = s.height;
|
---|
568 | }
|
---|
569 |
|
---|
570 | /* Either show or hide the render SPU's window. */
|
---|
571 | void
|
---|
572 | renderspu_SystemShowWindow(WindowInfo *window, GLboolean showIt)
|
---|
573 | {
|
---|
574 | CRASSERT(window);
|
---|
575 | CRASSERT(window->window);
|
---|
576 |
|
---|
577 | if (!IsValidWindowPtr(window->window))
|
---|
578 | return;
|
---|
579 |
|
---|
580 | if(showIt)
|
---|
581 | {
|
---|
582 | /* Force moving the win to the right position before we show it */
|
---|
583 | renderspu_SystemWindowPosition (window, window->x, window->y);
|
---|
584 | OSStatus status = noErr;
|
---|
585 | /* Send a event to the main thread, cause some function of Carbon
|
---|
586 | * aren't thread safe */
|
---|
587 | EventRef evt;
|
---|
588 | status = CreateEvent(NULL, kEventClassVBox, kEventVBoxShowWindow, 0, kEventAttributeNone, &evt);
|
---|
589 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemShowWindow): CreateEvent Failed");
|
---|
590 | status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof (window->window), &window->window);
|
---|
591 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemShowWindow): SetEventParameter Failed");
|
---|
592 | status = SetEventParameter(evt, kEventParamUserData, typeVoidPtr, sizeof (window), &window);
|
---|
593 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemWindowShow): SetEventParameter Failed");
|
---|
594 | //status = SendEventToEventTarget (evt, GetWindowEventTarget (HIViewGetWindow ((HIViewRef)render_spu_parent_window_id)));
|
---|
595 | status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
|
---|
596 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemShowWindow): PostEventToQueue Failed");
|
---|
597 | }
|
---|
598 | else
|
---|
599 | {
|
---|
600 | EventRef evt;
|
---|
601 | OSStatus status = CreateEvent(NULL, kEventClassVBox, kEventVBoxHideWindow, 0, kEventAttributeNone, &evt);
|
---|
602 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemShowWindow): CreateEvent Failed");
|
---|
603 | status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof (window->window), &window->window);
|
---|
604 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemShowWindow): SetEventParameter Failed");
|
---|
605 | status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
|
---|
606 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemShowWindow): PostEventToQueue Failed");
|
---|
607 | }
|
---|
608 | }
|
---|
609 |
|
---|
610 | void renderspu_SystemVBoxPresentComposition( WindowInfo *window, struct VBOXVR_SCR_COMPOSITOR * pCompositor, struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry )
|
---|
611 | {
|
---|
612 | renderspuVBoxPresentCompositionGeneric(window, pCompositor, pChangedEntry, 0);
|
---|
613 | }
|
---|
614 |
|
---|
615 | void
|
---|
616 | renderspu_SystemMakeCurrent(WindowInfo *window, GLint nativeWindow,
|
---|
617 | ContextInfo *context)
|
---|
618 | {
|
---|
619 | Boolean result;
|
---|
620 | /* DEBUG_MSG_POETZSCH (("makecurrent %d: \n", window->BltInfo.Base.id));*/
|
---|
621 |
|
---|
622 | CRASSERT(render_spu.ws.aglSetCurrentContext);
|
---|
623 | //crDebug( "renderspu_SystemMakeCurrent( %x, %i, %x )", window, nativeWindow, context );
|
---|
624 |
|
---|
625 | nativeWindow = 0;
|
---|
626 |
|
---|
627 | if(window && context)
|
---|
628 | {
|
---|
629 | CRASSERT(window->window);
|
---|
630 | CRASSERT(context->context);
|
---|
631 |
|
---|
632 | if(window->visual != context->visual)
|
---|
633 | {
|
---|
634 | crDebug("Render SPU (renderspu_SystemMakeCurrent): MakeCurrent visual mismatch (0x%x != 0x%x); remaking window.",
|
---|
635 | (uint)window->visual->visAttribs, (uint)context->visual->visAttribs);
|
---|
636 | /*
|
---|
637 | * XXX have to revisit this issue!!!
|
---|
638 | *
|
---|
639 | * But for now we destroy the current window
|
---|
640 | * and re-create it with the context's visual abilities
|
---|
641 | */
|
---|
642 | renderspu_SystemDestroyWindow(window);
|
---|
643 | renderspu_SystemCreateWindow(context->visual, window->visible,
|
---|
644 | window);
|
---|
645 | }
|
---|
646 |
|
---|
647 | /* This is the normal case: rendering to the render SPU's own window */
|
---|
648 | result = renderspuWindowAttachContext(window, window->window,
|
---|
649 | context);
|
---|
650 | /* XXX this is a total hack to work around an NVIDIA driver bug */
|
---|
651 | if(render_spu.self.GetFloatv && context->haveWindowPosARB)
|
---|
652 | {
|
---|
653 | GLfloat f[4];
|
---|
654 | render_spu.self.GetFloatv(GL_CURRENT_RASTER_POSITION, f);
|
---|
655 | if (!window->everCurrent || f[1] < 0.0)
|
---|
656 | {
|
---|
657 | crDebug("Render SPU (renderspu_SystemMakeCurrent): Resetting raster pos");
|
---|
658 | render_spu.self.WindowPos2iARB(0, 0);
|
---|
659 | }
|
---|
660 | }
|
---|
661 | /* Reapply the visible regions */
|
---|
662 | renderspu_SystemWindowApplyVisibleRegion(window);
|
---|
663 | }
|
---|
664 | else
|
---|
665 | renderspuWindowAttachContext (0, 0, 0);
|
---|
666 | }
|
---|
667 |
|
---|
668 | void
|
---|
669 | renderspu_SystemSwapBuffers(WindowInfo *window, GLint flags)
|
---|
670 | {
|
---|
671 | CRASSERT(window);
|
---|
672 | CRASSERT(window->window);
|
---|
673 |
|
---|
674 | ContextInfo *context = renderspuGetWindowContext(window);
|
---|
675 |
|
---|
676 | if(!context)
|
---|
677 | crError("Render SPU (renderspu_SystemSwapBuffers): SwapBuffers got a null context from the window");
|
---|
678 |
|
---|
679 | RTSemFastMutexRequest(render_spu.syncMutex);
|
---|
680 | // DEBUG_MSG_POETZSCH (("Swapped %d context %x visible: %d\n", window->BltInfo.Base.id, context->context, IsWindowVisible (window->window)));
|
---|
681 | if (context->visual &&
|
---|
682 | context->visual->visAttribs & CR_DOUBLE_BIT)
|
---|
683 | render_spu.ws.aglSwapBuffers(context->context);
|
---|
684 | else
|
---|
685 | glFlush();
|
---|
686 | RTSemFastMutexRelease(render_spu.syncMutex);
|
---|
687 |
|
---|
688 | /* This method seems called very often. To prevent the dock using all free
|
---|
689 | * resources we update the dock only two times per second. */
|
---|
690 | uint64_t curTS = RTTimeMilliTS();
|
---|
691 | if ((curTS - render_spu.uiDockUpdateTS) > 500)
|
---|
692 | {
|
---|
693 | OSStatus status = noErr;
|
---|
694 | /* Send a event to the main thread, cause some function of Carbon aren't
|
---|
695 | * thread safe */
|
---|
696 | EventRef evt;
|
---|
697 | status = CreateEvent(NULL, kEventClassVBox, kEventVBoxUpdateDock, 0, kEventAttributeNone, &evt);
|
---|
698 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemSwapBuffers): CreateEvent Failed");
|
---|
699 | status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
|
---|
700 | CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU (renderspu_SystemSwapBuffers): PostEventToQueue Failed");
|
---|
701 |
|
---|
702 | render_spu.uiDockUpdateTS = curTS;
|
---|
703 | }
|
---|
704 | }
|
---|
705 |
|
---|
706 | void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, const GLint* pRects)
|
---|
707 | {
|
---|
708 | CRASSERT(window);
|
---|
709 | CRASSERT(window->window);
|
---|
710 |
|
---|
711 | /* Remember any additional clipping stuff e.g. seamless regions */
|
---|
712 | if (window->hVisibleRegion)
|
---|
713 | {
|
---|
714 | DisposeRgn(window->hVisibleRegion);
|
---|
715 | window->hVisibleRegion = 0;
|
---|
716 | }
|
---|
717 |
|
---|
718 | if (cRects>0)
|
---|
719 | {
|
---|
720 | int i;
|
---|
721 | /* Create some temporary regions */
|
---|
722 | RgnHandle rgn = NewRgn();
|
---|
723 | SetEmptyRgn (rgn);
|
---|
724 | RgnHandle tmpRgn = NewRgn();
|
---|
725 | for (i=0; i<cRects; ++i)
|
---|
726 | {
|
---|
727 | SetRectRgn (tmpRgn,
|
---|
728 | pRects[4*i] , pRects[4*i+1],
|
---|
729 | pRects[4*i+2], pRects[4*i+3]);
|
---|
730 | //DEBUG_MSG_POETZSCH (("visible rect %d %d %d %d\n", pRects[4*i] , pRects[4*i+1],
|
---|
731 | // pRects[4*i+2], pRects[4*i+3]));
|
---|
732 | UnionRgn (rgn, tmpRgn, rgn);
|
---|
733 | }
|
---|
734 | DisposeRgn (tmpRgn);
|
---|
735 | window->hVisibleRegion = rgn;
|
---|
736 | }
|
---|
737 |
|
---|
738 | renderspu_SystemWindowApplyVisibleRegion(window);
|
---|
739 | }
|
---|
740 |
|
---|
741 | static void renderspu_SystemSetRootVisibleRegion(GLint cRects, GLint *pRects)
|
---|
742 | {
|
---|
743 | /* Remember the visible region of the root window if there is one */
|
---|
744 | if (render_spu.hRootVisibleRegion)
|
---|
745 | {
|
---|
746 | DisposeRgn(render_spu.hRootVisibleRegion);
|
---|
747 | render_spu.hRootVisibleRegion = 0;
|
---|
748 | }
|
---|
749 |
|
---|
750 | if (cRects>0)
|
---|
751 | {
|
---|
752 | int i;
|
---|
753 | render_spu.hRootVisibleRegion = NewRgn();
|
---|
754 | SetEmptyRgn (render_spu.hRootVisibleRegion);
|
---|
755 | RgnHandle tmpRgn = NewRgn();
|
---|
756 | for (i=0; i<cRects; ++i)
|
---|
757 | {
|
---|
758 | SetRectRgn (tmpRgn,
|
---|
759 | pRects[4*i] , pRects[4*i+1],
|
---|
760 | pRects[4*i+2], pRects[4*i+3]);
|
---|
761 | UnionRgn (render_spu.hRootVisibleRegion, tmpRgn, render_spu.hRootVisibleRegion);
|
---|
762 | }
|
---|
763 | DisposeRgn (tmpRgn);
|
---|
764 | }
|
---|
765 | }
|
---|
766 |
|
---|
767 | /*Assumes that all regions are in the guest coordinates system*/
|
---|
768 | static void renderspu_SystemWindowApplyVisibleRegion(WindowInfo *window)
|
---|
769 | {
|
---|
770 | ContextInfo *c = renderspuGetWindowContext(window);
|
---|
771 | RgnHandle rgn;
|
---|
772 | GLboolean result = true;
|
---|
773 |
|
---|
774 | DEBUG_MSG_POETZSCH (("ApplyVisibleRegion %x\n", window));
|
---|
775 |
|
---|
776 | if (!c || !c->context) return;
|
---|
777 |
|
---|
778 | rgn = NewRgn();
|
---|
779 | SetEmptyRgn(rgn);
|
---|
780 |
|
---|
781 | if (render_spu.hRootVisibleRegion)
|
---|
782 | {
|
---|
783 | /* The render_spu.hRootVisibleRegion has coordinates from the root
|
---|
784 | * window. We intersect it with the rect of the OpenGL window we
|
---|
785 | * currently process. */
|
---|
786 | SetRectRgn(rgn,
|
---|
787 | window->x, window->y,
|
---|
788 | window->x + window->BltInfo.width,
|
---|
789 | window->y + window->BltInfo.height);
|
---|
790 | SectRgn(render_spu.hRootVisibleRegion, rgn, rgn);
|
---|
791 | /* Because the clipping is done in the coordinate space of the OpenGL
|
---|
792 | * window we have to remove the x/y position from the newly created
|
---|
793 | * region. */
|
---|
794 | OffsetRgn (rgn, -window->x, -window->y);
|
---|
795 | }
|
---|
796 | else
|
---|
797 | {
|
---|
798 | /* If there is not root clipping region is available, create a base
|
---|
799 | * region with the size of the target window. This covers all
|
---|
800 | * needed/possible space. */
|
---|
801 | SetRectRgn(rgn, 0, 0, window->BltInfo.width, window->BltInfo.height);
|
---|
802 | }
|
---|
803 |
|
---|
804 | /* Now intersect the window clipping region with a additional region e.g.
|
---|
805 | * for the seamless mode. */
|
---|
806 | if (window->hVisibleRegion)
|
---|
807 | SectRgn(rgn, window->hVisibleRegion, rgn);
|
---|
808 |
|
---|
809 | if (rgn && !EmptyRgn(rgn))
|
---|
810 | {
|
---|
811 | /* Set the clip region to the context */
|
---|
812 | result = render_spu.ws.aglSetInteger(c->context, AGL_CLIP_REGION, (const GLint*)rgn);
|
---|
813 | CHECK_AGL_RC (result, "Render SPU (renderspu_SystemWindowVisibleRegion): SetInteger Failed");
|
---|
814 | result = render_spu.ws.aglEnable(c->context, AGL_CLIP_REGION);
|
---|
815 | CHECK_AGL_RC (result, "Render SPU (renderspu_SystemWindowVisibleRegion): Enable Failed");
|
---|
816 | }
|
---|
817 | /* Clear the region structure */
|
---|
818 | DisposeRgn (rgn);
|
---|
819 | }
|
---|
820 |
|
---|
821 | GLboolean
|
---|
822 | renderspu_SystemVBoxCreateWindow(VisualInfo *visual, GLboolean showIt,
|
---|
823 | WindowInfo *window)
|
---|
824 | {
|
---|
825 | CRASSERT(visual);
|
---|
826 | CRASSERT(window);
|
---|
827 |
|
---|
828 | WindowAttributes winAttr = kWindowNoShadowAttribute | kWindowCompositingAttribute | kWindowIgnoreClicksAttribute | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute;
|
---|
829 | WindowClass winClass = kOverlayWindowClass;
|
---|
830 | Rect windowRect;
|
---|
831 | OSStatus status = noErr;
|
---|
832 |
|
---|
833 | window->visual = visual;
|
---|
834 | window->nativeWindow = NULL;
|
---|
835 |
|
---|
836 | if(window->window && IsValidWindowPtr(window->window))
|
---|
837 | {
|
---|
838 | EventRef evt;
|
---|
839 | status = CreateEvent(NULL, kEventClassVBox, kEventVBoxDisposeWindow, 0, kEventAttributeNone, &evt);
|
---|
840 | CHECK_CARBON_RC_RETURN (status, "Render SPU (renderspu_SystemVBoxCreateWindow): CreateEvent Failed", false);
|
---|
841 | status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof (window->window), &window->window);
|
---|
842 | CHECK_CARBON_RC_RETURN (status, "Render SPU (renderspu_SystemVBoxCreateWindow): SetEventParameter Failed", false);
|
---|
843 | status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
|
---|
844 | CHECK_CARBON_RC_RETURN (status, "Render SPU (renderspu_SystemVBoxCreateWindow): PostEventToQueue Failed", false);
|
---|
845 | }
|
---|
846 |
|
---|
847 | windowRect.left = window->x;
|
---|
848 | windowRect.top = window->y;
|
---|
849 | windowRect.right = window->x + window->BltInfo.width;
|
---|
850 | windowRect.bottom = window->y + window->BltInfo.height;
|
---|
851 |
|
---|
852 | status = CreateNewWindow(winClass, winAttr, &windowRect, &window->window);
|
---|
853 | CHECK_CARBON_RC_RETURN (status, "Render SPU (renderspu_SystemVBoxCreateWindow): CreateNewWindow Failed", GL_FALSE);
|
---|
854 |
|
---|
855 | /* We set a title for debugging purposes */
|
---|
856 | CFStringRef title_string;
|
---|
857 | title_string = CFStringCreateWithCStringNoCopy(NULL, window->title,
|
---|
858 | kCFStringEncodingMacRoman, NULL);
|
---|
859 | SetWindowTitleWithCFString(window->BltInfo.window, title_string);
|
---|
860 | CFRelease(title_string);
|
---|
861 |
|
---|
862 | /* The parent has to be in its own group */
|
---|
863 | WindowRef parent = NULL;
|
---|
864 | if (render_spu_parent_window_id)
|
---|
865 | {
|
---|
866 | parent = HIViewGetWindow ((HIViewRef)render_spu_parent_window_id);
|
---|
867 | SetWindowGroup (parent, render_spu.pParentGroup);
|
---|
868 |
|
---|
869 | }
|
---|
870 |
|
---|
871 | /* Add the new window to the master group */
|
---|
872 | SetWindowGroup(window->window, render_spu.pMasterGroup);
|
---|
873 |
|
---|
874 | /* This will be initialized on the first attempt to attach the global
|
---|
875 | * context to this new window */
|
---|
876 | window->bufferName = -1;
|
---|
877 | window->dummyContext = NULL;
|
---|
878 | window->hVisibleRegion = 0;
|
---|
879 |
|
---|
880 | if(showIt)
|
---|
881 | renderspu_SystemShowWindow(window, GL_TRUE);
|
---|
882 |
|
---|
883 | crDebug("Render SPU (renderspu_SystemVBoxCreateWindow): actual window (x, y, width, height): %d, %d, %d, %d",
|
---|
884 | window->x, window->y, window->BltInfo.width, window->BltInfo.height);
|
---|
885 |
|
---|
886 | return GL_TRUE;
|
---|
887 | }
|
---|
888 |
|
---|