renderspu_cocoa_helper.m revision a8d502445ce722c6b9700c5579b4a38b58827b7d
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/* $Id$ */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/** @file
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync * VirtualBox OpenGL Cocoa Window System Helper Implementation.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/*
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * Copyright (C) 2009-2012 Oracle Corporation
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync *
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * available from http://www.virtualbox.org. This file is free software;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * you can redistribute it and/or modify it under the terms of the GNU
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * General Public License (GPL) as published by the Free Software
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include "renderspu_cocoa_helper.h"
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#import <Cocoa/Cocoa.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#undef PVM
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include "chromium.h" /* For the visual bits of chromium */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/thread.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/string.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/mem.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/time.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <iprt/assert.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <cr_vreg.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <cr_error.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include <cr_blitter.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#ifdef VBOX_WITH_CRDUMPER_THUMBNAIL
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# include <cr_pixeldata.h>
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#include "renderspu.h"
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/** @page pg_opengl_cocoa OpenGL - Cocoa Window System Helper
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync *
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * How this works:
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * In general it is not so easy like on the other platforms, cause Cocoa
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * doesn't support any clipping of already painted stuff. In Mac OS X there is
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * the concept of translucent canvas's e.g. windows and there it is just
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * painted what should be visible to the user. Unfortunately this isn't the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * concept of chromium. Therefor I reroute all OpenGL operation from the guest
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync * to a frame buffer object (FBO). This is a OpenGL extension, which is
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * supported by all OS X versions we support (AFAIC tell). Of course the guest
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * doesn't know that and we have to make sure that the OpenGL state always is
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * in the right state to paint into the FBO and not to the front/back buffer.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Several functions below (like cocoaBindFramebufferEXT, cocoaGetIntegerv,
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * ...) doing this. When a swap or finish is triggered by the guest, the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * content (which is already bound to an texture) is painted on the screen
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * within a separate OpenGL context. This allows the usage of the same
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * resources (texture ids, buffers ...) but at the same time having an
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * different internal OpenGL state. Another advantage is that we can paint a
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * thumbnail of the current output in a much more smaller (GPU accelerated
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * scale) version on a third context and use glReadPixels to get the actual
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * data. glReadPixels is a very slow operation, but as we just use a much more
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * smaller image, we can handle it (anyway this is only done 5 times per
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * second).
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync *
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Other things to know:
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * - If the guest request double buffering, we have to make sure there are two
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * buffers. We use the same FBO with 2 color attachments. Also glDrawBuffer
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * and glReadBuffer is intercepted to make sure it is painted/read to/from
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * the correct buffers. On swap our buffers are swapped and not the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * front/back buffer.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * - If the guest request a depth/stencil buffer, a combined render buffer for
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * this is created.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * - If the size of the guest OpenGL window changes, all FBO's, textures, ...
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * need to be recreated.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * - We need to track any changes to the parent window
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * (create/destroy/move/resize). The various classes like OverlayHelperView,
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync * OverlayWindow, ... are there for.
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync * - The HGCM service runs on a other thread than the Main GUI. Keeps this
508452243fd3328f7b9e0405d39fb9dc004e31b8vboxsync * always in mind (see e.g. performSelectorOnMainThread in renderFBOToView)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * - We make heavy use of late binding. We can not be sure that the GUI (or any
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * other third party GUI), overwrite our NSOpenGLContext. So we always ask if
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * this is our own one, before use. Really neat concept of Objective-C/Cocoa
f409459bdd4c15cdb8d7fb6c6d54338cce9ac814vboxsync * ;)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/* Debug macros */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#define FBO 1 /* Disable this to see how the output is without the FBO in the middle of the processing chain. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if 0
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# define CR_RENDER_FORCE_PRESENT_MAIN_THREAD /* force present schedule to main thread */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# define SHOW_WINDOW_BACKGROUND 1 /* Define this to see the window background even if the window is clipped */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# define DEBUG_VERBOSE /* Define this to get some debug info about the messages flow. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#ifdef DEBUG_misha
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# define DEBUG_MSG(text) \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync printf text
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# define DEBUG_WARN(text) do { \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync crWarning text ; \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Assert(0); \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync } while (0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# define DEBUG_MSG(text) \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync do {} while (0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# define DEBUG_WARN(text) do { \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync crWarning text ; \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync } while (0)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync#endif
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync#ifdef DEBUG_VERBOSE
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync# define DEBUG_MSG_1(text) \
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync DEBUG_MSG(text)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync#else
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync# define DEBUG_MSG_1(text) \
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync do {} while (0)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync#endif
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync#ifdef DEBUG_poetzsch
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync# define CHECK_GL_ERROR()\
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync do \
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync { \
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync checkGLError(__FILE__, __LINE__); \
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync }while (0);
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync static void checkGLError(char *file, int line)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync GLenum g = glGetError();
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync if (g != GL_NO_ERROR)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync char *errStr;
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync switch (g)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync {
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync case GL_INVALID_ENUM: errStr = RTStrDup("GL_INVALID_ENUM"); break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync case GL_INVALID_VALUE: errStr = RTStrDup("GL_INVALID_VALUE"); break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync case GL_INVALID_OPERATION: errStr = RTStrDup("GL_INVALID_OPERATION"); break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync case GL_STACK_OVERFLOW: errStr = RTStrDup("GL_STACK_OVERFLOW"); break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync case GL_STACK_UNDERFLOW: errStr = RTStrDup("GL_STACK_UNDERFLOW"); break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync case GL_OUT_OF_MEMORY: errStr = RTStrDup("GL_OUT_OF_MEMORY"); break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync case GL_TABLE_TOO_LARGE: errStr = RTStrDup("GL_TABLE_TOO_LARGE"); break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync default: errStr = RTStrDup("UNKNOWN"); break;
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync }
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync DEBUG_MSG(("%s:%d: glError %d (%s)\n", file, line, g, errStr));
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync RTMemFree(errStr);
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync }
9cb702c3a5fd2287c57c7c1e98a61ba9e357b4devboxsync }
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync#else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync# define CHECK_GL_ERROR()\
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync do {} while (0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#define GL_SAVE_STATE \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync do \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync { \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glPushAttrib(GL_ALL_ATTRIB_BITS); \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glMatrixMode(GL_PROJECTION); \
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync glPushMatrix(); \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glMatrixMode(GL_TEXTURE); \
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync glPushMatrix(); \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glMatrixMode(GL_COLOR); \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glPushMatrix(); \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glMatrixMode(GL_MODELVIEW); \
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glPushMatrix(); \
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync } \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync while(0);
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync#define GL_RESTORE_STATE \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync do \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync { \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glMatrixMode(GL_MODELVIEW); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glPopMatrix(); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glMatrixMode(GL_COLOR); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glPopMatrix(); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glMatrixMode(GL_TEXTURE); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glPopMatrix(); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glMatrixMode(GL_PROJECTION); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glPopMatrix(); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glPopClientAttrib(); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync glPopAttrib(); \
7e837ad8d6aeb3f86520ea7adb61e4eb15f2087evboxsync } \
ae017640afff8b6cc50453182a4edf2eb0903a12vboxsync while(0);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsyncstatic NSOpenGLContext * vboxCtxGetCurrent()
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync{
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync GET_CONTEXT(pCtxInfo);
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync if (pCtxInfo)
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync {
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync Assert(pCtxInfo->context);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return pCtxInfo->context;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return nil;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic bool vboxCtxSyncCurrentInfo()
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync GET_CONTEXT(pCtxInfo);
b986941f0aa5155c7fd37da0aa5876675a7680e4vboxsync NSOpenGLContext *pCtx = [NSOpenGLContext currentContext];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSView *pView = pCtx ? [pCtx view] : nil;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool fAdjusted = false;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pCtxInfo)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync WindowInfo *pWinInfo = pCtxInfo->currentWindow;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Assert(pWinInfo);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pCtxInfo->context != pCtx
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync || pWinInfo->window != pView)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync renderspu_SystemMakeCurrent(pWinInfo, 0, pCtxInfo);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fAdjusted = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pCtx)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [NSOpenGLContext clearCurrentContext];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync fAdjusted = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync return fAdjusted;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsynctypedef struct VBOX_CR_RENDER_CTX_INFO
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool fIsValid;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSOpenGLContext *pCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSView *pView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync} VBOX_CR_RENDER_CTX_INFO, *PVBOX_CR_RENDER_CTX_INFO;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncstatic void vboxCtxEnter(NSOpenGLContext*pCtx, PVBOX_CR_RENDER_CTX_INFO pCtxInfo)
42aef05f4b27fb393967e581be04be455064c80avboxsync{
42aef05f4b27fb393967e581be04be455064c80avboxsync NSOpenGLContext *pOldCtx = vboxCtxGetCurrent();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSView *pOldView = (pOldCtx ? [pOldCtx view] : nil);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync NSView *pView = [pCtx view];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool fNeedCtxSwitch = (pOldCtx != pCtx || pOldView != pView);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Assert(pCtx);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync // Assert(pOldCtx == m_pGLCtx);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync // Assert(pOldView == self);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync // Assert(fNeedCtxSwitch);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (fNeedCtxSwitch)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if(pOldCtx != nil)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync glFlush();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [pCtx makeCurrentContext];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync pCtxInfo->fIsValid = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync pCtxInfo->pCtx = pOldCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync pCtxInfo->pView = pView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pCtxInfo->fIsValid = false;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync}
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic void vboxCtxLeave(PVBOX_CR_RENDER_CTX_INFO pCtxInfo)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (pCtxInfo->fIsValid)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSOpenGLContext *pOldCtx = pCtxInfo->pCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSView *pOldView = pCtxInfo->pView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync glFlush();
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pOldCtx != nil)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if ([pOldCtx view] != pOldView)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [pOldCtx setView: pOldView];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [pOldCtx makeCurrentContext];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#ifdef DEBUG
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSOpenGLContext *pTstOldCtx = [NSOpenGLContext currentContext];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSView *pTstOldView = (pTstOldCtx ? [pTstOldCtx view] : nil);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Assert(pTstOldCtx == pOldCtx);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync Assert(pTstOldView == pOldView);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [NSOpenGLContext clearCurrentContext];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/** Custom OpenGL context class.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync *
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * This implementation doesn't allow to set a view to the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * context, but save the view for later use. Also it saves a copy of the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * pixel format used to create that context for later use. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@interface OverlayOpenGLContext: NSOpenGLContext
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@private
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSOpenGLPixelFormat *m_pPixelFormat;
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync NSView *m_pView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSOpenGLPixelFormat*)openGLPixelFormat;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@end
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@class DockOverlayView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/** The custom view class.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * This is the main class of the cocoa OpenGL implementation. It
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * manages an frame buffer object for the rendering of the guest
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * applications. The guest applications render in this frame buffer which
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * is bind to an OpenGL texture. To display the guest content, an secondary
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * shared OpenGL context of the main OpenGL context is created. The secondary
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * context is marked as non opaque & the texture is displayed on an object
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * which is composed out of the several visible region rectangles. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@interface OverlayView: NSView
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@private
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSView *m_pParentView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSWindow *m_pOverlayWin;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSOpenGLContext *m_pGLCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSOpenGLContext *m_pSharedGLCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTTHREAD mThread;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync GLuint m_FBOId;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /** The corresponding dock tile view of this OpenGL view & all helper
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * members. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DockOverlayView *m_DockTileView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync GLfloat m_FBOThumbScaleX;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync GLfloat m_FBOThumbScaleY;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync uint64_t m_uiDockUpdateTime;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* For clipping */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync GLint m_cClipRects;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync GLint *m_paClipRects;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Position/Size tracking */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSPoint m_Pos;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSSize m_Size;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync /** This is necessary for clipping on the root window */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSRect m_RootRect;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync float m_yInvRootOffset;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CR_BLITTER *m_pBlitter;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync WindowInfo *m_pWinInfo;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool m_fNeedViewportUpdate;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool m_fNeedCtxUpdate;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool m_fDataVisible;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bool m_fEverSized;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView winInfo:(WindowInfo*)pWinInfo;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setGLCtx:(NSOpenGLContext*)pCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSOpenGLContext*)glCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setParentView: (NSView*)view;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSView*)parentView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setOverlayWin: (NSWindow*)win;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSWindow*)overlayWin;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setPos:(NSPoint)pos;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSPoint)pos;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (bool)isEverSized;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setSize:(NSSize)size;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSSize)size;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)updateViewportCS;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxReshapePerform;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxReshapeOnResizePerform;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxReshapeOnReparentPerform;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)createDockTile;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)deleteDockTile;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)makeCurrentFBO;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)swapFBO;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxTryDraw;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxTryDrawUI;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxPresent:(const VBOXVR_SCR_COMPOSITOR*)pCompositor;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxPresentCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxPresentToDockTileCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxPresentToViewCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)presentComposition:(const VBOXVR_SCR_COMPOSITOR_ENTRY*)pChangedEntry;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxBlitterSyncWindow;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)clearVisibleRegions;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setVisibleRegions:(GLint)cRects paRects:(const GLint*)paRects;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSView*)dockTileScreen;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)reshapeDockTile;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)cleanupData;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@end
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/** Helper view.
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync *
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * This view is added as a sub view of the parent view to track
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * main window changes. Whenever the main window is changed
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * (which happens on fullscreen/seamless entry/exit) the overlay
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * window is informed & can add them self as a child window
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * again. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync@class OverlayWindow;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@interface OverlayHelperView: NSView
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4f3d37f3c8ea851c3d57304fac430764b77a84dcvboxsync@private
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync OverlayWindow *m_pOverlayWindow;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync}
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync-(id)initWithOverlayWindow:(OverlayWindow*)pOverlayWindow;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync@end
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync/** Custom window class.
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync *
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync * This is the overlay window which contains our custom NSView.
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync * Its a direct child of the Qt Main window. It marks its background
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync * transparent & non opaque to make clipping possible. It also disable mouse
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync * events and handle frame change events of the parent view. */
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync@interface OverlayWindow: NSWindow
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync{
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync@private
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync NSView *m_pParentView;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync OverlayView *m_pOverlayView;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync OverlayHelperView *m_pOverlayHelperView;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync NSThread *m_Thread;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync}
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (id)initWithParentView:(NSView*)pParentView overlayView:(OverlayView*)pOverlayView;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)parentWindowFrameChanged:(NSNotification *)note;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)parentWindowChanged:(NSWindow*)pWindow;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync@end
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync@interface DockOverlayView: NSView
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync{
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync NSBitmapImageRep *m_ThumbBitmap;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync NSImage *m_ThumbImage;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync NSLock *m_Lock;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync}
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)dealloc;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)cleanup;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)lock;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)unlock;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)setFrame:(NSRect)frame;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)drawRect:(NSRect)aRect;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (NSBitmapImageRep*)thumbBitmap;
4f3d37f3c8ea851c3d57304fac430764b77a84dcvboxsync- (NSImage*)thumbImage;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync@end
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync@implementation DockOverlayView
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (id)init
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync{
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync self = [super init];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (self)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync /* We need a lock cause the thumb image could be accessed from the main
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync * thread when someone is calling display on the dock tile & from the
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync * OpenGL thread when the thumbnail is updated. */
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync m_Lock = [[NSLock alloc] init];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync return self;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync}
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)dealloc
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync{
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [self cleanup];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [m_Lock release];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [super dealloc];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync}
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)cleanup
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync{
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (m_ThumbImage != nil)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [m_ThumbImage release];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync m_ThumbImage = nil;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if (m_ThumbBitmap != nil)
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync {
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [m_ThumbBitmap release];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync m_ThumbBitmap = nil;
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync }
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync}
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync- (void)lock
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync{
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [m_Lock lock];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync}
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync- (void)unlock
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync{
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync [m_Lock unlock];
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync}
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync
8ccde4f32d77b1ad3f02111f28a48ee85abf6779vboxsync- (void)setFrame:(NSRect)frame
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync{
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [super setFrame:frame];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [self lock];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync [self cleanup];
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync if ( frame.size.width > 0
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync && frame.size.height > 0)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Create a buffer for our thumbnail image. Its in the size of this view. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_ThumbBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync pixelsWide:frame.size.width
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync pixelsHigh:frame.size.height
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bitsPerSample:8
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync samplesPerPixel:4
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync hasAlpha:YES
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync isPlanar:NO
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync colorSpaceName:NSDeviceRGBColorSpace
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bitmapFormat:NSAlphaFirstBitmapFormat
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bytesPerRow:frame.size.width * 4
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync bitsPerPixel:8 * 4];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_ThumbImage = [[NSImage alloc] initWithSize:[m_ThumbBitmap size]];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_ThumbImage addRepresentation:m_ThumbBitmap];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self unlock];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (BOOL)isFlipped
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return YES;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)drawRect:(NSRect)aRect
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSRect frame;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self lock];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#ifdef SHOW_WINDOW_BACKGROUND
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7] set];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync frame = [self frame];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [NSBezierPath fillRect:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif /* SHOW_WINDOW_BACKGROUND */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (m_ThumbImage != nil)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_ThumbImage drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self unlock];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync- (NSBitmapImageRep*)thumbBitmap
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_ThumbBitmap;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSImage*)thumbImage
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_ThumbImage;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@end
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/********************************************************************************
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync*
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync* OverlayOpenGLContext class implementation
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync*
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync********************************************************************************/
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@implementation OverlayOpenGLContext
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync-(id)initWithFormat:(NSOpenGLPixelFormat*)format shareContext:(NSOpenGLContext*)share
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pPixelFormat = NULL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pView = NULL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync self = [super initWithFormat:format shareContext:share];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (self)
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync m_pPixelFormat = format;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OCTX(%p): init OverlayOpenGLContext\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return self;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)dealloc
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OCTX(%p): dealloc OverlayOpenGLContext\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pPixelFormat release];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync [super dealloc];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync-(bool)isDoubleBuffer
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync GLint val;
e48239695d41f806ff02d8a60b97dc20d4822d7avboxsync [m_pPixelFormat getValues:&val forAttribute:NSOpenGLPFADoubleBuffer forVirtualScreen:0];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return val == GL_TRUE ? YES : NO;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync-(void)setView:(NSView*)view
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync DEBUG_MSG(("OCTX(%p): setView: new view: %p\n", (void*)self, (void*)view));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if 1 /* def FBO */
3933885bc0c2c93436d858a14564c6179ec72872vboxsync m_pView = view;;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync#else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [super setView: view];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync#endif
3933885bc0c2c93436d858a14564c6179ec72872vboxsync}
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync-(NSView*)view
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#if 1 /* def FBO */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_pView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return [super view];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync#endif
3933885bc0c2c93436d858a14564c6179ec72872vboxsync}
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync-(void)clearDrawable
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OCTX(%p): clearDrawable\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync m_pView = NULL;;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [super clearDrawable];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync-(NSOpenGLPixelFormat*)openGLPixelFormat
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_pPixelFormat;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@end
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/********************************************************************************
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync*
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync* OverlayHelperView class implementation
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync*
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync********************************************************************************/
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@implementation OverlayHelperView
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync-(id)initWithOverlayWindow:(OverlayWindow*)pOverlayWindow
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync self = [super initWithFrame:NSZeroRect];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pOverlayWindow = pOverlayWindow;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OHVW(%p): init OverlayHelperView\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
a72b5355eb89aafe6bfcc8912cf02645d7cccceavboxsync return self;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync}
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync-(void)viewDidMoveToWindow
3933885bc0c2c93436d858a14564c6179ec72872vboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OHVW(%p): viewDidMoveToWindow: new win: %p\n", (void*)self, (void*)[self window]));
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pOverlayWindow parentWindowChanged:[self window]];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@end
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync/********************************************************************************
3933885bc0c2c93436d858a14564c6179ec72872vboxsync*
3933885bc0c2c93436d858a14564c6179ec72872vboxsync* OverlayWindow class implementation
3933885bc0c2c93436d858a14564c6179ec72872vboxsync*
3933885bc0c2c93436d858a14564c6179ec72872vboxsync********************************************************************************/
3933885bc0c2c93436d858a14564c6179ec72872vboxsync@implementation OverlayWindow
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync- (id)initWithParentView:(NSView*)pParentView overlayView:(OverlayView*)pOverlayView
3933885bc0c2c93436d858a14564c6179ec72872vboxsync{
3933885bc0c2c93436d858a14564c6179ec72872vboxsync NSWindow *pParentWin = nil;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync if((self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]))
3933885bc0c2c93436d858a14564c6179ec72872vboxsync {
3933885bc0c2c93436d858a14564c6179ec72872vboxsync m_pParentView = pParentView;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync m_pOverlayView = pOverlayView;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync m_Thread = [NSThread currentThread];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [m_pOverlayView setOverlayWin: self];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync m_pOverlayHelperView = [[OverlayHelperView alloc] initWithOverlayWindow:self];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync /* Add the helper view as a child of the parent view to get notifications */
060f7ec6ae5c99df18341ef2e1f3e91f4b0c89f1vboxsync [pParentView addSubview:m_pOverlayHelperView];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
060f7ec6ae5c99df18341ef2e1f3e91f4b0c89f1vboxsync /* Make sure this window is transparent */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#ifdef SHOW_WINDOW_BACKGROUND
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* For debugging */
cc74f15083bf80fbc96723a89faa06c15d0dead8vboxsync [self setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:0.7]];
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync#else
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync [self setBackgroundColor:[NSColor clearColor]];
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync#endif
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync [self setOpaque:NO];
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync [self setAlphaValue:.999];
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync /* Disable mouse events for this window */
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync [self setIgnoresMouseEvents:YES];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync pParentWin = [m_pParentView window];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync /* Initial set the position to the parents view top/left (Compiz fix). */
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync [self setFrameOrigin:
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [pParentWin convertBaseToScreen:
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [m_pParentView convertPoint:NSZeroPoint toView:nil]]];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync /* Set the overlay view as our content view */
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [self setContentView:m_pOverlayView];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync /* Add ourself as a child to the parent views window. Note: this has to
3933885bc0c2c93436d858a14564c6179ec72872vboxsync * be done last so that everything else is setup in
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync * parentWindowChanged. */
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [pParentWin addChildWindow:self ordered:NSWindowAbove];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync }
3933885bc0c2c93436d858a14564c6179ec72872vboxsync DEBUG_MSG(("OWIN(%p): init OverlayWindow\n", (void*)self));
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync return self;
3933885bc0c2c93436d858a14564c6179ec72872vboxsync}
cc74f15083bf80fbc96723a89faa06c15d0dead8vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync- (void)dealloc
3933885bc0c2c93436d858a14564c6179ec72872vboxsync{
3933885bc0c2c93436d858a14564c6179ec72872vboxsync DEBUG_MSG(("OWIN(%p): dealloc OverlayWindow\n", (void*)self));
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [[NSNotificationCenter defaultCenter] removeObserver:self];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [m_pOverlayHelperView removeFromSuperview];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [m_pOverlayHelperView release];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync [super dealloc];
3933885bc0c2c93436d858a14564c6179ec72872vboxsync}
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsync- (void)parentWindowFrameChanged:(NSNotification*)pNote
3933885bc0c2c93436d858a14564c6179ec72872vboxsync{
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync DEBUG_MSG(("OWIN(%p): parentWindowFrameChanged\n", (void*)self));
70ca8d009d026a301bf7fa08cd18c6494c45fdeevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Reposition this window with the help of the OverlayView. Perform the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * call in the OpenGL thread. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /*
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pOverlayView performSelector:@selector(vboxReshapePerform) onThread:m_Thread withObject:nil waitUntilDone:YES];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if ([m_pOverlayView isEverSized])
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if([NSThread isMainThread])
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pOverlayView vboxReshapePerform];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self performSelectorOnMainThread:@selector(vboxReshapePerform) withObject:nil waitUntilDone:NO];
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)parentWindowChanged:(NSWindow*)pWindow
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OWIN(%p): parentWindowChanged\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [[NSNotificationCenter defaultCenter] removeObserver:self];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if(pWindow != nil)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync /* Ask to get notifications when our parent window frame changes. */
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync [[NSNotificationCenter defaultCenter]
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync addObserver:self
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync selector:@selector(parentWindowFrameChanged:)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync name:NSWindowDidResizeNotification
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync object:pWindow];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Add us self as child window */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [pWindow addChildWindow:self ordered:NSWindowAbove];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Reshape the overlay view after a short waiting time to let the main
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync * window resize itself properly. */
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync /*
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pOverlayView performSelector:@selector(vboxReshapePerform) withObject:nil afterDelay:0.2];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [NSTimer scheduledTimerWithTimeInterval:0.2 target:m_pOverlayView selector:@selector(vboxReshapePerform) userInfo:nil repeats:NO];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if ([m_pOverlayView isEverSized])
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if([NSThread isMainThread])
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pOverlayView vboxReshapePerform];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync else
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync [self performSelectorOnMainThread:@selector(vboxReshapePerform) withObject:nil waitUntilDone:NO];
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@end
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/********************************************************************************
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync*
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync* OverlayView class implementation
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync*
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync********************************************************************************/
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync@implementation OverlayView
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (id)initWithFrame:(NSRect)frame thread:(RTTHREAD)aThread parentView:(NSView*)pParentView winInfo:(WindowInfo*)pWinInfo
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pParentView = pParentView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Make some reasonable defaults */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pGLCtx = nil;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pSharedGLCtx = nil;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync mThread = aThread;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_FBOId = 0;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_cClipRects = 0;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_paClipRects = NULL;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_Pos = NSZeroPoint;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_Size = NSMakeSize(1, 1);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_RootRect = NSMakeRect(0, 0, m_Size.width, m_Size.height);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_yInvRootOffset = 0;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pBlitter = nil;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pWinInfo = pWinInfo;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_fNeedViewportUpdate = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_fNeedCtxUpdate = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_fDataVisible = false;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_fEverSized = false;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync self = [super initWithFrame:frame];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): init OverlayView\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return self;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)cleanupData
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self deleteDockTile];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self setGLCtx:nil];
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync if (m_pSharedGLCtx)
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync {
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync if ([m_pSharedGLCtx view] == self)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pSharedGLCtx clearDrawable];
c9e3f6ad81ea9a279ffb537720699e552882c40avboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pSharedGLCtx release];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pSharedGLCtx = nil;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync CrBltTerm(m_pBlitter);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTMemFree(m_pBlitter);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pBlitter = nil;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self clearVisibleRegions];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)dealloc
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): dealloc OverlayView\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self cleanupData];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [super dealloc];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)drawRect:(NSRect)aRect
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self vboxTryDrawUI];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setGLCtx:(NSOpenGLContext*)pCtx
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): setGLCtx: new ctx: %p\n", (void*)self, (void*)pCtx));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (m_pGLCtx == pCtx)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* ensure the context drawable is cleared to avoid holding a reference to inexistent view */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (m_pGLCtx)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pGLCtx clearDrawable];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pGLCtx release];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /*[m_pGLCtx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];*/
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pGLCtx = pCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pCtx)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [pCtx retain];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSOpenGLContext*)glCtx
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_pGLCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSView*)parentView
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_pParentView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setParentView:(NSView*)pView
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): setParentView: new view: %p\n", (void*)self, (void*)pView));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pParentView = pView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setOverlayWin:(NSWindow*)pWin
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): setOverlayWin: new win: %p\n", (void*)self, (void*)pWin));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pOverlayWin = pWin;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSWindow*)overlayWin
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_pOverlayWin;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setPos:(NSPoint)pos
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): setPos: new pos: %d, %d\n", (void*)self, (int)pos.x, (int)pos.y));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_Pos = pos;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (m_fEverSized)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self performSelectorOnMainThread:@selector(vboxReshapePerform) withObject:nil waitUntilDone:NO];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* we need to redwar on regions change, however the compositor now is cleared
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * because all compositor&window data-related modifications are performed with compositor cleared
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * the renderspu client will re-set the compositor after modifications are complete
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * this way we indicate renderspu generic code not to ignore the empty compositor */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* generally this should not be needed for setPos because compositor should not be zeroed with it,
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * in any way setting this flag here should not hurt as it will be re-set on next present */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_pWinInfo->fCompositorPresentEmpty = GL_TRUE;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSPoint)pos
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_Pos;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (bool)isEverSized
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_fEverSized;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)setSize:(NSSize)size
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSOpenGLContext *pCurCtx;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSView *pCurView;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_Size = size;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_fEverSized = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): setSize: new size: %dx%d\n", (void*)self, (int)size.width, (int)size.height));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self performSelectorOnMainThread:@selector(vboxReshapeOnResizePerform) withObject:nil waitUntilDone:NO];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* we need to redwar on regions change, however the compositor now is cleared
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * because all compositor&window data-related modifications are performed with compositor cleared
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * the renderspu client will re-set the compositor after modifications are complete
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * this way we indicate renderspu generic code not to ignore the empty compositor */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* generally this should not be needed for setSize because compositor should not be zeroed with it,
c9e3f6ad81ea9a279ffb537720699e552882c40avboxsync * in any way setting this flag here should not hurt as it will be re-set on next present */
21ed14a0d745501ffc9a68be81c0abadc777b628vboxsync m_pWinInfo->fCompositorPresentEmpty = GL_TRUE;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (NSSize)size
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return m_Size;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)updateViewportCS
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): updateViewport\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Update the viewport for our OpenGL view */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [m_pSharedGLCtx update];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self vboxBlitterSyncWindow];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
629169500a4e1696f37dd3118a791d68278f71davboxsync /* Clear background to transparent */
629169500a4e1696f37dd3118a791d68278f71davboxsync glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
629169500a4e1696f37dd3118a791d68278f71davboxsync}
629169500a4e1696f37dd3118a791d68278f71davboxsync
629169500a4e1696f37dd3118a791d68278f71davboxsync- (void)vboxReshapeOnResizePerform
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self vboxReshapePerform];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self createDockTile];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* have to rebind GL_TEXTURE_RECTANGLE_ARB as m_FBOTexId could be changed in updateFBO call */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync m_fNeedViewportUpdate = true;
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync#if 0
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync pCurCtx = [NSOpenGLContext currentContext];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (pCurCtx && pCurCtx == m_pGLCtx && (pCurView = [pCurCtx view]) == self)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync {
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync [m_pGLCtx update];
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync m_fNeedCtxUpdate = false;
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync }
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync else
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync {
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync /* do it in a lazy way */
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync m_fNeedCtxUpdate = true;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync }
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync#endif
fb1975a6972d89de9e515bed0248db93f04ec9d8vboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxReshapeOnReparentPerform
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync [self createDockTile];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync}
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync- (void)vboxReshapePerform
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync{
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSRect parentFrame = NSZeroRect;
4c13f0d619c9707412b40eae8e3beafae5cf1858vboxsync NSPoint parentPos = NSZeroPoint;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSPoint childPos = NSZeroPoint;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync NSRect childFrame = NSZeroRect;
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync NSRect newFrame = NSZeroRect;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("OVIW(%p): vboxReshapePerform\n", (void*)self));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync parentFrame = [m_pParentView frame];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("FIXED parentFrame [%f:%f], [%f:%f]\n", parentFrame.origin.x, parentFrame.origin.y, parentFrame.size.width, parentFrame.size.height));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync parentPos = parentFrame.origin;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync parentPos.y += parentFrame.size.height;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("FIXED(view) parentPos [%f:%f]\n", parentPos.x, parentPos.y));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync parentPos = [m_pParentView convertPoint:parentPos toView:nil];
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("FIXED parentPos(win) [%f:%f]\n", parentPos.x, parentPos.y));
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync parentPos = [[m_pParentView window] convertBaseToScreen:parentPos];
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync DEBUG_MSG(("FIXED parentPos(screen) [%f:%f]\n", parentPos.x, parentPos.y));
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync parentFrame.origin = parentPos;
1207f59aa62006952dbb0bf7700decf34d8caeb2vboxsync
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync childPos = NSMakePoint(m_Pos.x, m_Pos.y + m_Size.height);
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync DEBUG_MSG(("FIXED(view) childPos [%f:%f]\n", childPos.x, childPos.y));
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync childPos = [m_pParentView convertPoint:childPos toView:nil];
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync DEBUG_MSG(("FIXED(win) childPos [%f:%f]\n", childPos.x, childPos.y));
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync childPos = [[m_pParentView window] convertBaseToScreen:childPos];
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync DEBUG_MSG(("FIXED childPos(screen) [%f:%f]\n", childPos.x, childPos.y));
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync childFrame = NSMakeRect(childPos.x, childPos.y, m_Size.width, m_Size.height);
b2c92fb03e119c7de54f86a32fae9c1d59bc479evboxsync DEBUG_MSG(("FIXED childFrame [%f:%f], [%f:%f]\n", childFrame.origin.x, childFrame.origin.y, childFrame.size.width, childFrame.size.height));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* We have to make sure that the overlay window will not be displayed out
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * of the parent window. So intersect both frames & use the result as the new
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * frame for the window. */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync newFrame = NSIntersectionRect(parentFrame, childFrame);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("[%#p]: parentFrame pos[%f : %f] size[%f : %f]\n",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync (void*)self,
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync parentFrame.origin.x, parentFrame.origin.y,
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync parentFrame.size.width, parentFrame.size.height));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("[%#p]: childFrame pos[%f : %f] size[%f : %f]\n",
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync (void*)self,
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync childFrame.origin.x, childFrame.origin.y,
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync childFrame.size.width, childFrame.size.height));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync DEBUG_MSG(("[%#p]: newFrame pos[%f : %f] size[%f : %f]\n",
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync (void*)self,
825c2485cf84eec495985ffd605a1c9cddee8c32vboxsync newFrame.origin.x, newFrame.origin.y,
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync newFrame.size.width, newFrame.size.height));
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync /* Later we have to correct the texture position in the case the window is
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * 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));
/*
NSScrollView *pScrollView = [[[m_pParentView window] contentView] enclosingScrollView];
if (pScrollView)
{
NSRect scrollRect = [pScrollView documentVisibleRect];
NSRect scrollRect = [m_pParentView visibleRect];
printf ("sc rect: %d %d %d %d\n", (int) scrollRect.origin.x,(int) scrollRect.origin.y,(int) scrollRect.size.width,(int) scrollRect.size.height);
NSRect b = [[m_pParentView superview] bounds];
printf ("bound rect: %d %d %d %d\n", (int) b.origin.x,(int) b.origin.y,(int) b.size.width,(int) b.size.height);
newFrame.origin.x += scrollRect.origin.x;
newFrame.origin.y += scrollRect.origin.y;
}
*/
/* Set the new frame. */
[[self window] setFrame:newFrame display:YES];
/* Inform the dock tile view as well */
[self reshapeDockTile];
/* 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);
}
}
- (void)createDockTile
{
NSView *pDockScreen = nil;
[self deleteDockTile];
/* Is there a dock tile preview enabled in the GUI? If so setup a
* additional thumbnail view for the dock tile. */
pDockScreen = [self dockTileScreen];
if (pDockScreen)
{
m_DockTileView = [[DockOverlayView alloc] init];
[self reshapeDockTile];
[pDockScreen addSubview:m_DockTileView];
}
}
- (void)deleteDockTile
{
if (m_DockTileView != nil)
{
[m_DockTileView removeFromSuperview];
[m_DockTileView release];
m_DockTileView = nil;
}
}
- (void)makeCurrentFBO
{
DEBUG_MSG(("OVIW(%p): makeCurrentFBO\n", (void*)self));
if (m_pGLCtx)
{
if ([m_pGLCtx view] != self)
{
/* We change the active view, so flush first */
if([NSOpenGLContext currentContext] != 0)
glFlush();
[m_pGLCtx setView: self];
CHECK_GL_ERROR();
}
/*
if ([NSOpenGLContext currentContext] != m_pGLCtx)
*/
{
[m_pGLCtx makeCurrentContext];
CHECK_GL_ERROR();
if (m_fNeedCtxUpdate == true)
{
[m_pGLCtx update];
m_fNeedCtxUpdate = false;
}
}
if (!m_FBOId)
{
glGenFramebuffersEXT(1, &m_FBOId);
Assert(m_FBOId);
}
}
}
- (bool)vboxSharedCtxCreate
{
if (m_pSharedGLCtx)
return true;
Assert(!m_pBlitter);
m_pBlitter = RTMemAlloc(sizeof (*m_pBlitter));
if (!m_pBlitter)
{
DEBUG_WARN(("m_pBlitter allocation failed"));
return false;
}
int rc = CrBltInit(m_pBlitter, NULL, false, false, &render_spu.GlobalShaders, &render_spu.blitterDispatch);
if (RT_SUCCESS(rc))
{
DEBUG_MSG(("blitter created successfully for view 0x%p\n", (void*)self));
}
else
{
DEBUG_WARN(("CrBltInit failed, rc %d", rc));
RTMemFree(m_pBlitter);
m_pBlitter = NULL;
return false;
}
GLint opaque = 0;
/* Create a shared context out of the main context. Use the same pixel format. */
NSOpenGLContext *pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx];
/* Set the new context as non opaque */
[pSharedGLCtx setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
/* Set this view as the drawable for the new context */
[pSharedGLCtx setView: self];
m_fNeedViewportUpdate = true;
m_pSharedGLCtx = pSharedGLCtx;
return true;
}
- (void)vboxTryDraw
{
glFlush();
/* issue to the gui thread */
[self setNeedsDisplay:YES];
}
- (void)vboxTryDrawUI
{
const VBOXVR_SCR_COMPOSITOR *pCompositor = renderspuVBoxCompositorAcquire(m_pWinInfo);
if (!m_fDataVisible && !pCompositor)
return;
VBOXVR_SCR_COMPOSITOR TmpCompositor;
if (pCompositor)
{
if (!m_pSharedGLCtx)
{
Assert(!m_fDataVisible);
renderspuVBoxCompositorRelease(m_pWinInfo);
if (![self vboxSharedCtxCreate])
{
DEBUG_WARN(("vboxSharedCtxCreate failed\n"));
return;
}
Assert(m_pSharedGLCtx);
pCompositor = renderspuVBoxCompositorAcquire(m_pWinInfo);
Assert(!m_fDataVisible);
if (!pCompositor)
return;
}
}
else
{
CrVrScrCompositorInit(&TmpCompositor, NULL);
pCompositor = &TmpCompositor;
}
if ([self lockFocusIfCanDraw])
{
[self vboxPresent:pCompositor];
if (pCompositor != &TmpCompositor)
renderspuVBoxCompositorRelease(m_pWinInfo);
[self unlockFocus];
}
else
{
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(vboxTryDrawUI) userInfo:nil repeats:NO];
}
}
- (void)swapFBO
{
[m_pGLCtx flushBuffer];
}
- (void)vboxPresent:(const VBOXVR_SCR_COMPOSITOR*)pCompositor
{
VBOX_CR_RENDER_CTX_INFO CtxInfo;
DEBUG_MSG(("OVIW(%p): renderFBOToView\n", (void*)self));
Assert(pCompositor);
vboxCtxEnter(m_pSharedGLCtx, &CtxInfo);
[self vboxPresentCS:pCompositor];
vboxCtxLeave(&CtxInfo);
}
- (void)vboxPresentCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor
{
{
if ([m_pSharedGLCtx view] != self)
{
DEBUG_MSG(("OVIW(%p): not current view of shared ctx! Switching ...\n", (void*)self));
[m_pSharedGLCtx setView: self];
m_fNeedViewportUpdate = true;
}
if (m_fNeedViewportUpdate)
{
[self updateViewportCS];
m_fNeedViewportUpdate = false;
}
/* Render FBO content to the dock tile when necessary. */
[self vboxPresentToDockTileCS:pCompositor];
/* change to #if 0 to see thumbnail image */
#if 1
[self vboxPresentToViewCS:pCompositor];
#else
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
[m_pSharedGLCtx flushBuffer];
#endif
}
}
DECLINLINE(void) vboxNSRectToRect(const NSRect *pR, RTRECT *pRect)
{
pRect->xLeft = (int)pR->origin.x;
pRect->yTop = (int)pR->origin.y;
pRect->xRight = (int)(pR->origin.x + pR->size.width);
pRect->yBottom = (int)(pR->origin.y + pR->size.height);
}
DECLINLINE(void) vboxNSRectToRectUnstretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch)
{
pRect->xLeft = (int)(pR->origin.x / xStretch);
pRect->yTop = (int)(pR->origin.y / yStretch);
pRect->xRight = (int)((pR->origin.x + pR->size.width) / xStretch);
pRect->yBottom = (int)((pR->origin.y + pR->size.height) / yStretch);
}
DECLINLINE(void) vboxNSRectToRectStretched(const NSRect *pR, RTRECT *pRect, float xStretch, float yStretch)
{
pRect->xLeft = (int)(pR->origin.x * xStretch);
pRect->yTop = (int)(pR->origin.y * yStretch);
pRect->xRight = (int)((pR->origin.x + pR->size.width) * xStretch);
pRect->yBottom = (int)((pR->origin.y + pR->size.height) * yStretch);
}
- (void)vboxPresentToViewCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor
{
NSRect r = [self frame];
float xStretch, yStretch;
DEBUG_MSG(("OVIW(%p): rF2V frame: [%i, %i, %i, %i]\n", (void*)self, (int)r.origin.x, (int)r.origin.y, (int)r.size.width, (int)r.size.height));
#if 1 /* Set to 0 to see the docktile instead of the real output */
VBOXVR_SCR_COMPOSITOR_CONST_ITERATOR CIter;
const VBOXVR_SCR_COMPOSITOR_ENTRY *pEntry;
CrVrScrCompositorConstIterInit(pCompositor, &CIter);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
glDrawBuffer(GL_BACK);
/* Clear background to transparent */
glClear(GL_COLOR_BUFFER_BIT);
m_fDataVisible = false;
CrVrScrCompositorGetStretching(pCompositor, &xStretch, &yStretch);
while ((pEntry = CrVrScrCompositorConstIterNext(&CIter)) != NULL)
{
uint32_t cRegions;
const RTRECT *paSrcRegions, *paDstRegions;
int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions, NULL);
uint32_t fFlags = CrVrScrCompositorEntryFlagsCombinedGet(pCompositor, pEntry);
if (RT_SUCCESS(rc))
{
uint32_t i;
int rc = CrBltEnter(m_pBlitter);
if (RT_SUCCESS(rc))
{
for (i = 0; i < cRegions; ++i)
{
const RTRECT * pSrcRect = &paSrcRegions[i];
const RTRECT * pDstRect = &paDstRegions[i];
RTRECT DstRect, RestrictDstRect;
RTRECT SrcRect, RestrictSrcRect;
vboxNSRectToRect(&m_RootRect, &RestrictDstRect);
VBoxRectIntersected(&RestrictDstRect, pDstRect, &DstRect);
if (VBoxRectIsZero(&DstRect))
continue;
VBoxRectTranslate(&DstRect, -RestrictDstRect.xLeft, -RestrictDstRect.yTop);
vboxNSRectToRectUnstretched(&m_RootRect, &RestrictSrcRect, xStretch, yStretch);
VBoxRectTranslate(&RestrictSrcRect, -CrVrScrCompositorEntryRectGet(pEntry)->xLeft, -CrVrScrCompositorEntryRectGet(pEntry)->yTop);
VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect);
if (VBoxRectIsZero(&SrcRect))
continue;
pSrcRect = &SrcRect;
pDstRect = &DstRect;
const CR_TEXDATA *pTexData = CrVrScrCompositorEntryTexGet(pEntry);
CrBltBlitTexMural(m_pBlitter, true, CrTdTexGet(pTexData), pSrcRect, pDstRect, 1, fFlags | CRBLT_F_NOALPHA);
m_fDataVisible = true;
}
CrBltLeave(m_pBlitter);
}
else
{
DEBUG_WARN(("CrBltEnter failed rc %d", rc));
}
}
else
{
Assert(0);
DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc));
}
}
#endif
/*
glFinish();
*/
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
[m_pSharedGLCtx flushBuffer];
}
- (void)presentComposition:(const VBOXVR_SCR_COMPOSITOR_ENTRY*)pChangedEntry
{
[self vboxTryDraw];
}
- (void)vboxBlitterSyncWindow
{
CR_BLITTER_WINDOW WinInfo;
NSRect r;
if (!m_pBlitter)
return;
memset(&WinInfo, 0, sizeof (WinInfo));
r = [self frame];
WinInfo.width = r.size.width;
WinInfo.height = r.size.height;
Assert(WinInfo.width == m_RootRect.size.width);
Assert(WinInfo.height == m_RootRect.size.height);
/*CrBltMuralSetCurrentInfo(m_pBlitter, NULL);*/
CrBltMuralSetCurrentInfo(m_pBlitter, &WinInfo);
CrBltCheckUpdateViewport(m_pBlitter);
}
#ifdef VBOX_WITH_CRDUMPER_THUMBNAIL
static int g_cVBoxTgaCtr = 0;
#endif
- (void)vboxPresentToDockTileCS:(const VBOXVR_SCR_COMPOSITOR*)pCompositor
{
NSRect r = [self frame];
NSRect rr = NSZeroRect;
GLint i = 0;
NSDockTile *pDT = nil;
float xStretch, yStretch;
if ([m_DockTileView thumbBitmap] != nil)
{
/* Only update after at least 200 ms, cause glReadPixels is
* heavy performance wise. */
uint64_t uiNewTime = RTTimeMilliTS();
VBOXVR_SCR_COMPOSITOR_CONST_ITERATOR CIter;
const VBOXVR_SCR_COMPOSITOR_ENTRY *pEntry;
if (uiNewTime - m_uiDockUpdateTime > 200)
{
m_uiDockUpdateTime = uiNewTime;
#if 0
/* todo: check this for optimization */
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, myTextureName);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_STORAGE_HINT_APPLE,
GL_STORAGE_SHARED_APPLE);
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA,
sizex, sizey, 0, GL_BGRA,
GL_UNSIGNED_INT_8_8_8_8_REV, myImagePtr);
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,
0, 0, 0, 0, 0, image_width, image_height);
glFlush();
/* Do other work processing here, using a double or triple buffer */
glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA,
GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
#endif
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
glDrawBuffer(GL_BACK);
/* Clear background to transparent */
glClear(GL_COLOR_BUFFER_BIT);
rr = [m_DockTileView frame];
CrVrScrCompositorGetStretching(pCompositor, &xStretch, &yStretch);
CrVrScrCompositorConstIterInit(pCompositor, &CIter);
while ((pEntry = CrVrScrCompositorConstIterNext(&CIter)) != NULL)
{
uint32_t cRegions;
const RTRECT *paSrcRegions, *paDstRegions;
int rc = CrVrScrCompositorEntryRegionsGet(pCompositor, pEntry, &cRegions, &paSrcRegions, &paDstRegions, NULL);
uint32_t fFlags = CrVrScrCompositorEntryFlagsCombinedGet(pCompositor, pEntry);
if (RT_SUCCESS(rc))
{
uint32_t i;
int rc = CrBltEnter(m_pBlitter);
if (RT_SUCCESS(rc))
{
for (i = 0; i < cRegions; ++i)
{
const RTRECT * pSrcRect = &paSrcRegions[i];
const RTRECT * pDstRect = &paDstRegions[i];
RTRECT SrcRect, DstRect, RestrictSrcRect, RestrictDstRect;
vboxNSRectToRect(&m_RootRect, &RestrictDstRect);
VBoxRectIntersected(&RestrictDstRect, pDstRect, &DstRect);
VBoxRectTranslate(&DstRect, -RestrictDstRect.xLeft, -RestrictDstRect.yTop);
VBoxRectStretch(&DstRect, m_FBOThumbScaleX, m_FBOThumbScaleY);
if (VBoxRectIsZero(&DstRect))
continue;
vboxNSRectToRectUnstretched(&m_RootRect, &RestrictSrcRect, xStretch, yStretch);
VBoxRectTranslate(&RestrictSrcRect, -CrVrScrCompositorEntryRectGet(pEntry)->xLeft, -CrVrScrCompositorEntryRectGet(pEntry)->yTop);
VBoxRectIntersected(&RestrictSrcRect, pSrcRect, &SrcRect);
if (VBoxRectIsZero(&SrcRect))
continue;
pSrcRect = &SrcRect;
pDstRect = &DstRect;
const CR_TEXDATA *pTexData = CrVrScrCompositorEntryTexGet(pEntry);
CrBltBlitTexMural(m_pBlitter, true, CrTdTexGet(pTexData), pSrcRect, pDstRect, 1, fFlags);
}
CrBltLeave(m_pBlitter);
}
else
{
DEBUG_WARN(("CrBltEnter failed rc %d", rc));
}
}
else
{
Assert(0);
DEBUG_MSG_1(("BlitStretched: CrVrScrCompositorEntryRegionsGet failed rc %d\n", rc));
}
}
glFinish();
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
glReadBuffer(GL_BACK);
/* Here the magic of reading the FBO content in our own buffer
* happens. We have to lock this access, in the case the dock
* is updated currently. */
[m_DockTileView lock];
glReadPixels(0, m_RootRect.size.height - rr.size.height, rr.size.width, rr.size.height,
GL_BGRA,
GL_UNSIGNED_INT_8_8_8_8,
[[m_DockTileView thumbBitmap] bitmapData]);
[m_DockTileView unlock];
#ifdef VBOX_WITH_CRDUMPER_THUMBNAIL
++g_cVBoxTgaCtr;
crDumpNamedTGAF((GLint)rr.size.width, (GLint)rr.size.height,
[[m_DockTileView thumbBitmap] bitmapData], "/Users/leo/vboxdumps/dump%d.tga", g_cVBoxTgaCtr);
#endif
pDT = [[NSApplication sharedApplication] dockTile];
/* Send a display message to the dock tile in the main thread */
[[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:NO];
}
}
}
- (void)clearVisibleRegions
{
if(m_paClipRects)
{
RTMemFree(m_paClipRects);
m_paClipRects = NULL;
}
m_cClipRects = 0;
}
- (void)setVisibleRegions:(GLint)cRects paRects:(const GLint*)paRects
{
GLint cOldRects = m_cClipRects;
DEBUG_MSG_1(("OVIW(%p): setVisibleRegions: cRects=%d\n", (void*)self, cRects));
[self clearVisibleRegions];
if (cRects > 0)
{
#ifdef DEBUG_poetzsch
int i =0;
for (i = 0; i < cRects; ++i)
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]));
#endif
m_paClipRects = (GLint*)RTMemAlloc(sizeof(GLint) * 4 * cRects);
m_cClipRects = cRects;
memcpy(m_paClipRects, paRects, sizeof(GLint) * 4 * cRects);
}
/* we need to redwar on regions change, however the compositor now is cleared
* because all compositor&window data-related modifications are performed with compositor cleared
* the renderspu client will re-set the compositor after modifications are complete
* this way we indicate renderspu generic code not to ignore the empty compositor */
m_pWinInfo->fCompositorPresentEmpty = GL_TRUE;
}
- (NSView*)dockTileScreen
{
NSView *contentView = [[[NSApplication sharedApplication] dockTile] contentView];
NSView *screenContent = nil;
/* First try the new variant which checks if this window is within the
screen which is previewed in the dock. */
if ([contentView respondsToSelector:@selector(screenContentWithParentView:)])
screenContent = [contentView performSelector:@selector(screenContentWithParentView:) withObject:(id)m_pParentView];
/* If it fails, fall back to the old variant (VBox...) */
else if ([contentView respondsToSelector:@selector(screenContent)])
screenContent = [contentView performSelector:@selector(screenContent)];
return screenContent;
}
- (void)reshapeDockTile
{
NSRect newFrame = NSZeroRect;
NSView *pView = [self dockTileScreen];
if (pView != nil)
{
NSRect dockFrame = [pView frame];
/* todo: this is not correct, we should use framebuffer size here, while parent view frame size may differ in case of scrolling */
NSRect parentFrame = [m_pParentView frame];
m_FBOThumbScaleX = (float)dockFrame.size.width / parentFrame.size.width;
m_FBOThumbScaleY = (float)dockFrame.size.height / parentFrame.size.height;
newFrame = NSMakeRect((int)(m_Pos.x * m_FBOThumbScaleX), (int)(dockFrame.size.height - (m_Pos.y + m_Size.height - m_yInvRootOffset) * m_FBOThumbScaleY), (int)(m_Size.width * m_FBOThumbScaleX), (int)(m_Size.height * m_FBOThumbScaleY));
/*
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));
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));
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);
*/
[m_DockTileView setFrame: newFrame];
}
}
@end
/********************************************************************************
*
* OpenGL context management
*
********************************************************************************/
void cocoaGLCtxCreate(NativeNSOpenGLContextRef *ppCtx, GLbitfield fVisParams, NativeNSOpenGLContextRef pSharedCtx)
{
NSOpenGLPixelFormat *pFmt = nil;
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
NSOpenGLPixelFormatAttribute attribs[24] =
{
NSOpenGLPFAWindow,
NSOpenGLPFAAccelerated,
NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)24
};
int i = 4;
if (fVisParams & CR_ALPHA_BIT)
{
DEBUG_MSG(("CR_ALPHA_BIT requested\n"));
attribs[i++] = NSOpenGLPFAAlphaSize;
attribs[i++] = 8;
}
if (fVisParams & CR_DEPTH_BIT)
{
DEBUG_MSG(("CR_DEPTH_BIT requested\n"));
attribs[i++] = NSOpenGLPFADepthSize;
attribs[i++] = 24;
}
if (fVisParams & CR_STENCIL_BIT)
{
DEBUG_MSG(("CR_STENCIL_BIT requested\n"));
attribs[i++] = NSOpenGLPFAStencilSize;
attribs[i++] = 8;
}
if (fVisParams & CR_ACCUM_BIT)
{
DEBUG_MSG(("CR_ACCUM_BIT requested\n"));
attribs[i++] = NSOpenGLPFAAccumSize;
if (fVisParams & CR_ALPHA_BIT)
attribs[i++] = 32;
else
attribs[i++] = 24;
}
if (fVisParams & CR_MULTISAMPLE_BIT)
{
DEBUG_MSG(("CR_MULTISAMPLE_BIT requested\n"));
attribs[i++] = NSOpenGLPFASampleBuffers;
attribs[i++] = 1;
attribs[i++] = NSOpenGLPFASamples;
attribs[i++] = 4;
}
if (fVisParams & CR_DOUBLE_BIT)
{
DEBUG_MSG(("CR_DOUBLE_BIT requested\n"));
attribs[i++] = NSOpenGLPFADoubleBuffer;
}
if (fVisParams & CR_STEREO_BIT)
{
/* We don't support that.
DEBUG_MSG(("CR_STEREO_BIT requested\n"));
attribs[i++] = NSOpenGLPFAStereo;
*/
}
/* Mark the end */
attribs[i++] = 0;
/* Choose a pixel format */
pFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
if (pFmt)
{
*ppCtx = [[OverlayOpenGLContext alloc] initWithFormat:pFmt shareContext:pSharedCtx];
/* Enable multi threaded OpenGL engine */
/*
CGLContextObj cglCtx = [*ppCtx CGLContextObj];
CGLError err = CGLEnable(cglCtx, kCGLCEMPEngine);
if (err != kCGLNoError)
printf ("Couldn't enable MT OpenGL engine!\n");
*/
DEBUG_MSG(("New context %X\n", (uint)*ppCtx));
}
[pPool release];
}
void cocoaGLCtxDestroy(NativeNSOpenGLContextRef pCtx)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[pCtx release];
/*[pCtx performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];*/
[pPool release];
}
/********************************************************************************
*
* View management
*
********************************************************************************/
void cocoaViewCreate(NativeNSViewRef *ppView, WindowInfo *pWinInfo, NativeNSViewRef pParentView, GLbitfield fVisParams)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
/* Create our worker view */
OverlayView* pView = [[OverlayView alloc] initWithFrame:NSZeroRect thread:RTThreadSelf() parentView:pParentView winInfo:pWinInfo];
if (pView)
{
/* We need a real window as container for the view */
[[OverlayWindow alloc] initWithParentView:pParentView overlayView:pView];
/* Return the freshly created overlay view */
*ppView = pView;
}
[pPool release];
}
void cocoaViewReparent(NativeNSViewRef pView, NativeNSViewRef pParentView)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
OverlayView* pOView = (OverlayView*)pView;
if (pOView)
{
/* Make sure the window is removed from any previous parent window. */
if ([[pOView overlayWin] parentWindow] != nil)
{
[[[pOView overlayWin] parentWindow] removeChildWindow:[pOView overlayWin]];
}
/* Set the new parent view */
[pOView setParentView: pParentView];
/* Add the overlay window as a child to the new parent window */
if (pParentView != nil)
{
[[pParentView window] addChildWindow:[pOView overlayWin] ordered:NSWindowAbove];
if ([pOView isEverSized])
[pOView performSelectorOnMainThread:@selector(vboxReshapeOnReparentPerform) withObject:nil waitUntilDone:NO];
}
}
[pPool release];
}
void cocoaViewDestroy(NativeNSViewRef pView)
{
NSWindow *pWin = nil;
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
/* Hide the view early */
[pView setHidden: YES];
pWin = [pView window];
[[NSNotificationCenter defaultCenter] removeObserver:pWin];
[pWin setContentView: nil];
[[pWin parentWindow] removeChildWindow: pWin];
/*
a = [pWin retainCount];
for (; a > 1; --a)
[pWin performSelector:@selector(release)]
*/
/* We can NOT run synchronously with the main thread since this may lead to a deadlock,
caused by main thread waiting xpcom thread, xpcom thread waiting to main hgcm thread,
and main hgcm thread waiting for us, this is why use waitUntilDone:NO,
which should cause no harm */
[pWin performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
/*
[pWin release];
*/
/* We can NOT run synchronously with the main thread since this may lead to a deadlock,
caused by main thread waiting xpcom thread, xpcom thread waiting to main hgcm thread,
and main hgcm thread waiting for us, this is why use waitUntilDone:NO.
We need to avoid concurrency though, so we cleanup some data right away via a cleanupData call */
[(OverlayView*)pView cleanupData];
/* There seems to be a bug in the performSelector method which is called in
* parentWindowChanged above. The object is retained but not released. This
* results in an unbalanced reference count, which is here manually
* decremented. */
/*
a = [pView retainCount];
for (; a > 1; --a)
*/
[pView performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
/*
[pView release];
*/
[pPool release];
}
void cocoaViewShow(NativeNSViewRef pView, GLboolean fShowIt)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[pView setHidden: fShowIt==GL_TRUE?NO:YES];
[pPool release];
}
void cocoaViewDisplay(NativeNSViewRef pView)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
DEBUG_MSG_1(("cocoaViewDisplay %p\n", (void*)pView));
[(OverlayView*)pView swapFBO];
[pPool release];
}
void cocoaViewSetPosition(NativeNSViewRef pView, NativeNSViewRef pParentView, int x, int y)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[(OverlayView*)pView setPos:NSMakePoint(x, y)];
[pPool release];
}
void cocoaViewSetSize(NativeNSViewRef pView, int w, int h)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[(OverlayView*)pView setSize:NSMakeSize(w, h)];
[pPool release];
}
void cocoaViewGetGeometry(NativeNSViewRef pView, int *pX, int *pY, int *pW, int *pH)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
NSRect frame = [[pView window] frame];
*pX = frame.origin.x;
*pY = frame.origin.y;
*pW = frame.size.width;
*pH = frame.size.height;
[pPool release];
}
void cocoaViewPresentComposition(NativeNSViewRef pView, const struct VBOXVR_SCR_COMPOSITOR_ENTRY *pChangedEntry)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
NSOpenGLContext *pCtx;
/* view should not necesserily have a context set */
pCtx = [(OverlayView*)pView glCtx];
if (!pCtx)
{
ContextInfo * pCtxInfo = renderspuDefaultSharedContextAcquire();
if (!pCtxInfo)
{
DEBUG_WARN(("renderspuDefaultSharedContextAcquire returned NULL"));
[pPool release];
return;
}
pCtx = pCtxInfo->context;
[(OverlayView*)pView setGLCtx:pCtx];
}
[(OverlayView*)pView presentComposition:pChangedEntry];
[pPool release];
}
void cocoaViewMakeCurrentContext(NativeNSViewRef pView, NativeNSOpenGLContextRef pCtx)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
DEBUG_MSG(("cocoaViewMakeCurrentContext(%p, %p)\n", (void*)pView, (void*)pCtx));
if (pView)
{
[(OverlayView*)pView setGLCtx:pCtx];
[(OverlayView*)pView makeCurrentFBO];
}
else
{
[NSOpenGLContext clearCurrentContext];
}
[pPool release];
}
void cocoaViewSetVisibleRegion(NativeNSViewRef pView, GLint cRects, const GLint* paRects)
{
NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
[(OverlayView*)pView setVisibleRegions:cRects paRects:paRects];
[pPool release];
}