/* * Allocate the state (dirty) bits data structures. * This should be called before we create any contexts. * We'll also create the default/NULL context at this time and make * it the current context by default. This means that if someone * tries to set GL state before calling MakeCurrent() they'll be * modifying the default state object, and not segfaulting on a NULL * pointer somewhere. */ void crStateInit(void) { unsigned int i; /* Purely initialize the context bits */ if (!__currentBits) { __currentBits = (CRStateBits *) crCalloc( sizeof(CRStateBits) ); crStateClientInitBits( &(__currentBits->client) ); crStateLightingInitBits( &(__currentBits->lighting) ); } else crWarning("State tracker is being re-initialized..\n"); for (i=0;i<CR_MAX_CONTEXTS;i++) g_availableContexts[i] = 0; #ifdef CHROMIUM_THREADSAFE if (!__isContextTLSInited) { # ifndef RT_OS_WINDOWS /* tls destructor is implemented for all platforms except windows*/ crInitTSDF(&__contextTSD, crStateThreadTlsDtor); # else /* windows should do cleanup via DllMain THREAD_DETACH notification */ crInitTSD(&__contextTSD); # endif __isContextTLSInited = 1; } #endif if (defaultContext) { /* Free the default/NULL context. * Ensures context bits are reset */ #ifdef CHROMIUM_THREADSAFE SetCurrentContext(NULL); VBoxTlsRefRelease(defaultContext); #else crStateFreeContext(defaultContext); __currentContext = NULL; #endif } /* Reset diff_api */ crMemZero(&diff_api, sizeof(SPUDispatchTable)); /* Allocate the default/NULL context */ defaultContext = crStateCreateContextId(0, NULL, CR_RGB_BIT, NULL); CRASSERT(g_availableContexts[0] == 0); g_availableContexts[0] = 1; /* in use forever */ #ifdef CHROMIUM_THREADSAFE SetCurrentContext(defaultContext); #else __currentContext = defaultContext; #endif }
/** * This function creates and initializes a new display list * manager. It returns a pointer to the manager, or NULL in * the case of insufficient memory. The dispatch table pointer * is passed in to allow the utilities to muck with the table * to gain functional control when GL calls are made. */ CRDLM DLM_APIENTRY *crDLMNewDLM(unsigned int userConfigSize, const CRDLMConfig *userConfig) { CRDLM *dlm; /* This is the default configuration. We'll overwrite it later * with user-supplied configuration information. */ CRDLMConfig config = { CRDLM_DEFAULT_BUFFERSIZE, }; dlm = crAlloc(sizeof(*dlm)); if (!dlm) { return NULL; } /* Start off by initializing all entries that require further * memory allocation, so we can free up all the memory if there's * a problem. */ if (!(dlm->displayLists = crAllocHashtable())) { crFree(dlm); return NULL; } /* The creator counts as the first user. */ dlm->userCount = 1; #ifdef CHROMIUM_THREADSAFE /* This mutex ensures that only one thread is changing the displayLists * hash at a time. Note that we may also need a mutex to guarantee that * the hash is not changed by one thread while another thread is * traversing it; this issue has not yet been resolved. */ crInitMutex(&(dlm->dlMutex)); /* Although the thread-specific data (TSD) functions will initialize * the thread key themselves when needed, those functions do not allow * us to specify a thread destructor. Since a thread could potentially * exit with considerable memory allocated (e.g. if a thread exits * after it has issued NewList but before EndList, and while there * are considerable content buffers allocated), I do the initialization * myself, in order to be able to reclaim those resources if a thread * exits. */ crInitTSDF(&(dlm->tsdKey), threadDestructor); crInitTSD(&CRDLMTSDKey); #endif /* Copy over any appropriate configuration values */ if (userConfig != NULL) { /* Copy over as much configuration information as is provided. * Note that if the CRDLMConfig structure strictly grows, this * allows forward compatability - routines compiled with * older versions of the structure will only initialize that * section of the structure that they know about. */ crMemcpy((void *)&config, (void *) userConfig, MIN(userConfigSize, sizeof(config))); } dlm->bufferSize = config.bufferSize; /* Return the pointer to the newly-allocated display list manager */ return dlm; }
/** * Init variables in the stub structure, install signal handler. */ static void stubInitVars(void) { WindowInfo *defaultWin; #ifdef CHROMIUM_THREADSAFE crInitMutex(&stub.mutex); #endif /* At the very least we want CR_RGB_BIT. */ stub.haveNativeOpenGL = GL_FALSE; stub.spu = NULL; stub.appDrawCursor = 0; stub.minChromiumWindowWidth = 0; stub.minChromiumWindowHeight = 0; stub.maxChromiumWindowWidth = 0; stub.maxChromiumWindowHeight = 0; stub.matchChromiumWindowCount = 0; stub.matchChromiumWindowID = NULL; stub.matchWindowTitle = NULL; stub.ignoreFreeglutMenus = 0; stub.threadSafe = GL_FALSE; stub.trackWindowSize = 0; stub.trackWindowPos = 0; stub.trackWindowVisibility = 0; stub.trackWindowVisibleRgn = 0; stub.mothershipPID = 0; stub.spu_dir = NULL; stub.freeContextNumber = MAGIC_CONTEXT_BASE; stub.contextTable = crAllocHashtable(); #ifndef RT_OS_WINDOWS # ifdef CHROMIUM_THREADSAFE if (!g_stubIsCurrentContextTSDInited) { crInitTSDF(&g_stubCurrentContextTSD, stubThreadTlsDtor); g_stubIsCurrentContextTSDInited = true; } # endif #endif stubSetCurrentContext(NULL); stub.windowTable = crAllocHashtable(); #ifdef CR_NEWWINTRACK stub.bShutdownSyncThread = false; stub.hSyncThread = NIL_RTTHREAD; #endif defaultWin = (WindowInfo *) crCalloc(sizeof(WindowInfo)); defaultWin->type = CHROMIUM; defaultWin->spuWindow = 0; /* window 0 always exists */ #ifdef WINDOWS defaultWin->hVisibleRegion = INVALID_HANDLE_VALUE; #elif defined(GLX) defaultWin->pVisibleRegions = NULL; defaultWin->cVisibleRegions = 0; #endif crHashtableAdd(stub.windowTable, 0, defaultWin); #if 1 atexit(stubExitHandler); signal(SIGTERM, stubSignalHandler); signal(SIGINT, stubSignalHandler); #ifndef WINDOWS signal(SIGPIPE, SIG_IGN); /* the networking code should catch this */ #endif #else (void) stubExitHandler; (void) stubSignalHandler; #endif }