RTDECL(int) RTEnvSetEx(RTENV Env, const char *pszVar, const char *pszValue) { AssertPtrReturn(pszVar, VERR_INVALID_POINTER); AssertReturn(*pszVar, VERR_INVALID_PARAMETER); AssertPtrReturn(pszValue, VERR_INVALID_POINTER); AssertReturn(strchr(pszVar, '=') == NULL, VERR_ENV_INVALID_VAR_NAME); int rc; if (Env == RTENV_DEFAULT) { #ifdef RT_OS_WINDOWS rc = RTEnvSetUtf8(pszVar, pszValue); #else /* * Since RTEnvPut isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary * conversions here. */ char *pszVarOtherCP; rc = RTStrUtf8ToCurrentCP(&pszVarOtherCP, pszVar); if (RT_SUCCESS(rc)) { char *pszValueOtherCP; rc = RTStrUtf8ToCurrentCP(&pszValueOtherCP, pszValue); if (RT_SUCCESS(rc)) { rc = RTEnvSet(pszVarOtherCP, pszValueOtherCP); RTStrFree(pszValueOtherCP); } RTStrFree(pszVarOtherCP); } #endif } else { PRTENVINTERNAL pIntEnv = Env; AssertPtrReturn(pIntEnv, VERR_INVALID_HANDLE); AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, VERR_INVALID_HANDLE); /* * Create the variable string. */ const size_t cchVar = strlen(pszVar); const size_t cchValue = strlen(pszValue); char *pszEntry = (char *)RTMemAlloc(cchVar + cchValue + 2); if (pszEntry) { memcpy(pszEntry, pszVar, cchVar); pszEntry[cchVar] = '='; memcpy(&pszEntry[cchVar + 1], pszValue, cchValue + 1); RTENV_LOCK(pIntEnv); /* * Find the location of the variable. (iVar = cVars if new) */ rc = VINF_SUCCESS; size_t iVar; for (iVar = 0; iVar < pIntEnv->cVars; iVar++) if ( !pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar) && ( pIntEnv->papszEnv[iVar][cchVar] == '=' || pIntEnv->papszEnv[iVar][cchVar] == '\0') ) break; if (iVar < pIntEnv->cVars) { /* * Replace the current entry. Simple. */ RTMemFree(pIntEnv->papszEnv[iVar]); pIntEnv->papszEnv[iVar] = pszEntry; } else { /* * New variable, append it. */ Assert(pIntEnv->cVars == iVar); rc = rtEnvIntAppend(pIntEnv, pszEntry); } RTENV_UNLOCK(pIntEnv); if (RT_FAILURE(rc)) RTMemFree(pszEntry); } else rc = VERR_NO_MEMORY; } return rc; }
int main(int argc, char **argv) { int rc; RTR3InitExe(argc, &argv, 0); for (int i = 1; i < argc; i++) { #ifdef VBOX_OPENGL if (strcmp(argv[i], "-gl") == 0) { gfOpenGL = 1; continue; } #endif if (strcmp(argv[i], "-loop") == 0 && ++i < argc) { guLoop = atoi(argv[i]); continue; } RTPrintf("Unrecognized option '%s'\n", argv[i]); return -1; } #ifdef RT_OS_WINDOWS /* Default to DirectX if nothing else set. "windib" would be possible. */ if (!RTEnvExist("SDL_VIDEODRIVER")) { _putenv("SDL_VIDEODRIVER=directx"); } #endif #ifdef RT_OS_WINDOWS _putenv("SDL_VIDEO_WINDOW_POS=0,0"); #else RTEnvSet("SDL_VIDEO_WINDOW_POS", "0,0"); #endif rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); if (rc != 0) { RTPrintf("Error: SDL_InitSubSystem failed with message '%s'\n", SDL_GetError()); return -1; } /* output what SDL is capable of */ const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); if (!videoInfo) { RTPrintf("No SDL video info available!\n"); return -1; } RTPrintf("SDL capabilities:\n"); RTPrintf(" Hardware surface support: %s\n", videoInfo->hw_available ? "yes" : "no"); RTPrintf(" Window manager available: %s\n", videoInfo->wm_available ? "yes" : "no"); RTPrintf(" Screen to screen blits accelerated: %s\n", videoInfo->blit_hw ? "yes" : "no"); RTPrintf(" Screen to screen colorkey blits accelerated: %s\n", videoInfo->blit_hw_CC ? "yes" : "no"); RTPrintf(" Screen to screen alpha blits accelerated: %s\n", videoInfo->blit_hw_A ? "yes" : "no"); RTPrintf(" Memory to screen blits accelerated: %s\n", videoInfo->blit_sw ? "yes" : "no"); RTPrintf(" Memory to screen colorkey blits accelerated: %s\n", videoInfo->blit_sw_CC ? "yes" : "no"); RTPrintf(" Memory to screen alpha blits accelerated: %s\n", videoInfo->blit_sw_A ? "yes" : "no"); RTPrintf(" Color fills accelerated: %s\n", videoInfo->blit_fill ? "yes" : "no"); RTPrintf(" Video memory in kilobytes: %d\n", videoInfo->video_mem); RTPrintf(" Optimal bpp mode: %d\n", videoInfo->vfmt->BitsPerPixel); char buf[256]; RTPrintf("Video driver SDL_VIDEODRIVER / active: %s/%s\n", RTEnvGet("SDL_VIDEODRIVER"), SDL_VideoDriverName(buf, sizeof(buf))); RTPrintf("\n" "Starting tests. Any key pressed inside the SDL window will abort this\n" "program at the end of the current test. Iterations = %u\n", guLoop); #ifdef VBOX_OPENGL RTPrintf("\n========== "ESC_BOLD"OpenGL is %s"ESC_NORM" ==========\n", gfOpenGL ? "ON" : "OFF"); #endif bench( 640, 480, 16); bench( 640, 480, 24); bench( 640, 480, 32); bench(1024, 768, 16); bench(1024, 768, 24); bench(1024, 768, 32); bench(1280, 1024, 16); bench(1280, 1024, 24); bench(1280, 1024, 32); RTPrintf("\nSuccess!\n"); return 0; }
RTDECL(int) RTEnvSetEx(RTENV Env, const char *pszVar, const char *pszValue) { AssertPtrReturn(pszVar, VERR_INVALID_POINTER); AssertReturn(*pszVar, VERR_INVALID_PARAMETER); AssertPtrReturn(pszValue, VERR_INVALID_POINTER); int rc; if (Env == RTENV_DEFAULT) { /* * Since RTEnvPut isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary * conversions here. */ char *pszVarOtherCP; rc = RTStrUtf8ToCurrentCP(&pszVarOtherCP, pszVar); if (RT_SUCCESS(rc)) { char *pszValueOtherCP; rc = RTStrUtf8ToCurrentCP(&pszValueOtherCP, pszValue); if (RT_SUCCESS(rc)) { rc = RTEnvSet(pszVarOtherCP, pszValueOtherCP); RTStrFree(pszValueOtherCP); } RTStrFree(pszVarOtherCP); } } else { PRTENVINTERNAL pIntEnv = Env; AssertPtrReturn(pIntEnv, VERR_INVALID_HANDLE); AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, VERR_INVALID_HANDLE); /* * Create the variable string. */ const size_t cchVar = strlen(pszVar); const size_t cchValue = strlen(pszValue); char *pszEntry = (char *)RTMemAlloc(cchVar + cchValue + 2); if (pszEntry) { memcpy(pszEntry, pszVar, cchVar); pszEntry[cchVar] = '='; memcpy(&pszEntry[cchVar + 1], pszValue, cchValue + 1); RTENV_LOCK(pIntEnv); /* * Find the location of the variable. (iVar = cVars if new) */ rc = VINF_SUCCESS; size_t iVar; for (iVar = 0; iVar < pIntEnv->cVars; iVar++) if ( !strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar) && pIntEnv->papszEnv[iVar][cchVar] == '=') break; if (iVar < pIntEnv->cVars) { /* * Replace the current entry. Simple. */ RTMemFree(pIntEnv->papszEnv[iVar]); pIntEnv->papszEnv[iVar] = pszEntry; } else { /* * Adding a new variable. Resize the array if required * and then insert the new value at the end. */ if (pIntEnv->cVars + 2 > pIntEnv->cAllocated) { void *pvNew = RTMemRealloc(pIntEnv->papszEnv, sizeof(char *) * (pIntEnv->cAllocated + RTENV_GROW_SIZE)); if (!pvNew) rc = VERR_NO_MEMORY; else { pIntEnv->papszEnv = (char **)pvNew; pIntEnv->cAllocated += RTENV_GROW_SIZE; for (size_t iNewVar = pIntEnv->cVars; iNewVar < pIntEnv->cAllocated; iNewVar++) pIntEnv->papszEnv[iNewVar] = NULL; } } if (RT_SUCCESS(rc)) { pIntEnv->papszEnv[iVar] = pszEntry; pIntEnv->papszEnv[iVar + 1] = NULL; /* this isn't really necessary, but doesn't hurt. */ pIntEnv->cVars++; Assert(pIntEnv->cVars == iVar + 1); } } RTENV_UNLOCK(pIntEnv); if (RT_FAILURE(rc)) RTMemFree(pszEntry); } else rc = VERR_NO_MEMORY; } return rc; }
/** * VBoxSUPSvc main(), Windows edition. * * * @returns 0 on success. * * @param argc Number of arguments in argv. * @param argv Argument vector. */ int main(int argc, char **argv) { /* * Initialize the IPRT first of all. */ #ifdef DEBUG_bird RTEnvSet("VBOX_LOG", "sup=~0"); RTEnvSet("VBOX_LOG_DEST", "file=E:\\temp\\VBoxSupSvc.log"); RTEnvSet("VBOX_LOG_FLAGS", "unbuffered thread msprog"); #endif int rc = RTR3InitExe(argc, &argv, 0); if (RT_FAILURE(rc)) { supSvcLogError("RTR3InitExe failed with rc=%Rrc", rc); return 1; } /* * Parse the initial arguments to determine the desired action. */ enum { kSupSvcAction_RunIt, kSupSvcAction_Create, kSupSvcAction_Delete, kSupSvcAction_Enable, kSupSvcAction_Disable, kSupSvcAction_QueryConfig, kSupSvcAction_QueryDescription, kSupSvcAction_Start, kSupSvcAction_Pause, kSupSvcAction_Continue, kSupSvcAction_Stop, kSupSvcAction_Interrogate, kSupSvcAction_End } enmAction = kSupSvcAction_RunIt; int iArg = 1; if (argc > 1) { if ( !stricmp(argv[iArg], "/RegServer") || !stricmp(argv[iArg], "install") || !stricmp(argv[iArg], "/i")) enmAction = kSupSvcAction_Create; else if ( !stricmp(argv[iArg], "/UnregServer") || !stricmp(argv[iArg], "/u") || !stricmp(argv[iArg], "uninstall") || !stricmp(argv[iArg], "delete")) enmAction = kSupSvcAction_Delete; else if (!stricmp(argv[iArg], "enable")) enmAction = kSupSvcAction_Enable; else if (!stricmp(argv[iArg], "disable")) enmAction = kSupSvcAction_Disable; else if (!stricmp(argv[iArg], "qconfig")) enmAction = kSupSvcAction_QueryConfig; else if (!stricmp(argv[iArg], "qdescription")) enmAction = kSupSvcAction_QueryDescription; else if ( !stricmp(argv[iArg], "start") || !stricmp(argv[iArg], "/t")) enmAction = kSupSvcAction_Start; else if (!stricmp(argv[iArg], "pause")) enmAction = kSupSvcAction_Start; else if (!stricmp(argv[iArg], "continue")) enmAction = kSupSvcAction_Continue; else if (!stricmp(argv[iArg], "stop")) enmAction = kSupSvcAction_Stop; else if (!stricmp(argv[iArg], "interrogate")) enmAction = kSupSvcAction_Interrogate; else if ( !stricmp(argv[iArg], "help") || !stricmp(argv[iArg], "?") || !stricmp(argv[iArg], "/?") || !stricmp(argv[iArg], "-?") || !stricmp(argv[iArg], "/h") || !stricmp(argv[iArg], "-h") || !stricmp(argv[iArg], "/help") || !stricmp(argv[iArg], "-help") || !stricmp(argv[iArg], "--help")) return supSvcWinShowHelp(); else if ( !stricmp(argv[iArg], "version") || !stricmp(argv[iArg], "/v") || !stricmp(argv[iArg], "-v") || !stricmp(argv[iArg], "/version") || !stricmp(argv[iArg], "-version") || !stricmp(argv[iArg], "--version")) return supSvcWinShowVersion(argc - iArg - 1, argv + iArg + 1); else iArg--; iArg++; } /* * Dispatch it. */ switch (enmAction) { case kSupSvcAction_RunIt: return supSvcWinRunIt(argc - iArg, argv + iArg); case kSupSvcAction_Create: return supSvcWinCreate(argc - iArg, argv + iArg); case kSupSvcAction_Delete: return supSvcWinDelete(argc - iArg, argv + iArg); case kSupSvcAction_Enable: return supSvcWinEnable(argc - iArg, argv + iArg); case kSupSvcAction_Disable: return supSvcWinDisable(argc - iArg, argv + iArg); case kSupSvcAction_QueryConfig: return supSvcWinQueryConfig(argc - iArg, argv + iArg); case kSupSvcAction_QueryDescription: return supSvcWinQueryDescription(argc - iArg, argv + iArg); case kSupSvcAction_Start: return supSvcWinStart(argc - iArg, argv + iArg); case kSupSvcAction_Pause: return supSvcWinPause(argc - iArg, argv + iArg); case kSupSvcAction_Continue: return supSvcWinContinue(argc - iArg, argv + iArg); case kSupSvcAction_Stop: return supSvcWinStop(argc - iArg, argv + iArg); case kSupSvcAction_Interrogate: return supSvcWinInterrogate(argc - iArg, argv + iArg); default: AssertMsgFailed(("enmAction=%d\n", enmAction)); return 1; } }
DECLEXPORT(int) WINAPI wglChoosePixelFormat_prox( HDC hdc, CONST PIXELFORMATDESCRIPTOR *pfd ) { DWORD okayFlags; CR_DDI_PROLOGUE(); stubInit(); /* * NOTE!!! * Here we're telling the renderspu not to use the GDI * equivalent's of ChoosePixelFormat/DescribePixelFormat etc * There are subtle differences in the use of these calls. */ RTEnvSet("CR_WGL_DO_NOT_USE_GDI", "yes"); if ( pfd->nSize != sizeof(*pfd) || pfd->nVersion != 1 ) { crError( "wglChoosePixelFormat: bad pfd\n" ); return 0; } okayFlags = ( PFD_DRAW_TO_WINDOW | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DOUBLEBUFFER_DONTCARE | PFD_SWAP_EXCHANGE | PFD_SWAP_COPY | /** @todo this is disabled due to VSG Open Inventor interop issues * it does not make any sense actually since reporting this * as well as choosing a pixel format with this cap would not do anything * since ICD stuff has its own pixelformat state var */ // PFD_STEREO | PFD_STEREO_DONTCARE | PFD_DEPTH_DONTCARE ); if ( pfd->dwFlags & ~okayFlags ) { crWarning( "wglChoosePixelFormat: only support flags=0x%x, but you gave me flags=0x%x", okayFlags, pfd->dwFlags ); return 0; } if ( pfd->iPixelType != PFD_TYPE_RGBA ) { crError( "wglChoosePixelFormat: only support RGBA\n" ); } if ( pfd->cColorBits > 32 || pfd->cRedBits > 8 || pfd->cGreenBits > 8 || pfd->cBlueBits > 8 || pfd->cAlphaBits > 8 ) { crWarning( "wglChoosePixelFormat: too much color precision requested\n" ); } if ( pfd->dwFlags & PFD_DOUBLEBUFFER ) desiredVisual |= CR_DOUBLE_BIT; if ( pfd->dwFlags & PFD_STEREO ) desiredVisual |= CR_STEREO_BIT; if ( pfd->cColorBits > 8) desiredVisual |= CR_RGB_BIT; if ( pfd->cAccumBits > 0 || pfd->cAccumRedBits > 0 || pfd->cAccumGreenBits > 0 || pfd->cAccumBlueBits > 0 || pfd->cAccumAlphaBits > 0 ) { crWarning( "wglChoosePixelFormat: asked for accumulation buffer, ignoring\n" ); } if ( pfd->cAccumBits > 0 ) desiredVisual |= CR_ACCUM_BIT; if ( pfd->cDepthBits > 32 ) { crError( "wglChoosePixelFormat; asked for too many depth bits\n" ); } if ( pfd->cDepthBits > 0 ) desiredVisual |= CR_DEPTH_BIT; if ( pfd->cStencilBits > 8 ) { crError( "wglChoosePixelFormat: asked for too many stencil bits\n" ); } if ( pfd->cStencilBits > 0 ) desiredVisual |= CR_STENCIL_BIT; if ( pfd->cAuxBuffers > 0 ) { crError( "wglChoosePixelFormat: asked for aux buffers\n" ); } if ( pfd->iLayerType != PFD_MAIN_PLANE ) { crError( "wglChoosePixelFormat: asked for a strange layer\n" ); } return 1; }