3 ** Copyright 2006, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
18 #define LOG_TAG "fillrate"
25 #include <GLES/glext.h>
27 #include <utils/StopWatch.h>
28 #include <WindowSurface.h>
31 using namespace android;
33 int main(int argc, char** argv)
35 EGLint configAttribs[] = {
48 WindowSurface windowSurface;
49 EGLNativeWindowType window = windowSurface.getSurface();
51 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
52 eglInitialize(dpy, &majorVersion, &minorVersion);
54 status_t err = EGLUtils::selectConfigForNativeWindow(
55 dpy, configAttribs, window, &config);
57 fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n");
61 surface = eglCreateWindowSurface(dpy, config, window, NULL);
62 context = eglCreateContext(dpy, config, NULL, NULL);
63 eglMakeCurrent(dpy, surface, surface, context);
64 eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
65 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
67 printf("w=%d, h=%d\n", w, h);
69 glBindTexture(GL_TEXTURE_2D, 0);
70 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
71 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
72 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
73 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
74 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
75 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
78 glEnable(GL_TEXTURE_2D);
81 uint32_t* t32 = (uint32_t*)malloc(512*512*4);
82 for (int y=0 ; y<512 ; y++) {
83 for (int x=0 ; x<512 ; x++) {
86 if (u*u+v*v < 256*256) {
87 t32[x+y*512] = 0x10FFFFFF;
89 t32[x+y*512] = 0x20FF0000;
94 const GLfloat vertices[4][2] = {
101 const GLfloat texCoords[4][2] = {
108 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
110 glViewport(0, 0, w, h);
111 glMatrixMode(GL_PROJECTION);
113 glOrthof(0, w, 0, h, 0, 1);
115 glEnableClientState(GL_VERTEX_ARRAY);
116 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
117 glVertexPointer(2, GL_FLOAT, 0, vertices);
118 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
120 eglSwapInterval(dpy, 1);
122 glClearColor(1,0,0,0);
123 glClear(GL_COLOR_BUFFER_BIT);
124 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
125 eglSwapBuffers(dpy, surface);
130 for (int c=1 ; c<32 ; c++) {
131 glClear(GL_COLOR_BUFFER_BIT);
132 for (int i=0 ; i<c ; i++) {
133 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
135 eglSwapBuffers(dpy, surface);
139 // for (int c=31 ; c>=1 ; c--) {
141 for (int c=1 ; c<32 ; c++) {
142 glClear(GL_COLOR_BUFFER_BIT);
143 nsecs_t now = systemTime();
144 for (int i=0 ; i<c ; i++) {
145 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
147 eglSwapBuffers(dpy, surface);
148 nsecs_t t = systemTime() - now;
152 for (int c=1, j=0 ; c<32 ; c++, j++) {
153 nsecs_t t = times[j];
154 printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0);