renderspu_cocoa_helper.m revision 7c19e11502220292d5270519296442234c2493cd
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync * VirtualBox OpenGL Cocoa Window System Helper Implementation.
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync * This source file is shared between the SharedOpenGL HGCM service and the
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync * SVGA3d emulation.
d14682a025d2c801f1e777f491092d2ebbe78c3cvboxsync * Copyright (C) 2009-2014 Oracle Corporation
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * available from http://www.virtualbox.org. This file is free software;
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * you can redistribute it and/or modify it under the terms of the GNU
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * General Public License (GPL) as published by the Free Software
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync/** @page pg_opengl_cocoa OpenGL - Cocoa Window System Helper
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * How this works:
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * In general it is not so easy like on the other platforms, cause Cocoa
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * doesn't support any clipping of already painted stuff. In Mac OS X there is
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * the concept of translucent canvas's e.g. windows and there it is just
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * painted what should be visible to the user. Unfortunately this isn't the
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * concept of chromium. Therefor I reroute all OpenGL operation from the guest
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * to a frame buffer object (FBO). This is a OpenGL extension, which is
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * supported by all OS X versions we support (AFAIC tell). Of course the guest
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * doesn't know that and we have to make sure that the OpenGL state always is
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * in the right state to paint into the FBO and not to the front/back buffer.
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * Several functions below (like cocoaBindFramebufferEXT, cocoaGetIntegerv,
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * ...) doing this. When a swap or finish is triggered by the guest, the
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * content (which is already bound to an texture) is painted on the screen
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * within a separate OpenGL context. This allows the usage of the same
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * resources (texture ids, buffers ...) but at the same time having an
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * different internal OpenGL state. Another advantage is that we can paint a
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * thumbnail of the current output in a much more smaller (GPU accelerated
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * scale) version on a third context and use glReadPixels to get the actual
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * data. glReadPixels is a very slow operation, but as we just use a much more
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * smaller image, we can handle it (anyway this is only done 5 times per
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * Other things to know:
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * - If the guest request double buffering, we have to make sure there are two
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * buffers. We use the same FBO with 2 color attachments. Also glDrawBuffer
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * and glReadBuffer is intercepted to make sure it is painted/read to/from
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * the correct buffers. On swap our buffers are swapped and not the
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * - If the guest request a depth/stencil buffer, a combined render buffer for
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * this is created.
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * - If the size of the guest OpenGL window changes, all FBO's, textures, ...
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * need to be recreated.
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * - We need to track any changes to the parent window
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * (create/destroy/move/resize). The various classes like OverlayHelperView,
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * OverlayWindow, ... are there for.
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * - The HGCM service runs on a other thread than the Main GUI. Keeps this
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * always in mind (see e.g. performSelectorOnMainThread in renderFBOToView)
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * - We make heavy use of late binding. We can not be sure that the GUI (or any
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * other third party GUI), overwrite our NSOpenGLContext. So we always ask if
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * this is our own one, before use. Really neat concept of Objective-C/Cocoa
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync/*******************************************************************************
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync* Header Files *
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync*******************************************************************************/
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync#undef PVM /* sys/param.h (included via Cocoa.h) pollutes the namespace with this define. */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# include "chromium.h" /* For the visual bits of chromium */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync/*******************************************************************************
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync* Defined Constants And Macros *
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync*******************************************************************************/
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync/* Debug macros */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync/** @def FBO
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Disable this to see how the output is without the FBO in the middle of the processing chain. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync/** @def CR_RENDER_FORCE_PRESENT_MAIN_THREAD
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Force present schedule to main thread. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync/** @def SHOW_WINDOW_BACKGROUND
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Define this to see the window background even if the window is clipped. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync/** @def DEBUG_VERBOSE
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Define this to get some debug info about the messages flow. */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_INFO(text) do { LogRel(text); AssertFailed(); } while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_WARN(text) do { LogRel(text); AssertFailed(); } while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_INFO(text) do { crWarning text; AssertFailed(); } while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_WARN(text) do { crWarning text; AssertFailed(); } while (0)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync# define DEBUG_MSG(text) do { printf text; } while (0)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync# define DEBUG_MSG_1(text) do { printf text; } while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_INFO(text) do { LogRel(text); } while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_WARN(text) do { LogRel(text); } while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_INFO(text) do { crInfo text; } while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_WARN(text) do { crWarning text; } while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_MSG_NOT_VMSVGA3D(a_TextArgs) do {} while (0)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define COCOA_LOG_FLOW(a_TextArgs) LogFlow(a_TextArgs)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define DEBUG_MSG_NOT_VMSVGA3D(a_TextArgs) DEBUG_MSG(a_TextArgs)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync# define COCOA_LOG_FLOW(a_TextArgs) DEBUG_MSG(a_TextArgs)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync#define DEBUG_FUNC_ENTER() DEBUG_MSG(("==>%s\n", __PRETTY_FUNCTION__))
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync#define DEBUG_FUNC_LEAVE() DEBUG_MSG(("<==%s\n", __PRETTY_FUNCTION__))
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync } while (0)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync } while (0)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync# define DEBUG_CHECK_GL_ERROR() do { checkGLError(__FILE__, __LINE__); } while (0);
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync const char *errStr;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync case GL_INVALID_ENUM: errStr = "GL_INVALID_ENUM"; break;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync case GL_INVALID_VALUE: errStr = "GL_INVALID_VALUE"; break;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync case GL_INVALID_OPERATION: errStr = "GL_INVALID_OPERATION"; break;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync case GL_STACK_OVERFLOW: errStr = "GL_STACK_OVERFLOW"; break;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync case GL_STACK_UNDERFLOW: errStr = "GL_STACK_UNDERFLOW"; break;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync case GL_OUT_OF_MEMORY: errStr = "GL_OUT_OF_MEMORY"; break;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync case GL_TABLE_TOO_LARGE: errStr = "GL_TABLE_TOO_LARGE"; break;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("%s:%d: glError %d (%s)\n", pszFile, iLine, uGlErr, errStr));
7c19e11502220292d5270519296442234c2493cdvboxsync * VMSVGA3D compatibility glue.
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync //NativeNSViewRef window;
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync //NativeNSViewRef nativeWindow; /**< for render_to_app_window */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncstatic void vmsvga3DWinInfoDestroy(WindowInfo *pWinInfo)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync /** @todo */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncDECLINLINE(void) renderspuWinRetain(WindowInfo *pWinInfo)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncDECLINLINE(void) renderspuWinRelease(WindowInfo *pWinInfo)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync uint32_t cRefs = ASMAtomicDecU32(&pWinInfo->cRefs);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncstatic int renderspuVBoxCompositorLock(WindowInfo *pWinInfo, PCVBOXVR_SCR_COMPOSITOR *ppCompositor)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync int rc = RTCritSectEnter(&pWinInfo->CompositorLock);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncstatic int renderspuVBoxCompositorUnlock(WindowInfo *pWinInfo)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync int rc = RTCritSectLeave(&pWinInfo->CompositorLock);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncstatic PCVBOXVR_SCR_COMPOSITOR renderspuVBoxCompositorAcquire(WindowInfo *pWinInfo)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync int rc = RTCritSectEnter(&pWinInfo->CompositorLock);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync PCVBOXVR_SCR_COMPOSITOR pCompositor = pWinInfo->pCompositor;
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync Assert(!CrVrScrCompositorIsEmpty(pWinInfo->pCompositor));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync /* if no compositor is set, release the lock and return */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncstatic void renderspuVBoxCompositorRelease(WindowInfo *pWinInfo)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync Assert(!CrVrScrCompositorIsEmpty(pWinInfo->pCompositor));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync int rc = RTCritSectLeave(&pWinInfo->CompositorLock);
ece707b8d97e63ed54d4b48d7a8d841187e0023cvboxsync NSOpenGLContext *pCtx = [NSOpenGLContext currentContext];
ece707b8d97e63ed54d4b48d7a8d841187e0023cvboxsync renderspu_SystemMakeCurrent(pWinInfo, 0, pCtxInfo);
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * State carrying structure for use with vboxCtxEnter and vboxCtxLeave
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync/** Pointer to render context info for use with vboxCtxEnter/Leave. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsynctypedef VBOX_CR_RENDER_CTX_INFO *PVBOX_CR_RENDER_CTX_INFO;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsyncstatic void vboxCtxEnter(NSOpenGLContext *pNewCtx, PVBOX_CR_RENDER_CTX_INFO pCtxInfo)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /** @todo r=bird: Why do we save the NEW VIEW here? vboxCtxLeave calls it 'pOldView'. Bug? */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* No context switch necessary. */
3a45119099f0df5230e8304145168aa5e2a3f1a1vboxsyncstatic void vboxCtxLeave(PVBOX_CR_RENDER_CTX_INFO pCtxInfo)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* vboxCtxEnter saves the new view, not the old. So, what we actually
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync do here is switching the view of the old context to that of the new
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync one (wrt vboxCtxEnter) before making it current. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /** @todo r=bird: Figure out what we really want to do here, and either rename
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * pOldView or fix the code. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync NSView *pTstOldView = pTstOldCtx ? [pTstOldCtx view] : nil;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Custom OpenGL context class.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * This implementation doesn't allow to set a view to the context, but save the
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * view for later use. Also it saves a copy of the pixel format used to create
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * that context for later use.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Abstrack task class.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync/** Run method that the child classes must reimplement.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * This will abort the process. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Generic task class for executing a given method select.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (id)initWithObject:(id)aObject selector:(SEL)aSelector arg:(id)aArg;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Initializes a VBoxTaskPerformSelector.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @param aObject The object (reference not consumed).
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @param aSelector The method selector.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @param aArg The method argument (reference not consumed).
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync- (id)initWithObject:(id)aObject selector:(SEL)aSelector arg:(id)aArg
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync [m_Object performSelector:m_Selector withObject:m_Arg];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Adds a task to the composite task object.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @param pTask Task to add. Reference is NOT consumed.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Dequeue a task.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync VBoxTask *pTask = (VBoxTask *)[m_pArray objectAtIndex:m_CurIndex];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Remove the first 1025 empty entires.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Run the task and release it.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync VBoxTask *pTask = (VBoxTask*)[m_pArray objectAtIndex:m_CurIndex];
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync DEBUG_WARN(("dealloc with non-empty tasks! %p\n", pTask));
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync- (void)addObj:(id)aObject selector:(SEL)aSelector arg:(id)aArg;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync s_pRunner = [[VBoxMainThreadTaskRunner alloc] init];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /** @todo r=bird: Unbalanced [self retain]. */
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync [self performSelectorOnMainThread:@selector(runTasks) withObject:nil waitUntilDone:NO];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Adds a task calling an object method (selector).
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @param aObject The object (reference not consumed)..
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @param aSelector The method selector.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @param aArg The method argument (reference not consumed).
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync- (void)addObj:(id)aObject selector:(SEL)aSelector arg:(id)aArg
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync VBoxTaskPerformSelector *pSelTask = [[VBoxTaskPerformSelector alloc] initWithObject:aObject selector:aSelector arg:aArg];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Internal method for running the pending tasks.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /** @todo r=bird: This release and the retain in the add method aren't
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * necessarily balanced if there are more than one call to add().
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * This could probably end up deleting the singleton prematurely and leave
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * globalInstance() returning pointers to a stale object in freed memory,
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * quite possibly causing crashes or/and heap corruption. */
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync DEBUG_WARN(("run tasks called not on main thread!\n"));
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync [self performSelectorOnMainThread:@selector(runTasks) withObject:nil waitUntilDone:YES];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Callback for calling runTasks via renderspuCalloutClient.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @param pvUser The VBoxMainThreadTaskRunner singleton.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsyncstatic DECLCALLBACK(void) VBoxMainThreadTaskRunner_RcdRunCallback(void *pvUser)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync VBoxMainThreadTaskRunner *pRunner = (VBoxMainThreadTaskRunner *)pvUser;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync Assert(pRunner == [VBoxMainThreadTaskRunner globalInstance]);
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Runs pending tasks synchronously, if possible in the current context.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * @returns true if executed tasks, false if not possible.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Call on main thread (?) via renderspuCalloutClient (whatever that is).
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync renderspuCalloutClient(VBoxMainThreadTaskRunner_RcdRunCallback, self);
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync return true;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Run directly if on main thread.
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync return true;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Not possible. */
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync return false;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /** @todo r=bird: WTF is the point of the deallocator. The object is a singelton
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * stored in an inaccessible static variable! */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * The custom view class.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * This is the main class of the cocoa OpenGL implementation. It manages a
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * frame buffer object for the rendering of the guest applications. The guest
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * applications render in this frame buffer which is bound to an OpenGL texture.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * To display the guest content, a secondary shared OpenGL context of the main
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * OpenGL context is created. The secondary context is marked as non-opaque and
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * the texture is displayed on an object which is composed out of the several
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * visible region rectangles.
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync /** The corresponding dock tile view of this OpenGL view & all helper
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync * members. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /** @name For clipping
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync * @remarks appears to be unused and a complete waste of time + heap.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /** @name Position/Size tracking
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync /** This is necessary for clipping on the root window */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView *)pParentView winInfo:(WindowInfo *)pWinInfo;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (void)vboxPresent:(const VBOXVR_SCR_COMPOSITOR *)pCompositor;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (void)vboxPresentCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (void)vboxPresentToDockTileCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (void)vboxPresentToViewCS:(const VBOXVR_SCR_COMPOSITOR *)pCompositor;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (void)presentComposition:(const VBOXVR_SCR_COMPOSITOR_ENTRY *)pChangedEntry;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (void)setVisibleRegions:(GLint)cRects paRects:(const GLint *)paRects;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Helper view.
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync * This view is added as a sub view of the parent view to track
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync * main window changes. Whenever the main window is changed
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync * (which happens on fullscreen/seamless entry/exit) the overlay
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync * window is informed & can add them self as a child window
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync-(id)initWithOverlayWindow:(OverlayWindow *)pOverlayWindow;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Custom window class.
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync * This is the overlay window which contains our custom NSView.
bcd589d9db90b68d3af5d6839c1d613bb64d4c04vboxsync * Its a direct child of the Qt Main window. It marks its background
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * transparent & non opaque to make clipping possible. It also disable mouse
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * events and handle frame change events of the parent view.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (id)initWithParentView:(NSView *)pParentView overlayView:(OverlayView *)pOverlayView;
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync- (void)parentWindowFrameChanged:(NSNotification *)note;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Dock overlay view class.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * We need a lock cause the thumb image could be accessed from the main
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync * thread when someone is calling display on the dock tile & from the
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * OpenGL thread when the thumbnail is updated.
2dd7b4388106de88d20f33a8aa6c85c8babf507bvboxsync /* Create a buffer for our thumbnail image. Its in the size of this view. */
2dd7b4388106de88d20f33a8aa6c85c8babf507bvboxsync m_ThumbBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
2dd7b4388106de88d20f33a8aa6c85c8babf507bvboxsync m_ThumbImage = [[NSImage alloc] initWithSize:[m_ThumbBitmap size]];
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync [[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7] set];
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync [NSBezierPath fillRect:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync [m_ThumbImage drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync/********************************************************************************
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync* OverlayOpenGLContext class implementation
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync********************************************************************************/
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync-(id)initWithFormat:(NSOpenGLPixelFormat *)format shareContext:(NSOpenGLContext *)share
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync self = [super initWithFormat:format shareContext:share];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OCTX(%p): init OverlayOpenGLContext\n", (void *)self));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OCTX(%p): dealloc OverlayOpenGLContext\n", (void *)self));
c9a593aa048a154e59b52d1237d89e3cdaee9b3dvboxsync [m_pPixelFormat getValues:&val forAttribute:NSOpenGLPFADoubleBuffer forVirtualScreen:0];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void *)self, (void *)view));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync return [super view];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void *)self));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync/********************************************************************************
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync* OverlayHelperView class implementation
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync********************************************************************************/
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync-(id)initWithOverlayWindow:(OverlayWindow *)pOverlayWindow
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OHVW(%p): init OverlayHelperView\n", (void *)self));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OHVW(%p): viewDidMoveToWindow: new win: %p\n", (void *)self, (void *)[self window]));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync [m_pOverlayWindow parentWindowChanged:[self window]];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync/********************************************************************************
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync* OverlayWindow class implementation
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync********************************************************************************/
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (id)initWithParentView:(NSView *)pParentView overlayView:(OverlayView *)pOverlayView
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync m_pOverlayHelperView = [[OverlayHelperView alloc] initWithOverlayWindow:self];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Add the helper view as a child of the parent view to get notifications */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Make sure this window is transparent */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* For debugging */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync [self setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7]];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Disable mouse events for this window */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Initial set the position to the parents view top/left (Compiz fix). */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync [m_pParentView convertPoint:NSZeroPoint toView:nil]]];
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync /* Set the overlay view as our content view */
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync /* Add ourself as a child to the parent views window. Note: this has to
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync * be done last so that everything else is setup in
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * parentWindowChanged. */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync [pParentWin addChildWindow:self ordered:NSWindowAbove];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OWIN(%p): init OverlayWindow\n", (void *)self));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void *)self));
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync [[NSNotificationCenter defaultCenter] removeObserver:self];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (void)parentWindowFrameChanged:(NSNotification *)pNote
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OWIN(%p): parentWindowFrameChanged\n", (void *)self));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Reposition this window with the help of the OverlayView. Perform the
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * call in the OpenGL thread.
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync [m_pOverlayView performSelector:@selector(vboxReshapePerform) onThread:m_Thread withObject:nil waitUntilDone:YES];
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync [self performSelectorOnMainThread:@selector(vboxReshapePerform) withObject:nil waitUntilDone:NO];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OWIN(%p): parentWindowChanged\n", (void *)self));
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync [[NSNotificationCenter defaultCenter] removeObserver:self];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Ask to get notifications when our parent window frame changes. */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Add us self as child window */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync [pWindow addChildWindow:self ordered:NSWindowAbove];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Reshape the overlay view after a short waiting time to let the main
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * window resize itself properly.
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync [m_pOverlayView performSelector:@selector(vboxReshapePerform) withObject:nil afterDelay:0.2];
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync [NSTimer scheduledTimerWithTimeInterval:0.2 target:m_pOverlayView selector:@selector(vboxReshapePerform) userInfo:nil repeats:NO];
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync [self performSelectorOnMainThread:@selector(vboxReshapePerform) withObject:nil waitUntilDone:NO];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync/********************************************************************************
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync* OverlayView class implementation
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync********************************************************************************/
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync- (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView *)pParentView winInfo:(WindowInfo *)pWinInfo
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p aThread=%p pParentView=%p pWinInfo=%p\n", __PRETTY_FUNCTION__, (void *)self,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync (void *)aThread, (void *)pParentView, (void *)pWinInfo));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Make some reasonable defaults */
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync m_RootRect = NSMakeRect(0, 0, m_Size.width, m_Size.height);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns self=%p\n", __PRETTY_FUNCTION__, (void *)self));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p aRect=%d,%d %d,%d\n", __PRETTY_FUNCTION__, (void *)self, (int)aRect.origin.x, (int)aRect.origin.y,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pCtx=%p (old=%p)\n", __PRETTY_FUNCTION__, (void *)self, (void *)pCtx, m_pGLCtx));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Only do something if the context changes.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Ensure the context drawable is cleared to avoid holding a reference to inexistent view. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /*[m_pGLCtx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];*/
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p returns %p\n", __PRETTY_FUNCTION__, (void *)self, (void *)m_pGLCtx));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p returns %p\n", __PRETTY_FUNCTION__, (void *)self, (void *)m_pParentView));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pView=%p (old=%p)\n", __PRETTY_FUNCTION__, (void *)self, (void *)pView, m_pParentView));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pWin=%p (old=%p)\n", __PRETTY_FUNCTION__, (void *)self, (void *)pWin, m_pOverlayWin));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p returns %p\n", __PRETTY_FUNCTION__, (void *)self, (void *)m_pOverlayWin));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pos=%d,%d (old pos=%d,%d)\n", __PRETTY_FUNCTION__, (void *)self, (int)pos.x, (int)pos.y,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pPos=%p (%d,%d) (old pos=%d,%d)\n", __PRETTY_FUNCTION__, (void *)self, pPos,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync (int)[pPos pointValue].x, (int)[pPos pointValue].y, (int)m_Pos.x, (int)m_Pos.y));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pos=%d,%d (old pos=%d,%d)\n", __PRETTY_FUNCTION__, (void *)self, (int)pos.x, (int)pos.y,
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync [pRunner addObj:self selector:@selector(vboxSetPosUIObj:) arg:pPos];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p returns %d,%d\n", __PRETTY_FUNCTION__, (void *)self, (int)m_Pos.x, (int)m_Pos.y));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p returns %d\n", __PRETTY_FUNCTION__, (void *)self, m_fEverSized));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Hide the view early. */
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync [[NSNotificationCenter defaultCenter] removeObserver:pWin];
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync /* We can NOT run synchronously with the main thread since this may lead to a deadlock,
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync caused by main thread waiting xpcom thread, xpcom thread waiting to main hgcm thread,
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync and main hgcm thread waiting for us, this is why use waitUntilDone:NO,
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync which should cause no harm. */
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync [pWin performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync /* We can NOT run synchronously with the main thread since this may lead to a deadlock,
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync caused by main thread waiting xpcom thread, xpcom thread waiting to main hgcm thread,
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync and main hgcm thread waiting for us, this is why use waitUntilDone:NO.
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync We need to avoid concurrency though, so we cleanup some data right away via a cleanupData call. */
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync [self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pSize=%p (%d,%d)\n", __PRETTY_FUNCTION__, (void *)self, (void *)pSize,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync (int)[pSize sizeValue].width, (int)[pSize sizeValue].height));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p size=%d,%d\n", __PRETTY_FUNCTION__, (void *)self, (int)size.width, (int)size.height));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG(("OVIW(%p): vboxSetSize: new size: %dx%d\n", (void *)self, (int)m_Size.width, (int)m_Size.height));
d66955d5e795c1a7cf73c38a799fed204d83c38cvboxsync /* ensure window contents is updated after that */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p size=%d,%d\n", __PRETTY_FUNCTION__, (void *)self, (int)size.width, (int)size.height));
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync [pRunner addObj:self selector:@selector(vboxSetSizeUIObj:) arg:pSize];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p returns %d,%d\n", __PRETTY_FUNCTION__, (void *)self, (int)m_Size.width, (int)m_Size.height));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Update the viewport for our OpenGL view. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Clear background to transparent. */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync /* have to rebind GL_TEXTURE_RECTANGLE_ARB as m_FBOTexId could be changed in updateFBO call */
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync if (pCurCtx && pCurCtx == m_pGLCtx && (pCurView = [pCurCtx view]) == self)
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync /* do it in a lazy way */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p - m_DockTileView=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)m_DockTileView));
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync DEBUG_MSG(("FIXED parentFrame [%f:%f], [%f:%f]\n", parentFrame.origin.x, parentFrame.origin.y, parentFrame.size.width, parentFrame.size.height));
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync DEBUG_MSG(("FIXED(view) parentPos [%f:%f]\n", parentPos.x, parentPos.y));
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync parentPos = [m_pParentView convertPoint:parentPos toView:nil];
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync DEBUG_MSG(("FIXED parentPos(win) [%f:%f]\n", parentPos.x, parentPos.y));
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync parentPos = [[m_pParentView window] convertBaseToScreen:parentPos];
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync DEBUG_MSG(("FIXED parentPos(screen) [%f:%f]\n", parentPos.x, parentPos.y));
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync childPos = NSMakePoint(m_Pos.x, m_Pos.y + m_Size.height);
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync DEBUG_MSG(("FIXED(view) childPos [%f:%f]\n", childPos.x, childPos.y));
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync childPos = [m_pParentView convertPoint:childPos toView:nil];
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync DEBUG_MSG(("FIXED(win) childPos [%f:%f]\n", childPos.x, childPos.y));
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync childPos = [[m_pParentView window] convertBaseToScreen:childPos];
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync DEBUG_MSG(("FIXED childPos(screen) [%f:%f]\n", childPos.x, childPos.y));
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync childFrame = NSMakeRect(childPos.x, childPos.y, m_Size.width, m_Size.height);
cb445170c831c6c56d2d82261e9193b66ceb98a7vboxsync DEBUG_MSG(("FIXED childFrame [%f:%f], [%f:%f]\n", childFrame.origin.x, childFrame.origin.y, childFrame.size.width, childFrame.size.height));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* We have to make sure that the overlay window will not be displayed out
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * of the parent window. So intersect both frames & use the result as the new
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync * frame for the window. */
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync newFrame = NSIntersectionRect(parentFrame, childFrame);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync DEBUG_MSG(("[%#p]: parentFrame pos[%f : %f] size[%f : %f]\n",
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync (void *)self, parentFrame.origin.x, parentFrame.origin.y, parentFrame.size.width, parentFrame.size.height));
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync DEBUG_MSG(("[%#p]: childFrame pos[%f : %f] size[%f : %f]\n",
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync (void *)self, childFrame.origin.x, childFrame.origin.y, childFrame.size.width, childFrame.size.height));
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync DEBUG_MSG(("[%#p]: newFrame pos[%f : %f] size[%f : %f]\n",
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync (void *)self, newFrame.origin.x, newFrame.origin.y, newFrame.size.width, newFrame.size.height));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Later we have to correct the texture position in the case the window is
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync * out of the parents window frame. So save the shift values for later use. */
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync m_RootRect.origin.x = newFrame.origin.x - childFrame.origin.x;
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync m_RootRect.origin.y = childFrame.size.height + childFrame.origin.y - (newFrame.size.height + newFrame.origin.y);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync m_yInvRootOffset = newFrame.origin.y - childFrame.origin.y;
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync DEBUG_MSG(("[%#p]: m_RootRect pos[%f : %f] size[%f : %f]\n",
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync (void *)self, m_RootRect.origin.x, m_RootRect.origin.y, m_RootRect.size.width, m_RootRect.size.height));
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync NSScrollView *pScrollView = [[[m_pParentView window] contentView] enclosingScrollView];
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync if (pScrollView)
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync NSRect scrollRect = [pScrollView documentVisibleRect];
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync NSRect scrollRect = [m_pParentView visibleRect];
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync printf ("sc rect: %d %d %d %d\n", (int) scrollRect.origin.x,(int) scrollRect.origin.y,(int) scrollRect.size.width,(int) scrollRect.size.height);
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync NSRect b = [[m_pParentView superview] bounds];
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync printf ("bound rect: %d %d %d %d\n", (int) b.origin.x,(int) b.origin.y,(int) b.size.width,(int) b.size.height);
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync newFrame.origin.x += scrollRect.origin.x;
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync newFrame.origin.y += scrollRect.origin.y;
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Set the new frame. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Inform the dock tile view as well. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Make sure the context is updated accordingly. */
2f4c1bacd54af5063c3185cc8eab03e4e8ef9b90vboxsync /* [self updateViewport]; */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Is there a dock tile preview enabled in the GUI? If so setup a
416817daa142e9bb7eaf14a1b10577978a5e691bvboxsync * additional thumbnail view for the dock tile. */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns - m_DockTileView\n", __PRETTY_FUNCTION__, (void *)m_DockTileView));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p - m_DockTileView=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)m_DockTileView));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* We change the active view, so flush first */
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync if ([NSOpenGLContext currentContext] != m_pGLCtx)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns true (m_pSharedGLCtx=%p)\n", __PRETTY_FUNCTION__, (void *)m_pSharedGLCtx));
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync return true;
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns false - m_pBlitter allocation failed\n", __PRETTY_FUNCTION__));
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync return false;
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync int rc = CrBltInit(m_pBlitter, NULL, false /*fCreateNewCtx*/, false /*fForceDrawBlt*/,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync &render_spu.GlobalShaders, &render_spu.blitterDispatch
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns false - CrBltInit failed with rc=%Rrc\n", __PRETTY_FUNCTION__, rc));
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync return false;
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: blitter (%p) created successfully for view 0x%p\n", (void *)m_pBlitter, (void *)self));
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync /* Create a shared context out of the main context. Use the same pixel format. */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync NSOpenGLPixelFormat *pPixelFormat = [(OverlayOpenGLContext *)m_pGLCtx openGLPixelFormat];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync NSOpenGLContext *pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:pPixelFormat shareContext:m_pGLCtx];
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync /* Set the new context as non opaque */
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync [pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync /* Set this view as the drawable for the new context */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns true - new m_pSharedGLCtx=%p\n", __PRETTY_FUNCTION__, (void *)m_pSharedGLCtx));
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync return true;
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Issue to the gui thread. */
53911b04965533f5d40b5ab2f840381efee79328vboxsync [self performSelectorOnMainThread:@selector(vboxTryDrawUI) withObject:nil waitUntilDone:NO];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p fVisible=%d\n", __PRETTY_FUNCTION__, (void *)self, fVisible));
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync NSNumber *pVisObj = [NSNumber numberWithBool:fVisible];
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync [pRunner addObj:self selector:@selector(vboxSetVisibleUIObj:) arg:pVisObj];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p fVisible=%d\n", __PRETTY_FUNCTION__, (void *)self, fVisible));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pVisibleObj=%p(%d)\n", __PRETTY_FUNCTION__,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync (void *)self, (void *)pVisibleObj, [pVisibleObj boolValue]));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pParentView=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)pParentView));
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync [pRunner addObj:self selector:@selector(vboxReparentUI:) arg:pParentView];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pParentView=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)pParentView));
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync /* Make sure the window is removed from any previous parent window. */
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync [[[self overlayWin] parentWindow] removeChildWindow:[self overlayWin]];
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync /* Set the new parent view */
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync /* Add the overlay window as a child to the new parent window */
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync [[pParentView window] addChildWindow:[self overlayWin] ordered:NSWindowAbove];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns - request to draw on a hidden view\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns - request to draw a view w/o a parent\n", __PRETTY_FUNCTION__));
ee357d0503e525172eab0eeb8f5befc2993c7ea5vboxsync int rc = renderspuVBoxCompositorLock(m_pWinInfo, &pCompositor);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns - renderspuVBoxCompositorLock failed (%Rrc)\n", __PRETTY_FUNCTION__, rc));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns - noCompositorUI\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns - vboxSharedCtxCreate failed\n", __PRETTY_FUNCTION__));
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync pCompositor = renderspuVBoxCompositorAcquire(m_pWinInfo);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns - Failed to reacquire compositor\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync DEBUG_MSG(("%s: NeedCleanup\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: Calling vboxPresent\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: NotVisible\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: Reschedule\n", __PRETTY_FUNCTION__));
a8d502445ce722c6b9700c5579b4a38b58827b7dvboxsync [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(vboxTryDrawUI) userInfo:nil repeats:NO];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p - m_pGLCtx=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)m_pGLCtx));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync- (void)vboxPresent:(PCVBOXVR_SCR_COMPOSITOR)pCompositor
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pCompositor=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)pCompositor));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync /*DEBUG_MSG(("OVIW(%p): renderFBOToView\n", (void *)self));*/
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync- (void)vboxPresentCS:(PCVBOXVR_SCR_COMPOSITOR)pCompositor
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pCompositor=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)pCompositor));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: Not current view of shared ctx! Switching... (self=%p, view=%p, m_pSharedGLCtx)\n",
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync __PRETTY_FUNCTION__, (void *)self, (void *)[m_pSharedGLCtx view], (void *)m_pSharedGLCtx));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* Render FBO content to the dock tile when necessary. */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /* change to #if 0 to see thumbnail image */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsyncDECLINLINE(void) vboxNSRectToRect(const NSRect *pR, RTRECT *pRect)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync pRect->xRight = (int)(pR->origin.x + pR->size.width);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync pRect->yBottom = (int)(pR->origin.y + pR->size.height);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsyncDECLINLINE(void) vboxNSRectToRectUnstretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync pRect->xRight = (int)((pR->origin.x + pR->size.width) / xStretch);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync pRect->yBottom = (int)((pR->origin.y + pR->size.height) / yStretch);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsyncDECLINLINE(void) vboxNSRectToRectStretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch)
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync pRect->xRight = (int)((pR->origin.x + pR->size.width) * xStretch);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync pRect->yBottom = (int)((pR->origin.y + pR->size.height) * yStretch);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync- (void)vboxPresentToViewCS:(PCVBOXVR_SCR_COMPOSITOR)pCompositor
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p - r={%d,%d %d,%d}\n", __PRETTY_FUNCTION__, (void *)self,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync (int)r.origin.x, (int)r.origin.y, (int)r.size.width, (int)r.size.height));
2f4c1bacd54af5063c3185cc8eab03e4e8ef9b90vboxsync#if 1 /* Set to 0 to see the docktile instead of the real output */
01df41f7a4e5f7de195a059541d1c89676da9673vboxsync CrVrScrCompositorConstIterInit(pCompositor, &CIter);
2f4c1bacd54af5063c3185cc8eab03e4e8ef9b90vboxsync /* Clear background to transparent */
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync CrVrScrCompositorGetStretching(pCompositor, &xStretch, &yStretch);
01df41f7a4e5f7de195a059541d1c89676da9673vboxsync while ((pEntry = CrVrScrCompositorConstIterNext(&CIter)) != NULL)
8cfe2efff2058bd07777056112155ea5353dcfbavboxsync int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions, NULL);
3ea1dbf096240fc221aea99352a74c17a367a9b6vboxsync uint32_t fFlags = CrVrScrCompositorEntryFlagsCombinedGet(pCompositor, pEntry);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync VBoxRectIntersected(&RestrictDstRect, pDstRect, &DstRect);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync VBoxRectTranslate(&DstRect, -RestrictDstRect.xLeft, -RestrictDstRect.yTop);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync vboxNSRectToRectUnstretched(&m_RootRect, &RestrictSrcRect, xStretch, yStretch);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect);
01df41f7a4e5f7de195a059541d1c89676da9673vboxsync CrBltBlitTexMural(m_pBlitter, true, CrTdTexGet(pTexData), pSrcRect, pDstRect, 1, fFlags | CRBLT_F_NOALPHA);
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync AssertMsgFailed(("CrBltEnter failed rc %Rrc", rc));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync AssertMsgFailed(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %Rrc\n", rc));
2f4c1bacd54af5063c3185cc8eab03e4e8ef9b90vboxsync DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync glFinish();
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync- (void)presentComposition:(PCVBOXVR_SCR_COMPOSITOR_ENTRY)pChangedEntry
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pChangedEntry=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)pChangedEntry));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
01df41f7a4e5f7de195a059541d1c89676da9673vboxsync /*CrBltMuralSetCurrentInfo(m_pBlitter, NULL);*/
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync- (void)vboxPresentToDockTileCS:(PCVBOXVR_SCR_COMPOSITOR)pCompositor
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p pCompositor=%p\n", __PRETTY_FUNCTION__, (void *)self, (void *)pCompositor));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * Only update after at least 200 ms, cause glReadPixels is
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * heavy performance wise.
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync /* todo: check this for optimization */
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName);
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_STORAGE_HINT_APPLE,
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync /* Do other work processing here, using a double or triple buffer */
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA,
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync /* Clear background to transparent */
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync CrVrScrCompositorGetStretching(pCompositor, &xStretch, &yStretch);
01df41f7a4e5f7de195a059541d1c89676da9673vboxsync CrVrScrCompositorConstIterInit(pCompositor, &CIter);
01df41f7a4e5f7de195a059541d1c89676da9673vboxsync while ((pEntry = CrVrScrCompositorConstIterNext(&CIter)) != NULL)
8cfe2efff2058bd07777056112155ea5353dcfbavboxsync int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions, NULL);
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync uint32_t fFlags = CrVrScrCompositorEntryFlagsCombinedGet(pCompositor, pEntry);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync VBoxRectIntersected(&RestrictDstRect, pDstRect, &DstRect);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync VBoxRectTranslate(&DstRect, -RestrictDstRect.xLeft, -RestrictDstRect.yTop);
6e519506bee0a7f680824b1ca5d8e3fead3ae95evboxsync VBoxRectScale(&DstRect, m_FBOThumbScaleX, m_FBOThumbScaleY);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync vboxNSRectToRectUnstretched(&m_RootRect, &RestrictSrcRect, xStretch, yStretch);
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect);
01df41f7a4e5f7de195a059541d1c89676da9673vboxsync CrBltBlitTexMural(m_pBlitter, true, CrTdTexGet(pTexData), pSrcRect, pDstRect, 1, fFlags);
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync AssertMsgFailed(("CrBltEnter failed rc %Rrc", rc));
2f4c1bacd54af5063c3185cc8eab03e4e8ef9b90vboxsync DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync AssertMsgFailed(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %Rrc\n", rc));
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync /* Here the magic of reading the FBO content in our own buffer
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * happens. We have to lock this access, in the case the dock
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync * is updated currently. */
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync glReadPixels(0, m_RootRect.size.height - rr.size.height, rr.size.width, rr.size.height,
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync crDumpNamedTGAF((GLint)rr.size.width, (GLint)rr.size.height,
8d1da51eb6665874aa82bf03668e03d1a0d63223vboxsync [[m_DockTileView thumbBitmap] bitmapData], "/Users/leo/vboxdumps/dump%d.tga", g_cVBoxTgaCtr);
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync pDT = [[NSApplication sharedApplication] dockTile];
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync /* Send a display message to the dock tile in the main thread */
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync [[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync- (void)setVisibleRegions:(GLint)cRects paRects:(const GLint *)paRects
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p cRects=%d paRects=%p\n", __PRETTY_FUNCTION__, (void *)self, cRects, (void *)paRects));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG_1(("OVIW(%p): setVisibleRegions: %d - %d %d %d %d\n", (void *)self, i, paRects[i * 4], paRects[i * 4 + 1], paRects[i * 4 + 2], paRects[i * 4 + 3]));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync m_paClipRects = (GLint *)RTMemDup(paRects, sizeof(GLint) * 4 * cRects);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns\n", __PRETTY_FUNCTION__));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: self=%p\n", __PRETTY_FUNCTION__, (void *)self));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync NSView *pContentView = [[[NSApplication sharedApplication] dockTile] contentView];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * First try the new variant which checks if this window is within the
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * screen which is previewed in the dock.
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync if ([pContentView respondsToSelector:@selector(screenContentWithParentView:)])
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync pScreenContent = [pContentView performSelector:@selector(screenContentWithParentView:) withObject:(id)m_pParentView];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * If it fails, fall back to the old variant (VBox...).
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync else if ([pContentView respondsToSelector:@selector(screenContent)])
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync pScreenContent = [pContentView performSelector:@selector(screenContent)];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns %p (pContentView=%p)\n", __PRETTY_FUNCTION__, (void *)pScreenContent, (void *)pContentView));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync /** @todo This is not correct, we should use framebuffer size here, while
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync * parent view frame size may differ in case of scrolling. */
9161d9a8318db73b2848c1feaef3880980474e64vboxsync m_FBOThumbScaleX = (float)dockFrame.size.width / parentFrame.size.width;
9161d9a8318db73b2848c1feaef3880980474e64vboxsync m_FBOThumbScaleY = (float)dockFrame.size.height / parentFrame.size.height;
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync newFrame = NSMakeRect((int)(m_Pos.x * m_FBOThumbScaleX),
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync (int)(dockFrame.size.height - (m_Pos.y + m_Size.height - m_yInvRootOffset) * m_FBOThumbScaleY),
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync NSRect newFrame = NSMakeRect ((int)roundf(m_Pos.x * m_FBOThumbScaleX), (int)roundf(dockFrame.size.height - (m_Pos.y + m_Size.height) * m_FBOThumbScaleY), (int)roundf(m_Size.width * m_FBOThumbScaleX), (int)roundf(m_Size.height * m_FBOThumbScaleY));
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync NSRect newFrame = NSMakeRect ((m_Pos.x * m_FBOThumbScaleX), (dockFrame.size.height - (m_Pos.y + m_Size.height) * m_FBOThumbScaleY), (m_Size.width * m_FBOThumbScaleX), (m_Size.height * m_FBOThumbScaleY));
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync printf ("%f %f %f %f - %f %f\n", newFrame.origin.x, newFrame.origin.y, newFrame.size.width, newFrame.size.height, m_Size.height, m_FBOThumbScaleY);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("%s: returns - newFrame={%d,%d %d,%d} pView=%d\n", __PRETTY_FUNCTION__, (int)newFrame.origin.x,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync (int)newFrame.origin.y, (int)newFrame.size.width, (int)newFrame.size.height, (void *)pView));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync/********************************************************************************
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync* OpenGL context management
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync********************************************************************************/
ad1aea7f006b1feaea275f858b5b574ae61bfe39vboxsyncvoid cocoaGLCtxCreate(NativeNSOpenGLContextRef *ppCtx, GLbitfield fVisParams, NativeNSOpenGLContextRef pSharedCtx)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaGLCtxCreate: ppCtx=%p fVisParams=%#x pSharedCtx=%p\n", (void *)ppCtx, fVisParams, (void *)pSharedCtx));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
529e6bec97f5ef2e005c99c205c9624583ecb7f0vboxsync NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
b9473064e26edc9a65150b4206ea1e52f3ca600avboxsync NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW((" CR_MULTISAMPLE_BIT requested\n"));
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync /* We don't support that.
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW((" CR_STEREO_BIT requested\n"));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync attribs[i++] = NSOpenGLPFAStereo;
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW((" Offline rendering is enabled\n"));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Mark the end */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Choose a pixel format */
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync pFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
aaa6e7826ca134b41d12c1f570bd7874ae1d8135vboxsync *ppCtx = [[OverlayOpenGLContext alloc] initWithFormat:pFmt shareContext:pSharedCtx];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Enable multi threaded OpenGL engine */
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync CGLContextObj cglCtx = [*ppCtx CGLContextObj];
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync CGLError err = CGLEnable(cglCtx, kCGLCEMPEngine);
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync if (err != kCGLNoError)
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync printf ("Couldn't enable MT OpenGL engine!\n");
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaGLCtxDestroy: returns *ppCtx=%p\n", (void *)*ppCtx));
c4bfe32373c55416bf49dc29ebf45dfa560b4692vboxsyncvoid cocoaGLCtxDestroy(NativeNSOpenGLContextRef pCtx)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaGLCtxDestroy: pCtx=%p\n", (void *)pCtx));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
01df41f7a4e5f7de195a059541d1c89676da9673vboxsync /*[pCtx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];*/
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync/********************************************************************************
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync* View management
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync********************************************************************************/
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncstatic OverlayView *vboxViewCreate(WindowInfo *pWinInfo, NativeNSViewRef pParentView)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("vboxViewCreate: pWinInfo=%p pParentView=%p\n", pWinInfo, (void *)pParentView));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync /* Create our worker view. */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync OverlayView *pView = [[OverlayView alloc] initWithFrame:NSZeroRect
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* We need a real window as container for the view */
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync [[OverlayWindow alloc] initWithParentView:pParentView overlayView:pView];
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync /* Return the freshly created overlay view */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("vboxViewCreate: returns %p\n", (void *)pView));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("vboxViewCreate: returns NULL\n"));
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsyncstatic DECLCALLBACK(void) vboxRcdCreateView(void *pvCb)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync CR_RCD_CREATEVIEW *pCreateView = (CR_RCD_CREATEVIEW *)pvCb;
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync pCreateView->pView = vboxViewCreate(pCreateView->pWinInfo, pCreateView->pParentView);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("vboxRcdCreateView: returns pView=%p\n", (void *)pCreateView->pView));
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsyncvoid cocoaViewCreate(NativeNSViewRef *ppView, WindowInfo *pWinInfo, NativeNSViewRef pParentView, GLbitfield fVisParams)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewCreate: ppView=%p pWinInfo=%p pParentView=%p fVisParams=%#x\n",
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync (void *)ppView, (void *)pWinInfo, (void *)pParentView, fVisParams));
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync /* make sure all tasks are run, to preserve the order */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync renderspuCalloutClient(vboxRcdCreateView, &CreateView);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync DEBUG_MSG_NOT_VMSVGA3D(("no callout available on createWindow\n"));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewCreate: returns *ppView=%p\n", (void *)*ppView));
c4bfe32373c55416bf49dc29ebf45dfa560b4692vboxsyncvoid cocoaViewReparent(NativeNSViewRef pView, NativeNSViewRef pParentView)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewReparent: pView=%p pParentView=%p\n", (void *)pView, (void *)pParentView));
2dd7b4388106de88d20f33a8aa6c85c8babf507bvboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewDestroy: pView=%p\n", (void *)pView));
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync [pRunner addObj:pView selector:@selector(vboxDestroy) arg:nil];
c4bfe32373c55416bf49dc29ebf45dfa560b4692vboxsyncvoid cocoaViewShow(NativeNSViewRef pView, GLboolean fShowIt)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewShow: pView=%p fShowIt=%d\n", (void *)pView, fShowIt));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewDisplay: pView=%p\n", (void *)pView));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync DEBUG_WARN(("cocoaViewDisplay should never happen!\n"));
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsync DEBUG_MSG_1(("cocoaViewDisplay %p\n", (void *)pView));
c4bfe32373c55416bf49dc29ebf45dfa560b4692vboxsyncvoid cocoaViewSetPosition(NativeNSViewRef pView, NativeNSViewRef pParentView, int x, int y)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewSetPosition: pView=%p pParentView=%p x=%d y=%d\n", (void *)pView, (void *)pParentView, x, y));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync [(OverlayView *)pView vboxSetPos:NSMakePoint(x, y)];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewSetPosition: returns\n"));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncvoid cocoaViewSetSize(NativeNSViewRef pView, int cx, int cy)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewSetSize: pView=%p cx=%d cy=%d\n", (void *)pView, cx, cy));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync [(OverlayView *)pView vboxSetSize:NSMakeSize(cx, cy)];
6ba96ad7028e4d559a5998de4bab0b71a8251c99vboxsyncstatic DECLCALLBACK(void) vboxRcdGetGeomerty(void *pvUser)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync CR_RCD_GETGEOMETRY *pGetGeometry = (CR_RCD_GETGEOMETRY *)pvUser;
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync pGetGeometry->rect = [[pGetGeometry->pView window] frame];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("vboxRcdGetGeomerty: (x,y)=(%d,%d) (cx,cy)=(%d,%d)\n", pGetGeometry->rect.origin.x, pGetGeometry->rect.origin.y,
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync pGetGeometry->rect.size.width, pGetGeometry->rect.heigth));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncvoid cocoaViewGetGeometry(NativeNSViewRef pView, int *px, int *py, int *pcx, int *pcy)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewGetGeometry: pView=%p px=%p py=%p pcx=%p pcy=%p\n",
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync (void *)pView, (void *)px, (void *)py, (void *)pcx, (void *)pcy));
e23e238e79c2d0e00beb102d43bdb4e40cb8534fvboxsync /* make sure all tasks are run, to preserve the order */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync VBoxMainThreadTaskRunner *pRunner = [VBoxMainThreadTaskRunner globalInstance];
5414e69c0f099d0a46301eb9c20cb1536ab1e71avboxsync renderspuCalloutClient(vboxRcdGetGeomerty, &GetGeometry);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync DEBUG_MSG_NOT_VMSVGA3D(("no callout available on getGeometry\n"));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewGetGeometry: returns *px=%d, *py=%d, *pcx=%d, *pcy=%d\n", *px, *py, *pcx, *pcy));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncvoid cocoaViewPresentComposition(NativeNSViewRef pView, PCVBOXVR_SCR_COMPOSITOR_ENTRY pChangedEntry)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewPresentComposition: pView=%p pChangedEntry=%p\n", (void *)pView, (void *)pChangedEntry));
610972deee47d5e5229ccdb6c86cbb332d2b4626vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
ece707b8d97e63ed54d4b48d7a8d841187e0023cvboxsync /* view should not necesserily have a context set */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync ContextInfo *pCtxInfo = renderspuDefaultSharedContextAcquire();
ece707b8d97e63ed54d4b48d7a8d841187e0023cvboxsync DEBUG_WARN(("renderspuDefaultSharedContextAcquire returned NULL"));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync [(OverlayView *)pView presentComposition:pChangedEntry];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewPresentComposition: returns\n"));
2f4c1bacd54af5063c3185cc8eab03e4e8ef9b90vboxsyncvoid cocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewMakeCurrentContext: pView=%p pCtx=%p\n", (void *)pView, (void *)pCtx));
5a07658d13590eba51dd98ef335a73d2a11edaa7vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewMakeCurrentContext: returns\n"));
ee357d0503e525172eab0eeb8f5befc2993c7ea5vboxsyncGLboolean cocoaViewNeedsEmptyPresent(NativeNSViewRef pView)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewNeedsEmptyPresent: pView=%p\n", (void *)pView));
ee357d0503e525172eab0eeb8f5befc2993c7ea5vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync GLboolean fNeedsPresent = [(OverlayView *)pView vboxNeedsEmptyPresent];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewNeedsEmptyPresent: returns %d\n", fNeedsPresent));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncvoid cocoaViewSetVisibleRegion(NativeNSViewRef pView, GLint cRects, const GLint *paRects)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewSetVisibleRegion: pView=%p cRects=%d paRects=%p)\n", (void *)pView, cRects, (void const *)paRects));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync [(OverlayView *)pView setVisibleRegions:cRects paRects:paRects];
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync COCOA_LOG_FLOW(("cocoaViewSetVisibleRegion: returns\n"));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync * VMSVGA3D interface.
7c19e11502220292d5270519296442234c2493cdvboxsyncVMSVGA3D_DECL(void) vmsvga3dCocoaCreateContext(NativeNSOpenGLContextRef *ppCtx, NativeNSOpenGLContextRef pSharedCtx, bool fLegacy)
7c19e11502220292d5270519296442234c2493cdvboxsync cocoaGLCtxCreate(ppCtx, CR_ALPHA_BIT | CR_DEPTH_BIT | CR_DOUBLE_BIT | (fLegacy ? VMSVGA3D_LEGACY_PROFILE_BIT : 0),
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncVMSVGA3D_DECL(void) vmsvga3dCocoaDestroyContext(NativeNSOpenGLContextRef pCtx)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncVMSVGA3D_DECL(void) vmsvga3dCocoaCreateView(NativeNSViewRef *ppView, NativeNSViewRef pParentView)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync /** @todo share WinInfo with caller and maintain it better. */
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync WindowInfo *pWinInfo = (WindowInfo *)RTMemAllocZ(sizeof(WindowInfo));
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsync cocoaViewCreate(ppView, pWinInfo, pParentView, 0 /* fVisParams - ignored */);
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncVMSVGA3D_DECL(void) vmsvga3dCocoaDestroyView(NativeNSViewRef pView)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncVMSVGA3D_DECL(void) vmsvga3dCocoaViewSetPosition(NativeNSViewRef pView, NativeNSViewRef pParentView, int x, int y)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncVMSVGA3D_DECL(void) vmsvga3dCocoaViewSetSize(NativeNSViewRef pView, int w, int h)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncVMSVGA3D_DECL(void) vmsvga3dCocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx)
892e4404b22b024dd58b9561787a5ac46a02b6c5vboxsyncVMSVGA3D_DECL(void) vmsvga3dCocoaSwapBuffers(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx)