//Link a framebuffer to a surface in the current context static void attach_surface(EGLDisplay display, struct context *current, struct surface *surface) { if(!surface->buffer) { //An attached surface must have a buffer surface_dequeue_buffer(surface); LOGV("attach_surface - 1" ); if(surface->buffer) { LOGV("attach_surface - 2" ); attach_buffer( display, surface ); //yay LOGV("attach_surface - 3 (yay)" ); } else { LOGV("attach_surface() Failed to dequeue buffer: surface = %p, Thread = %d", surface, gettid()); } } else { LOGV("attach_surface() - already got buffer, so we are happy: surface = %p, Thread = %d", surface, gettid()); } surface->made_current = 1; }
void a9_compute(int tid, struct buffer* buffers, int start_indx, int end_indx) { int i, j ; histo[0] = (int*)(buffers[1].bo[0]->map) ; histo[1] = (int*)(buffers[2].bo[0]->map) ; histo[2] = (int*)(buffers[3].bo[0]->map) ; histo[3] = (int*)(buffers[4].bo[0]->map) ; histo[4] = (int*)(buffers[5].bo[0]->map) ; for(i=0 ; i<NUM_ITER ; i++) { if(tid == 0) { call_barrier(0) ; pthread_barrier_wait(&barrier0); compute_a9_thread1(buffers, start_indx, end_indx) ; pthread_barrier_wait(&barrier1); if(remote_fd.sysm3 >= 0) { detach_buffer(buffers[1], remote_fd.sysm3, 0) ; detach_buffer(buffers[2], remote_fd.sysm3, 0) ; attach_buffer(buffers[1], remote_fd.sysm3, 0) ; attach_buffer(buffers[2], remote_fd.sysm3, 0) ; } if(remote_fd.dsp >= 0) { detach_buffer(buffers[1], remote_fd.dsp, 0) ; detach_buffer(buffers[2], remote_fd.dsp, 0) ; attach_buffer(buffers[1], remote_fd.dsp, 0) ; attach_buffer(buffers[2], remote_fd.dsp, 0) ; } pthread_barrier_wait(&barrier2); call_barrier(1) ; compute_gray_level_mapping() ; pthread_barrier_wait(&barrier3); compute_image_a9_thread1(buffers, start_indx, end_indx) ; } else { pthread_barrier_wait(&barrier0); compute_a9_thread2(buffers, start_indx, end_indx) ; pthread_barrier_wait(&barrier1); pthread_barrier_wait(&barrier2); pthread_barrier_wait(&barrier3); compute_image_a9_thread2(buffers, start_indx, end_indx) ; } } }
void parallel_kernel_reg_detect(int tid, struct buffer* buffers, int start_indx, int end_indx) { int i, j, cnt ; int* sum_tang = (int*)(buffers[0].bo[0]->map) ; int* mean = (int*)(buffers[1].bo[0]->map) ; int* diff = (int*)(buffers[2].bo[0]->map) ; int* sum_diff = (int*)(buffers[3].bo[0]->map) ; int* tmp = (int*)(buffers[4].bo[0]->map) ; int* path = (int*)(buffers[5].bo[0]->map) ; for (i = start_indx ; i < end_indx ; i++) for (j = 0; j < MAXGRID; j++) { sum_tang[i*MAXGRID+j] = (i+1)*(j+1); mean[i*MAXGRID+j] = (i-j)/MAXGRID; path[i*MAXGRID+j] = (i*(j-1))/MAXGRID; } for (j = start_indx ; j < end_indx ; j++) for (i = j; i <= MAXGRID - 1; i++) for (cnt = 0; cnt <= LENGTH - 1; cnt++) { diff[j*MAXGRID*LENGTH + i*LENGTH + cnt] = sum_tang[j*MAXGRID + i]; } for (j = start_indx ; j < end_indx ; j++) { for (i = j; i <= MAXGRID - 1; i++) { sum_diff[j*MAXGRID*LENGTH + i*LENGTH + 0] = diff[j*MAXGRID*LENGTH + i*LENGTH + 0] ; for (cnt = 1; cnt <= LENGTH - 1; cnt++) { sum_diff[j*MAXGRID*LENGTH + i*LENGTH + cnt] = sum_diff[j*MAXGRID*LENGTH + i*LENGTH + cnt-1] + diff[j*MAXGRID*LENGTH + i*LENGTH + cnt]; } mean[j*MAXGRID+i] = sum_diff[j*MAXGRID*LENGTH + i*LENGTH + LENGTH-1]; } } if(tid == 0) { if(remote_fd.sysm3 >= 0) { detach_buffer(buffers[1], remote_fd.sysm3, 0) ; attach_buffer(buffers[1], remote_fd.sysm3, 0) ; } if(remote_fd.dsp >= 0) { detach_buffer(buffers[1], remote_fd.dsp, 0) ; attach_buffer(buffers[1], remote_fd.dsp, 0) ; } call_barrier(1) ; } pthread_barrier_wait(&barrier1) ; int x ; for (j = start_indx ; j < end_indx ; j++) { x = 0 ; tmp[j*MAXGRID+j] = mean[x*MAXGRID+j] ; //printf("tmp[%d][%d] = %d\n", j, j, tmp[j*MAXGRID+j]) ; for (i = j+1; i <= MAXGRID - 1; i++) { x++ ; tmp[j*MAXGRID+i] = tmp[j*MAXGRID+i-1] + mean[x*MAXGRID+i]; //printf("tmp[%d][%d] = %d\n", j, i, tmp[j*MAXGRID+i]) ; } } if(tid == 0) { if(remote_fd.sysm3 >= 0) { detach_buffer(buffers[4], remote_fd.sysm3, 0) ; attach_buffer(buffers[4], remote_fd.sysm3, 0) ; } if(remote_fd.dsp >= 0) { detach_buffer(buffers[4], remote_fd.dsp, 0) ; attach_buffer(buffers[4], remote_fd.dsp, 0) ; } call_barrier(2) ; } pthread_barrier_wait(&barrier2) ; //print_array((int*)tmp) ; for (j = start_indx ; j < end_indx ; j++) { x = 0 ; for (i = j ; i <= MAXGRID - 1; i++) { path[j*MAXGRID+i] = tmp[x*MAXGRID+i] ; x++ ; } } //print_array((int*)path) ; }
EGLBoolean eglSwapBuffers(EGLDisplay display, EGLSurface surface_) { struct context *current_context = brcm_egl_get_current(); struct surface *surface = (struct surface *)surface_; if( !current_context ) { LOGE("eglSwapBuffers() - TODO - function called but no current context is valid"); return false; } //nothing bound? if(surface_ == EGL_NO_SURFACE) { LOGE("eglSwapBuffers(%p) error: EGL_BAD_SURFACE Thread: %d", current_context, gettid()); return EGL_FALSE; } //do we have an android native window already assigned to our egl context? if(surface->window) { //check that the context wasn't deleted //TODO - explain why this could occur #if 0 if(egl_is_context_lost(thread)) { thread->error = EGL_CONTEXT_LOST; LOGE("eglSwapBuffers(%p) error: EGL_CONTEXT_LOST, Thread: %d", current_context, gettid()); return EGL_FALSE; } #endif LOGD_IF(current_context->profiling, "eglSwapBuffers(%d, %p) %d", (int)display, (void *)surface, gettid()); //todo - add in invalidates here #ifndef BRCM_V3D_OPT glFinish(); #else glFinish(); glFlush(); if(surface->buffer->format == HAL_PIXEL_FORMAT_YCbCr_422_I) convert_to_yuv(current_context->composer,surface->buffer); #endif //TODO - if we don't get a buffer below, then v3d will have a pointer to memory that it can't write to anymore EGLint res = glGetError(); if (res == GL_OUT_OF_MEMORY) { LOGE("eglSwapBuffers Error 0x%x",res); return false; } //send the current buffer out surface_enqueue_buffer( surface); sync_composer(current_context->composer); //grab a new buffer and bind it to V3D if( !surface_dequeue_buffer(surface) ) LOGE("surface_dequeue_buffer FATAL error - no buffer to attach"); attach_buffer(display, surface); return EGL_TRUE; } else { LOGE("eglSwapBuffers called but no window bound!" ); } return EGL_FALSE; }