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> 286ef57d7b368ebbac5f2b27c36a9032fee1cda8b1Andy McFadden#include <WindowSurface.h> 296ef57d7b368ebbac5f2b27c36a9032fee1cda8b1Andy McFadden#include <EGLUtils.h> 30591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 31591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopianusing namespace android; 32591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 3311e77b524ecfb10e3d79c1481d560e9d6f6fcda5Chih-Hung Hsiehint 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 486ef57d7b368ebbac5f2b27c36a9032fee1cda8b1Andy McFadden WindowSurface windowSurface; 496ef57d7b368ebbac5f2b27c36a9032fee1cda8b1Andy McFadden EGLNativeWindowType window = windowSurface.getSurface(); 501d3bcd6e217e7ef177287d06f6fdf6149f453830Mathias Agopian 51591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 52591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglInitialize(dpy, &majorVersion, &minorVersion); 53653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian 54653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian status_t err = EGLUtils::selectConfigForNativeWindow( 55653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian dpy, configAttribs, window, &config); 56653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian if (err) { 57653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); 58653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian return 0; 59591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 60653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian 61653870d5e945ff94ff8136c97db0a016fc119683Mathias Agopian surface = eglCreateWindowSurface(dpy, config, window, NULL); 62591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian context = eglCreateContext(dpy, config, NULL, NULL); 63591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglMakeCurrent(dpy, surface, surface, context); 64591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglQuerySurface(dpy, surface, EGL_WIDTH, &w); 65591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); 66591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 67591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian printf("w=%d, h=%d\n", w, h); 68591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 69591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glBindTexture(GL_TEXTURE_2D, 0); 70591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 71591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 721c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 731c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 74591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 75591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 76591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glDisable(GL_DITHER); 771c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glEnable(GL_BLEND); 78591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glEnable(GL_TEXTURE_2D); 79591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glColor4f(1,1,1,1); 80591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 81591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian uint32_t* t32 = (uint32_t*)malloc(512*512*4); 82591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian for (int y=0 ; y<512 ; y++) { 83591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian for (int x=0 ; x<512 ; x++) { 841c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian int u = x-256; 851c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian int v = y-256; 861c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian if (u*u+v*v < 256*256) { 871c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian t32[x+y*512] = 0x10FFFFFF; 881c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } else { 891c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian t32[x+y*512] = 0x20FF0000; 901c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } 91591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 92591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 93591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 943bded9177b579d96d72397d73b8f85bba47ec438Chih-Hung Hsieh const GLfloat fh = h; 953bded9177b579d96d72397d73b8f85bba47ec438Chih-Hung Hsieh const GLfloat fw = w; 96591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian const GLfloat vertices[4][2] = { 973bded9177b579d96d72397d73b8f85bba47ec438Chih-Hung Hsieh { 0, 0 }, 983bded9177b579d96d72397d73b8f85bba47ec438Chih-Hung Hsieh { 0, fh }, 993bded9177b579d96d72397d73b8f85bba47ec438Chih-Hung Hsieh { fw, fh }, 1003bded9177b579d96d72397d73b8f85bba47ec438Chih-Hung Hsieh { fw, 0 } 101591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian }; 102591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 103591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian const GLfloat texCoords[4][2] = { 104591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 0, 0 }, 105591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 0, 1 }, 106591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 1, 1 }, 107591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian { 1, 0 } 108591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian }; 109591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 110591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32); 111591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 112591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glViewport(0, 0, w, h); 113591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glMatrixMode(GL_PROJECTION); 114591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glLoadIdentity(); 115591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glOrthof(0, w, 0, h, 0, 1); 116591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 117591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glEnableClientState(GL_VERTEX_ARRAY); 118591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glEnableClientState(GL_TEXTURE_COORD_ARRAY); 1191c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glVertexPointer(2, GL_FLOAT, 0, vertices); 120591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glTexCoordPointer(2, GL_FLOAT, 0, texCoords); 121591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 1221c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian eglSwapInterval(dpy, 1); 1231c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 124591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glClearColor(1,0,0,0); 125591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glClear(GL_COLOR_BUFFER_BIT); 126591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 127591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglSwapBuffers(dpy, surface); 128591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian 1291c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1301c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian nsecs_t times[32]; 1311c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1321c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian for (int c=1 ; c<32 ; c++) { 1331c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glClear(GL_COLOR_BUFFER_BIT); 1341c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian for (int i=0 ; i<c ; i++) { 1351c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 1361c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } 1371c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian eglSwapBuffers(dpy, surface); 1381c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } 1391c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1401c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1411c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian // for (int c=31 ; c>=1 ; c--) { 1421c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian int j=0; 143591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian for (int c=1 ; c<32 ; c++) { 144591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glClear(GL_COLOR_BUFFER_BIT); 145591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian nsecs_t now = systemTime(); 146591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian for (int i=0 ; i<c ; i++) { 147591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 148591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 149591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian eglSwapBuffers(dpy, surface); 150591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian nsecs_t t = systemTime() - now; 1511c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian times[j++] = t; 1521c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian } 1531c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1541c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian for (int c=1, j=0 ; c<32 ; c++, j++) { 1551c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian nsecs_t t = times[j]; 1567e9cd8e8f8395f2a00946c477a4a52912beadbe0Chih-Hung Hsieh printf("%lld\t%d\t%f\n", (long long)t, c, (double(t)/c)/1000000.0); 157591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian } 1581c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1591c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1601c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 1611c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian eglTerminate(dpy); 1621c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 163591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian return 0; 164591018aaf9e95b9d2f6d9742194e940605b1bffaMathias Agopian} 165