1591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian/* 2591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** 3591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** Copyright 2006, The Android Open Source Project 4591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** 5591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** Licensed under the Apache License, Version 2.0 (the "License"); 6591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** you may not use this file except in compliance with the License. 7591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** You may obtain a copy of the License at 8591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** 9591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** http://www.apache.org/licenses/LICENSE-2.0 10591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** 11591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** Unless required by applicable law or agreed to in writing, software 12591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** distributed under the License is distributed on an "AS IS" BASIS, 13591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** See the License for the specific language governing permissions and 15591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian** limitations under the License. 16591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian*/ 17591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 18591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian#define LOG_TAG "fillrate" 19591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 20591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian#include <stdlib.h> 21591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian#include <stdio.h> 22591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 23591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian#include <EGL/egl.h> 24591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian#include <GLES/gl.h> 25591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian#include <GLES/glext.h> 26591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 27591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian#include <utils/StopWatch.h> 28591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian#include <ui/FramebufferNativeWindow.h> 29870b8aa15cb5c722b5d8eb7726eaa5f1a7c23d69Mathias Agopian#include "EGLUtils.h" 30591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 31591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopianusing namespace android; 32591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 33591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopianint main(int argc, char** argv) 34591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian{ 35591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGLint configAttribs[] = { 36591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGL_DEPTH_SIZE, 0, 37591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGL_NONE 38591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian }; 39591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 40591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGLint majorVersion; 41591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGLint minorVersion; 42591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGLContext context; 43653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian EGLConfig config; 44591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGLSurface surface; 45591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGLint w, h; 46591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian EGLDisplay dpy; 47591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 481d3bcd6e217e7ef177287d06f6fdf6149f453830Mathias Agopian EGLNativeWindowType window = android_createDisplaySurface(); 491d3bcd6e217e7ef177287d06f6fdf6149f453830Mathias Agopian 50591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 51591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglInitialize(dpy, &majorVersion, &minorVersion); 52653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian 53653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian status_t err = EGLUtils::selectConfigForNativeWindow( 54653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian dpy, configAttribs, window, &config); 55653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian if (err) { 56653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); 57653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian return 0; 58591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 59653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian 60653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian surface = eglCreateWindowSurface(dpy, config, window, NULL); 61591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian context = eglCreateContext(dpy, config, NULL, NULL); 62591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglMakeCurrent(dpy, surface, surface, context); 63591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglQuerySurface(dpy, surface, EGL_WIDTH, &w); 64591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); 65591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 66591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian printf("w=%d, h=%d\n", w, h); 67591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 68591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glBindTexture(GL_TEXTURE_2D, 0); 69591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 70591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 711c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 721c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 73591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 74591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 75591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glDisable(GL_DITHER); 761c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glEnable(GL_BLEND); 77591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glEnable(GL_TEXTURE_2D); 78591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glColor4f(1,1,1,1); 79591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 80591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian uint32_t* t32 = (uint32_t*)malloc(512*512*4); 81591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian for (int y=0 ; y<512 ; y++) { 82591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian for (int x=0 ; x<512 ; x++) { 831c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian int u = x-256; 841c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian int v = y-256; 851c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian if (u*u+v*v < 256*256) { 861c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian t32[x+y*512] = 0x10FFFFFF; 871c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } else { 881c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian t32[x+y*512] = 0x20FF0000; 891c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } 90591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 91591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 92591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 93591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian const GLfloat vertices[4][2] = { 94591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 0, 0 }, 95591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 0, h }, 96591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { w, h }, 97591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { w, 0 } 98591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian }; 99591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 100591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian const GLfloat texCoords[4][2] = { 101591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 0, 0 }, 102591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 0, 1 }, 103591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 1, 1 }, 104591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 1, 0 } 105591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian }; 106591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 107591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32); 108591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 109591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glViewport(0, 0, w, h); 110591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glMatrixMode(GL_PROJECTION); 111591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glLoadIdentity(); 112591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glOrthof(0, w, 0, h, 0, 1); 113591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 114591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glEnableClientState(GL_VERTEX_ARRAY); 115591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glEnableClientState(GL_TEXTURE_COORD_ARRAY); 1161c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glVertexPointer(2, GL_FLOAT, 0, vertices); 117591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexCoordPointer(2, GL_FLOAT, 0, texCoords); 118591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 1191c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian eglSwapInterval(dpy, 1); 1201c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 121591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glClearColor(1,0,0,0); 122591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glClear(GL_COLOR_BUFFER_BIT); 123591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 124591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglSwapBuffers(dpy, surface); 125591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 1261c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1271c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian nsecs_t times[32]; 1281c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1291c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian for (int c=1 ; c<32 ; c++) { 1301c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glClear(GL_COLOR_BUFFER_BIT); 1311c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian for (int i=0 ; i<c ; i++) { 1321c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 1331c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } 1341c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian eglSwapBuffers(dpy, surface); 1351c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } 1361c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1371c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1381c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian // for (int c=31 ; c>=1 ; c--) { 1391c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian int j=0; 140591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian for (int c=1 ; c<32 ; c++) { 141591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glClear(GL_COLOR_BUFFER_BIT); 142591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian nsecs_t now = systemTime(); 143591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian for (int i=0 ; i<c ; i++) { 144591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 145591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 146591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglSwapBuffers(dpy, surface); 147591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian nsecs_t t = systemTime() - now; 1481c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian times[j++] = t; 1491c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } 1501c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1511c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian for (int c=1, j=0 ; c<32 ; c++, j++) { 1521c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian nsecs_t t = times[j]; 153591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0); 154591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 1551c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1561c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1571c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1581c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian eglTerminate(dpy); 1591c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 160591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian return 0; 161591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian} 162