static CRHashIdPool *crAllocHashIdPool( void ) { CRHashIdPool *pool = (CRHashIdPool *) crCalloc(sizeof(CRHashIdPool)); pool->freeList = (FreeElem *) crCalloc(sizeof(FreeElem)); pool->freeList->min = 1; pool->freeList->max = CR_MAXUINT; pool->freeList->next = NULL; pool->freeList->prev = NULL; return pool; }
int32_t crVBoxServerAddClient(uint32_t u32ClientID) { CRClient *newClient; if (cr_server.numClients>=CR_MAX_CLIENTS) { return VERR_MAX_THRDS_REACHED; } newClient = (CRClient *) crCalloc(sizeof(CRClient)); crDebug("crServer: AddClient u32ClientID=%d", u32ClientID); newClient->spu_id = 0; newClient->currentCtx = cr_server.DummyContext; newClient->currentContextNumber = -1; newClient->conn = crNetAcceptClient(cr_server.protocol, NULL, cr_server.tcpip_port, cr_server.mtu, 0); newClient->conn->u32ClientID = u32ClientID; cr_server.clients[cr_server.numClients++] = newClient; crServerAddToRunQueue(newClient); return VINF_SUCCESS; }
/** * Establish a connection with a server. * \param server the server to connect to, in the form * "protocol://servername:port" where the port specifier * is optional and if the protocol is missing it is assumed * to be "tcpip". * \param default_port the port to connect to, if port not specified in the * server URL string. * \param mtu desired maximum transmission unit size (in bytes) */ CRConnection * crNetConnectToServer( const char *server, unsigned short default_port, int mtu) { char hostname[4096], protocol[4096]; unsigned short port; CRConnection *conn; crDebug( "In crNetConnectToServer( \"%s\", port=%d, mtu=%d )", server, default_port, mtu ); CRASSERT( cr_net.initialized ); if (mtu < CR_MINIMUM_MTU) { crError( "You tried to connect to server \"%s\" with an mtu of %d, " "but the minimum MTU is %d", server, mtu, CR_MINIMUM_MTU ); } /* Tear the URL apart into relevant portions. */ if ( !crParseURL( server, protocol, hostname, &port, default_port ) ) { crError( "Malformed URL: \"%s\"", server ); } crDebug( "Connecting to %s on port %d, with protocol %s", hostname, port, protocol ); conn = (CRConnection *) crCalloc( sizeof(*conn) ); if (!conn) return NULL; /* init the non-zero fields */ conn->type = CR_NO_CONNECTION; /* we don't know yet */ conn->recv_credits = CR_INITIAL_RECV_CREDITS; conn->hostname = crStrdup( hostname ); conn->port = port; conn->mtu = mtu; conn->buffer_size = mtu; conn->endianness = crDetermineEndianness(); #ifdef CHROMIUM_THREADSAFE crInitMutex(&conn->messageList.lock); crInitCondition(&conn->messageList.nonEmpty); #endif /* now, just dispatch to the appropriate protocol's initialization functions. */ InitConnection(conn, protocol, mtu); if (!crNetConnect( conn )) { crDebug("crNetConnectToServer() failed, freeing the connection"); crFree( conn ); return NULL; } crDebug( "Done connecting to %s (swapping=%d)", server, conn->swap ); #ifndef NDEBUG crNetDumpConnectionInfo(conn); #endif return conn; }
GLint renderspuWindowCreateEx( const char *dpyName, GLint visBits, GLint id ) { WindowInfo *window; VisualInfo *visual; GLboolean showIt; if (id <= 0) { id = (GLint)crHashtableAllocKeys(render_spu.windowTable, 1); if (id <= 0) { crWarning("failed to allocate window id"); return -1; } } else { if (crHashtableIsKeyUsed(render_spu.windowTable, id)) { crWarning("the specified window key %d is in use", id); return -1; } } if (!dpyName || crStrlen(render_spu.display_string) > 0) dpyName = render_spu.display_string; visual = renderspuFindVisual( dpyName, visBits ); if (!visual) { crWarning( "Render SPU: Couldn't create a window, renderspuFindVisual returned NULL" ); return -1; } /* Allocate WindowInfo */ window = (WindowInfo *) crCalloc(sizeof(WindowInfo)); if (!window) { crWarning( "Render SPU: Couldn't create a window" ); return -1; } crHashtableAdd(render_spu.windowTable, id, window); showIt = 0; /* crDebug("Render SPU: Creating window (visBits=0x%x, id=%d)", visBits, window->BltInfo.Base.id); */ /* Have GLX/WGL/AGL create the window */ if (!renderspuWindowInit( window, visual, showIt, id )) { crFree(window); crWarning( "Render SPU: Couldn't create a window, renderspu_SystemCreateWindow failed" ); return -1; } return window->BltInfo.Base.id; }
static bool crDLMLoadListInstance(PSSMHANDLE pSSM, DLMListInfo *pListInfo, SPUDispatchTable *dispatchTable) { uint32_t cbInstance = 0; DLMInstanceList *pInstance; int32_t rc; /* Get Display List item size. */ rc = SSMR3GetU32(pSSM, &cbInstance); if (RT_SUCCESS(rc)) { /* Allocate memory for the item, initialize it and put into the list. */ pInstance = crCalloc(cbInstance); if (pInstance) { crMemset(pInstance, 0, cbInstance); rc = SSMR3GetMem(pSSM, pInstance, cbInstance); AssertRCReturn(rc, rc); if (RT_SUCCESS(rc)) { pInstance->execute = crDLMGetExecuteRoutine(pInstance->iVBoxOpCode); if (pInstance->execute) { pInstance->execute(pInstance, dispatchTable); pInstance->next = NULL; pInstance->stateNext = NULL; pInstance->cbInstance = cbInstance; pListInfo->numInstances++; if (!pListInfo->first) pListInfo->first = pInstance; if (pListInfo->last) pListInfo->last->next = pInstance; pListInfo->last = pInstance; return true; } else crError("Restoring Display Lists: unknown list item (opcode=%u).", pInstance->iVBoxOpCode); } else crError("Restoring Display Lists: can't read list element size."); } else crError("Restoring Display Lists: not enough memory, aborting."); } else crError("Restoring Display Lists: saved state file might be corrupted."); return false; }
/* * 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 }
static GLint BINARYSWAPSPU_APIENTRY binaryswapspuCreateContext(const char *dpyName, GLint visBits, GLint shareCtx) { static GLint freeID = 0; ContextInfo *context; GLint childVisBits, superVisBits; GLint childShareCtx = 0, superShareCtx = 0; CRASSERT(binaryswap_spu.child.BarrierCreateCR); if (shareCtx > 0) { /* get child/super context IDs */ context = (ContextInfo *) crHashtableSearch(binaryswap_spu.contextTable, shareCtx); if (context) { childShareCtx = context->childContext; superShareCtx = context->renderContext; } } if (freeID != 0) { crError("Binaryswap cannot support multiple contexts"); return 0; } context = (ContextInfo *) crCalloc(sizeof(ContextInfo)); if (!context) { crWarning("binaryswap SPU: create context failed."); return -1; } binaryswapspuTweakVisBits(visBits, &childVisBits, &superVisBits); context->renderContext = binaryswap_spu.super.CreateContext(dpyName, superVisBits, superShareCtx); context->childContext = binaryswap_spu.child.CreateContext(dpyName, childVisBits, childShareCtx); context->childVisBits = childVisBits; context->superVisBits = superVisBits; if (context->renderContext < 0 || context->childContext < 0) { crFree(context); return -1; } /* put into hash table */ crHashtableAdd(binaryswap_spu.contextTable, freeID, context); freeID++; return freeID - 1; }
/** * Accept a connection from a client. * \param protocol the protocol to use (such as "tcpip" or "gm") * \param hostname optional hostname of the expected client (may be NULL) * \param port number of the port to accept on * \param mtu maximum transmission unit * \param broker either 1 or 0 to indicate if connection is brokered through * the mothership * \return new CRConnection object, or NULL */ CRConnection * crNetAcceptClient( const char *protocol, const char *hostname, unsigned short port, unsigned int mtu, int broker ) { CRConnection *conn; CRASSERT( cr_net.initialized ); conn = (CRConnection *) crCalloc( sizeof( *conn ) ); if (!conn) return NULL; /* init the non-zero fields */ conn->type = CR_NO_CONNECTION; /* we don't know yet */ conn->recv_credits = CR_INITIAL_RECV_CREDITS; conn->port = port; conn->mtu = mtu; conn->buffer_size = mtu; conn->broker = broker; conn->endianness = crDetermineEndianness(); conn->teac_id = -1; conn->teac_rank = -1; conn->tcscomm_id = -1; conn->tcscomm_rank = -1; /* now, just dispatch to the appropriate protocol's initialization functions. */ crDebug("In crNetAcceptClient( protocol=\"%s\" port=%d mtu=%d )", protocol, (int) port, (int) mtu); /* special case */ if ( !crStrncmp( protocol, "file", crStrlen( "file" ) ) || !crStrncmp( protocol, "swapfile", crStrlen( "swapfile" ) ) ) { char filename[4096]; char protocol_only[4096]; cr_net.use_file++; if (!crParseURL(protocol, protocol_only, filename, NULL, 0)) { crError( "Malformed URL: \"%s\"", protocol ); } conn->hostname = crStrdup( filename ); /* call the protocol-specific init routines */ // ktd (add) InitConnection(conn, protocol_only, mtu); // ktd (add) } else { /* call the protocol-specific init routines */ InitConnection(conn, protocol, mtu); } crNetAccept( conn, hostname, port ); return conn; }
static ContextInfo * renderspuCreateContextInternal(const char *dpyName, GLint visBits, GLint idCtx, ContextInfo * sharedContext) { ContextInfo *context; VisualInfo *visual; if (idCtx <= 0) { idCtx = (GLint)crHashtableAllocKeys(render_spu.contextTable, 1); if (idCtx <= 0) { crWarning("failed to allocate context id"); return NULL; } } else { if (crHashtableIsKeyUsed(render_spu.contextTable, idCtx)) { crWarning("the specified ctx key %d is in use", idCtx); return NULL; } } if (!dpyName || crStrlen(render_spu.display_string)>0) dpyName = render_spu.display_string; visual = renderspuFindVisual(dpyName, visBits); if (!visual) return NULL; context = (ContextInfo *) crCalloc(sizeof(ContextInfo)); if (!context) return NULL; context->BltInfo.Base.id = idCtx; context->shared = sharedContext; if (!renderspu_SystemCreateContext(visual, context, sharedContext)) return NULL; crHashtableAdd(render_spu.contextTable, idCtx, context); context->BltInfo.Base.visualBits = visual->visAttribs; /* crDebug("Render SPU: CreateContext(%s, 0x%x) returning %d", dpyName, visBits, context->BltInfo.Base.id); */ if (sharedContext) ASMAtomicIncU32(&sharedContext->cRefs); context->cRefs = 1; return context; }
CRPackContext *crPackNewContext(void) { CRPackContext *pc = crCalloc(sizeof(CRPackContext)); if (!pc) return NULL; crInitMutex(&pc->mutex); pc->u32CmdBlockState = 0; pc->Flush = NULL; pc->SendHuge = NULL; pc->updateBBOX = 0; return pc; }
static SPUFunctions * readbackSPUInit( int id, SPU *child, SPU *self, unsigned int context_id, unsigned int num_contexts ) { WindowInfo *window; (void) context_id; (void) num_contexts; #ifdef CHROMIUM_THREADSAFE crDebug("Readback SPU: thread-safe"); #endif crMemZero(&readback_spu, sizeof(readback_spu)); readback_spu.id = id; readback_spu.has_child = 0; if (child) { crSPUInitDispatchTable( &(readback_spu.child) ); crSPUCopyDispatchTable( &(readback_spu.child), &(child->dispatch_table) ); readback_spu.has_child = 1; } else { /* don't override any API functions - use the Render SPU functions */ static SPUNamedFunctionTable empty_table[] = { { NULL, NULL } }; readback_functions.table = empty_table; } crSPUInitDispatchTable( &(readback_spu.super) ); crSPUCopyDispatchTable( &(readback_spu.super), &(self->superSPU->dispatch_table) ); readbackspuGatherConfiguration( &readback_spu ); readback_spu.contextTable = crAllocHashtable(); readback_spu.windowTable = crAllocHashtable(); /* create my default window (window number 0) */ window = (WindowInfo *) crCalloc(sizeof(WindowInfo)); CRASSERT(window); window->index = 0; window->renderWindow = 0; /* default render SPU window */ window->childWindow = 0; /* default child SPU window */ readbackspuTweakVisBits(readback_spu.default_visual, &window->childVisBits, &window->superVisBits); crHashtableAdd(readback_spu.windowTable, 0, window); readback_spu.gather_conn = NULL; return &readback_functions; }
static CRBufferObject *AllocBufferObject(GLuint name) { CRBufferObject *b = crCalloc(sizeof(CRBufferObject)); if (b) { b->refCount = 1; b->id = name; b->hwid = name; b->usage = GL_STATIC_DRAW_ARB; b->access = GL_READ_WRITE_ARB; b->bResyncOnRead = GL_FALSE; } return b; }
PCR_BLITTER renderspuVBoxPresentBlitterGet( WindowInfo *window ) { PCR_BLITTER pBlitter = window->pBlitter; if (!pBlitter) { if (render_spu.blitterTable) { crHashtableLock(render_spu.blitterTable); pBlitter = (PCR_BLITTER)crHashtableSearch(render_spu.blitterTable, window->visual->visAttribs); } if (!pBlitter) { int rc; CR_BLITTER_CONTEXT ctx; pBlitter = (PCR_BLITTER)crCalloc(sizeof (*pBlitter)); if (!pBlitter) { crWarning("failed to allocate blitter"); return NULL; } /* @todo: this is the assumption that crserverlib uses context 1 as a default one * need to do it in a more proper way */ ctx.Base.id = 1; ctx.Base.visualBits = window->visual->visAttribs; rc = CrBltInit(pBlitter, &ctx, true, true, render_spu.blitterDispatch); if (!RT_SUCCESS(rc)) { crWarning("CrBltInit failed, rc %d", rc); crFree(pBlitter); return NULL; } if (render_spu.blitterTable) { crHashtableAdd( render_spu.blitterTable, window->visual->visAttribs, pBlitter ); } } if (render_spu.blitterTable) crHashtableUnlock(render_spu.blitterTable); Assert(pBlitter); window->pBlitter = pBlitter; } CrBltMuralSetCurrent(pBlitter, &window->BltInfo); return pBlitter; }
/** * Create a new _Chromium_ window, not GLX, WGL or CGL. * Called by crWindowCreate() only. */ GLint stubNewWindow( const char *dpyName, GLint visBits ) { WindowInfo *winInfo; GLint spuWin, size[2]; spuWin = stub.spu->dispatch_table.WindowCreate( dpyName, visBits ); if (spuWin < 0) { return -1; } winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo)); if (!winInfo) { stub.spu->dispatch_table.WindowDestroy(spuWin); return -1; } winInfo->type = CHROMIUM; /* Ask the head SPU for the initial window size */ size[0] = size[1] = 0; stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, size); if (size[0] == 0 && size[1] == 0) { /* use some reasonable defaults */ size[0] = size[1] = 512; } winInfo->width = size[0]; winInfo->height = size[1]; winInfo->mapped = 1; if (!dpyName) dpyName = ""; crStrncpy(winInfo->dpyName, dpyName, MAX_DPY_NAME); winInfo->dpyName[MAX_DPY_NAME-1] = 0; /* Use spuWin as the hash table index and GLX/WGL handle */ #ifdef WINDOWS winInfo->drawable = (HDC) spuWin; #elif defined(Darwin) winInfo->drawable = (CGSWindowID) spuWin; #elif defined(GLX) winInfo->drawable = (GLXDrawable) spuWin; #endif winInfo->spuWindow = spuWin; crHashtableAdd(stub.windowTable, (unsigned int) spuWin, winInfo); return spuWin; }
void crStateClientInitBits (CRClientBits *c) { int i; /* XXX why GLCLIENT_BIT_ALLOC? */ c->v = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); c->n = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); c->c = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); c->s = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); c->i = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); for ( i = 0; i < CR_MAX_TEXTURE_UNITS; i++ ) c->t[i] = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); c->e = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); c->f = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); #ifdef CR_NV_vertex_program for ( i = 0; i < CR_MAX_VERTEX_ATTRIBS; i++ ) c->a[i] = (CRbitvalue *) crCalloc(GLCLIENT_BIT_ALLOC*sizeof(CRbitvalue)); #endif }
/** * Allocate a new shared state object. * Contains texture objects, display lists, etc. */ static CRSharedState * crStateAllocShared(void) { CRSharedState *s = (CRSharedState *) crCalloc(sizeof(CRSharedState)); if (s) { s->textureTable = crAllocHashtable(); s->dlistTable = crAllocHashtable(); s->buffersTable = crAllocHashtable(); s->fbTable = crAllocHashtable(); s->rbTable = crAllocHashtable(); s->refCount = 1; /* refcount is number of contexts using this state */ s->saveCount = 0; } return s; }
CRHashTable *crAllocHashtable( void ) { int i; CRHashTable *hash = (CRHashTable *) crCalloc( sizeof( CRHashTable )) ; hash->num_elements = 0; for (i = 0 ; i < CR_NUM_BUCKETS ; i++) { hash->buckets[i] = NULL; } hash->idPool = crAllocHashIdPool(); #ifdef CHROMIUM_THREADSAFE crInitMutex(&hash->mutex); #endif return hash; }
void DLM_APIENTRY crDLMCompileCallList( GLuint list ) { struct instanceCallList *instance; instance = crCalloc(sizeof(struct instanceCallList)); if (!instance) { crdlm_error(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "out of memory adding CallList to display list"); return; } /* Put in the parameters */ instance->list = list; /* Add to the display list correctly */ crdlm_add_to_list((DLMInstanceList *)instance, executeCallList); }
/** * Allocate a new ContextInfo object, initialize it, put it into the * context hash table. If type==CHROMIUM, call the head SPU's * CreateContext() function too. */ ContextInfo * stubNewContext( const char *dpyName, GLint visBits, ContextType type, unsigned long shareCtx ) { GLint spuContext = -1, spuShareCtx = 0; ContextInfo *context; if (shareCtx > 0) { /* translate shareCtx to a SPU context ID */ context = (ContextInfo *) crHashtableSearch(stub.contextTable, shareCtx); if (context) spuShareCtx = context->spuContext; } if (type == CHROMIUM) { spuContext = stub.spu->dispatch_table.CreateContext(dpyName, visBits, spuShareCtx); if (spuContext < 0) return NULL; } context = crCalloc(sizeof(ContextInfo)); if (!context) { stub.spu->dispatch_table.DestroyContext(spuContext); return NULL; } if (!dpyName) dpyName = ""; context->id = stub.freeContextNumber++; context->type = type; context->spuContext = spuContext; context->visBits = visBits; context->currentDrawable = NULL; crStrncpy(context->dpyName, dpyName, MAX_DPY_NAME); context->dpyName[MAX_DPY_NAME-1] = 0; #if defined(GLX) || defined(DARWIN) context->share = (ContextInfo *) crHashtableSearch(stub.contextTable, (unsigned long) shareCtx); #endif crHashtableAdd(stub.contextTable, context->id, (void *) context); return context; }
static GLint BINARYSWAPSPU_APIENTRY binaryswapspuWindowCreate(const char *dpyName, GLint visBits) { WindowInfo *window; static GLint freeID = 1; /* skip default window 0 */ GLint childVisBits, superVisBits; /* Error out on second window */ if (freeID != 1) { crError("Binaryswap can't deal with multiple windows!"); return 0; } /* allocate window */ window = (WindowInfo *) crCalloc(sizeof(WindowInfo)); if (!window) { crWarning("binaryswap SPU: unable to allocate window."); return -1; } binaryswapspuTweakVisBits(visBits, &childVisBits, &superVisBits); /* init window */ window->index = freeID; window->renderWindow = binaryswap_spu.super.WindowCreate(dpyName, superVisBits); window->childWindow = binaryswap_spu.child.WindowCreate(dpyName, childVisBits); window->width = -1; /* unknown */ window->height = -1; /* unknown */ window->msgBuffer = NULL; window->childVisBits = childVisBits; window->superVisBits = superVisBits; if (window->renderWindow < 0 || window->childWindow < 0) { crFree(window); return -1; } /* put into hash table */ crHashtableAdd(binaryswap_spu.windowTable, window->index, window); freeID++; return freeID - 1; }
void crHashtableAdd( CRHashTable *h, unsigned long key, void *data ) { CRHashNode *node = (CRHashNode *) crCalloc( sizeof( CRHashNode ) ); #ifdef CHROMIUM_THREADSAFE crLockMutex(&h->mutex); #endif node->key = key; node->data = data; node->next = h->buckets[crHash( key )]; h->buckets[ crHash( key ) ] = node; h->num_elements++; crHashIdPoolAllocId (h->idPool, key); #ifdef CHROMIUM_THREADSAFE crUnlockMutex(&h->mutex); #endif }
void vboxCrFpsInit(PVBOXCRFPS pFps, uint32_t cPeriods) { crMemset(pFps, 0, sizeof (*pFps)); pFps->mcPeriods = cPeriods; pFps->mpaPeriods = crCalloc(sizeof (pFps->mpaPeriods[0]) * cPeriods); pFps->mpaBytes = crCalloc(sizeof (pFps->mpaBytes[0]) * cPeriods); pFps->mpaBytesSent = crCalloc(sizeof (pFps->mpaBytesSent[0]) * cPeriods); pFps->mpaCalls = crCalloc(sizeof (pFps->mpaCalls[0]) * cPeriods); pFps->mpaOps = crCalloc(sizeof (pFps->mpaOps[0]) * cPeriods); pFps->mpaTimes = crCalloc(sizeof (pFps->mpaTimes[0]) * cPeriods); }
/** * Accept a new client connection, create a new CRClient and add to run queue. */ void crServerAddNewClient(void) { CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient)); if (newClient) { newClient->spu_id = cr_server.client_spu_id; newClient->conn = crNetAcceptClient( cr_server.protocol, NULL, cr_server.tcpip_port, cr_server.mtu, 1 ); newClient->currentCtx = cr_server.DummyContext; /* add to array */ cr_server.clients[cr_server.numClients++] = newClient; crServerAddToRunQueue( newClient ); } }
/** * Accept a new client connection, create a new CRClient and add to run queue. */ void glStubAddNewClient(void) { CRClient *newClient = (CRClient *) crCalloc(sizeof(CRClient)); if (newClient) { newClient->spu_id = cr_server.client_spu_id; newClient->conn = crNetAcceptClient( cr_server.protocol, NULL, cr_server.tcpip_port, cr_server.mtu ); /* This used to be brokered, unknown. Andres */ newClient->currentCtx = cr_server.DummyContext; /* add to array */ cr_server.clients[cr_server.numClients++] = newClient; glStubAddToRunQueue( newClient ); } }
void DLM_APIENTRY crDLMCompileCallLists( GLsizei n, GLenum type, const GLvoid * lists ) { struct instanceCallLists *instance; instance = crCalloc(sizeof(struct instanceCallLists) + crdlm_pointers_CallLists(NULL, n, type, lists)); if (!instance) { crdlm_error(__LINE__, __FILE__, GL_OUT_OF_MEMORY, "out of memory adding CallLists to display list"); return; } instance->n = n; instance->type = type; if (lists == NULL) { instance->lists = NULL; } else { instance->lists = instance->listsData; } (void) crdlm_pointers_CallLists(instance, n, type, lists); crdlm_add_to_list((DLMInstanceList *)instance, executeCallLists); }
/* * 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; if (defaultContext) { /* Free the default/NULL context. * Ensures context bits are reset */ crStateFreeContext(defaultContext); #ifdef CHROMIUM_THREADSAFE crSetTSD(&__contextTSD, NULL); #else __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 crSetTSD(&__contextTSD, defaultContext); #else __currentContext = defaultContext; #endif }
/* * Mark the given Id as being allocated. */ static GLboolean crHashIdPoolAllocId( CRHashIdPool *pool, GLuint id ) { FreeElem *f; f = pool->freeList; while (f) { if (id >= f->min && id <= f->max) { /* found the block */ if (id == f->min) { f->min++; } else if (id == f->max) { f->max--; } else { /* somewhere in the middle - split the block */ FreeElem *newelem = (FreeElem *) crCalloc(sizeof(FreeElem)); newelem->min = id + 1; newelem->max = f->max; f->max = id - 1; newelem->next = f->next; if (f->next) f->next->prev = newelem; newelem->prev = f; f->next = newelem; } return GL_TRUE; } f = f->next; } /* if we get here, the ID was already allocated - that's OK */ return GL_FALSE; }
stubGetWindowInfo( Display *dpy, GLXDrawable drawable ) #endif { WindowInfo *winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) drawable); if (!winInfo) { winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo)); if (!winInfo) return NULL; #ifdef GLX crStrncpy(winInfo->dpyName, DisplayString(dpy), MAX_DPY_NAME); winInfo->dpyName[MAX_DPY_NAME-1] = 0; winInfo->dpy = dpy; #elif defined(Darwin) winInfo->connection = _CGSDefaultConnection(); // store our connection as default #endif winInfo->drawable = drawable; winInfo->type = UNDECIDED; winInfo->spuWindow = -1; winInfo->mapped = -1; /* don't know */ crHashtableAdd(stub.windowTable, (unsigned int) drawable, winInfo); } return winInfo; }
DECLEXPORT(HGLRC) WINAPI VBoxCreateContext( HDC hdc, struct VBOXUHGSMI *pHgsmi ) { char *dpyName; ContextInfo *context; CR_DDI_PROLOGUE(); stubInit(); CRASSERT(stub.contextTable); dpyName = crCalloc(MAX_DPY_NAME); if (dpyName) { crMemset(dpyName, 0, MAX_DPY_NAME); sprintf(dpyName, "%p", hdc); } #ifndef VBOX_CROGL_USE_VBITS_SUPERSET if (stub.haveNativeOpenGL) desiredVisual |= ComputeVisBits( hdc ); #endif context = stubNewContext(dpyName, desiredVisual, UNDECIDED, 0 #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) , pHgsmi #else , NULL #endif ); /* Not needed any more. */ crFree(dpyName); if (!context) return 0; return (HGLRC) context->id; }
static CRRenderbufferObject * crStateRenderbufferAllocate(CRContext *ctx, GLuint name) { CRRenderbufferObject *buffer = (CRRenderbufferObject*) crCalloc(sizeof(CRRenderbufferObject)); CRSTATE_CHECKERR_RET(!buffer, GL_OUT_OF_MEMORY, "crStateRenderbufferAllocate", NULL); buffer->id = name; #ifndef IN_GUEST diff_api.GenRenderbuffersEXT(1, &buffer->hwid); if (!buffer->hwid) { crWarning("GenRenderbuffersEXT failed!"); crFree(buffer); return NULL; } #else buffer->hwid = name; #endif buffer->internalformat = GL_RGBA; crHashtableAdd(ctx->shared->rbTable, name, buffer); CR_STATE_SHAREDOBJ_USAGE_INIT(buffer); return buffer; }