static void draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned char *data) { GLf x[8]; memset(x, 0, sizeof(x)); #if REQUIRES_POWER_OF_2 int w2=next_power2(w); int h2=next_power2(h); int y; if (w2 != w || h2 != h) { char *newpix=g_malloc0(w2*h2*4); for (y=0 ; y < h ; y++) memcpy(newpix+y*w2*4, data+y*w*4, w*4); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w2, h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, newpix); g_free(newpix); w=w2; h=h2; } else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); #endif x[0]+=glF(1); x[2]+=glF(1); x[3]+=glF(1); x[7]+=glF(1); #if USE_OPENGLES2 glUniform1i(gr->use_texture_location, 1); glEnableVertexAttribArray(gr->texture_position_location); glVertexAttribPointer (gr->texture_position_location, 2, GL_FLOAT, 0, 0, x ); #else glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D); glTexCoordPointer(2, GL_F, 0, x); #endif glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); draw_rectangle_es(gr, p, w, h); #if USE_OPENGLES2 glUniform1i(gr->use_texture_location, 0); glDisableVertexAttribArray(gr->texture_position_location); #else glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); #endif glDisable(GL_BLEND); }
/*-----------------------------------------------------------------------------------------------*/ void* seqarray_push_ex(void *pparray, uint *size, allocator_t *alloc, uint element_size, uint count) { void** parray = (void**)pparray; assert(count > 0); const uint old_size = *size; *size += count; uint curr_capacity = old_size ? max_u(16, next_power2(old_size)) : 0; uint new_capacity = max_u(16, next_power2(*size)); if (curr_capacity < new_capacity) { *parray = kj_realloc(*parray, new_capacity * element_size, alloc); } return (char*)(*parray) + element_size * old_size; }
squeue * squeue_new(size_t capacity, size_t elem_size) { int rc; size_t realcap; squeue *q; if (!elem_size) return NULL; realcap = next_power2(capacity); if (!realcap) return NULL; // check for overflow of sizeof(squeue) + realcap * elem_size if ((realcap > (SIZE_MAX - sizeof(squeue))/elem_size) || (elem_size > (SIZE_MAX - sizeof(squeue))/realcap)) return NULL; // TODO: align on cache line q = calloc(1, sizeof(squeue) + realcap * elem_size); if (!q) return NULL; q->capacity = realcap; q->elem_size = elem_size; rc = pthread_mutex_init(&q->lock, NULL); if (rc != 0) { free(q); return NULL; } rc = pthread_cond_init(&q->pushers, NULL); if (rc != 0) { pthread_mutex_destroy(&q->lock); free(q); return NULL; } rc = pthread_cond_init(&q->poppers, NULL); if (rc != 0) { pthread_mutex_destroy(&q->lock); pthread_cond_destroy(&q->pushers); free(q); return NULL; } return q; }