/*!**************************************************************************** @Function main @Input argc Number of arguments @Input argv Command line arguments @Return int result code to OS @Description Main function of the program ******************************************************************************/ int main(int argc, char **argv) { int testID = 0, err; //default char *extensions; unsigned int delta; NATIVE_PIXMAP_STRUCT* pNativePixmap = NULL; /* Initialise all globals */ initialise_globals(&gTest); /* Pre init step - check the arguments */ if(argc < 11) { SGXPERF_ERR_printf("Error: Invalid number of operands \n\n"); SGXPERF_ERR_printf("%s",helpString); exit(-1); } testID = atol(argv[1]); if(testID > MAX_TEST_ID || testID < 0) { SGXPERF_ERR_printf("Error: No test available with this ID %d\n\n", testID); SGXPERF_ERR_printf("%s",helpString); exit(-1); } gTest.inNumberOfObjectsPerSide = atol(argv[7]); gTest.inSurfaceType = atol(argv[8]); if(argc < 4) { if(testID > 2) //1 and 2 do not need textures { SGXPERF_ERR_printf("Error: Invalid number of operands for selected testID %d\n\n", testID); SGXPERF_ERR_printf("%s",helpString); exit(-1); } } else { gTest.inTextureWidth = atol(argv[2]); gTest.inTextureHeight = atol(argv[3]); } gTest.inRotationEnabled = 0; //Rotation is unused in latest version if(argc >= 5) gTest.inRotationEnabled = atol(argv[4]); gTest.inPixelFormat = 0; if(argc >= 6) gTest.inPixelFormat = atol(argv[5]); if(gTest.inPixelFormat != SGXPERF_RGB565 && gTest.inPixelFormat != SGXPERF_ARGB8888 && gTest.inPixelFormat != SGXPERF_BYTE8) { SGXPERF_ERR_printf("Error: Unsupported pixel format for texture %d \n\n", gTest.inPixelFormat); SGXPERF_ERR_printf("%s",helpString); exit(-1); } //read extra params gTest.numTestIterations = atol(argv[9]); gTest.inFPS =atol(argv[10]); gTest.msToSleep = 1000/gTest.inFPS; gTest.cookie = argv[11]; if((gTest.inTextureWidth > 8000) || (gTest.inTextureHeight > 8000)) { SGXPERF_ERR_printf("Error: Width or Height exceeds 8000 \n\n"); SGXPERF_ERR_printf("%s",helpString); exit(-1); } #ifndef _ENABLE_CMEM if(testID == 6 || testID == 7 || gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16 || gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32) { SGXPERF_ERR_printf("ERROR: Cannot run native pixmap tests without CMEM\n"); exit(-1); } #endif #ifndef _ENABLE_BUFFERCLASS if(testID == 8) { SGXPERF_ERR_printf("ERROR: Cannot run test8 without BUFFERCLASS driver\n"); exit(-1); } #endif //for pixmap related tests, surface cannot be pixmap if(testID == 6 && gTest.inSurfaceType != SGXPERF_SURFACE_TYPE_WINDOW) { SGXPERF_ERR_printf("ERROR: Cannot run native pixmap eglimage test with pixmap surface\n"); goto cleanup; } signal(SIGINT, sgxperf_signal_handler); #ifdef _ENABLE_CMEM //Initialise the CMEM module. //CMEM ko should be inserted before this point SGXPERF_printf("Configuring CMEM\n"); CMEM_init(); #endif //Allocate texture for use in GL texturing modes(can also be done from CMEM if memory permits gTest._textureData = (unsigned int*)malloc(gTest.inTextureWidth*gTest.inTextureHeight*4 + PAGE_SIZE); if(!gTest._textureData) { SGXPERF_ERR_printf("ERROR: No malloc memory for allocating texture!\n"); goto cleanup; } delta =(PAGE_SIZE - ((unsigned int)gTest._textureData & (PAGE_SIZE-1))); gTest.textureData = (unsigned int*)((char*)gTest._textureData + delta); memset(gTest.textureData, 0, gTest.inTextureWidth*gTest.inTextureHeight*4); set_texture(gTest.inTextureWidth, gTest.inTextureHeight, (unsigned char*)gTest.textureData, gTest.inPixelFormat); //initialise egl err = common_eglinit(&gTest, testID, gTest.inSurfaceType, &pNativePixmap); if(err) { SGXPERF_ERR_printf("ERROR: eglinit - err = %d\n", err); goto cleanup; } GLuint uiFragShader, uiVertShader; // Used to hold the fragment and vertex shader handles GLuint uiProgramObject; // Used to hold the program handle (made out of the two previous shaders // Create the fragment shader object uiFragShader = glCreateShader(GL_FRAGMENT_SHADER); // Load the source code into it if((testID == 3) || (testID == 5) || (testID == 6) || (testID == 7) || (testID == 14) || (testID == 17)) glShaderSource(uiFragShader, 1, (const char**)&pszFragTextureShader, NULL); else if(testID == 11) //Edge detect with RGB input glShaderSource(uiFragShader, 1, (const char**)&pszFragEdgeRGBDetectShader, NULL); else if(testID == 12) //Edge detect with YUV input glShaderSource(uiFragShader, 1, (const char**)&pszFragEdgeYUVDetectShader, NULL); else if(testID == 8) //IMG texture stream2 glShaderSource(uiFragShader, 1, (const char**)&pszFragIMGTextureStreamShader, NULL); else if(testID == 16) //EGLImage streaming glShaderSource(uiFragShader, 1, (const char**)&pszFragEGLImageShader, NULL); else glShaderSource(uiFragShader, 1, (const char**)&pszFragNoTextureShader, NULL); // Compile the source code glCompileShader(uiFragShader); // Check if compilation succeeded GLint bShaderCompiled; glGetShaderiv(uiFragShader, GL_COMPILE_STATUS, &bShaderCompiled); if (!bShaderCompiled) { // An error happened, first retrieve the length of the log message int i32InfoLogLength, i32CharsWritten; glGetShaderiv(uiFragShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength); // Allocate enough space for the message and retrieve it char* pszInfoLog = new char[i32InfoLogLength]; glGetShaderInfoLog(uiFragShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog); // Displays the error SGXPERF_ERR_printf("Failed to compile fragment shader: %s\n", pszInfoLog); delete [] pszInfoLog; goto cleanup; } // Loads the vertex shader in the same way uiVertShader = glCreateShader(GL_VERTEX_SHADER); if((testID == 3) || (testID == 5) || (testID == 6) || (testID == 7) || (testID == 8) || (testID == 11) || (testID == 12) || (testID == 14) || (testID == 16) || (testID == 17)) glShaderSource(uiVertShader, 1, (const char**)&pszVertTextureShader, NULL); else { SGXPERF_ERR_printf("INFO: Using no-texture vertex shader\n"); glShaderSource(uiVertShader, 1, (const char**)&pszVertNoTextureShader, NULL); } glCompileShader(uiVertShader); glGetShaderiv(uiVertShader, GL_COMPILE_STATUS, &bShaderCompiled); if (!bShaderCompiled) { int i32InfoLogLength, i32CharsWritten; glGetShaderiv(uiVertShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength); char* pszInfoLog = new char[i32InfoLogLength]; glGetShaderInfoLog(uiVertShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog); SGXPERF_ERR_printf("Failed to compile vertex shader: %s\n", pszInfoLog); delete [] pszInfoLog; goto cleanup; } // Create the shader program uiProgramObject = glCreateProgram(); // Attach the fragment and vertex shaders to it glAttachShader(uiProgramObject, uiFragShader); glAttachShader(uiProgramObject, uiVertShader); // Bind the custom vertex attribute "myVertex" to location VERTEX_ARRAY glBindAttribLocation(uiProgramObject, VERTEX_ARRAY, "inVertex"); glBindAttribLocation(uiProgramObject, TEXCOORD_ARRAY, "inTexCoord"); // Link the program glLinkProgram(uiProgramObject); // Check if linking succeeded in the same way we checked for compilation success GLint bLinked; glGetProgramiv(uiProgramObject, GL_LINK_STATUS, &bLinked); if (!bLinked) { int ui32InfoLogLength, ui32CharsWritten; glGetProgramiv(uiProgramObject, GL_INFO_LOG_LENGTH, &ui32InfoLogLength); char* pszInfoLog = new char[ui32InfoLogLength]; glGetProgramInfoLog(uiProgramObject, ui32InfoLogLength, &ui32CharsWritten, pszInfoLog); SGXPERF_ERR_printf("Failed to link program: %s\n", pszInfoLog); delete [] pszInfoLog; goto cleanup; } // Actually use the created program glUseProgram(uiProgramObject); #ifdef _ENABLE_TEST16 if(testID == 16) { int sampler = glGetUniformLocation(uiProgramObject, "yuvTexSampler"); glUniform1i(sampler, 0); } #endif //set rotation variables to init gTest.matrixLocation = glGetUniformLocation(uiProgramObject, "MVPMatrix"); memset(gTest.mat_final, 0, sizeof(gTest.mat_final)); gTest.mat_final[0] = gTest.mat_final[5] = gTest.mat_final[10] = gTest.mat_final[15] = 1.0; glUniformMatrix4fv( gTest.matrixLocation, 1, GL_FALSE, gTest.mat_final); /* Set rowsize for edge detect */ if(testID == 11) { glUniform1f(glGetUniformLocation(uiProgramObject, "rowSize"), 256.0); glUniform1f(glGetUniformLocation(uiProgramObject, "columnSize"), 256.0); } else if(testID == 12) { glUniform1f(glGetUniformLocation(uiProgramObject, "rowSize"), 128.0); glUniform1f(glGetUniformLocation(uiProgramObject, "columnSize"), 160.0); } /* Set clear */ glClearColor(0.2f, 0.8f, 1.0f, 1.0f); // blueish greenish red :) glClear(GL_COLOR_BUFFER_BIT); /* Do various tests */ switch(testID) { case 0: extensions = (char*)glGetString(GL_EXTENSIONS); SGXPERF_ERR_printf("\nTESTID = 0: GL SUPPORTED EXTENSIONS = \n%s\n", extensions); extensions = (char*)eglQueryString(gTest.eglDisplay, EGL_EXTENSIONS); SGXPERF_ERR_printf("\nTESTID = 0: EGL SUPPORTED EXTENSIONS = \n%s\n", extensions); break; case 1: /* Fill entire screen with single colour, no objects */ test1(&gTest); break; case 2: /* Draw a coloured rectangle filling entire screen */ test2(&gTest); break; case 3: /* Move a coloured rectangle of half screen size to another half with same parameters */ test3(&gTest); break; case 4: /* Alpha blending full surface texture */ test4(&gTest); break; case 5: /* Alpha blending full surface WITHOUT texture */ test5(&gTest); break; case 8: #ifdef _ENABLE_TEST8 /* GL_IMG_texture_stream */ test8(&gTest); #endif break; case 10: /* PVR2D test */ test10(&gTest); break; case 11: /* Edge detection test - test3 with new shader */ test3(&gTest); break; #ifdef _ENABLE_TEST8 case 12: /* Edge detection test - test8 with new shader */ test8(&gTest); break; #endif case 13: /* Line drawing */ test13(&gTest); break; #ifdef _ENABLE_TEST14 case 14: /* Context Switch */ test14(&gTest); break; #endif #ifdef _ENABLE_TEST15 case 15: /* YUV-RGB conversion with PVR2D */ test15(&gTest); break; #endif #ifdef _ENABLE_TEST16 case 16: /* YUV-Streaming with EGLImage */ test16(&gTest); break; #endif #ifdef _ENABLE_TEST17 case 17: /* FBO */ test17(&gTest); break; #endif default: /* Sorry guys, we tried ! */ SGXPERF_ERR_printf("No matching test code\n"); break; } #ifdef _ENABLE_CMEM /* PIXMAP loopback test */ if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16 || gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32) { #if 1 /* Use this for checking out the output in the pixmap */ /* For DEBUGGING ONLY */ FILE *fp = fopen("pixmap.raw", "wb"); int numbytes; if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32) numbytes = 4; //ARGB8888 if(gTest.inSurfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16) numbytes = 2; //RGB565 SGXPERF_ERR_printf("Writing pixmap data to file pixmap.raw\n"); fwrite((void*)pNativePixmap->lAddress, 1, gTest.inTextureWidth*gTest.inTextureHeight*numbytes, fp); fclose(fp); #endif } #endif //CMEM needed for pixmap loopback // Frees the OpenGL handles for the program and the 2 shaders glDeleteProgram(uiProgramObject); glDeleteShader(uiFragShader); glDeleteShader(uiVertShader); cleanup: if(gTest._textureData) free(gTest._textureData); common_egldeinit(&gTest, testID, pNativePixmap); #ifdef _ENABLE_CMEM CMEM_exit(); #endif return 0; }
/* * TODO: add some kind of error reporting here */ void play(char *inFileStr) { char *f; long totalframes = 0; long tseconds = 0; struct AUDIO_HEADER header; int bitrate, fs, g, cnt = 0; while ((f = new_next_arg(inFileStr, &inFileStr))) { if (!f || !*f) return; if ((in_file=fopen(f,"r"))==NULL) { if (!do_hook(MODULE_LIST, "AMP ERROR open %s", f)) put_it("Could not open file: %s\n", f); continue; } filesize = file_size(f); initialise_globals(); if ((g=gethdr(&header))!=0) { report_header_error(g); continue; } if (header.protection_bit==0) getcrc(); if (setup_audio(&header)!=0) { yell("Cannot set up audio. Exiting"); continue; } filesize -= sizeof(header); switch (header.layer) { case 1: { if (layer3_frame(&header,cnt)) { yell(" error. blip."); continue; } break; } case 2: { if (layer2_frame(&header,cnt)) { yell(" error. blip."); continue; } break; } default: continue; } bitrate=t_bitrate[header.ID][3-header.layer][header.bitrate_index]; fs=t_sampling_frequency[header.ID][header.sampling_frequency]; if (header.ID) framesize=144000*bitrate/fs; else framesize=72000*bitrate/fs; totalframes = (filesize / (framesize + 1)) - 1; tseconds = (totalframes * 1152/ t_sampling_frequency[header.ID][header.sampling_frequency]); if (A_AUDIO_PLAY) { char *p = strrchr(f, '/'); if (!p) p = f; else p++; if (!do_hook(MODULE_LIST, "AMP PLAY %lu %lu %s", tseconds, filesize, p)) bitchsay("Playing: %s\n", p); } /* * */ if (!(fseek(in_file, 0, SEEK_END))) { char id3_tag[256]; if (!fseek(in_file, -128, SEEK_END) && (fread(id3_tag,128, 1, in_file) == 1)) { if (!strncmp(id3_tag, "TAG", 3)) print_id3_tag(in_file, id3_tag); } fseek(in_file,0,SEEK_SET); } decodeMPEG(&header); do_hook(MODULE_LIST, "AMP CLOSE %s", f); close_audio(); fclose(in_file); } }