VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-cocoa.m@ 53946

Last change on this file since 53946 was 53946, checked in by vboxsync, 10 years ago

header fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.5 KB
Line 
1/** @file
2 * VirtualBox OpenGL Cocoa Window System Helper Implementation.
3 *
4 * @remarks Inspired by HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m.
5 */
6
7/*
8 * Copyright (C) 2009-2014 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "DevVGA-SVGA3d-cocoa.h"
20#import <Cocoa/Cocoa.h>
21#import <OpenGL/gl.h>
22
23#include <iprt/thread.h>
24
25/* Debug macros */
26#if 0 /*def DEBUG_VERBOSE*/
27/*# error "should be disabled!"*/
28# define DEBUG_INFO(text) do { \
29 crWarning text ; \
30 Assert(0); \
31 } while (0)
32
33# define DEBUG_MSG(text) \
34 printf text
35
36# define DEBUG_WARN(text) do { \
37 crWarning text ; \
38 Assert(0); \
39 } while (0)
40
41# define DEBUG_MSG_1(text) \
42 DEBUG_MSG(text)
43
44# define DEBUG_FUNC_ENTER() \
45 int cchDebugFuncEnter = printf("==>%s\n", __PRETTY_FUNCTION__)
46
47#define DEBUG_FUNC_LEAVE() do { \
48 DEBUG_MSG(("<==%s\n", __PRETTY_FUNCTION__)); \
49 } while (0)
50
51#define DEBUG_FUNC_RET(valuefmtnl) do { \
52 DEBUG_MSG(("<==%s returns", __PRETTY_FUNCTION__)); \
53 DEBUG_MSG(valuefmtnl); \
54 } while (0)
55
56#else
57
58# define DEBUG_INFO(text) do { \
59 crInfo text ; \
60 } while (0)
61
62# define DEBUG_MSG(text) \
63 do {} while (0)
64
65# define DEBUG_WARN(text) do { \
66 crWarning text ; \
67 } while (0)
68
69# define DEBUG_MSG_1(text) \
70 do {} while (0)
71
72# define DEBUG_FUNC_ENTER() int cchDebugFuncEnter = 0
73# define DEBUG_FUNC_LEAVE() NOREF(cchDebugFuncEnter)
74# define DEBUG_FUNC_RET(valuefmtnl) DEBUG_FUNC_LEAVE()
75
76#endif
77
78# define CHECK_GL_ERROR()\
79 do {} while (0)
80
81
82/** Custom OpenGL context class.
83 *
84 * This implementation doesn't allow to set a view to the
85 * context, but save the view for later use. Also it saves a copy of the
86 * pixel format used to create that context for later use. */
87@interface VMSVGA3DOpenGLContext: NSOpenGLContext
88{
89@private
90 NSOpenGLPixelFormat *m_pPixelFormat;
91 NSView *m_pView;
92}
93- (NSOpenGLPixelFormat*)openGLPixelFormat;
94@end
95
96@interface VMSVGA3DOverlayView: NSView
97{
98@private
99 NSView *m_pParentView;
100 NSWindow *m_pOverlayWin;
101
102 NSOpenGLContext *m_pGLCtx;
103
104 /* Position/Size tracking */
105 NSPoint m_Pos;
106 NSSize m_Size;
107
108 /** This is necessary for clipping on the root window */
109 NSRect m_RootRect;
110 float m_yInvRootOffset;
111}
112- (id)initWithFrame:(NSRect)frame parentView:(NSView*)pparentView;
113- (void)setGLCtx:(NSOpenGLContext*)pCtx;
114- (NSOpenGLContext*)glCtx;
115- (void)setOverlayWin: (NSWindow*)win;
116- (NSWindow*)overlayWin;
117- (void)setPos:(NSPoint)pos;
118- (NSPoint)pos;
119- (void)setSize:(NSSize)size;
120- (NSSize) size;
121- (void)updateViewportCS;
122- (void)reshape;
123@end
124
125/** Helper view.
126 *
127 * This view is added as a sub view of the parent view to track
128 * main window changes. Whenever the main window is changed
129 * (which happens on fullscreen/seamless entry/exit) the overlay
130 * window is informed & can add them self as a child window
131 * again. */
132@class VMSVGA3DOverlayWindow;
133@interface VMSVGA3DOverlayHelperView: NSView
134{
135@private
136 VMSVGA3DOverlayWindow *m_pOverlayWindow;
137}
138-(id)initWithOverlayWindow:(VMSVGA3DOverlayWindow*)pOverlayWindow;
139@end
140
141/** Custom window class.
142 *
143 * This is the overlay window which contains our custom NSView.
144 * Its a direct child of the Qt Main window. It marks its background
145 * transparent & non opaque to make clipping possible. It also disable mouse
146 * events and handle frame change events of the parent view. */
147@interface VMSVGA3DOverlayWindow: NSWindow
148{
149@private
150 NSView *m_pParentView;
151 VMSVGA3DOverlayView *m_pOverlayView;
152 VMSVGA3DOverlayHelperView *m_pOverlayHelperView;
153 NSThread *m_Thread;
154}
155- (id)initWithParentView:(NSView*)pParentView overlayView:(VMSVGA3DOverlayView*)pOverlayView;
156- (void)parentWindowFrameChanged:(NSNotification *)note;
157- (void)parentWindowChanged:(NSWindow*)pWindow;
158@end
159
160
161/********************************************************************************
162*
163* VMSVGA3DOpenGLContext class implementation
164*
165********************************************************************************/
166@implementation VMSVGA3DOpenGLContext
167
168-(id)initWithFormat:(NSOpenGLPixelFormat*)format shareContext:(NSOpenGLContext*)share
169{
170 DEBUG_FUNC_ENTER();
171
172 m_pPixelFormat = NULL;
173 m_pView = NULL;
174
175 self = [super initWithFormat:format shareContext:share];
176 if (self)
177 m_pPixelFormat = format;
178
179 DEBUG_MSG(("OCTX(%p): init VMSVGA3DOpenGLContext\n", (void*)self));
180 DEBUG_FUNC_RET(("%p\n", (void *)self));
181 return self;
182}
183
184- (void)dealloc
185{
186 DEBUG_FUNC_ENTER();
187 DEBUG_MSG(("OCTX(%p): dealloc VMSVGA3DOpenGLContext\n", (void*)self));
188
189 [m_pPixelFormat release];
190
191m_pPixelFormat = NULL;
192m_pView = NULL;
193
194 [super dealloc];
195 DEBUG_FUNC_LEAVE();
196}
197
198-(bool)isDoubleBuffer
199{
200 DEBUG_FUNC_ENTER();
201 GLint val;
202 [m_pPixelFormat getValues:&val forAttribute:NSOpenGLPFADoubleBuffer forVirtualScreen:0];
203 DEBUG_FUNC_RET(("%d\n", val == 1 ? YES : NO));
204 return val == 1 ? YES : NO;
205}
206
207-(void)setView:(NSView*)view
208{
209 DEBUG_FUNC_ENTER();
210 DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void*)self, (void*)view));
211
212 m_pView = view;
213
214 DEBUG_FUNC_LEAVE();
215}
216
217-(NSView*)view
218{
219 DEBUG_FUNC_ENTER();
220 DEBUG_FUNC_RET(("%p\n", (void *)m_pView));
221 return m_pView;
222}
223
224-(void)clearDrawable
225{
226 DEBUG_FUNC_ENTER();
227 DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void*)self));
228
229 m_pView = NULL;
230 [super clearDrawable];
231
232 DEBUG_FUNC_LEAVE();
233}
234
235-(NSOpenGLPixelFormat*)openGLPixelFormat
236{
237 DEBUG_FUNC_ENTER();
238 DEBUG_FUNC_RET(("%p\n", (void *)m_pPixelFormat));
239 return m_pPixelFormat;
240}
241
242@end
243
244
245
246/********************************************************************************
247*
248* VMSVGA3DOverlayHelperView class implementation
249*
250********************************************************************************/
251@implementation VMSVGA3DOverlayHelperView
252
253-(id)initWithOverlayWindow:(VMSVGA3DOverlayWindow*)pOverlayWindow
254{
255 DEBUG_FUNC_ENTER();
256
257 self = [super initWithFrame:NSZeroRect];
258
259 m_pOverlayWindow = pOverlayWindow;
260
261 DEBUG_MSG(("OHVW(%p): init OverlayHelperView\n", (void*)self));
262 DEBUG_FUNC_RET(("%p\n", (void *)self));
263 return self;
264}
265
266-(void)viewDidMoveToWindow
267{
268 DEBUG_FUNC_ENTER();
269 DEBUG_MSG(("OHVW(%p): viewDidMoveToWindow: new win: %p\n", (void*)self, (void*)[self window]));
270
271 [m_pOverlayWindow parentWindowChanged:[self window]];
272
273 DEBUG_FUNC_LEAVE();
274}
275
276@end
277
278/********************************************************************************
279*
280* VMSVGA3DOverlayWindow class implementation
281*
282********************************************************************************/
283@implementation VMSVGA3DOverlayWindow
284
285- (id)initWithParentView:(NSView*)pParentView overlayView:(VMSVGA3DOverlayView*)pOverlayView
286{
287 DEBUG_FUNC_ENTER();
288 NSWindow *pParentWin = nil;
289
290 if((self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]))
291 {
292 m_pParentView = pParentView;
293 m_pOverlayView = pOverlayView;
294 m_Thread = [NSThread currentThread];
295
296 [m_pOverlayView setOverlayWin: self];
297
298 m_pOverlayHelperView = [[VMSVGA3DOverlayHelperView alloc] initWithOverlayWindow:self];
299 /* Add the helper view as a child of the parent view to get notifications */
300 [pParentView addSubview:m_pOverlayHelperView];
301
302 /* Make sure this window is transparent */
303#ifdef SHOW_WINDOW_BACKGROUND
304 /* For debugging */
305 [self setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7]];
306#else
307 [self setBackgroundColor:[NSColor clearColor]];
308#endif
309 [self setOpaque:NO];
310 [self setAlphaValue:.999];
311 /* Disable mouse events for this window */
312 [self setIgnoresMouseEvents:YES];
313
314 pParentWin = [m_pParentView window];
315
316 /* Initial set the position to the parents view top/left (Compiz fix). */
317 [self setFrameOrigin:
318 [pParentWin convertBaseToScreen:
319 [m_pParentView convertPoint:NSZeroPoint toView:nil]]];
320
321 /* Set the overlay view as our content view */
322 [self setContentView:m_pOverlayView];
323
324 /* Add ourself as a child to the parent views window. Note: this has to
325 * be done last so that everything else is setup in
326 * parentWindowChanged. */
327 [pParentWin addChildWindow:self ordered:NSWindowAbove];
328 }
329 DEBUG_MSG(("OWIN(%p): init OverlayWindow\n", (void*)self));
330 DEBUG_FUNC_RET(("%p\n", (void *)self));
331 return self;
332}
333
334- (void)dealloc
335{
336 DEBUG_FUNC_ENTER();
337 DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void*)self));
338
339 [[NSNotificationCenter defaultCenter] removeObserver:self];
340
341 [m_pOverlayHelperView removeFromSuperview];
342 [m_pOverlayHelperView release];
343
344 [super dealloc];
345 DEBUG_FUNC_LEAVE();
346}
347
348- (void)parentWindowFrameChanged:(NSNotification*)pNote
349{
350 DEBUG_FUNC_ENTER();
351 DEBUG_MSG(("OWIN(%p): parentWindowFrameChanged\n", (void*)self));
352
353 [m_pOverlayView reshape];
354
355 DEBUG_FUNC_LEAVE();
356}
357
358- (void)parentWindowChanged:(NSWindow*)pWindow
359{
360 DEBUG_FUNC_ENTER();
361 DEBUG_MSG(("OWIN(%p): parentWindowChanged\n", (void*)self));
362
363 [[NSNotificationCenter defaultCenter] removeObserver:self];
364
365 if(pWindow != nil)
366 {
367 /* Ask to get notifications when our parent window frame changes. */
368 [[NSNotificationCenter defaultCenter]
369 addObserver:self
370 selector:@selector(parentWindowFrameChanged:)
371 name:NSWindowDidResizeNotification
372 object:pWindow];
373 /* Add us self as child window */
374 [pWindow addChildWindow:self ordered:NSWindowAbove];
375 [m_pOverlayView reshape];
376 }
377
378 DEBUG_FUNC_LEAVE();
379}
380
381@end
382
383/********************************************************************************
384*
385* VMSVGA3DOverlayView class implementation
386*
387********************************************************************************/
388@implementation VMSVGA3DOverlayView
389
390- (id)initWithFrame:(NSRect) frame parentView:(NSView*)pParentView
391{
392 DEBUG_FUNC_ENTER();
393
394 m_pParentView = pParentView;
395 /* Make some reasonable defaults */
396 m_pGLCtx = nil;
397 m_Pos = NSZeroPoint;
398 m_Size = NSMakeSize(1, 1);
399 m_RootRect = NSMakeRect(0, 0, m_Size.width, m_Size.height);
400 m_yInvRootOffset = 0;
401
402 self = [super initWithFrame: frame];
403
404 DEBUG_MSG(("OVIW(%p): init VMSVGA3DOverlayView\n", (void*)self));
405 DEBUG_FUNC_RET(("%p\n", (void *)self));
406 return self;
407}
408
409- (void)cleanupData
410{
411 DEBUG_FUNC_ENTER();
412
413 /*[self deleteDockTile];*/
414
415 [self setGLCtx:nil];
416
417#if 0
418 if (m_pSharedGLCtx)
419 {
420 if ([m_pSharedGLCtx view] == self)
421 [m_pSharedGLCtx clearDrawable];
422
423 [m_pSharedGLCtx release];
424
425 m_pSharedGLCtx = nil;
426
427 CrBltTerm(m_pBlitter);
428
429 RTMemFree(m_pBlitter);
430
431 m_pBlitter = nil;
432 }
433#endif
434
435 /*[self clearVisibleRegions];*/
436
437 DEBUG_FUNC_LEAVE();
438}
439
440- (void)dealloc
441{
442 DEBUG_FUNC_ENTER();
443 DEBUG_MSG(("OVIW(%p): dealloc OverlayView\n", (void*)self));
444
445 [self cleanupData];
446
447 [super dealloc];
448
449 DEBUG_FUNC_LEAVE();
450}
451
452
453- (void)setGLCtx:(NSOpenGLContext*)pCtx
454{
455 DEBUG_FUNC_ENTER();
456
457 DEBUG_MSG(("OVIW(%p): setGLCtx: new ctx: %p (old: %p)\n", (void*)self, (void*)pCtx, (void *)m_pGLCtx));
458 if (m_pGLCtx == pCtx)
459 {
460 DEBUG_FUNC_LEAVE();
461 return;
462 }
463
464 /* ensure the context drawable is cleared to avoid holding a reference to inexistent view */
465 if (m_pGLCtx)
466 {
467 [m_pGLCtx clearDrawable];
468 [m_pGLCtx release];
469 /*[m_pGLCtx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];*/
470 }
471 m_pGLCtx = pCtx;
472 if (pCtx)
473 [pCtx retain];
474
475 DEBUG_FUNC_LEAVE();
476}
477
478- (NSOpenGLContext*)glCtx
479{
480 DEBUG_FUNC_ENTER();
481 DEBUG_FUNC_RET(("%p\n", (void *)m_pGLCtx));
482 return m_pGLCtx;
483}
484
485- (void)setOverlayWin:(NSWindow*)pWin
486{
487 DEBUG_FUNC_ENTER();
488 DEBUG_MSG(("OVIW(%p): setOverlayWin: new win: %p\n", (void*)self, (void*)pWin));
489 m_pOverlayWin = pWin;
490 DEBUG_FUNC_LEAVE();
491}
492
493- (NSWindow*)overlayWin
494{
495 DEBUG_FUNC_ENTER();
496 DEBUG_FUNC_RET(("%p\n", (void *)m_pOverlayWin));
497 return m_pOverlayWin;
498}
499
500- (void)setPos:(NSPoint)pos
501{
502 DEBUG_FUNC_ENTER();
503
504 m_Pos = pos;
505 [self reshape];
506 DEBUG_FUNC_LEAVE();
507}
508
509- (NSPoint)pos
510{
511 DEBUG_FUNC_ENTER();
512 DEBUG_FUNC_RET(("%f,%f\n", m_Pos.x, m_Pos.y));
513 return m_Pos;
514}
515
516- (void)setSize:(NSSize)size
517{
518 DEBUG_FUNC_ENTER();
519 m_Size = size;
520 [self reshape];
521 DEBUG_FUNC_LEAVE();
522}
523
524- (NSSize)size
525{
526 DEBUG_FUNC_ENTER();
527 DEBUG_FUNC_RET(("%f,%f\n", m_Size.width, m_Size.height));
528 return m_Size;
529}
530
531- (void)updateViewportCS
532{
533 DEBUG_FUNC_ENTER();
534 DEBUG_MSG(("OVIW(%p): updateViewport\n", (void*)self));
535
536 /* Update the viewport for our OpenGL view */
537/* [m_pSharedGLCtx update]; */
538
539 /* Clear background to transparent */
540/* glClearColor(0.0f, 0.0f, 0.0f, 0.0f);*/
541 DEBUG_FUNC_LEAVE();
542}
543
544- (void)reshape
545{
546 DEBUG_FUNC_ENTER();
547 NSRect parentFrame = NSZeroRect;
548 NSPoint parentPos = NSZeroPoint;
549 NSPoint childPos = NSZeroPoint;
550 NSRect childFrame = NSZeroRect;
551 NSRect newFrame = NSZeroRect;
552
553 DEBUG_MSG(("OVIW(%p): reshape\n", (void*)self));
554
555 /* Getting the right screen coordinates of the parents frame is a little bit
556 * complicated. */
557 parentFrame = [m_pParentView frame];
558 DEBUG_MSG(("FIXED parentFrame [%f:%f], [%f:%f]\n", parentFrame.origin.x, parentFrame.origin.y, parentFrame.size.width, parentFrame.size.height));
559 parentPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:NSMakePoint(parentFrame.origin.x, parentFrame.origin.y + parentFrame.size.height)]];
560 parentFrame.origin.x = parentPos.x;
561 parentFrame.origin.y = parentPos.y;
562
563 /* Calculate the new screen coordinates of the overlay window. */
564 childPos = NSMakePoint(m_Pos.x, m_Pos.y + m_Size.height);
565 childPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:childPos]];
566 DEBUG_MSG(("FIXED childPos(screen) [%f:%f]\n", childPos.x, childPos.y));
567
568 /* Make a frame out of it. */
569 childFrame = NSMakeRect(childPos.x, childPos.y, m_Size.width, m_Size.height);
570 DEBUG_MSG(("FIXED childFrame [%f:%f], [%f:%f]\n", childFrame.origin.x, childFrame.origin.y, childFrame.size.width, childFrame.size.height));
571
572 /* We have to make sure that the overlay window will not be displayed out
573 * of the parent window. So intersect both frames & use the result as the new
574 * frame for the window. */
575 newFrame = NSIntersectionRect(parentFrame, childFrame);
576
577 DEBUG_MSG(("[%p]: parentFrame pos[%f : %f] size[%f : %f]\n",
578 (void*)self,
579 parentFrame.origin.x, parentFrame.origin.y,
580 parentFrame.size.width, parentFrame.size.height));
581 DEBUG_MSG(("[%p]: childFrame pos[%f : %f] size[%f : %f]\n",
582 (void*)self,
583 childFrame.origin.x, childFrame.origin.y,
584 childFrame.size.width, childFrame.size.height));
585
586 DEBUG_MSG(("[%p]: newFrame pos[%f : %f] size[%f : %f]\n",
587 (void*)self,
588 newFrame.origin.x, newFrame.origin.y,
589 newFrame.size.width, newFrame.size.height));
590
591 /* Later we have to correct the texture position in the case the window is
592 * out of the parents window frame. So save the shift values for later use. */
593 m_RootRect.origin.x = newFrame.origin.x - childFrame.origin.x;
594 m_RootRect.origin.y = childFrame.size.height + childFrame.origin.y - (newFrame.size.height + newFrame.origin.y);
595 m_RootRect.size = newFrame.size;
596 m_yInvRootOffset = newFrame.origin.y - childFrame.origin.y;
597
598 DEBUG_MSG(("[%p]: m_RootRect pos[%f : %f] size[%f : %f]\n",
599 (void*)self,
600 m_RootRect.origin.x, m_RootRect.origin.y,
601 m_RootRect.size.width, m_RootRect.size.height));
602
603 /* Set the new frame. */
604 [[self window] setFrame:newFrame display:YES];
605
606#if 0
607 /* Make sure the context is updated according */
608 /* [self updateViewport]; */
609 if (m_pSharedGLCtx)
610 {
611 VBOX_CR_RENDER_CTX_INFO CtxInfo;
612 vboxCtxEnter(m_pSharedGLCtx, &CtxInfo);
613
614 [self updateViewportCS];
615
616 vboxCtxLeave(&CtxInfo);
617 }
618#endif
619 DEBUG_FUNC_LEAVE();
620}
621
622@end
623
624
625void vmsvga3dCocoaCreateContext(NativeNSOpenGLContextRef *ppCtx, NativeNSOpenGLContextRef pShareCtx, bool fOtherProfile)
626{
627 DEBUG_FUNC_ENTER();
628 NSOpenGLPixelFormat *pFmt = nil;
629 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
630
631#if 1
632 // @todo galitsyn: NSOpenGLPFAWindow was deprecated starting from OSX 10.9.
633 // Consider to remove it and check if it's harmless.
634 NSOpenGLPixelFormatAttribute attribs[] =
635 {
636 NSOpenGLPFAWindow,
637 NSOpenGLPFADoubleBuffer,
638 NSOpenGLPFAAccelerated,
639 NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
640 NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)8,
641 NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
642 0
643 };
644#else
645 NSOpenGLPixelFormatAttribute attribs[] =
646 {
647 NSOpenGLPFADoubleBuffer,
648 NSOpenGLPFAAccelerated,
649 NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
650 NSOpenGLPFADepthSize, 24,
651 NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
652 0
653 };
654#endif
655
656 /* Choose a pixel format */
657 pFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
658
659 if (pFmt)
660 {
661 *ppCtx = [[VMSVGA3DOpenGLContext alloc] initWithFormat:pFmt shareContext:pShareCtx];
662 DEBUG_MSG(("New context %p\n", (void *)*ppCtx));
663 }
664
665 [pPool release];
666
667 DEBUG_FUNC_LEAVE();
668}
669
670void vmsvga3dCocoaDestroyContext(NativeNSOpenGLContextRef pCtx)
671{
672 DEBUG_FUNC_ENTER();
673 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
674 [pCtx release];
675 [pPool release];
676 DEBUG_FUNC_LEAVE();
677}
678
679void vmsvga3dCocoaCreateView(NativeNSViewRef *ppView, NativeNSViewRef pParentView)
680{
681 DEBUG_FUNC_ENTER();
682 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
683
684 /* Create our worker view */
685 VMSVGA3DOverlayView* pView = [[VMSVGA3DOverlayView alloc] initWithFrame:NSZeroRect parentView:pParentView];
686
687 if (pView)
688 {
689 /* We need a real window as container for the view */
690 [[VMSVGA3DOverlayWindow alloc] initWithParentView:pParentView overlayView:pView];
691 /* Return the freshly created overlay view */
692 *ppView = pView;
693 }
694
695 [pPool release];
696 DEBUG_FUNC_LEAVE();
697}
698
699void vmsvga3dCocoaDestroyView(NativeNSViewRef pView)
700{
701 DEBUG_FUNC_ENTER();
702 NSWindow *pWin = nil;
703
704 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
705 [pView setHidden: YES];
706
707 [pWin release];
708 [pView release];
709
710 [pPool release];
711 DEBUG_FUNC_LEAVE();
712}
713
714void vmsvga3dCocoaViewSetPosition(NativeNSViewRef pView, NativeNSViewRef pParentView, int x, int y)
715{
716 DEBUG_FUNC_ENTER();
717 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
718
719 [(VMSVGA3DOverlayView*)pView setPos:NSMakePoint(x, y)];
720
721 [pPool release];
722}
723
724void vmsvga3dCocoaViewSetSize(NativeNSViewRef pView, int w, int h)
725{
726 DEBUG_FUNC_ENTER();
727 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
728
729 [(VMSVGA3DOverlayView*)pView setSize:NSMakeSize(w, h)];
730
731 [pPool release];
732 DEBUG_FUNC_LEAVE();
733}
734
735void vmsvga3dCocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx)
736{
737 DEBUG_FUNC_ENTER();
738 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
739
740 DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", (void*)pView, (void*)pCtx));
741
742 if (pView)
743 {
744 [(VMSVGA3DOverlayView*)pView setGLCtx:pCtx];
745/* [(VMSVGA3DOverlayView*)pView makeCurrentFBO];*/
746 [pCtx makeCurrentContext];
747 }
748 else
749 {
750 [NSOpenGLContext clearCurrentContext];
751 }
752
753 [pPool release];
754 DEBUG_FUNC_LEAVE();
755}
756
757void vmsvga3dCocoaSwapBuffers(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx)
758{
759 DEBUG_FUNC_ENTER();
760 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
761
762 [pCtx flushBuffer];
763
764 [pPool release];
765 DEBUG_FUNC_LEAVE();
766}
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