VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/render/renderspu_agl.c@ 17450

最後變更 在這個檔案從17450是 17022,由 vboxsync 提交於 16 年 前

renderspu_agl.c: Just made it build and link, it will not work.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 23.1 KB
 
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
14#include <stdio.h>
15
16#include "cr_environment.h"
17#include "cr_error.h"
18#include "cr_string.h"
19#include "cr_mem.h"
20#include "renderspu.h"
21
22/* Some necessary global defines */
23WindowGroupRef gParentGroup = NULL;
24WindowGroupRef gMasterGroup = NULL;
25GLint gCurrentBufferName = 1;
26uint64_t gDockUpdateTS = 0;
27
28enum
29{
30 /* Event classes */
31 kEventClassVBox = 'vbox',
32 /* Event kinds */
33 kEventVBoxShowWindow = 'swin',
34 kEventVBoxMoveWindow = 'mwin',
35 kEventVBoxResizeWindow = 'rwin',
36 kEventVBoxUpdateDock = 'udck'
37};
38
39#ifdef __LP64__ /** @todo port to 64-bit darwin. */
40# define renderspuSetWindowContext(w, c) \
41 AssertFailed()
42# define renderspuGetWindowContext(w) \
43 ( (ContextInfo *) GetWRefCon( ((w)->nativeWindow ? (w)->nativeWindow : (w)->window) ) )
44#else
45# define renderspuSetWindowContext(w, c) \
46 ( SetWRefCon( (w), (unsigned long) (c) ) )
47# define renderspuGetWindowContext(w) \
48 ( (ContextInfo *) GetWRefCon( ((w)->nativeWindow ? (w)->nativeWindow : (w)->window) ) )
49#endif
50
51/* Debug macros */
52#define DEBUG_MSG_RESULT(result, text) \
53 crDebug(text" (%d; %s:%d)", (int)(result), __FILE__, __LINE__)
54
55#define CHECK_CARBON_RC(result, text) \
56 if((result) != noErr) \
57 DEBUG_MSG_RESULT(result, text);
58
59#define CHECK_CARBON_RC_RETURN(result, text, ret) \
60 if((result) != noErr) \
61 { \
62 DEBUG_MSG_RESULT(result, text); \
63 return ret; \
64 }
65
66#define CHECK_CARBON_RC_RETURN_VOID(result, text) \
67 CHECK_CARBON_RC_RETURN(result, text,)
68
69#define CHECK_AGL_RC(result, text) \
70 if(!(result)) \
71 { \
72 GLenum error = render_spu.ws.aglGetError(); \
73 DEBUG_MSG_RESULT(result, text); \
74 }
75
76/* Window event handler */
77static pascal OSStatus
78windowEvtHndlr(EventHandlerCallRef myHandler, EventRef event, void* userData)
79{
80 /* Currently this is *NOT* used */
81
82#pragma unused (userData)
83 WindowRef window = NULL;
84 Rect rectPort = { 0, 0, 0, 0 };
85 OSStatus result = eventNotHandledErr;
86 UInt32 class = GetEventClass( event );
87 UInt32 kind = GetEventKind( event );
88
89 GetEventParameter(event, kEventParamDirectObject, typeWindowRef,
90 NULL, sizeof(WindowRef), NULL, &window);
91 if( window )
92 GetWindowPortBounds( window, &rectPort );
93
94 switch (class) {
95 case kEventClassWindow:
96 switch (kind) {
97 case kEventWindowActivated:
98#ifndef __LP64__ /* not available for 64-bit processes? */
99 case kEventWindowDrawContent:
100#endif
101 break;
102
103 case kEventWindowClose:
104 HideWindow( window );
105#ifdef __LP64__ /** @todo port to 64-bit darwin. */
106#else
107 SetWRefCon( window, (int)NULL );
108#endif
109
110 crWarning( "Render SPU: caught kEventWindowClose -- quitting." );
111 break;
112
113 case kEventWindowShown:
114 /* build gl */
115#ifndef __LP64__ /** @todo port to 64-bit darwin! Need to cehck if this event is generated or not (it probably isn't). */
116 if( window == FrontWindow() )
117 SetUserFocusWindow( window );
118 InvalWindowRect( window, &rectPort );
119#endif
120 break;
121
122 case kEventWindowBoundsChanged:
123 /* resize
124 update */
125 break;
126
127 case kEventWindowZoomed:
128 /* zoom button */
129 break;
130 }
131 break;
132 }
133
134 return result;
135}
136
137GLboolean
138renderspu_SystemInitVisual(VisualInfo *visual)
139{
140 if(visual->visAttribs & CR_PBUFFER_BIT)
141 crWarning("Render SPU: PBuffers not support on Darwin/AGL yet.");
142
143 return GL_TRUE;
144}
145
146GLboolean
147renderspuChoosePixelFormat(ContextInfo *context, AGLPixelFormat *pix)
148{
149 GLbitfield visAttribs = context->visual->visAttribs;
150 GLint attribs[32];
151 GLint ind = 0;
152
153#define ATTR_ADD(s) ( attribs[ind++] = (s) )
154#define ATTR_ADDV(s,v) ( ATTR_ADD((s)), ATTR_ADD((v)) )
155
156 CRASSERT(render_spu.ws.aglChoosePixelFormat);
157
158 ATTR_ADD(AGL_RGBA);
159/* ATTR_ADDV(AGL_RED_SIZE, 1);
160 ATTR_ADDV(AGL_GREEN_SIZE, 1);
161 ATTR_ADDV(AGL_BLUE_SIZE, 1); */
162
163/* if( render_spu.fullscreen )*/
164/* ATTR_ADD(AGL_FULLSCREEN);*/
165
166 if( visAttribs & CR_ALPHA_BIT )
167 ATTR_ADDV(AGL_ALPHA_SIZE, 1);
168
169 if( visAttribs & CR_DOUBLE_BIT )
170 ATTR_ADD(AGL_DOUBLEBUFFER);
171
172 if( visAttribs & CR_STEREO_BIT )
173 ATTR_ADD(AGL_STEREO);
174
175 if( visAttribs & CR_DEPTH_BIT )
176 ATTR_ADDV(AGL_DEPTH_SIZE, 1);
177
178 if( visAttribs & CR_STENCIL_BIT )
179 ATTR_ADDV(AGL_STENCIL_SIZE, 1);
180
181 if( visAttribs & CR_ACCUM_BIT ) {
182 ATTR_ADDV(AGL_ACCUM_RED_SIZE, 1);
183 ATTR_ADDV(AGL_ACCUM_GREEN_SIZE, 1);
184 ATTR_ADDV(AGL_ACCUM_BLUE_SIZE, 1);
185 if( visAttribs & CR_ALPHA_BIT )
186 ATTR_ADDV(AGL_ACCUM_ALPHA_SIZE, 1);
187 }
188
189 if( visAttribs & CR_MULTISAMPLE_BIT ) {
190 ATTR_ADDV(AGL_SAMPLE_BUFFERS_ARB, 1);
191 ATTR_ADDV(AGL_SAMPLES_ARB, 4);
192 }
193
194 if( visAttribs & CR_OVERLAY_BIT )
195 ATTR_ADDV(AGL_LEVEL, 1);
196
197 ATTR_ADD(AGL_NONE);
198
199 *pix = render_spu.ws.aglChoosePixelFormat( NULL, 0, attribs );
200
201 return (*pix != NULL);
202}
203
204void
205renderspuDestroyPixelFormat(ContextInfo *context, AGLPixelFormat *pix)
206{
207 render_spu.ws.aglDestroyPixelFormat( *pix );
208 *pix = NULL;
209}
210
211GLboolean
212renderspu_SystemCreateContext(VisualInfo *visual, ContextInfo *context, ContextInfo *sharedContext)
213{
214 AGLPixelFormat pix;
215
216 (void) sharedContext;
217 CRASSERT(visual);
218 CRASSERT(context);
219
220 context->visual = visual;
221
222 if( !renderspuChoosePixelFormat(context, &pix) ) {
223 crError( "Render SPU: Unable to create pixel format" );
224 return GL_FALSE;
225 }
226
227 context->context = render_spu.ws.aglCreateContext( pix, NULL );
228 renderspuDestroyPixelFormat( context, &pix );
229
230 if( !context->context ) {
231 crError( "Render SPU: Could not create rendering context" );
232 return GL_FALSE;
233 }
234
235 return GL_TRUE;
236}
237
238void
239renderspu_SystemDestroyContext(ContextInfo *context)
240{
241 if(!context)
242 return;
243
244 render_spu.ws.aglSetDrawable(context->context, NULL);
245 render_spu.ws.aglSetCurrentContext(NULL);
246 if(context->context)
247 {
248 render_spu.ws.aglDestroyContext(context->context);
249 context->context = NULL;
250 }
251
252 context->visual = NULL;
253}
254
255void
256renderspuFullscreen(WindowInfo *window, GLboolean fullscreen)
257{
258 /* Real fullscreen isn't supported by VirtualBox */
259}
260
261GLboolean
262renderspuWindowAttachContext(WindowInfo *wi, WindowRef window,
263 ContextInfo *context)
264{
265 GLboolean result;
266
267 if(!context || !wi)
268 return render_spu.ws.aglSetCurrentContext( NULL );
269
270 /* Flush old context first */
271 if (context->currentWindow->window != window)
272 render_spu.self.Flush();
273 /* If the window buffer name is uninitialized we have to create a new
274 * dummy context. */
275 if (wi->bufferName == -1)
276 {
277 /* Use the same visual bits as those in the context structure */
278 AGLPixelFormat pix;
279 if( !renderspuChoosePixelFormat(context, &pix) )
280 {
281 crError( "Render SPU: Unable to create pixel format" );
282 return GL_FALSE;
283 }
284 /* Create the dummy context */
285 wi->dummyContext = render_spu.ws.aglCreateContext( pix, NULL );
286 renderspuDestroyPixelFormat( context, &pix );
287 if( !wi->dummyContext )
288 {
289 crError( "Render SPU: Could not create rendering context" );
290 return GL_FALSE;
291 }
292 AGLDrawable drawable;
293#ifdef __LP64__ /** @todo port to 64-bit darwin. */
294 drawable = NULL;
295#else
296 drawable = (AGLDrawable) GetWindowPort(window);
297#endif
298 /* New global buffer name */
299 wi->bufferName = gCurrentBufferName++;
300 /* Set the new buffer name to the dummy context. This enable the
301 * sharing of the same hardware buffer afterwards. */
302 result = render_spu.ws.aglSetInteger(wi->dummyContext, AGL_BUFFER_NAME, &wi->bufferName);
303 CHECK_AGL_RC (result, "Render SPU: SetInteger Failed");
304 /* Assign the dummy context to the window */
305 result = render_spu.ws.aglSetDrawable(wi->dummyContext, drawable);
306 CHECK_AGL_RC (result, "Render SPU: SetDrawable Failed");
307 }
308
309 AGLDrawable oldDrawable;
310 AGLDrawable newDrawable;
311
312 oldDrawable = render_spu.ws.aglGetDrawable(context->context);
313#ifdef __LP64__ /** @todo port to 64-bit darwin. */
314 newDrawable = oldDrawable;
315#else
316 newDrawable = (AGLDrawable) GetWindowPort(window);
317#endif
318 /* Only switch the context if the drawable has changed */
319 if (oldDrawable != newDrawable)
320 {
321 /* Reset the current context */
322 result = render_spu.ws.aglSetDrawable(context->context, NULL);
323 CHECK_AGL_RC (result, "Render SPU: SetDrawable Failed");
324 /* Set the buffer name of the dummy context to the current context
325 * also. After that both share the same hardware buffer. */
326 render_spu.ws.aglSetInteger (context->context, AGL_BUFFER_NAME, &wi->bufferName);
327 CHECK_AGL_RC (result, "Render SPU: SetInteger Failed");
328 /* Set the new drawable */
329#ifdef __LP64__ /** @todo port to 64-bit darwin. */
330 result = -1;
331#else
332 result = render_spu.ws.aglSetDrawable(context->context, newDrawable);
333#endif
334 CHECK_AGL_RC (result, "Render SPU: SetDrawable Failed");
335 renderspuSetWindowContext( window, context );
336 }
337 result = render_spu.ws.aglSetCurrentContext(context->context);
338 CHECK_AGL_RC (result, "Render SPU: SetCurrentContext Failed");
339 result = render_spu.ws.aglUpdateContext(context->context);
340 CHECK_AGL_RC (result, "Render SPU: UpdateContext Failed");
341
342 return result;
343}
344
345GLboolean
346renderspu_SystemCreateWindow(VisualInfo *visual, GLboolean showIt,
347 WindowInfo *window)
348{
349 return GL_TRUE;
350}
351
352void
353renderspu_SystemDestroyWindow(WindowInfo *window)
354{
355 CRASSERT(window);
356 CRASSERT(window->visual);
357
358 if(!window->nativeWindow)
359 DisposeWindow(window->window);
360
361 /* Delete the dummy context */
362 if(window->dummyContext)
363 {
364 render_spu.ws.aglSetDrawable(window->dummyContext, NULL);
365 render_spu.ws.aglDestroyContext(window->dummyContext);
366 window->dummyContext = NULL;
367 }
368
369 /* Reset some values */
370 window->bufferName = -1;
371 window->visual = NULL;
372 window->window = NULL;
373}
374
375void
376renderspu_SystemWindowSize(WindowInfo *window, GLint w, GLint h)
377{
378 CRASSERT(window);
379 CRASSERT(window->window);
380
381 OSStatus status = noErr;
382 /* Send a event to the main thread, cause some function of Carbon aren't
383 * thread safe */
384 EventRef evt;
385 status = CreateEvent(NULL, kEventClassVBox, kEventVBoxResizeWindow, 0, kEventAttributeNone, &evt);
386 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: CreateEvent Failed");
387 status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof(window->window), &window->window);
388 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: SetEventParameter Failed");
389 HISize s = CGSizeMake (w, h);
390 status = SetEventParameter(evt, kEventParamDimensions, typeHISize, sizeof (s), &s);
391 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: SetEventParameter Failed");
392 status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
393 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: PostEventToQueue Failed");
394
395 /* Update the context */
396 GLboolean result = true;
397 ContextInfo *context = renderspuGetWindowContext(window);
398 if (context &&
399 context->context)
400 {
401 result = render_spu.ws.aglUpdateContext(context->context);
402 CHECK_AGL_RC (result, "Render SPU: UpdateContext Failed");
403 }
404 /* save the new size */
405 window->width = w;
406 window->height = h;
407}
408
409void
410renderspu_SystemGetWindowGeometry(WindowInfo *window,
411 GLint *x, GLint *y,
412 GLint *w, GLint *h)
413{
414 CRASSERT(window);
415 CRASSERT(window->window);
416
417 OSStatus status = noErr;
418 Rect r;
419 status = GetWindowBounds(window->window, kWindowStructureRgn, &r);
420 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: GetWindowBounds Failed");
421
422 *x = (int) r.left;
423 *y = (int) r.top;
424 *w = (int) (r.right - r.left);
425 *h = (int) (r.bottom - r.top);
426}
427
428void
429renderspu_SystemGetMaxWindowSize(WindowInfo *window,
430 GLint *w, GLint *h)
431{
432 CRASSERT(window);
433 CRASSERT(window->window);
434
435 OSStatus status = noErr;
436 HISize s;
437#ifdef __LP64__ /** @todo port to 64-bit darwin. */
438 status = -1;
439#else
440 status = GetWindowResizeLimits (window->window, NULL, &s);
441#endif
442 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: GetWindowResizeLimits Failed");
443
444 *w = s.width;
445 *h = s.height;
446}
447
448void
449renderspu_SystemWindowPosition(WindowInfo *window,
450 GLint x, GLint y)
451{
452 CRASSERT(window);
453 CRASSERT(window->window);
454
455 OSStatus status = noErr;
456 /* Send a event to the main thread, cause some function of Carbon aren't
457 * thread safe */
458 EventRef evt;
459 status = CreateEvent(NULL, kEventClassVBox, kEventVBoxMoveWindow, 0, kEventAttributeNone, &evt);
460 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: CreateEvent Failed");
461 status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof(window->window), &window->window);
462 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: SetEventParameter Failed");
463 HIPoint p = CGPointMake (x, y);
464 status = SetEventParameter(evt, kEventParamOrigin, typeHIPoint, sizeof (p), &p);
465 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: SetEventParameter Failed");
466 status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
467 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: PostEventToQueue Failed");
468
469 /* Update the context */
470 GLboolean result = true;
471 ContextInfo *context = renderspuGetWindowContext(window);
472 if (context &&
473 context->context)
474 {
475 result = render_spu.ws.aglUpdateContext(context->context);
476 CHECK_AGL_RC (result, "Render SPU: UpdateContext Failed");
477 }
478}
479
480/* Either show or hide the render SPU's window. */
481void
482renderspu_SystemShowWindow(WindowInfo *window, GLboolean showIt)
483{
484 CRASSERT(window);
485 CRASSERT(window->window);
486
487 if (!IsValidWindowPtr(window->window))
488 return;
489
490 if(showIt)
491 {
492 /* Force moving the win to the right position before we show it */
493 renderspu_SystemWindowPosition (window, window->x, window->y);
494 OSStatus status = noErr;
495 /* Send a event to the main thread, cause some function of Carbon
496 * aren't thread safe */
497 EventRef evt;
498 status = CreateEvent(NULL, kEventClassVBox, kEventVBoxShowWindow, 0, kEventAttributeNone, &evt);
499 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: CreateEvent Failed");
500 status = SetEventParameter(evt, kEventParamWindowRef, typeWindowRef, sizeof (window->window), &window->window);
501 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: SetEventParameter Failed");
502 status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
503 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: PostEventToQueue Failed");
504 }
505 else
506 HideWindow(window->window);
507
508 /* Update the context */
509 GLboolean result = true;
510 ContextInfo *context = renderspuGetWindowContext(window);
511 if (context &&
512 context->context)
513 {
514 result = render_spu.ws.aglUpdateContext(context->context);
515 CHECK_AGL_RC (result, "Render SPU: UpdateContext Failed");
516 }
517
518 window->visible = showIt;
519}
520
521void
522renderspu_SystemMakeCurrent(WindowInfo *window, GLint nativeWindow,
523 ContextInfo *context)
524{
525 Boolean result;
526
527 CRASSERT(render_spu.ws.aglSetCurrentContext);
528/* crDebug( "renderspu_SystemMakeCurrent( %x, %i, %x )", window, nativeWindow, context );*/
529
530 if(window && context)
531 {
532 CRASSERT(window->window);
533 CRASSERT(context->context);
534
535 if(window->visual != context->visual)
536 {
537 crDebug("Render SPU: MakeCurrent visual mismatch (0x%x != 0x%x); remaking window.",
538 (uint)window->visual->visAttribs, (uint)context->visual->visAttribs);
539 /*
540 * XXX have to revisit this issue!!!
541 *
542 * But for now we destroy the current window
543 * and re-create it with the context's visual abilities
544 */
545 renderspu_SystemDestroyWindow(window);
546 renderspu_SystemCreateWindow(context->visual, window->visible,
547 window);
548 }
549
550 /* This is the normal case: rendering to the render SPU's own window */
551 result = renderspuWindowAttachContext(window, window->window,
552 context);
553 /* XXX this is a total hack to work around an NVIDIA driver bug */
554 if(render_spu.self.GetFloatv && context->haveWindowPosARB)
555 {
556 GLfloat f[4];
557 render_spu.self.GetFloatv(GL_CURRENT_RASTER_POSITION, f);
558 if (!window->everCurrent || f[1] < 0.0)
559 {
560 crDebug("Render SPU: Resetting raster pos");
561 render_spu.self.WindowPos2iARB(0, 0);
562 }
563 }
564 }
565 else
566 renderspuWindowAttachContext (0, 0, 0);
567}
568
569void
570renderspu_SystemSwapBuffers(WindowInfo *window, GLint flags)
571{
572 CRASSERT(window);
573 CRASSERT(window->window);
574
575 ContextInfo *context = renderspuGetWindowContext(window);
576
577 if(!context)
578 crError("Render SPU: SwapBuffers got a null context from the window");
579
580 render_spu.ws.aglSwapBuffers(context->context);
581
582
583 /* This method seems called very often. To prevent the dock using all free
584 * resources we update the dock only two times per second. */
585 uint64_t curTS = RTTimeMilliTS();
586 if ((curTS - gDockUpdateTS) > 500)
587 {
588 OSStatus status = noErr;
589 /* Send a event to the main thread, cause some function of Carbon aren't
590 * thread safe */
591 EventRef evt;
592 status = CreateEvent(NULL, kEventClassVBox, kEventVBoxUpdateDock, 0, kEventAttributeNone, &evt);
593 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: CreateEvent Failed");
594 status = PostEventToQueue(GetMainEventQueue(), evt, kEventPriorityStandard);
595 CHECK_CARBON_RC_RETURN_VOID (status, "Render SPU: PostEventToQueue Failed");
596
597 gDockUpdateTS = curTS;
598 }
599}
600
601void renderspu_SystemWindowVisibleRegion(WindowInfo *window, GLint cRects, GLint* pRects)
602{
603 CRASSERT(window);
604 CRASSERT(window->window);
605
606 ContextInfo *c;
607 c = renderspuGetWindowContext (window);
608 if (c &&
609 c->context)
610 {
611 int i;
612 /* Create some temporary regions */
613 RgnHandle rgn = NewRgn();
614 SetEmptyRgn (rgn);
615 RgnHandle tmpRgn = NewRgn();
616 for (i=0; i<cRects; ++i)
617 {
618 SetRectRgn (tmpRgn,
619 pRects[4*i] , pRects[4*i+1],
620 pRects[4*i+2], pRects[4*i+3]);
621 UnionRgn (rgn, tmpRgn, rgn);
622 }
623 DisposeRgn (tmpRgn);
624
625 GLboolean result = true;
626 /* Set the clip region to the context */
627 result = render_spu.ws.aglSetInteger(c->context, AGL_CLIP_REGION, (const GLint*)rgn);
628 CHECK_AGL_RC (result, "Render SPU: SetInteger Failed");
629 result = render_spu.ws.aglEnable(c->context, AGL_CLIP_REGION);
630 CHECK_AGL_RC (result, "Render SPU: Enable Failed");
631 /* Clear the region structure */
632 DisposeRgn (rgn);
633 }
634}
635
636GLboolean
637renderspu_SystemVBoxCreateWindow(VisualInfo *visual, GLboolean showIt,
638 WindowInfo *window)
639{
640 CRASSERT(visual);
641 CRASSERT(window);
642
643 WindowAttributes winAttr = kWindowNoShadowAttribute | kWindowCompositingAttribute | kWindowIgnoreClicksAttribute | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute;
644 WindowClass winClass = kOverlayWindowClass;
645 Rect windowRect;
646 OSStatus status = noErr;
647
648 window->visual = visual;
649 window->nativeWindow = NULL;
650
651 if(window->window && IsValidWindowPtr(window->window))
652 /* Destroy the old one */
653 DisposeWindow(window->window);
654
655 windowRect.left = window->x;
656 windowRect.top = window->y;
657 windowRect.right = window->x + window->width;
658 windowRect.bottom = window->y + window->height;
659
660 status = CreateNewWindow(winClass, winAttr, &windowRect, &window->window);
661 CHECK_CARBON_RC_RETURN (status, "Render SPU: CreateNewWindow Failed", GL_FALSE);
662
663 /* We set a title for debugging purposes */
664 CFStringRef title_string;
665 title_string = CFStringCreateWithCStringNoCopy(NULL, window->title,
666 kCFStringEncodingMacRoman, NULL);
667 SetWindowTitleWithCFString(window->window, title_string);
668 CFRelease(title_string);
669
670 /* We need grouping so create a master group for this & all following
671 * windows & one group for the parent. */
672 if(!gMasterGroup || !gParentGroup)
673 {
674 status = CreateWindowGroup(kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse | kWindowGroupAttrFixedLevel, &gMasterGroup);
675 CHECK_CARBON_RC_RETURN (status, "Render SPU: CreateWindowGroup Failed", GL_FALSE);
676 status = CreateWindowGroup(kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrSharedActivation | kWindowGroupAttrHideOnCollapse | kWindowGroupAttrFixedLevel, &gParentGroup);
677 CHECK_CARBON_RC_RETURN (status, "Render SPU: CreateWindowGroup Failed", GL_FALSE);
678 /* Make the correct z-layering */
679 SendWindowGroupBehind (gParentGroup, gMasterGroup);
680 /* and set the gParentGroup as parent for gMasterGroup. */
681#ifdef __LP64__ /** @todo port to 64-bit darwin. */
682#else
683 SetWindowGroupParent (gMasterGroup, gParentGroup);
684#endif
685 }
686
687 /* The parent has to be in its own group */
688 WindowRef parent = NULL;
689 if (render_spu_parent_window_id)
690 {
691 parent = HIViewGetWindow ((HIViewRef)render_spu_parent_window_id);
692 SetWindowGroup (parent, gParentGroup);
693 }
694 /* Add the new window to the master group */
695 SetWindowGroup(window->window, gMasterGroup);
696
697 /* Own handler needed? */
698 {
699 /* Even though there are still issues with the windows themselves,
700 install the event handlers */
701 EventTypeSpec event_list[] = { {kEventClassWindow, kEventWindowClose} };
702
703 window->event_handler = NewEventHandlerUPP( windowEvtHndlr );
704
705 /*InstallWindowEventHandler(window->window, window->event_handler,
706 GetEventTypeCount(event_list), event_list,
707 NULL, NULL);*/
708 }
709
710 /* This will be initialized on the first attempt to attach the global
711 * context to this new window */
712 window->bufferName = -1;
713 window->dummyContext = NULL;
714
715 if(showIt)
716 renderspu_SystemShowWindow(window, GL_TRUE);
717
718 crDebug("Render SPU: actual window (x, y, width, height): %d, %d, %d, %d",
719 window->x, window->y, window->width, window->height);
720
721 return GL_TRUE;
722}
723
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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