/** * \param fence if non-null, returns pointer to a fence which can be waited on */ void llvmpipe_flush( struct pipe_context *pipe, struct pipe_fence_handle **fence, const char *reason) { struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); draw_flush(llvmpipe->draw); /* ask the setup module to flush */ lp_setup_flush(llvmpipe->setup, fence, reason); /* Enable to dump BMPs of the color/depth buffers each frame */ if (0) { static unsigned frame_no = 1; char filename[256]; unsigned i; for (i = 0; i < llvmpipe->framebuffer.nr_cbufs; i++) { util_snprintf(filename, sizeof(filename), "cbuf%u_%u", i, frame_no); debug_dump_surface_bmp(&llvmpipe->pipe, filename, llvmpipe->framebuffer.cbufs[i]); } if (0) { util_snprintf(filename, sizeof(filename), "zsbuf_%u", frame_no); debug_dump_surface_bmp(&llvmpipe->pipe, filename, llvmpipe->framebuffer.zsbuf); } ++frame_no; } }
/* Sets "Link" header, if content manager is on */ NSAPI_PUBLIC void CM_set_link_header(Request *rq) { char link[CM_BUFF_LEN]; char *uri; if ( !CM_get_status() ) /* if cm is off. don't do anything */ return; uri = pblock_findkeyval(pb_key_uri, rq->reqpb); /* e.g. Link: <http://www.glyphica.com/index.html?services>; rel="services" */ if (pervs_vars()->Vsecurity_active) { if (pervs_vars()->Vport == 443) util_snprintf(link, CM_BUFF_LEN, "<https://%s%s?%s>; rel=\"%s\"", pervs_vars()->Vserver_hostname, uri, CM_SERVICES_NS,CM_SERVICES_NS ); else util_snprintf(link, CM_BUFF_LEN, "<https://%s:%d%s?%s>; rel=\"%s\"", pervs_vars()->Vserver_hostname, pervs_vars()->Vport, uri, CM_SERVICES_NS,CM_SERVICES_NS ); } else { if (pervs_vars()->Vport == 80) util_snprintf( link, CM_BUFF_LEN, "<http://%s%s?%s>; rel=\"%s\"", pervs_vars()->Vserver_hostname, uri, CM_SERVICES_NS,CM_SERVICES_NS ); else util_snprintf( link, CM_BUFF_LEN, "<http://%s:%d%s?%s>; rel=\"%s\"", pervs_vars()->Vserver_hostname, pervs_vars()->Vport, uri, CM_SERVICES_NS,CM_SERVICES_NS ); } pblock_nvinsert("Link", link, rq->srvhdrs); }
struct util_dl_library * pipe_loader_find_module(struct pipe_loader_device *dev, const char *library_paths) { struct util_dl_library *lib; const char *next; char path[PATH_MAX]; int len, ret; for (next = library_paths; *next; library_paths = next + 1) { next = util_strchrnul(library_paths, ':'); len = next - library_paths; if (len) ret = util_snprintf(path, sizeof(path), "%.*s/%s%s%s", len, library_paths, MODULE_PREFIX, dev->driver_name, UTIL_DL_EXT); else ret = util_snprintf(path, sizeof(path), "%s%s%s", MODULE_PREFIX, dev->driver_name, UTIL_DL_EXT); if (ret > 0 && ret < sizeof(path)) { lib = util_dl_open(path); if (lib) { return lib; } } } return NULL; }
static struct vg_shader * setup_lookup_single(struct vg_context *ctx, void *user_data) { char buffer[1024]; VGImageChannel channel = (VGImageChannel)(user_data); struct vg_shader *shader; switch(channel) { case VG_RED: util_snprintf(buffer, 1023, lookup_single_asm, "xxxx"); break; case VG_GREEN: util_snprintf(buffer, 1023, lookup_single_asm, "yyyy"); break; case VG_BLUE: util_snprintf(buffer, 1023, lookup_single_asm, "zzzz"); break; case VG_ALPHA: util_snprintf(buffer, 1023, lookup_single_asm, "wwww"); break; default: debug_assert(!"Unknown color channel"); } shader = shader_create_from_text(ctx->pipe, buffer, 200, PIPE_SHADER_FRAGMENT); return shader; }
/* returns "Link" header, if content manager is on. Null otherwise */ NSAPI_PUBLIC int CM_get_link_header(char *uri, char *link, int size ) { if ( !CM_get_status() ) /* if cm is off. don't do anything */ return 0; /* e.g. Link: <http://www.glyphica.com/index.html?services>; rel ="services" */ if (pervs_vars()->Vsecurity_active) { if (pervs_vars()->Vport == 443) util_snprintf(link, size, "Link: <https://%s%s?%s>; rel=\"%s\"", pervs_vars()->Vserver_hostname, uri, CM_SERVICES_NS,CM_SERVICES_NS ); else util_snprintf(link, size, "Link: <https://%s:%d%s?%s>; rel=\"%s\"", pervs_vars()->Vserver_hostname, pervs_vars()->Vport, uri, CM_SERVICES_NS,CM_SERVICES_NS ); } else { if (pervs_vars()->Vport == 80) util_snprintf( link, size, "Link: <http://%s%s?%s>; rel=\"%s\"", pervs_vars()->Vserver_hostname, uri, CM_SERVICES_NS,CM_SERVICES_NS ); else util_snprintf( link, size, "Link: <http://%s:%d%s?%s>; rel=\"%s\"", pervs_vars()->Vserver_hostname, pervs_vars()->Vport, uri, CM_SERVICES_NS,CM_SERVICES_NS ); } return 1; }
static void init_logging(struct pipe_screen *screen) { static const char *log_prefix = "Mesa: "; char host_log[1000]; /* Log Version to Host */ util_snprintf(host_log, sizeof(host_log) - strlen(log_prefix), "%s%s", log_prefix, svga_get_name(screen)); svga_host_log(host_log); util_snprintf(host_log, sizeof(host_log) - strlen(log_prefix), "%s%s" #ifdef MESA_GIT_SHA1 " (" MESA_GIT_SHA1 ")" #endif , log_prefix, PACKAGE_VERSION); svga_host_log(host_log); /* If the SVGA_EXTRA_LOGGING env var is set, log the process's command * line (program name and arguments). */ if (debug_get_bool_option("SVGA_EXTRA_LOGGING", FALSE)) { char cmdline[1000]; if (os_get_command_line(cmdline, sizeof(cmdline))) { util_snprintf(host_log, sizeof(host_log) - strlen(log_prefix), "%s%s", log_prefix, cmdline); svga_host_log(host_log); } } }
void softpipe_flush( struct pipe_context *pipe, unsigned flags, struct pipe_fence_handle **fence ) { struct softpipe_context *softpipe = softpipe_context(pipe); uint i; draw_flush(softpipe->draw); if (flags & SP_FLUSH_TEXTURE_CACHE) { unsigned sh; for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) { for (i = 0; i < softpipe->num_sampler_views[sh]; i++) { sp_flush_tex_tile_cache(softpipe->tex_cache[sh][i]); } } } /* If this is a swapbuffers, just flush color buffers. * * The zbuffer changes are not discarded, but held in the cache * in the hope that a later clear will wipe them out. */ for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) if (softpipe->cbuf_cache[i]) sp_flush_tile_cache(softpipe->cbuf_cache[i]); if (softpipe->zsbuf_cache) sp_flush_tile_cache(softpipe->zsbuf_cache); softpipe->dirty_render_cache = FALSE; /* Enable to dump BMPs of the color/depth buffers each frame */ #if 0 if (flags & PIPE_FLUSH_END_OF_FRAME) { static unsigned frame_no = 1; static char filename[256]; util_snprintf(filename, sizeof(filename), "cbuf_%u.bmp", frame_no); debug_dump_surface_bmp(pipe, filename, softpipe->framebuffer.cbufs[0]); util_snprintf(filename, sizeof(filename), "zsbuf_%u.bmp", frame_no); debug_dump_surface_bmp(pipe, filename, softpipe->framebuffer.zsbuf); ++frame_no; } #endif if (fence) *fence = (void*)(intptr_t)1; }
void StatsVirtualServerNode::setInterfaces(const VirtualServer* vs) { interfaces.clear(); interfaces.ensureCapacity(128); int nIndex = 0; int nItfCount = vs->getHttpListenerNameCount(); // Calculate the length requirement for assignment const Configuration* configuration = ConfigurationManager::getConfiguration(); for (nIndex = 0; configuration && (nIndex < nItfCount); nIndex++) { const ListenSocketConfig* lsc; lsc = configuration->getLsc(*vs->getHttpListenerName(nIndex)); if (lsc) { char iface[70] = ""; util_snprintf(iface, sizeof(iface), "%s:%d", lsc->ip.getStringValue(), lsc->port.getInt32Value()); interfaces.append(iface); const char* spaceSeparater = " "; if (nIndex != nItfCount - 1) { interfaces.append(" "); } } } if (configuration) configuration->unref(); }
ast_expression *fold_constgen_string(fold_t *fold, const char *str, bool translate) { hash_table_t *table = (translate) ? fold->imm_string_untranslate : fold->imm_string_dotranslate; ast_value *out = NULL; size_t hash = util_hthash(table, str); if ((out = (ast_value*)util_htgeth(table, str, hash))) return (ast_expression*)out; if (translate) { char name[32]; util_snprintf(name, sizeof(name), "dotranslate_%lu", (unsigned long)(fold->parser->translated++)); out = ast_value_new(parser_ctx(fold->parser), name, TYPE_STRING); out->expression.flags |= AST_FLAG_INCLUDE_DEF; /* def needs to be included for translatables */ } else out = ast_value_new(fold_ctx(fold), "#IMMEDIATE", TYPE_STRING); out->cvq = CV_CONST; out->hasvalue = true; out->isimm = true; out->constval.vstring = parser_strdup(str); vec_push(fold->imm_string, out); util_htseth(table, str, hash, out); return (ast_expression*)out; }
char *_add_table_event(EVENT_HANDLER *handler) { HANDLE event; char *err; EVENT_HANDLER *tmp; if(!(event = CreateEvent(NULL, FALSE, FALSE, handler->event_name))) { err = (char *)MALLOC(ERR_MSG_LEN); util_snprintf(err, ERR_MSG_LEN, "could not open create event %s (%s)", handler->event_name, system_errmsg()); TERMINATE_HANDLER_THREAD(); return err; } if (!events) { events = (HANDLE *)MALLOC(sizeof(HANDLE)); } else { events = (HANDLE *)REALLOC(events, (sizeof(events) + sizeof(HANDLE))); } events[event_number -1] = event; if (!handler_table) { handler_table = handler; } else { /* Prevent duplicate handlers from being entered */ for (tmp = handler_table; tmp; tmp = tmp->next) { if (!strcmp(tmp->event_name, handler->event_name)) { return NULL; } } handler->next = handler_table; handler_table = handler; } return NULL; }
char *delete_handler(char *event) { char *err; ENTER_EVENT_LOCK; if (!handler_thread) { err = (char *)MALLOC(ERR_MSG_LEN); util_snprintf(err, ERR_MSG_LEN, "handler thread is not present"); RELEASE_EVENT_LOCK; return err; } /* suspend handler */ if (err = _suspend_handler()) { RELEASE_EVENT_LOCK; return err; } if (err = _delete_event(event)) { RELEASE_EVENT_LOCK; return err; } /* reset the handler to wake up and listen on the new event */ if (err = _resume_handler()) { RELEASE_EVENT_LOCK; return err; } RELEASE_EVENT_LOCK; return NULL; }
static const char * fd_screen_get_name(struct pipe_screen *pscreen) { static char buffer[128]; util_snprintf(buffer, sizeof(buffer), "FD%03d", fd_screen(pscreen)->device_id); return buffer; }
char *initialize_event_handler(char *serverid) { char *err; char mutex_name[EVENT_LEN]; HANDLE event; /* First create the global lock -acquire ownership immediately */ util_snprintf(mutex_name, EVENT_LEN, "%s.event_handler", serverid); eventMutex = CreateMutex(NULL, TRUE, mutex_name); if (eventMutex == NULL) { err = (char *)MALLOC(ERR_MSG_LEN); util_snprintf(err, ERR_MSG_LEN, "Failed to create mutex for event handler %s", system_errmsg()); return err; } /* Create the resume and suspend event names */ util_snprintf(resume, EVENT_LEN, "%s.resume", serverid); util_snprintf(suspend, EVENT_LEN, "%s.suspend", serverid); /* Create the global event to resume the event handler thread */ if(!(event = CreateEvent(NULL, FALSE, FALSE, resume))) { err = (char *)MALLOC(ERR_MSG_LEN); util_snprintf(err, ERR_MSG_LEN, "could not open create event %s (%s)", resume, system_errmsg()); RELEASE_EVENT_LOCK; return err; } resumeEvent = (HANDLE *)MALLOC(sizeof(HANDLE)); resumeEvent[0] = event; if (!handler_thread) { if (err = _create_handler_thread()) { RELEASE_EVENT_LOCK; return err; } } /* Release mutex */ RELEASE_EVENT_LOCK; return NULL; }
static const char * nouveau_screen_get_name(struct pipe_screen *pscreen) { struct nouveau_device *dev = nouveau_screen(pscreen)->device; static char buffer[128]; util_snprintf(buffer, sizeof(buffer), "NV%02X", dev->chipset); return buffer; }
static const char * brw_get_name(struct pipe_screen *screen) { static char buffer[128]; const char *chipset; switch (brw_screen(screen)->chipset.pci_id) { case PCI_CHIP_I965_G: chipset = "I965_G"; break; case PCI_CHIP_I965_Q: chipset = "I965_Q"; break; case PCI_CHIP_I965_G_1: chipset = "I965_G_1"; break; case PCI_CHIP_I946_GZ: chipset = "I946_GZ"; break; case PCI_CHIP_I965_GM: chipset = "I965_GM"; break; case PCI_CHIP_I965_GME: chipset = "I965_GME"; break; case PCI_CHIP_GM45_GM: chipset = "GM45_GM"; break; case PCI_CHIP_IGD_E_G: chipset = "IGD_E_G"; break; case PCI_CHIP_Q45_G: chipset = "Q45_G"; break; case PCI_CHIP_G45_G: chipset = "G45_G"; break; case PCI_CHIP_G41_G: chipset = "G41_G"; break; case PCI_CHIP_B43_G: chipset = "B43_G"; break; case PCI_CHIP_ILD_G: chipset = "ILD_G"; break; case PCI_CHIP_ILM_G: chipset = "ILM_G"; break; default: chipset = "unknown"; break; } util_snprintf(buffer, sizeof(buffer), "i965 (chipset: %s)", chipset); return buffer; }
static int qc_vtos(qc_program_t *prog) { char buffer[512]; qcany_t *num; qcany_t str; CheckArgs(1); num = GetArg(0); util_snprintf(buffer, sizeof(buffer), "'%g %g %g'", num->vector[0], num->vector[1], num->vector[2]); str.string = prog_tempstring(prog, buffer); Return(str); return 0; }
static const char * etna_screen_get_name(struct pipe_screen *pscreen) { struct etna_screen *priv = etna_screen(pscreen); static char buffer[128]; util_snprintf(buffer, sizeof(buffer), "Vivante GC%x rev %04x", priv->model, priv->revision); return buffer; }
static int qc_etos(qc_program_t *prog) { char buffer[512]; qcany_t *num; qcany_t str; CheckArgs(1); num = GetArg(0); util_snprintf(buffer, sizeof(buffer), "%i", num->_int); str.string = prog_tempstring(prog, buffer); Return(str); return 0; }
int NTStatsServer::buildConnectionName(const char* instanceName, char* outputPath, int sizeOutputPath) { if (instanceName == NULL) { instanceName = conf_get_true_globals()->Vserver_id; } return util_snprintf(outputPath, sizeOutputPath, "\\\\.\\pipe\\iWSStats-%s", instanceName); }
static void svga_flush( struct pipe_context *pipe, struct pipe_fence_handle **fence, unsigned flags) { struct svga_context *svga = svga_context(pipe); /* Emit buffered drawing commands, and any back copies. */ svga_surfaces_flush( svga ); if (flags & PIPE_FLUSH_FENCE_FD) svga->swc->hints |= SVGA_HINT_FLAG_EXPORT_FENCE_FD; /* Flush command queue. */ svga_context_flush(svga, fence); SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n", __FUNCTION__, fence ? *fence : 0x0); /* Enable to dump BMPs of the color/depth buffers each frame */ if (0) { struct pipe_framebuffer_state *fb = &svga->curr.framebuffer; static unsigned frame_no = 1; char filename[256]; unsigned i; for (i = 0; i < fb->nr_cbufs; i++) { util_snprintf(filename, sizeof(filename), "cbuf%u_%04u.bmp", i, frame_no); debug_dump_surface_bmp(&svga->pipe, filename, fb->cbufs[i]); } if (0 && fb->zsbuf) { util_snprintf(filename, sizeof(filename), "zsbuf_%04u.bmp", frame_no); debug_dump_surface_bmp(&svga->pipe, filename, fb->zsbuf); } ++frame_no; } }
void lp_format_intrinsic(char *name, size_t size, const char *name_root, LLVMTypeRef type) { unsigned length = 0; unsigned width; char c; LLVMTypeKind kind = LLVMGetTypeKind(type); if (kind == LLVMVectorTypeKind) { length = LLVMGetVectorSize(type); type = LLVMGetElementType(type); kind = LLVMGetTypeKind(type); } switch (kind) { case LLVMIntegerTypeKind: c = 'i'; width = LLVMGetIntTypeWidth(type); break; case LLVMFloatTypeKind: c = 'f'; width = 32; break; case LLVMDoubleTypeKind: c = 'f'; width = 64; break; default: unreachable("unexpected LLVMTypeKind"); } if (length) { util_snprintf(name, size, "%s.v%u%c%u", name_root, length, c, width); } else { util_snprintf(name, size, "%s.%c%u", name_root, c, width); } }
/** * Dump an image to a .raw or .ppm file (depends on OS). * \param format PIPE_FORMAT_x * \param cpp bytes per pixel * \param width width in pixels * \param height height in pixels * \param stride row stride in bytes */ void debug_dump_image(const char *prefix, unsigned format, unsigned cpp, unsigned width, unsigned height, unsigned stride, const void *data) { /* write a ppm file */ char filename[256]; FILE *f; util_snprintf(filename, sizeof(filename), "%s.ppm", prefix); f = fopen(filename, "w"); if (f) { int i, x, y; int r, g, b; const uint8_t *ptr = (uint8_t *) data; /* XXX this is a hack */ switch (format) { case PIPE_FORMAT_B8G8R8A8_UNORM: r = 2; g = 1; b = 0; break; default: r = 0; g = 1; b = 1; } fprintf(f, "P6\n"); fprintf(f, "# ppm-file created by osdemo.c\n"); fprintf(f, "%i %i\n", width, height); fprintf(f, "255\n"); fclose(f); f = fopen(filename, "ab"); /* reopen in binary append mode */ for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { i = y * stride + x * cpp; fputc(ptr[i + r], f); /* write red */ fputc(ptr[i + g], f); /* write green */ fputc(ptr[i + b], f); /* write blue */ } } fclose(f); } else { fprintf(stderr, "Can't open %s for writing\n", filename); } }
/* * Linux perf profiler integration. * * See also: * - http://penberg.blogspot.co.uk/2009/06/jato-has-profiler.html * - https://github.com/penberg/jato/commit/73ad86847329d99d51b386f5aba692580d1f8fdc * - http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=80d496be89ed7dede5abee5c057634e80a31c82d */ extern "C" void lp_profile(LLVMValueRef func, const void *code) { #if defined(__linux__) && defined(PROFILE) static boolean first_time = TRUE; static FILE *perf_map_file = NULL; static int perf_asm_fd = -1; if (first_time) { /* * We rely on the disassembler for determining a function's size, but * the disassembly is a leaky and slow operation, so avoid running * this except when running inside linux perf, which can be inferred * by the PERF_BUILDID_DIR environment variable. */ if (getenv("PERF_BUILDID_DIR")) { pid_t pid = getpid(); char filename[256]; util_snprintf(filename, sizeof filename, "/tmp/perf-%llu.map", (unsigned long long)pid); perf_map_file = fopen(filename, "wt"); util_snprintf(filename, sizeof filename, "/tmp/perf-%llu.map.asm", (unsigned long long)pid); mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; perf_asm_fd = open(filename, O_WRONLY | O_CREAT, mode); } first_time = FALSE; } if (perf_map_file) { const char *symbol = LLVMGetValueName(func); unsigned long addr = (uintptr_t)code; llvm::raw_fd_ostream Out(perf_asm_fd, false); Out << symbol << ":\n"; unsigned long size = disassemble(code, Out); fprintf(perf_map_file, "%lx %lx %s\n", addr, size, symbol); fflush(perf_map_file); } #else (void)func; (void)code; #endif }
static struct vg_shader * setup_convolution(struct vg_context *ctx, void *user_data) { char buffer[1024]; VGint num_consts = (VGint)(long)(user_data); struct vg_shader *shader; util_snprintf(buffer, 1023, convolution_asm, num_consts, num_consts / 2 + 1); shader = shader_create_from_text(ctx->pipe, buffer, 200, PIPE_SHADER_FRAGMENT); return shader; }
char *_resume_handler() { HANDLE resume_event; char *err; resume_event = OpenEvent(EVENT_ALL_ACCESS, FALSE, resume); if (resume_event == NULL) { err = (char *)MALLOC(ERR_MSG_LEN); util_snprintf(err, ERR_MSG_LEN, "could not open resume event (%s)", system_errmsg()); return err; } if(!SetEvent(resume_event)) { err = (char *)MALLOC(ERR_MSG_LEN); util_snprintf(err, ERR_MSG_LEN, "cannot set reset event (%s)", system_errmsg()); return err; } return NULL; }
char *_create_rotation_thread() { char *err; handler_thread = systhread_start(15, 65536, _wait_for_events, NULL); if (handler_thread == NULL) { err = (char *)MALLOC(ERR_MSG_LEN); util_snprintf(err, ERR_MSG_LEN, "Failed to start event handler thread %s", system_errmsg()); return err; } return NULL; }
/** * Generate sin(a) */ LLVMValueRef lp_build_sin(struct lp_build_context *bld, LLVMValueRef a) { const struct lp_type type = bld->type; LLVMTypeRef vec_type = lp_build_vec_type(type); char intrinsic[32]; /* TODO: optimize the constant case */ assert(type.floating); util_snprintf(intrinsic, sizeof intrinsic, "llvm.sin.v%uf%u", type.length, type.width); return lp_build_intrinsic_unary(bld->builder, intrinsic, vec_type, a); }
const char * debug_dump_enum(const struct debug_named_value *names, unsigned long value) { static char rest[64]; while(names->name) { if(names->value == value) return names->name; ++names; } util_snprintf(rest, sizeof(rest), "0x%08lx", value); return rest; }
static EGLBoolean dlopen_gl_lib_cb(const char *dir, size_t len, void *callback_data) { const char *name = (const char *) callback_data; char path[1024]; int ret; if (len) { assert(len <= INT_MAX && "path is insanely long!"); ret = util_snprintf(path, sizeof(path), "%.*s/%s" UTIL_DL_EXT, (int)len, dir, name); } else { ret = util_snprintf(path, sizeof(path), "%s" UTIL_DL_EXT, name); } if (ret > 0 && ret < sizeof(path)) { egl_st_gl_lib = util_dl_open(path); if (egl_st_gl_lib) _eglLog(_EGL_DEBUG, "loaded %s", path); } return !egl_st_gl_lib; }
static const GLubyte * st_get_string(struct gl_context * ctx, GLenum name) { struct st_context *st = st_context(ctx); struct pipe_screen *screen = st->pipe->screen; switch (name) { case GL_VENDOR: { const char *vendor = screen->get_vendor( screen ); util_snprintf(st->vendor, sizeof(st->vendor), "%s", vendor); return (GLubyte *) st->vendor; } case GL_RENDERER: util_snprintf(st->renderer, sizeof(st->renderer), "Gallium %s on %s", ST_VERSION_STRING, screen->get_name( screen )); return (GLubyte *) st->renderer; default: return NULL; } }