#include #include #include #include #include #include #include #include extern void gears_init(int width, int height); static EGLint attribute_list[] = { EGL_NATIVE_VISUAL_ID, 0, EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 5, EGL_BLUE_SIZE, 5, EGL_ALPHA_SIZE, EGL_DONT_CARE, EGL_DEPTH_SIZE, 16, EGL_NONE }; static EGLint attribute_list_tmp[] = { EGL_NATIVE_VISUAL_ID, 0, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, 4, EGL_DEPTH_SIZE, 1, EGL_STENCIL_SIZE, 1, EGL_SAMPLE_BUFFERS, 0, EGL_LEVEL, 0, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, EGL_NONE }; static gf_display_t gf_disp; static gf_dev_t gf_dev; static EGLConfig config; static EGLContext econtext; static EGLint num_config; static gf_dev_info_t info; static gf_display_info_t disp_info; int time_elapsed() { static uint64_t init_clock_cycles; static int timer_installed; static uint64_t cycles_per_sec; uint64_t timestamp; /* Return number of milliseconds since first call */ if (!timer_installed) { init_clock_cycles = ClockCycles(); timer_installed = 1; return 0; } timestamp = ClockCycles(); if (timestamp < init_clock_cycles) { /* Counter wrapped */ timestamp += (UINT64_MAX-init_clock_cycles) + 1; } else { timestamp -= init_clock_cycles; } if (cycles_per_sec == 0) cycles_per_sec = SYSPAGE_ENTRY(qtime)->cycles_per_sec; if (timestamp > 1000*1000*1000) return timestamp / cycles_per_sec * 1000; else return timestamp * 1000 / cycles_per_sec; } int init_gears( EGLDisplay *display, EGLSurface *surface, gf_surface_t *gf_surface, int width, int height, int init_flag ) { if( init_flag ) { /* initialize the graphics device */ if( gf_dev_attach(&gf_dev, GF_DEVICE_INDEX(0), &info ) != GF_ERR_OK ) { perror("gf_dev_attach()"); return -1; } if( gf_display_attach( &gf_disp, gf_dev, 0, &disp_info) != GF_ERR_OK) { fprintf(stderr, "gf_display_attach() failed\n"); exit(EXIT_FAILURE); } /* get an EGL display connection */ *display = eglGetDisplay(gf_dev); if( *display == EGL_NO_DISPLAY ) { fprintf(stderr, "eglGetDisplay() failed\n"); return -1; } /* initialize the EGL display connection */ if (eglInitialize(*display, NULL, NULL) != EGL_TRUE) { fprintf(stderr, "eglInitialize: error 0x%x\n", eglGetError()); exit(EXIT_FAILURE); } attribute_list_tmp[1] = disp_info.format; /* Look for a compatible EGL frame buffer configuration */ if( EGL_TRUE != eglChooseConfig( *display, attribute_list_tmp, &config, 1, &num_config ) ) { printf("EGLError = 0x%x", eglGetError()); perror( "eglChooseConfig()" ); return -1; } /* create an EGL rendering context */ if( NULL == (econtext = eglCreateContext( *display, config, EGL_NO_CONTEXT, NULL )) ) { perror( "eglCreateContext()" ); return -1; } } else { // free the existing surface. eglMakeCurrent( *display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroySurface( *display, *surface ); gf_surface_free( *gf_surface ); } if( GF_ERR_OK != gf_surface_create( gf_surface, gf_dev, width, height, disp_info.format, NULL, 0 ) ) { perror( "gf_surface_create()" ); gf_display_detach( gf_disp ); gf_dev_detach( gf_dev ); return NULL; } /* create an EGL window surface */ *surface = eglCreatePixmapSurface( *display, config, *gf_surface, NULL ); if( *surface == EGL_NO_SURFACE) { fprintf(stderr, "Create surface failed: 0x%x\n", eglGetError()); exit(EXIT_FAILURE); } /* connect the context to the surface */ if (eglMakeCurrent( *display, *surface, *surface, econtext) == EGL_FALSE) { fprintf(stderr, "Make current failed: 0x%x\n", eglGetError()); exit(EXIT_FAILURE); } gears_init( width, height ); return 0; }