boolean debug_get_bool_option(const char *name, boolean dfault) { const char *str = os_get_option(name); boolean result; if(str == NULL) result = dfault; else if(!util_strcmp(str, "n")) result = FALSE; else if(!util_strcmp(str, "no")) result = FALSE; else if(!util_strcmp(str, "0")) result = FALSE; else if(!util_strcmp(str, "f")) result = FALSE; else if(!util_strcmp(str, "F")) result = FALSE; else if(!util_strcmp(str, "false")) result = FALSE; else if(!util_strcmp(str, "FALSE")) result = FALSE; else result = TRUE; if (debug_get_option_should_print()) debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE"); return result; }
long debug_get_num_option(const char *name, long dfault) { long result; const char *str; str = os_get_option(name); if(!str) result = dfault; else { long sign; char c; c = *str++; if(c == '-') { sign = -1; c = *str++; } else { sign = 1; } result = 0; while('0' <= c && c <= '9') { result = result*10 + (c - '0'); c = *str++; } result *= sign; } if (debug_get_option_should_print()) debug_printf("%s: %s = %li\n", __FUNCTION__, name, result); return result; }
void os_log_message(const char *message) { /* If the GALLIUM_LOG_FILE environment variable is set to a valid filename, * write all messages to that file. */ static FILE *fout = NULL; if (!fout) { /* one-time init */ const char *filename = os_get_option("GALLIUM_LOG_FILE"); if (filename) fout = fopen(filename, "w"); if (!fout) fout = stderr; } #if defined(PIPE_SUBSYSTEM_WINDOWS_USER) OutputDebugStringA(message); if(GetConsoleWindow() && !IsDebuggerPresent()) { fflush(stdout); fputs(message, fout); fflush(fout); } else if (fout != stderr) { fputs(message, fout); fflush(fout); } #else /* !PIPE_SUBSYSTEM_WINDOWS */ fflush(stdout); fputs(message, fout); fflush(fout); #endif }
/** * Return the name of the current process. * \param procname returns the process name * \param size size of the procname buffer * \return TRUE or FALSE for success, failure */ boolean os_get_process_name(char *procname, size_t size) { const char *name; /* First, check if the GALLIUM_PROCESS_NAME env var is set to * override the normal process name query. */ name = os_get_option("GALLIUM_PROCESS_NAME"); if (!name) { /* do normal query */ #if defined(PIPE_SUBSYSTEM_WINDOWS_USER) char szProcessPath[MAX_PATH]; char *lpProcessName; char *lpProcessExt; GetModuleFileNameA(NULL, szProcessPath, Elements(szProcessPath)); lpProcessName = strrchr(szProcessPath, '\\'); lpProcessName = lpProcessName ? lpProcessName + 1 : szProcessPath; lpProcessExt = strrchr(lpProcessName, '.'); if (lpProcessExt) { *lpProcessExt = '\0'; } name = lpProcessName; #elif defined(__GLIBC__) || defined(__CYGWIN__) name = program_invocation_short_name; #elif defined(PIPE_OS_BSD) || defined(PIPE_OS_APPLE) /* *BSD and OS X */ name = getprogname(); #elif defined(PIPE_OS_HAIKU) image_info info; get_image_info(B_CURRENT_TEAM, &info); name = info.name; #else #warning unexpected platform in os_process.c return FALSE; #endif } assert(size > 0); assert(procname); if (name && procname && size > 0) { strncpy(procname, name, size); procname[size - 1] = '\0'; return TRUE; } else { return FALSE; } }
const char * debug_get_option(const char *name, const char *dfault) { const char *result; result = os_get_option(name); if(!result) result = dfault; debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)"); return result; }
uint64_t debug_get_flags_option(const char *name, const struct debug_named_value *flags, uint64_t dfault) { uint64_t result; const char *str; const struct debug_named_value *orig = flags; unsigned namealign = 0; str = os_get_option(name); if (!str) result = dfault; else if (!util_strcmp(str, "help")) { result = dfault; _debug_printf("%s: help for %s:\n", __FUNCTION__, name); for (; flags->name; ++flags) namealign = MAX2(namealign, strlen(flags->name)); for (flags = orig; flags->name; ++flags) _debug_printf("| %*s [0x%0*"PRIx64"]%s%s\n", namealign, flags->name, (int)sizeof(uint64_t)*CHAR_BIT/4, flags->value, flags->desc ? " " : "", flags->desc ? flags->desc : ""); } else { result = 0; while (flags->name) { if (str_has_option(str, flags->name)) result |= flags->value; ++flags; } } if (debug_get_option_should_print()) { if (str) { debug_printf("%s: %s = 0x%"PRIx64" (%s)\n", __FUNCTION__, name, result, str); } else { debug_printf("%s: %s = 0x%"PRIx64"\n", __FUNCTION__, name, result); } } return result; }
unsigned long debug_get_flags_option(const char *name, const struct debug_named_value *flags, unsigned long dfault) { unsigned long result; const char *str; str = os_get_option(name); if(!str) result = dfault; else if (!util_strcmp(str, "help")) { result = dfault; while (flags->name) { debug_printf("%s: help for %s: %s [0x%lx]\n", __FUNCTION__, name, flags->name, flags->value); flags++; } } else { result = 0; while( flags->name ) { if (!util_strcmp(str, "all") || util_strstr(str, flags->name )) result |= flags->value; ++flags; } } if (str) { debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__, name, result, str); } else { debug_printf("%s: %s = 0x%lx\n", __FUNCTION__, name, result); } return result; }
long debug_get_num_option(const char *name, long dfault) { long result; const char *str; str = os_get_option(name); if (!str) { result = dfault; } else { char *endptr; result = strtol(str, &endptr, 0); if (str == endptr) { /* Restore the default value when no digits were found. */ result = dfault; } } if (debug_get_option_should_print()) debug_printf("%s: %s = %li\n", __FUNCTION__, name, result); return result; }
boolean stw_init(const struct stw_winsys *stw_winsys) { static struct stw_device stw_dev_storage; struct pipe_screen *screen; debug_disable_error_message_boxes(); debug_printf("%s\n", __FUNCTION__); assert(!stw_dev); stw_tls_init(); stw_dev = &stw_dev_storage; memset(stw_dev, 0, sizeof(*stw_dev)); #ifdef DEBUG stw_dev->memdbg_no = debug_memory_begin(); #endif stw_dev->stw_winsys = stw_winsys; stw_dev->stapi = stw_st_create_api(); stw_dev->smapi = CALLOC_STRUCT(st_manager); if (!stw_dev->stapi || !stw_dev->smapi) goto error1; screen = stw_winsys->create_screen(); if (!screen) goto error1; if (stw_winsys->get_adapter_luid) stw_winsys->get_adapter_luid(screen, &stw_dev->AdapterLuid); stw_dev->smapi->screen = screen; stw_dev->smapi->get_param = stw_get_param; stw_dev->screen = screen; stw_dev->max_2d_levels = screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); stw_dev->max_2d_length = 1 << (stw_dev->max_2d_levels - 1); InitializeCriticalSection(&stw_dev->ctx_mutex); InitializeCriticalSection(&stw_dev->fb_mutex); stw_dev->ctx_table = handle_table_create(); if (!stw_dev->ctx_table) { goto error1; } stw_pixelformat_init(); /* env var override for WGL_EXT_swap_control, useful for testing/debugging */ const char *s = os_get_option("WGL_SWAP_INTERVAL"); if (s) { stw_dev->swap_interval = atoi(s); } stw_dev->refresh_rate = get_refresh_rate(); stw_dev->initialized = true; return TRUE; error1: FREE(stw_dev->smapi); if (stw_dev->stapi) stw_dev->stapi->destroy(stw_dev->stapi); stw_dev = NULL; return FALSE; }