load.c revision a051bdf4014b39aee0375b4a6df8f8cb7e11ece8
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/* Copyright (c) 2001, Stanford University
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * All rights reserved
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync *
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * See the file LICENSE.txt for information on redistributing this software.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_spu.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_net.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_error.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_mem.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_string.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_net.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_environment.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_process.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_rand.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_netserver.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "stub.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include <stdlib.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include <string.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include <signal.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include <iprt/initterm.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include <iprt/thread.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include <iprt/err.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include <iprt/asm.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifndef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# include <sys/types.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# include <unistd.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef CHROMIUM_THREADSAFE
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include "cr_threads.h"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * If you change this, see the comments in tilesortspu_context.c
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#define MAGIC_CONTEXT_BASE 500
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#define CONFIG_LOOKUP_FILE ".crconfigs"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#define PYTHON_EXE "python.exe"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#define PYTHON_EXE "python"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic char* gsViewportHackApps[] = {"googleearth.exe", NULL};
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic int stub_initialized = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/* NOTE: 'SPUDispatchTable glim' is declared in NULLfuncs.py now */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/* NOTE: 'SPUDispatchTable stubThreadsafeDispatch' is declared in tsfuncs.c */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncStub stub;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubInitNativeDispatch( void )
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#define MAX_FUNCS 1000
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync SPUNamedFunctionTable gl_funcs[MAX_FUNCS];
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int numFuncs;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync numFuncs = crLoadOpenGL( &stub.wsInterface, gl_funcs );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.haveNativeOpenGL = (numFuncs > 0);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* XXX call this after context binding */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync numFuncs += crLoadOpenGLExtensions( &stub.wsInterface, gl_funcs + numFuncs );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync CRASSERT(numFuncs < MAX_FUNCS);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crSPUInitDispatchTable( &stub.nativeDispatch );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crSPUInitDispatch( &stub.nativeDispatch, gl_funcs );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crSPUInitDispatchNops( &stub.nativeDispatch );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#undef MAX_FUNCS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/** Pointer to the SPU's real glClear and glViewport functions */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic ClearFunc_t origClear;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic ViewportFunc_t origViewport;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic SwapBuffersFunc_t origSwapBuffers;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic DrawBufferFunc_t origDrawBuffer;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic ScissorFunc_t origScissor;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubCheckWindowState(WindowInfo *window, GLboolean bFlushOnChange)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync bool bForceUpdate = false;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync bool bChanged = false;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* @todo install hook and track for WM_DISPLAYCHANGE */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync DEVMODE devMode;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync devMode.dmSize = sizeof(DEVMODE);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (devMode.dmPelsWidth!=window->dmPelsWidth || devMode.dmPelsHeight!=window->dmPelsHeight)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Resolution changed(%d,%d), forcing window Pos/Size update", devMode.dmPelsWidth, devMode.dmPelsHeight);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync window->dmPelsWidth = devMode.dmPelsWidth;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync window->dmPelsHeight = devMode.dmPelsHeight;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync bForceUpdate = true;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync#endif
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync bChanged = stubUpdateWindowGeometry(window, bForceUpdate) || bForceUpdate;
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync#if defined(GLX) || defined (WINDOWS)
e7c4c205cb0af88b5ef0786be46da94847a9a37bvboxsync if (stub.trackWindowVisibleRgn)
e7c4c205cb0af88b5ef0786be46da94847a9a37bvboxsync {
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync bChanged = stubUpdateWindowVisibileRegions(window) || bChanged;
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (stub.trackWindowVisibility && window->type == CHROMIUM && window->drawable) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync const int mapped = stubIsWindowVisible(window);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (mapped != window->mapped) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Dispatched: WindowShow(%i, %i)", window->spuWindow, mapped);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu->dispatch_table.WindowShow(window->spuWindow, mapped);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync window->mapped = mapped;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync bChanged = true;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (bFlushOnChange && bChanged)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu->dispatch_table.Flush();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic bool stubSystemWindowExist(WindowInfo *pWindow)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!WindowFromDC(pWindow->drawable))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return false;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Window root;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int x, y;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync unsigned int border, depth, w, h;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Display *dpy;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync dpy = stubGetWindowDisplay(pWindow);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync XLOCK(dpy);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!XGetGeometry(dpy, pWindow->drawable, &root, &x, &y, &w, &h, &border, &depth))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync XUNLOCK(dpy);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return false;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync XUNLOCK(dpy);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return true;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubCheckWindowsCB(unsigned long key, void *data1, void *data2)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync WindowInfo *pWindow = (WindowInfo *) data1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ContextInfo *pCtx = (ContextInfo *) data2;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (pWindow == pCtx->currentDrawable
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync || pWindow->type!=CHROMIUM
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync || pWindow->pOwner!=pCtx)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!stubSystemWindowExist(pWindow))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crWindowDestroy((GLint)pWindow->hWnd);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crWindowDestroy((GLint)pWindow->drawable);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubCheckWindowState(pWindow, GL_FALSE);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubCheckWindowsState(void)
241adddf415cbdf66230864a215b24415f482e72vboxsync{
241adddf415cbdf66230864a215b24415f482e72vboxsync CRASSERT(stub.trackWindowSize || stub.trackWindowPos);
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync if (!stub.currentContext)
241adddf415cbdf66230864a215b24415f482e72vboxsync return;
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync#if defined(CR_NEWWINTRACK) && !defined(WINDOWS)
241adddf415cbdf66230864a215b24415f482e72vboxsync crLockMutex(&stub.mutex);
241adddf415cbdf66230864a215b24415f482e72vboxsync#endif
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsync stubCheckWindowState(stub.currentContext->currentDrawable, GL_TRUE);
241adddf415cbdf66230864a215b24415f482e72vboxsync crHashtableWalk(stub.windowTable, stubCheckWindowsCB, stub.currentContext);
241adddf415cbdf66230864a215b24415f482e72vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#if defined(CR_NEWWINTRACK) && !defined(WINDOWS)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crUnlockMutex(&stub.mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync}
859c9a7cc74066a52cf7e76d54169859e7705c3dvboxsync
859c9a7cc74066a52cf7e76d54169859e7705c3dvboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Override the head SPU's glClear function.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * We're basically trapping this function so that we can poll the
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync * application window size at a regular interval.
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync */
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsyncstatic void SPU_APIENTRY trapClear(GLbitfield mask)
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync{
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync stubCheckWindowsState();
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync /* call the original SPU glClear function */
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync origClear(mask);
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync}
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * As above, but for glViewport. Most apps call glViewport before
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * glClear when a window is resized.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
241adddf415cbdf66230864a215b24415f482e72vboxsyncstatic void SPU_APIENTRY trapViewport(GLint x, GLint y, GLsizei w, GLsizei h)
241adddf415cbdf66230864a215b24415f482e72vboxsync{
241adddf415cbdf66230864a215b24415f482e72vboxsync stubCheckWindowsState();
241adddf415cbdf66230864a215b24415f482e72vboxsync /* call the original SPU glViewport function */
241adddf415cbdf66230864a215b24415f482e72vboxsync if (!stub.viewportHack)
241adddf415cbdf66230864a215b24415f482e72vboxsync {
241adddf415cbdf66230864a215b24415f482e72vboxsync origViewport(x, y, w, h);
241adddf415cbdf66230864a215b24415f482e72vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int winX, winY;
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync unsigned int winW, winH;
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync WindowInfo *pWindow;
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync pWindow = stub.currentContext->currentDrawable;
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync stubGetWindowGeometry(pWindow, &winX, &winY, &winW, &winH);
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync origViewport(0, 0, winW, winH);
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync }
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync}
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsyncstatic void SPU_APIENTRY trapSwapBuffers(GLint window, GLint flags)
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync{
a8ce9568e18b8c1a49833bf3b3ac2b2cc634b13cvboxsync stubCheckWindowsState();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync origSwapBuffers(window, flags);
241adddf415cbdf66230864a215b24415f482e72vboxsync}
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsyncstatic void SPU_APIENTRY trapDrawBuffer(GLenum buf)
241adddf415cbdf66230864a215b24415f482e72vboxsync{
241adddf415cbdf66230864a215b24415f482e72vboxsync stubCheckWindowsState();
241adddf415cbdf66230864a215b24415f482e72vboxsync origDrawBuffer(buf);
241adddf415cbdf66230864a215b24415f482e72vboxsync}
241adddf415cbdf66230864a215b24415f482e72vboxsync
241adddf415cbdf66230864a215b24415f482e72vboxsyncstatic void SPU_APIENTRY trapScissor(GLint x, GLint y, GLsizei w, GLsizei h)
241adddf415cbdf66230864a215b24415f482e72vboxsync{
241adddf415cbdf66230864a215b24415f482e72vboxsync int winX, winY;
241adddf415cbdf66230864a215b24415f482e72vboxsync unsigned int winW, winH;
241adddf415cbdf66230864a215b24415f482e72vboxsync WindowInfo *pWindow;
241adddf415cbdf66230864a215b24415f482e72vboxsync pWindow = stub.currentContext->currentDrawable;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubGetWindowGeometry(pWindow, &winX, &winY, &winW, &winH);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync origScissor(0, 0, winW, winH);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Use the GL function pointers in <spu> to initialize the static glim
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * dispatch table.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubInitSPUDispatch(SPU *spu)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crSPUInitDispatchTable( &stub.spuDispatch );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crSPUCopyDispatchTable( &stub.spuDispatch, &(spu->dispatch_table) );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (stub.trackWindowSize || stub.trackWindowPos || stub.trackWindowVisibleRgn) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* patch-in special glClear/Viewport function to track window sizing */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync origClear = stub.spuDispatch.Clear;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync origViewport = stub.spuDispatch.Viewport;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync origSwapBuffers = stub.spuDispatch.SwapBuffers;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync origDrawBuffer = stub.spuDispatch.DrawBuffer;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync origScissor = stub.spuDispatch.Scissor;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spuDispatch.Clear = trapClear;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spuDispatch.Viewport = trapViewport;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (stub.viewportHack)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spuDispatch.Scissor = trapScissor;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /*stub.spuDispatch.SwapBuffers = trapSwapBuffers;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spuDispatch.DrawBuffer = trapDrawBuffer;*/
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crSPUCopyDispatchTable( &glim, &stub.spuDispatch );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync// Callback function, used to destroy all created contexts
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void hsWalkStubDestroyContexts(unsigned long key, void *data1, void *data2)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubDestroyContext(key);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * This is called when we exit.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * We call all the SPU's cleanup functions.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubSPUTearDown(void)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("stubSPUTearDown");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!stub_initialized) return;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub_initialized = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# ifndef CR_NEWWINTRACK
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubUninstallWindowMessageHook();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef CR_NEWWINTRACK
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ASMAtomicWriteBool(&stub.bShutdownSyncThread, true);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync //delete all created contexts
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubMakeCurrent( NULL, NULL);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crHashtableWalk(stub.contextTable, hsWalkStubDestroyContexts, NULL);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* shutdown, now trap any calls to a NULL dispatcher */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crSPUCopyDispatchTable(&glim, &stubNULLDispatch);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
4791a729647f035b6561d292c9f848dd1fc797a9vboxsync crSPUUnloadChain(stub.spu);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifndef Linux
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crUnloadOpenGL();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetTearDown();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef GLX
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (stub.xshmSI.shmid>=0)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync shmctl(stub.xshmSI.shmid, IPC_RMID, 0);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync shmdt(stub.xshmSI.shmaddr);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crFreeHashtable(stub.pGLXPixmapsHash, crFree);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crFreeHashtable(stub.windowTable, crFree);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crFreeHashtable(stub.contextTable, NULL);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crMemset(&stub, 0, sizeof(stub) );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubSPUSafeTearDown(void)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef CHROMIUM_THREADSAFE
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync CRmutex *mutex;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!stub_initialized) return;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub_initialized = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef CHROMIUM_THREADSAFE
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync mutex = &stub.mutex;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crLockMutex(mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("stubSPUSafeTearDown");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# ifndef CR_NEWWINTRACK
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubUninstallWindowMessageHook();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#if defined(WINDOWS) && defined(CR_NEWWINTRACK)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crUnlockMutex(mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (RTThreadGetState(stub.hSyncThread)!=RTTHREADSTATE_TERMINATED)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ASMAtomicWriteBool(&stub.bShutdownSyncThread, true);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (PostThreadMessage(RTThreadGetNative(stub.hSyncThread), WM_QUIT, 0, 0))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync RTThreadWait(stub.hSyncThread, 1000, NULL);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Sync thread killed before DLL_PROCESS_DETACH");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crLockMutex(mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetTearDown();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crMemset(&stub, 0, sizeof(stub));
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef CHROMIUM_THREADSAFE
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crUnlockMutex(mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crFreeMutex(mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubExitHandler(void)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubSPUSafeTearDown();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Called when we receive a SIGTERM signal.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubSignalHandler(int signo)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubSPUSafeTearDown();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync exit(0); /* this causes stubExitHandler() to be called */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Init variables in the stub structure, install signal handler.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubInitVars(void)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync WindowInfo *defaultWin;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef CHROMIUM_THREADSAFE
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crInitMutex(&stub.mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* At the very least we want CR_RGB_BIT. */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.haveNativeOpenGL = GL_FALSE;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.appDrawCursor = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.minChromiumWindowWidth = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.minChromiumWindowHeight = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.maxChromiumWindowWidth = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.maxChromiumWindowHeight = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.matchChromiumWindowCount = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.matchChromiumWindowID = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.matchWindowTitle = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.ignoreFreeglutMenus = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.threadSafe = GL_FALSE;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.trackWindowSize = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.trackWindowPos = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.trackWindowVisibility = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.trackWindowVisibleRgn = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.mothershipPID = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu_dir = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.freeContextNumber = MAGIC_CONTEXT_BASE;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.contextTable = crAllocHashtable();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.currentContext = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.windowTable = crAllocHashtable();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef CR_NEWWINTRACK
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.bShutdownSyncThread = false;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.hSyncThread = NIL_RTTHREAD;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync defaultWin = (WindowInfo *) crCalloc(sizeof(WindowInfo));
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync defaultWin->type = CHROMIUM;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync defaultWin->spuWindow = 0; /* window 0 always exists */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync defaultWin->hVisibleRegion = INVALID_HANDLE_VALUE;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#elif defined(GLX)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync defaultWin->pVisibleRegions = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync defaultWin->cVisibleRegions = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crHashtableAdd(stub.windowTable, 0, defaultWin);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#if 1
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync atexit(stubExitHandler);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync signal(SIGTERM, stubSignalHandler);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync signal(SIGINT, stubSignalHandler);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifndef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync signal(SIGPIPE, SIG_IGN); /* the networking code should catch this */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync (void) stubExitHandler;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync (void) stubSignalHandler;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Return a free port number for the mothership to use, or -1 if we
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * can't find one.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic int
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncGenerateMothershipPort(void)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync const int MAX_PORT = 10100;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync unsigned short port;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* generate initial port number randomly */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crRandAutoSeed();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync port = (unsigned short) crRandInt(10001, MAX_PORT);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* XXX should implement a free port check here */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return port;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /*
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * See if this port number really is free, try another if needed.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync struct sockaddr_in servaddr;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int so_reuseaddr = 1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int sock, k;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* create socket */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync sock = socket(AF_INET, SOCK_STREAM, 0);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync CRASSERT(sock > 2);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* deallocate socket/port when we exit */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync k = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync (char *) &so_reuseaddr, sizeof(so_reuseaddr));
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync CRASSERT(k == 0);
fd60bfdb327b9b1e7a6d084cf368fb7f07c566cfvboxsync
223935479ac42db56b7b7a7d16548d590022996avboxsync /* initialize the servaddr struct */
223935479ac42db56b7b7a7d16548d590022996avboxsync crMemset(&servaddr, 0, sizeof(servaddr) );
223935479ac42db56b7b7a7d16548d590022996avboxsync servaddr.sin_family = AF_INET;
223935479ac42db56b7b7a7d16548d590022996avboxsync servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
fd60bfdb327b9b1e7a6d084cf368fb7f07c566cfvboxsync
fd60bfdb327b9b1e7a6d084cf368fb7f07c566cfvboxsync while (port < MAX_PORT) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* Bind to the given port number, return -1 if we fail */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync servaddr.sin_port = htons((unsigned short) port);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync k = bind(sock, (struct sockaddr *) &servaddr, sizeof(servaddr));
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (k) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* failed to create port. try next one. */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync port++;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync else {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* free the socket/port now so mothership can make it */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync close(sock);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return port;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif /* WINDOWS */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return -1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Try to determine which mothership configuration to use for this program.
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync */
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsyncstatic char **
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsyncLookupMothershipConfig(const char *procName)
64863d3a0ffadf1ac248b295b78be5d55db6ee13vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync const int procNameLen = crStrlen(procName);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync FILE *f;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync const char *home;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync char configPath[1000];
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* first, check if the CR_CONFIG env var is set */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync const char *conf = crGetenv("CR_CONFIG");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (conf && crStrlen(conf) > 0)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return crStrSplit(conf, " ");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* second, look up config name from config file */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync home = crGetenv("HOME");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (home)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync sprintf(configPath, "%s/%s", home, CONFIG_LOOKUP_FILE);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crStrcpy(configPath, CONFIG_LOOKUP_FILE); /* from current dir */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* Check if the CR_CONFIG_PATH env var is set. */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync const char *conf = crGetenv("CR_CONFIG_PATH");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (conf)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crStrcpy(configPath, conf); /* from env var */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync f = fopen(configPath, "r");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!f) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync while (!feof(f)) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync char line[1000];
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync char **args;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync fgets(line, 999, f);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync line[crStrlen(line) - 1] = 0; /* remove trailing newline */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (crStrncmp(line, procName, procNameLen) == 0 &&
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync (line[procNameLen] == ' ' || line[procNameLen] == '\t'))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crWarning("Using Chromium configuration for %s from %s",
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync procName, configPath);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync args = crStrSplit(line + procNameLen + 1, " ");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return args;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync fclose(f);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic int Mothership_Awake = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Signal handler to determine when mothership is ready.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncMothershipPhoneHome(int signo)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Got signal %d: mothership is awake!", signo);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Mothership_Awake = 1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncvoid stubSetDefaultConfigurationOptions(void)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync unsigned char key[16]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.appDrawCursor = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.minChromiumWindowWidth = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.minChromiumWindowHeight = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.maxChromiumWindowWidth = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.maxChromiumWindowHeight = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.matchChromiumWindowID = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.numIgnoreWindowID = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.matchWindowTitle = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.ignoreFreeglutMenus = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.trackWindowSize = 1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.trackWindowPos = 1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.trackWindowVisibility = 1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.trackWindowVisibleRgn = 1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.matchChromiumWindowCount = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu_dir = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetSetRank(0);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetSetContextRange(32, 35);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetSetNodeRange("iam0", "iamvis20");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetSetKey(key,sizeof(key));
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.force_pbuffers = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.viewportHack = 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync char name[1000];
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int i;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* Apply viewport hack only if we're running under wine */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (NULL!=GetModuleHandle("wined3d.dll"))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crGetProcName(name, 1000);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync for (i=0; gsViewportHackApps[i]; ++i)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!stricmp(name, gsViewportHackApps[i]))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.viewportHack = 1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync break;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef CR_NEWWINTRACK
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic void stubSyncTrCheckWindowsCB(unsigned long key, void *data1, void *data2)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync WindowInfo *pWindow = (WindowInfo *) data1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ContextInfo *pCtx = (ContextInfo *) data2;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (pWindow->type!=CHROMIUM || pWindow->spuWindow==0)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu->dispatch_table.VBoxPackSetInjectID(pWindow->u32ClientID);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!stubSystemWindowExist(pWindow))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crWindowDestroy((GLint)pWindow->hWnd);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crWindowDestroy((GLint)pWindow->drawable);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /*No need to flush here as crWindowDestroy does it*/
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubCheckWindowState(pWindow, GL_TRUE);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstatic DECLCALLBACK(int) stubSyncThreadProc(RTTHREAD ThreadSelf, void *pvUser)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync MSG msg;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync (void) pvUser;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Sync thread started");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crLockMutex(&stub.mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu->dispatch_table.VBoxPackSetInjectThread();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crUnlockMutex(&stub.mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync RTThreadUserSignal(ThreadSelf);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync while(!stub.bShutdownSyncThread)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crHashtableWalk(stub.windowTable, stubSyncTrCheckWindowsCB, NULL);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync RTThreadSleep(50);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (WM_QUIT==msg.message)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Sync thread got WM_QUIT");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync break;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync TranslateMessage(&msg);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync DispatchMessage(&msg);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crLockMutex(&stub.mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crHashtableWalk(stub.windowTable, stubSyncTrCheckWindowsCB, NULL);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crUnlockMutex(&stub.mutex);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync RTThreadSleep(50);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Sync thread stopped");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return 0;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/**
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Do one-time initializations for the faker.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * Returns TRUE on success, FALSE otherwise.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncbool
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncstubInit(void)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* Here is where we contact the mothership to find out what we're supposed
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * to be doing. Networking code in a DLL initializer. I sure hope this
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * works :)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync *
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * HOW can I pass the mothership address to this if I already know it?
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync CRConnection *conn = NULL;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync char response[1024];
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync char **spuchain;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int num_spus;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int *spu_ids;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync char **spu_names;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync const char *app_id;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int i;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (stub_initialized)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return true;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubInitVars();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crGetProcName(response, 1024);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Stub launched for %s", response);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* @todo check if it'd be of any use on other than guests, no use for windows */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync app_id = crGetenv( "CR_APPLICATION_ID_NUMBER" );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetInit( NULL, NULL );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifndef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync CRNetServer ns;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ns.name = "vboxhgcm://host:0";
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ns.buffer_size = 1024;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetServerConnect(&ns);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!ns.conn)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crWarning("Failed to connect to host. Make sure 3D acceleration is enabled for this VM.");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return false;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetFreeConnection(ns.conn);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#if 0 && defined(CR_NEWWINTRACK)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Status st = XInitThreads();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (st==0)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crWarning("XInitThreads returned %i", (int)st);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync strcpy(response, "2 0 feedback 1 pack");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync spuchain = crStrSplit( response, " " );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync num_spus = crStrToInt( spuchain[0] );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync spu_ids = (int *) crAlloc( num_spus * sizeof( *spu_ids ) );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync spu_names = (char **) crAlloc( num_spus * sizeof( *spu_names ) );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync for (i = 0 ; i < num_spus ; i++)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync spu_ids[i] = crStrToInt( spuchain[2*i+1] );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync spu_names[i] = crStrdup( spuchain[2*i+2] );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug( "SPU %d/%d: (%d) \"%s\"", i+1, num_spus, spu_ids[i], spu_names[i] );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubSetDefaultConfigurationOptions();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.spu = crSPULoadChain( num_spus, spu_ids, spu_names, stub.spu_dir, NULL );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crFree( spuchain );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crFree( spu_ids );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync for (i = 0; i < num_spus; ++i)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crFree(spu_names[i]);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crFree( spu_names );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync // spu chain load failed somewhere
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!stub.spu) {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return false;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crSPUInitDispatchTable( &glim );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* This is unlikely to change -- We still want to initialize our dispatch
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * table with the functions of the first SPU in the chain. */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubInitSPUDispatch( stub.spu );
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* we need to plug one special stub function into the dispatch table */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync glim.GetChromiumParametervCR = stub_GetChromiumParametervCR;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#if !defined(VBOX_NO_NATIVEGL)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync /* Load pointers to native OpenGL functions into stub.nativeDispatch */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubInitNativeDispatch();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/*crDebug("stub init");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncraise(SIGINT);*/
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# ifndef CR_NEWWINTRACK
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubInstallWindowMessageHook();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
859c9a7cc74066a52cf7e76d54169859e7705c3dvboxsync
859c9a7cc74066a52cf7e76d54169859e7705c3dvboxsync#ifdef CR_NEWWINTRACK
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync int rc;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync RTR3Init();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Starting sync thread");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync rc = RTThreadCreate(&stub.hSyncThread, stubSyncThreadProc, NULL, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "Sync");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (RT_FAILURE(rc))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crError("Failed to start sync thread! (%x)", rc);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync RTThreadUserWait(stub.hSyncThread, 60 * 1000);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync RTThreadUserReset(stub.hSyncThread);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Going on");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef GLX
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.xshmSI.shmid = -1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.bShmInitFailed = GL_FALSE;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub.pGLXPixmapsHash = crAllocHashtable();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stub_initialized = 1;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return true;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/* Sigh -- we can't do initialization at load time, since Windows forbids
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync * the loading of other libraries from DLLMain. */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef LINUX
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/* GCC crap
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync *void (*stub_init_ptr)(void) __attribute__((section(".ctors"))) = __stubInit; */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#ifdef WINDOWS
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#define WIN32_LEAN_AND_MEAN
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#include <windows.h>
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync/* Windows crap */
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncBOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync{
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync (void) lpvReserved;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync switch (fdwReason)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync case DLL_PROCESS_ATTACH:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync CRNetServer ns;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetInit(NULL, NULL);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ns.name = "vboxhgcm://host:0";
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ns.buffer_size = 1024;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetServerConnect(&ns);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if (!ns.conn)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crDebug("Failed to connect to host (is guest 3d acceleration enabled?), aborting ICD load.");
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return FALSE;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync else
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync crNetFreeConnection(ns.conn);
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync break;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync case DLL_PROCESS_DETACH:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync {
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync stubSPUSafeTearDown();
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync break;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync case DLL_THREAD_ATTACH:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync break;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync case DLL_THREAD_DETACH:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync break;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync default:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync break;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync }
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return TRUE;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync}
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#endif
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync