static int enum_handles( struct process *process, void *user ) { struct enum_handle_info *info = user; struct handle_table *table = process->handles; struct handle_entry *entry; struct handle_info *handle; unsigned int i; if (!table) return 0; for (i = 0, entry = table->entries; i <= table->last; i++, entry++) { if (!entry->ptr) continue; if (!info->handle) { info->count++; continue; } assert( info->count ); handle = info->handle++; handle->owner = process->id; handle->handle = index_to_handle(i); handle->access = entry->access & ~RESERVED_ALL; info->count--; } return 0; }
/* destroy a handle table */ static void handle_table_destroy( struct object *obj ) { int i; struct handle_table *table = (struct handle_table *)obj; struct handle_entry *entry; assert( obj->ops == &handle_table_ops ); /* first notify all objects that handles are being closed */ if (table->process) { for (i = 0, entry = table->entries; i <= table->last; i++, entry++) { struct object *obj = entry->ptr; if (obj) obj->ops->close_handle( obj, table->process, index_to_handle(i) ); } } for (i = 0, entry = table->entries; i <= table->last; i++, entry++) { struct object *obj = entry->ptr; entry->ptr = NULL; if (obj) release_object_from_handle( obj ); } free( table->entries ); }
/* this is needed for window stations and desktops (don't ask...) */ obj_handle_t find_inherited_handle( struct process *process, const struct object_ops *ops ) { struct handle_table *table = process->handles; struct handle_entry *ptr; int i; if (!table) return 0; for (i = 0, ptr = table->entries; i <= table->last; i++, ptr++) { if (!ptr->ptr) continue; if (ptr->ptr->ops != ops) continue; if (ptr->access & RESERVED_INHERIT) return index_to_handle(i); } return 0; }
/* this is needed for window stations and desktops */ obj_handle_t enumerate_handles( struct process *process, const struct object_ops *ops, unsigned int *index ) { struct handle_table *table = process->handles; unsigned int i; struct handle_entry *entry; if (!table) return 0; for (i = *index, entry = &table->entries[i]; i <= table->last; i++, entry++) { if (!entry->ptr) continue; if (entry->ptr->ops != ops) continue; *index = i + 1; return index_to_handle(i); } return 0; }
/* allocate the first free entry in the handle table */ static obj_handle_t alloc_entry( struct handle_table *table, void *obj, unsigned int access ) { struct handle_entry *entry = table->entries + table->free; int i; for (i = table->free; i <= table->last; i++, entry++) if (!entry->ptr) goto found; if (i >= table->count) { if (!grow_handle_table( table )) return 0; entry = table->entries + i; /* the entries may have moved */ } table->last = i; found: table->free = i + 1; entry->ptr = grab_object_for_handle( obj ); entry->access = access; return index_to_handle(i); }
GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t visibility, GrSLType type, const char* name, int count, const char** outName) { GrAssert(name && strlen(name)); SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_ShaderType | kFragment_ShaderType); GrAssert(0 == (~kVisibilityMask & visibility)); GrAssert(0 != visibility); BuilderUniform& uni = fUniforms.push_back(); UniformHandle h = index_to_handle(fUniforms.count() - 1); GR_DEBUGCODE(UniformHandle h2 =) fUniformManager.appendUniform(type, count); // We expect the uniform manager to initially have no uniforms and that all uniforms are added // by this function. Therefore, the handles should match. GrAssert(h2 == h); uni.fVariable.setType(type); uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier); SkString* uniName = uni.fVariable.accessName(); if (kNonStageIdx == fCurrentStageIdx) { uniName->printf("u%s", name); } else { uniName->printf("u%s%d", name, fCurrentStageIdx); } uni.fVariable.setArrayCount(count); uni.fVisibility = visibility; // If it is visible in both the VS and FS, the precision must match. // We declare a default FS precision, but not a default VS. So set the var // to use the default FS precision. if ((kVertex_ShaderType | kFragment_ShaderType) == visibility) { // the fragment and vertex precisions must match uni.fVariable.setPrecision(kDefaultFragmentPrecision); } if (NULL != outName) { *outName = uni.fVariable.c_str(); } return h; }
/* dump a handle table */ static void handle_table_dump( struct object *obj, int verbose ) { int i; struct handle_table *table = (struct handle_table *)obj; struct handle_entry *entry; assert( obj->ops == &handle_table_ops ); fprintf( stderr, "Handle table last=%d count=%d process=%p\n", table->last, table->count, table->process ); if (!verbose) return; entry = table->entries; for (i = 0; i <= table->last; i++, entry++) { if (!entry->ptr) continue; fprintf( stderr, " %04x: %p %08x ", index_to_handle(i), entry->ptr, entry->access ); dump_object_name( entry->ptr ); entry->ptr->ops->dump( entry->ptr, 0 ); } }