DevVGA-SVGA3d-cocoa.m revision 07557d07616212d7ba6e7ab3059e85cb14633775
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/** @file
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * VirtualBox OpenGL Cocoa Window System Helper Implementation.
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync *
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * @remarks Inspired by HostServices/SharedOpenGL/render/renderspu_cocoa_helper.m.
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync */
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync/*
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync * Copyright (C) 2009-2014 Oracle Corporation
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync *
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 */
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#include "DevVGA-SVGA3d-cocoa.h"
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#import <Cocoa/Cocoa.h>
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#import <OpenGL/gl.h>
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#include <iprt/thread.h>
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/* Debug macros */
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#if 0 /*def DEBUG_VERBOSE*/
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/*# error "should be disabled!"*/
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_INFO(text) do { \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync crWarning text ; \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync Assert(0); \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_MSG(text) \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync printf text
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_WARN(text) do { \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync crWarning text ; \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync Assert(0); \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_MSG_1(text) \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_MSG(text)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_FUNC_ENTER() \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync int cchDebugFuncEnter = printf("==>%s\n", __PRETTY_FUNCTION__)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#define DEBUG_FUNC_LEAVE() do { \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_MSG(("<==%s\n", __PRETTY_FUNCTION__)); \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#define DEBUG_FUNC_RET(valuefmtnl) do { \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_MSG(("<==%s returns", __PRETTY_FUNCTION__)); \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_MSG(valuefmtnl); \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#else
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_INFO(text) do { \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync crInfo text ; \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_MSG(text) \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync do {} while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_WARN(text) do { \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync crWarning text ; \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync } while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define DEBUG_MSG_1(text) \
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync do {} while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
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
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync#endif
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync# define CHECK_GL_ERROR()\
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync do {} while (0)
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/** Custom OpenGL context class.
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync *
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@interface VMSVGA3DOpenGLContext: NSOpenGLContext
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync{
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync@private
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync NSOpenGLPixelFormat *m_pPixelFormat;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync NSView *m_pView;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync}
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync- (NSOpenGLPixelFormat*)openGLPixelFormat;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync@end
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync@interface VMSVGA3DOverlayView: NSView
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync{
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync@private
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync NSView *m_pParentView;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync NSWindow *m_pOverlayWin;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync NSOpenGLContext *m_pGLCtx;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync /* Position/Size tracking */
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync NSPoint m_Pos;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync NSSize m_Size;
5d69af51557e9e9db029ecd243e820383af49b18vboxsync
5d69af51557e9e9db029ecd243e820383af49b18vboxsync /** This is necessary for clipping on the root window */
5d69af51557e9e9db029ecd243e820383af49b18vboxsync NSRect m_RootRect;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync float m_yInvRootOffset;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync}
ed24120b1d8a2eddf4291a9654cf45b2372135abvboxsync- (id)initWithFrame:(NSRect)frame parentView:(NSView*)pparentView;
ed24120b1d8a2eddf4291a9654cf45b2372135abvboxsync- (void)setGLCtx:(NSOpenGLContext*)pCtx;
ed24120b1d8a2eddf4291a9654cf45b2372135abvboxsync- (NSOpenGLContext*)glCtx;
ed24120b1d8a2eddf4291a9654cf45b2372135abvboxsync- (void)setOverlayWin: (NSWindow*)win;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync- (NSWindow*)overlayWin;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync- (void)setPos:(NSPoint)pos;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync- (NSPoint)pos;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync- (void)setSize:(NSSize)size;
ed24120b1d8a2eddf4291a9654cf45b2372135abvboxsync- (NSSize) size;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync- (void)updateViewportCS;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync- (void)reshape;
5d69af51557e9e9db029ecd243e820383af49b18vboxsync@end
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
5d69af51557e9e9db029ecd243e820383af49b18vboxsync/** Helper view.
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync *
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. */
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync@class VMSVGA3DOverlayWindow;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync@interface VMSVGA3DOverlayHelperView: NSView
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync{
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync@private
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync VMSVGA3DOverlayWindow *m_pOverlayWindow;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync}
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync-(id)initWithOverlayWindow:(VMSVGA3DOverlayWindow*)pOverlayWindow;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync@end
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync/** Custom window class.
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync *
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@interface VMSVGA3DOverlayWindow: NSWindow
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync{
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync@private
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync NSView *m_pParentView;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync VMSVGA3DOverlayView *m_pOverlayView;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync VMSVGA3DOverlayHelperView *m_pOverlayHelperView;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync NSThread *m_Thread;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync}
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync- (id)initWithParentView:(NSView*)pParentView overlayView:(VMSVGA3DOverlayView*)pOverlayView;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync- (void)parentWindowFrameChanged:(NSNotification *)note;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync- (void)parentWindowChanged:(NSWindow*)pWindow;
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync@end
4d8251400411b4dcf2c86b5b0376a326ff45938cvboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync/********************************************************************************
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync*
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync* VMSVGA3DOpenGLContext class implementation
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync*
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync********************************************************************************/
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync@implementation VMSVGA3DOpenGLContext
468c2bcb36eb9a032f5dd0fcb34db10bd58e9996vboxsync
de210ca38246009981a22de928a52566c8c53970vboxsync-(id)initWithFormat:(NSOpenGLPixelFormat*)format shareContext:(NSOpenGLContext*)share
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync{
68e97031354932600728a42c3d454abf04f8c8d1vboxsync DEBUG_FUNC_ENTER();
68e97031354932600728a42c3d454abf04f8c8d1vboxsync
68e97031354932600728a42c3d454abf04f8c8d1vboxsync m_pPixelFormat = NULL;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync m_pView = NULL;
68e97031354932600728a42c3d454abf04f8c8d1vboxsync
68e97031354932600728a42c3d454abf04f8c8d1vboxsync self = [super initWithFormat:format shareContext:share];
68e97031354932600728a42c3d454abf04f8c8d1vboxsync if (self)
68e97031354932600728a42c3d454abf04f8c8d1vboxsync m_pPixelFormat = format;
68e97031354932600728a42c3d454abf04f8c8d1vboxsync
68e97031354932600728a42c3d454abf04f8c8d1vboxsync DEBUG_MSG(("OCTX(%p): init VMSVGA3DOpenGLContext\n", (void*)self));
68e97031354932600728a42c3d454abf04f8c8d1vboxsync DEBUG_FUNC_RET(("%p\n", (void *)self));
468c2bcb36eb9a032f5dd0fcb34db10bd58e9996vboxsync return self;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync}
68e97031354932600728a42c3d454abf04f8c8d1vboxsync
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync- (void)dealloc
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync{
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync DEBUG_FUNC_ENTER();
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync DEBUG_MSG(("OCTX(%p): dealloc VMSVGA3DOpenGLContext\n", (void*)self));
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync [m_pPixelFormat release];
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsyncm_pPixelFormat = NULL;
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsyncm_pView = NULL;
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync [super dealloc];
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync DEBUG_FUNC_LEAVE();
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync}
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync-(bool)isDoubleBuffer
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync{
468c2bcb36eb9a032f5dd0fcb34db10bd58e9996vboxsync DEBUG_FUNC_ENTER();
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync GLint val;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync [m_pPixelFormat getValues:&val forAttribute:NSOpenGLPFADoubleBuffer forVirtualScreen:0];
5d69af51557e9e9db029ecd243e820383af49b18vboxsync DEBUG_FUNC_RET(("%d\n", val == 1 ? YES : NO));
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync return val == 1 ? YES : NO;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync}
68e97031354932600728a42c3d454abf04f8c8d1vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync-(void)setView:(NSView*)view
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync{
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_FUNC_ENTER();
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void*)self, (void*)view));
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
9429e79ee2743cb878d5f3680e2dcad036125e02vboxsync m_pView = view;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_FUNC_LEAVE();
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync}
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync-(NSView*)view
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync{
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_FUNC_ENTER();
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_FUNC_RET(("%p\n", (void *)m_pView));
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync return m_pView;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync}
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
5d69af51557e9e9db029ecd243e820383af49b18vboxsync-(void)clearDrawable
5d69af51557e9e9db029ecd243e820383af49b18vboxsync{
5d69af51557e9e9db029ecd243e820383af49b18vboxsync DEBUG_FUNC_ENTER();
5d69af51557e9e9db029ecd243e820383af49b18vboxsync DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void*)self));
5d69af51557e9e9db029ecd243e820383af49b18vboxsync
5d69af51557e9e9db029ecd243e820383af49b18vboxsync m_pView = NULL;
5d69af51557e9e9db029ecd243e820383af49b18vboxsync [super clearDrawable];
68e97031354932600728a42c3d454abf04f8c8d1vboxsync
5d69af51557e9e9db029ecd243e820383af49b18vboxsync DEBUG_FUNC_LEAVE();
5d69af51557e9e9db029ecd243e820383af49b18vboxsync}
5d69af51557e9e9db029ecd243e820383af49b18vboxsync
5d69af51557e9e9db029ecd243e820383af49b18vboxsync-(NSOpenGLPixelFormat*)openGLPixelFormat
5d69af51557e9e9db029ecd243e820383af49b18vboxsync{
5d69af51557e9e9db029ecd243e820383af49b18vboxsync DEBUG_FUNC_ENTER();
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync DEBUG_FUNC_RET(("%p\n", (void *)m_pPixelFormat));
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync return m_pPixelFormat;
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync}
ba8183e1a0c699f5b5131a03e157fc7e39ed3009vboxsync
de210ca38246009981a22de928a52566c8c53970vboxsync@end
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync/********************************************************************************
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync*
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync* VMSVGA3DOverlayHelperView class implementation
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync*
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync********************************************************************************/
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync@implementation VMSVGA3DOverlayHelperView
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync-(id)initWithOverlayWindow:(VMSVGA3DOverlayWindow*)pOverlayWindow
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync{
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_ENTER();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync self = [super initWithFrame:NSZeroRect];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync m_pOverlayWindow = pOverlayWindow;
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OHVW(%p): init OverlayHelperView\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_RET(("%p\n", (void *)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync return self;
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync}
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync-(void)viewDidMoveToWindow
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync{
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_ENTER();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OHVW(%p): viewDidMoveToWindow: new win: %p\n", (void*)self, (void*)[self window]));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [m_pOverlayWindow parentWindowChanged:[self window]];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_LEAVE();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync}
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync@end
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync/********************************************************************************
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync*
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync* VMSVGA3DOverlayWindow class implementation
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync*
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync********************************************************************************/
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync@implementation VMSVGA3DOverlayWindow
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync- (id)initWithParentView:(NSView*)pParentView overlayView:(VMSVGA3DOverlayView*)pOverlayView
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync{
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_ENTER();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync NSWindow *pParentWin = nil;
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
de210ca38246009981a22de928a52566c8c53970vboxsync if((self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]))
de210ca38246009981a22de928a52566c8c53970vboxsync {
de210ca38246009981a22de928a52566c8c53970vboxsync m_pParentView = pParentView;
de210ca38246009981a22de928a52566c8c53970vboxsync m_pOverlayView = pOverlayView;
de210ca38246009981a22de928a52566c8c53970vboxsync m_Thread = [NSThread currentThread];
de210ca38246009981a22de928a52566c8c53970vboxsync
de210ca38246009981a22de928a52566c8c53970vboxsync [m_pOverlayView setOverlayWin: self];
de210ca38246009981a22de928a52566c8c53970vboxsync
f8df398d066204e2bf0ba209ea3554fc113fb484vboxsync m_pOverlayHelperView = [[VMSVGA3DOverlayHelperView alloc] initWithOverlayWindow:self];
68e97031354932600728a42c3d454abf04f8c8d1vboxsync /* Add the helper view as a child of the parent view to get notifications */
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync [pParentView addSubview:m_pOverlayHelperView];
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync /* Make sure this window is transparent */
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync#ifdef SHOW_WINDOW_BACKGROUND
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync /* For debugging */
de210ca38246009981a22de928a52566c8c53970vboxsync [self setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7]];
de210ca38246009981a22de928a52566c8c53970vboxsync#else
de210ca38246009981a22de928a52566c8c53970vboxsync [self setBackgroundColor:[NSColor clearColor]];
de210ca38246009981a22de928a52566c8c53970vboxsync#endif
de210ca38246009981a22de928a52566c8c53970vboxsync [self setOpaque:NO];
de210ca38246009981a22de928a52566c8c53970vboxsync [self setAlphaValue:.999];
68e97031354932600728a42c3d454abf04f8c8d1vboxsync /* Disable mouse events for this window */
de210ca38246009981a22de928a52566c8c53970vboxsync [self setIgnoresMouseEvents:YES];
68e97031354932600728a42c3d454abf04f8c8d1vboxsync
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync pParentWin = [m_pParentView window];
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync
58ca9f00941a16020aa7f72c3af005df1cb218d6vboxsync /* Initial set the position to the parents view top/left (Compiz fix). */
de210ca38246009981a22de928a52566c8c53970vboxsync [self setFrameOrigin:
de210ca38246009981a22de928a52566c8c53970vboxsync [pParentWin convertBaseToScreen:
de210ca38246009981a22de928a52566c8c53970vboxsync [m_pParentView convertPoint:NSZeroPoint toView:nil]]];
de210ca38246009981a22de928a52566c8c53970vboxsync
de210ca38246009981a22de928a52566c8c53970vboxsync /* Set the overlay view as our content view */
de210ca38246009981a22de928a52566c8c53970vboxsync [self setContentView:m_pOverlayView];
de210ca38246009981a22de928a52566c8c53970vboxsync
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];
de210ca38246009981a22de928a52566c8c53970vboxsync }
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OWIN(%p): init OverlayWindow\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_RET(("%p\n", (void *)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync return self;
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync}
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync- (void)dealloc
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync{
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_ENTER();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [[NSNotificationCenter defaultCenter] removeObserver:self];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [m_pOverlayHelperView removeFromSuperview];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [m_pOverlayHelperView release];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [super dealloc];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_LEAVE();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync}
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync- (void)parentWindowFrameChanged:(NSNotification*)pNote
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync{
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_ENTER();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OWIN(%p): parentWindowFrameChanged\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [m_pOverlayView reshape];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_LEAVE();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync}
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync- (void)parentWindowChanged:(NSWindow*)pWindow
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync{
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_FUNC_ENTER();
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync DEBUG_MSG(("OWIN(%p): parentWindowChanged\n", (void*)self));
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync [[NSNotificationCenter defaultCenter] removeObserver:self];
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync if(pWindow != nil)
817d003403ed9395143bd4ba88fbd9cb60e5eeebvboxsync {
/* Ask to get notifications when our parent window frame changes. */
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(parentWindowFrameChanged:)
name:NSWindowDidResizeNotification
object:pWindow];
/* Add us self as child window */
[pWindow addChildWindow:self ordered:NSWindowAbove];
[m_pOverlayView reshape];
}
DEBUG_FUNC_LEAVE();
}
@end
/********************************************************************************
*
* VMSVGA3DOverlayView class implementation
*
********************************************************************************/
@implementation VMSVGA3DOverlayView
- (id)initWithFrame:(NSRect) frame parentView:(NSView*)pParentView
{
DEBUG_FUNC_ENTER();
m_pParentView = pParentView;
/* Make some reasonable defaults */
m_pGLCtx = nil;
m_Pos = NSZeroPoint;
m_Size = NSMakeSize(1, 1);
m_RootRect = NSMakeRect(0, 0, m_Size.width, m_Size.height);
m_yInvRootOffset = 0;
self = [super initWithFrame: frame];
DEBUG_MSG(("OVIW(%p): init VMSVGA3DOverlayView\n", (void*)self));
DEBUG_FUNC_RET(("%p\n", (void *)self));
return self;
}
- (void)cleanupData
{
DEBUG_FUNC_ENTER();
/*[self deleteDockTile];*/
[self setGLCtx:nil];
#if 0
if (m_pSharedGLCtx)
{
if ([m_pSharedGLCtx view] == self)
[m_pSharedGLCtx clearDrawable];
[m_pSharedGLCtx release];
m_pSharedGLCtx = nil;
CrBltTerm(m_pBlitter);
RTMemFree(m_pBlitter);
m_pBlitter = nil;
}
#endif
/*[self clearVisibleRegions];*/
DEBUG_FUNC_LEAVE();
}
- (void)dealloc
{
DEBUG_FUNC_ENTER();
DEBUG_MSG(("OVIW(%p): dealloc OverlayView\n", (void*)self));
[self cleanupData];
[super dealloc];
DEBUG_FUNC_LEAVE();
}
- (void)setGLCtx:(NSOpenGLContext*)pCtx
{
DEBUG_FUNC_ENTER();
DEBUG_MSG(("OVIW(%p): setGLCtx: new ctx: %p (old: %p)\n", (void*)self, (void*)pCtx, (void *)m_pGLCtx));
if (m_pGLCtx == pCtx)
{
DEBUG_FUNC_LEAVE();
return;
}
/* ensure the context drawable is cleared to avoid holding a reference to inexistent view */
if (m_pGLCtx)
{
[m_pGLCtx clearDrawable];
[m_pGLCtx release];
/*[m_pGLCtx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];*/
}
m_pGLCtx = pCtx;
if (pCtx)
[pCtx retain];
DEBUG_FUNC_LEAVE();
}
- (NSOpenGLContext*)glCtx
{
DEBUG_FUNC_ENTER();
DEBUG_FUNC_RET(("%p\n", (void *)m_pGLCtx));
return m_pGLCtx;
}
- (void)setOverlayWin:(NSWindow*)pWin
{
DEBUG_FUNC_ENTER();
DEBUG_MSG(("OVIW(%p): setOverlayWin: new win: %p\n", (void*)self, (void*)pWin));
m_pOverlayWin = pWin;
DEBUG_FUNC_LEAVE();
}
- (NSWindow*)overlayWin
{
DEBUG_FUNC_ENTER();
DEBUG_FUNC_RET(("%p\n", (void *)m_pOverlayWin));
return m_pOverlayWin;
}
- (void)setPos:(NSPoint)pos
{
DEBUG_FUNC_ENTER();
m_Pos = pos;
[self reshape];
DEBUG_FUNC_LEAVE();
}
- (NSPoint)pos
{
DEBUG_FUNC_ENTER();
DEBUG_FUNC_RET(("%f,%f\n", m_Pos.x, m_Pos.y));
return m_Pos;
}
- (void)setSize:(NSSize)size
{
DEBUG_FUNC_ENTER();
m_Size = size;
[self reshape];
DEBUG_FUNC_LEAVE();
}
- (NSSize)size
{
DEBUG_FUNC_ENTER();
DEBUG_FUNC_RET(("%f,%f\n", m_Size.width, m_Size.height));
return m_Size;
}
- (void)updateViewportCS
{
DEBUG_FUNC_ENTER();
DEBUG_MSG(("OVIW(%p): updateViewport\n", (void*)self));
/* Update the viewport for our OpenGL view */
/* [m_pSharedGLCtx update]; */
/* Clear background to transparent */
/* glClearColor(0.0f, 0.0f, 0.0f, 0.0f);*/
DEBUG_FUNC_LEAVE();
}
- (void)reshape
{
DEBUG_FUNC_ENTER();
NSRect parentFrame = NSZeroRect;
NSPoint parentPos = NSZeroPoint;
NSPoint childPos = NSZeroPoint;
NSRect childFrame = NSZeroRect;
NSRect newFrame = NSZeroRect;
DEBUG_MSG(("OVIW(%p): reshape\n", (void*)self));
/* Getting the right screen coordinates of the parents frame is a little bit
* complicated. */
parentFrame = [m_pParentView frame];
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)]];
parentFrame.origin.x = parentPos.x;
parentFrame.origin.y = parentPos.y;
/* Calculate the new screen coordinates of the overlay window. */
childPos = NSMakePoint(m_Pos.x, m_Pos.y + m_Size.height);
childPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:childPos]];
DEBUG_MSG(("FIXED childPos(screen) [%f:%f]\n", childPos.x, childPos.y));
/* Make a frame out of it. */
childFrame = NSMakeRect(childPos.x, childPos.y, m_Size.width, m_Size.height);
DEBUG_MSG(("FIXED childFrame [%f:%f], [%f:%f]\n", childFrame.origin.x, childFrame.origin.y, childFrame.size.width, childFrame.size.height));
/* We have to make sure that the overlay window will not be displayed out
* of the parent window. So intersect both frames & use the result as the new
* frame for the window. */
newFrame = NSIntersectionRect(parentFrame, childFrame);
DEBUG_MSG(("[%p]: parentFrame pos[%f : %f] size[%f : %f]\n",
(void*)self,
parentFrame.origin.x, parentFrame.origin.y,
parentFrame.size.width, parentFrame.size.height));
DEBUG_MSG(("[%p]: childFrame pos[%f : %f] size[%f : %f]\n",
(void*)self,
childFrame.origin.x, childFrame.origin.y,
childFrame.size.width, childFrame.size.height));
DEBUG_MSG(("[%p]: newFrame pos[%f : %f] size[%f : %f]\n",
(void*)self,
newFrame.origin.x, newFrame.origin.y,
newFrame.size.width, newFrame.size.height));
/* Later we have to correct the texture position in the case the window is
* out of the parents window frame. So save the shift values for later use. */
m_RootRect.origin.x = newFrame.origin.x - childFrame.origin.x;
m_RootRect.origin.y = childFrame.size.height + childFrame.origin.y - (newFrame.size.height + newFrame.origin.y);
m_RootRect.size = newFrame.size;
m_yInvRootOffset = newFrame.origin.y - childFrame.origin.y;
DEBUG_MSG(("[%p]: m_RootRect pos[%f : %f] size[%f : %f]\n",
(void*)self,
m_RootRect.origin.x, m_RootRect.origin.y,
m_RootRect.size.width, m_RootRect.size.height));
/* Set the new frame. */
[[self window] setFrame:newFrame display:YES];
#if 0
/* Make sure the context is updated according */
/* [self updateViewport]; */
if (m_pSharedGLCtx)
{
VBOX_CR_RENDER_CTX_INFO CtxInfo;
vboxCtxEnter(m_pSharedGLCtx, &CtxInfo);
[self updateViewportCS];
vboxCtxLeave(&CtxInfo);
}
#endif
DEBUG_FUNC_LEAVE();
}
@end
void vmsvga3dCocoaCreateContext(NativeNSOpenGLContextRef *ppCtx, NativeNSOpenGLContextRef pShareCtx, bool fOtherProfile)
{
DEBUG_FUNC_ENTER();
NSOpenGLPixelFormat *pFmt = nil;
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
#if 1
// @todo galitsyn: NSOpenGLPFAWindow was deprecated starting from OSX 10.9.
// Consider to remove it and check if it's harmless.
NSOpenGLPixelFormatAttribute attribs[] =
{
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)8,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24,
0
};
#else
NSOpenGLPixelFormatAttribute attribs[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
#endif
/* Choose a pixel format */
pFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
if (pFmt)
{
*ppCtx = [[VMSVGA3DOpenGLContext alloc] initWithFormat:pFmt shareContext:pShareCtx];
DEBUG_MSG(("New context %p\n", (void *)*ppCtx));
}
[pPool release];
DEBUG_FUNC_LEAVE();
}
void vmsvga3dCocoaDestroyContext(NativeNSOpenGLContextRef pCtx)
{
DEBUG_FUNC_ENTER();
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[pCtx release];
[pPool release];
DEBUG_FUNC_LEAVE();
}
void vmsvga3dCocoaCreateView(NativeNSViewRef *ppView, NativeNSViewRef pParentView)
{
DEBUG_FUNC_ENTER();
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
/* Create our worker view */
VMSVGA3DOverlayView* pView = [[VMSVGA3DOverlayView alloc] initWithFrame:NSZeroRect parentView:pParentView];
if (pView)
{
/* We need a real window as container for the view */
[[VMSVGA3DOverlayWindow alloc] initWithParentView:pParentView overlayView:pView];
/* Return the freshly created overlay view */
*ppView = pView;
}
[pPool release];
DEBUG_FUNC_LEAVE();
}
void vmsvga3dCocoaDestroyView(NativeNSViewRef pView)
{
DEBUG_FUNC_ENTER();
NSWindow *pWin = nil;
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[pView setHidden: YES];
[pWin release];
[pView release];
[pPool release];
DEBUG_FUNC_LEAVE();
}
void vmsvga3dCocoaViewSetPosition(NativeNSViewRef pView, NativeNSViewRef pParentView, int x, int y)
{
DEBUG_FUNC_ENTER();
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[(VMSVGA3DOverlayView*)pView setPos:NSMakePoint(x, y)];
[pPool release];
}
void vmsvga3dCocoaViewSetSize(NativeNSViewRef pView, int w, int h)
{
DEBUG_FUNC_ENTER();
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[(VMSVGA3DOverlayView*)pView setSize:NSMakeSize(w, h)];
[pPool release];
DEBUG_FUNC_LEAVE();
}
void vmsvga3dCocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx)
{
DEBUG_FUNC_ENTER();
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", (void*)pView, (void*)pCtx));
if (pView)
{
[(VMSVGA3DOverlayView*)pView setGLCtx:pCtx];
/* [(VMSVGA3DOverlayView*)pView makeCurrentFBO];*/
[pCtx makeCurrentContext];
}
else
{
[NSOpenGLContext clearCurrentContext];
}
[pPool release];
DEBUG_FUNC_LEAVE();
}
void vmsvga3dCocoaSwapBuffers(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx)
{
DEBUG_FUNC_ENTER();
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[pCtx flushBuffer];
[pPool release];
DEBUG_FUNC_LEAVE();
}