DevVGA-SVGA3d-cocoa.m revision 07557d07616212d7ba6e7ab3059e85cb14633775
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * VirtualBox OpenGL Cocoa Window System Helper Implementation.
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * @remarks Inspired by HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m.
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * Copyright (C) 2009-2014 Oracle Corporation
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * available from http://www.virtualbox.org. This file is free software;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * you can redistribute it and/or modify it under the terms of the GNU
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * General Public License (GPL) as published by the Free Software
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/* Debug macros */
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/*# error "should be disabled!"*/
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync int cchDebugFuncEnter = printf("==>%s\n", __PRETTY_FUNCTION__)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_MSG(("<==%s returns", __PRETTY_FUNCTION__)); \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync do {} while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync do {} while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_FUNC_ENTER() int cchDebugFuncEnter = 0
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_FUNC_LEAVE() NOREF(cchDebugFuncEnter)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_FUNC_RET(valuefmtnl) DEBUG_FUNC_LEAVE()
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync do {} while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/** Custom OpenGL context class.
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * This implementation doesn't allow to set a view to the
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * context, but save the view for later use. Also it saves a copy of the
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * pixel format used to create that context for later use. */
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync /* Position/Size tracking */
5d69af51557e9e9db029ecd243e820383af49b18vboxsync /** This is necessary for clipping on the root window */
ed24120b1d8a2eddf4291a9654cf45b2372135abvboxsync- (id)initWithFrame:(NSRect)frame parentView:(NSView*)pparentView;
5d69af51557e9e9db029ecd243e820383af49b18vboxsync/** Helper view.
ed24120b1d8a2eddf4291a9654cf45b2372135abvboxsync * This view is added as a sub view of the parent view to track
5d69af51557e9e9db029ecd243e820383af49b18vboxsync * main window changes. Whenever the main window is changed
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * (which happens on fullscreen/seamless entry/exit) the overlay
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * window is informed & can add them self as a child window
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * again. */
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync-(id)initWithOverlayWindow:(VMSVGA3DOverlayWindow*)pOverlayWindow;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync/** Custom window class.
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync * This is the overlay window which contains our custom NSView.
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync * Its a direct child of the Qt Main window. It marks its background
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync * transparent & non opaque to make clipping possible. It also disable mouse
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync * events and handle frame change events of the parent view. */
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync- (id)initWithParentView:(NSView*)pParentView overlayView:(VMSVGA3DOverlayView*)pOverlayView;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync- (void)parentWindowFrameChanged:(NSNotification *)note;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/********************************************************************************
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync* VMSVGA3DOpenGLContext class implementation
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync********************************************************************************/
de210ca38246009981a22de928a52566c8c53970vboxsync-(id)initWithFormat:(NSOpenGLPixelFormat*)format shareContext:(NSOpenGLContext*)share
68e97031354932600728a42c3d454abf04f8c8d1vboxsync self = [super initWithFormat:format shareContext:share];
68e97031354932600728a42c3d454abf04f8c8d1vboxsync DEBUG_MSG(("OCTX(%p): init VMSVGA3DOpenGLContext\n", (void*)self));
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync DEBUG_MSG(("OCTX(%p): dealloc VMSVGA3DOpenGLContext\n", (void*)self));
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync [m_pPixelFormat getValues:&val forAttribute:NSOpenGLPFADoubleBuffer forVirtualScreen:0];
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void*)self, (void*)view));
5d69af51557e9e9db029ecd243e820383af49b18vboxsync DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync/********************************************************************************
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync* VMSVGA3DOverlayHelperView class implementation
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync********************************************************************************/
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync-(id)initWithOverlayWindow:(VMSVGA3DOverlayWindow*)pOverlayWindow
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OHVW(%p): init OverlayHelperView\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OHVW(%p): viewDidMoveToWindow: new win: %p\n", (void*)self, (void*)[self window]));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [m_pOverlayWindow parentWindowChanged:[self window]];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync/********************************************************************************
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync* VMSVGA3DOverlayWindow class implementation
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync********************************************************************************/
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync- (id)initWithParentView:(NSView*)pParentView overlayView:(VMSVGA3DOverlayView*)pOverlayView
de210ca38246009981a22de928a52566c8c53970vboxsync if((self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]))
f8df398d066204e2bf0ba209ea3554fc113fb484vboxsync m_pOverlayHelperView = [[VMSVGA3DOverlayHelperView alloc] initWithOverlayWindow:self];
68e97031354932600728a42c3d454abf04f8c8d1vboxsync /* Add the helper view as a child of the parent view to get notifications */
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync /* Make sure this window is transparent */
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync /* For debugging */
de210ca38246009981a22de928a52566c8c53970vboxsync [self setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7]];
68e97031354932600728a42c3d454abf04f8c8d1vboxsync /* Disable mouse events for this window */
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync /* Initial set the position to the parents view top/left (Compiz fix). */
de210ca38246009981a22de928a52566c8c53970vboxsync [m_pParentView convertPoint:NSZeroPoint toView:nil]]];
de210ca38246009981a22de928a52566c8c53970vboxsync /* Set the overlay view as our content view */
de210ca38246009981a22de928a52566c8c53970vboxsync /* Add ourself as a child to the parent views window. Note: this has to
de210ca38246009981a22de928a52566c8c53970vboxsync * be done last so that everything else is setup in
f8df398d066204e2bf0ba209ea3554fc113fb484vboxsync * parentWindowChanged. */
de210ca38246009981a22de928a52566c8c53970vboxsync [pParentWin addChildWindow:self ordered:NSWindowAbove];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OWIN(%p): init OverlayWindow\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [[NSNotificationCenter defaultCenter] removeObserver:self];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync- (void)parentWindowFrameChanged:(NSNotification*)pNote
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OWIN(%p): parentWindowFrameChanged\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OWIN(%p): parentWindowChanged\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [[NSNotificationCenter defaultCenter] removeObserver:self];
@end
return self;
- (void)cleanupData
if (m_pSharedGLCtx)
- (void)dealloc
[super dealloc];
DEBUG_MSG(("OVIW(%p): setGLCtx: new ctx: %p (old: %p)\n", (void*)self, (void*)pCtx, (void *)m_pGLCtx));
if (m_pGLCtx)
if (pCtx)
return m_pGLCtx;
return m_pOverlayWin;
return m_Pos;
return m_Size;
- (void)updateViewportCS
- (void)reshape
DEBUG_MSG(("FIXED parentFrame [%f:%f], [%f:%f]\n", parentFrame.origin.x, parentFrame.origin.y, parentFrame.size.width, parentFrame.size.height));
parentPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:NSMakePoint(parentFrame.origin.x, parentFrame.origin.y + parentFrame.size.height)]];
childPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:childPos]];
DEBUG_MSG(("FIXED childFrame [%f:%f], [%f:%f]\n", childFrame.origin.x, childFrame.origin.y, childFrame.size.width, childFrame.size.height));
(void*)self,
(void*)self,
(void*)self,
m_RootRect.origin.y = childFrame.size.height + childFrame.origin.y - (newFrame.size.height + newFrame.origin.y);
(void*)self,
if (m_pSharedGLCtx)
@end
void vmsvga3dCocoaCreateContext(NativeNSOpenGLContextRef *ppCtx, NativeNSOpenGLContextRef pShareCtx, bool fOtherProfile)
if (pFmt)
VMSVGA3DOverlayView* pView = [[VMSVGA3DOverlayView alloc] initWithFrame:NSZeroRect parentView:pParentView];
if (pView)
if (pView)