| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | ** | 
|  | 3 | ** Copyright 2006, The Android Open Source Project | 
|  | 4 | ** | 
|  | 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 | 
|  | 8 | ** | 
|  | 9 | **     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 10 | ** | 
|  | 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. | 
|  | 16 | */ | 
|  | 17 |  | 
|  | 18 | #define LOG_TAG "fillrate" | 
|  | 19 |  | 
|  | 20 | #include <stdlib.h> | 
|  | 21 | #include <stdio.h> | 
|  | 22 |  | 
|  | 23 | #include <EGL/egl.h> | 
|  | 24 | #include <GLES/gl.h> | 
|  | 25 | #include <GLES/glext.h> | 
|  | 26 |  | 
|  | 27 | #include <utils/StopWatch.h> | 
|  | 28 | #include <ui/FramebufferNativeWindow.h> | 
| Mathias Agopian | 870b8aa | 2012-02-24 16:42:46 -0800 | [diff] [blame] | 29 | #include "EGLUtils.h" | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 30 |  | 
|  | 31 | using namespace android; | 
|  | 32 |  | 
|  | 33 | int main(int argc, char** argv) | 
|  | 34 | { | 
|  | 35 | EGLint configAttribs[] = { | 
|  | 36 | EGL_DEPTH_SIZE, 0, | 
|  | 37 | EGL_NONE | 
|  | 38 | }; | 
|  | 39 |  | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 40 | EGLint majorVersion; | 
|  | 41 | EGLint minorVersion; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 42 | EGLContext context; | 
| Mathias Agopian | 653870d | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 43 | EGLConfig config; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 44 | EGLSurface surface; | 
|  | 45 | EGLint w, h; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 46 | EGLDisplay dpy; | 
|  | 47 |  | 
| Mathias Agopian | 1d3bcd6 | 2009-08-10 16:48:22 -0700 | [diff] [blame] | 48 | EGLNativeWindowType window = android_createDisplaySurface(); | 
|  | 49 |  | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 50 | dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 
|  | 51 | eglInitialize(dpy, &majorVersion, &minorVersion); | 
| Mathias Agopian | 653870d | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 52 |  | 
| Mathias Agopian | 653870d | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 53 | status_t err = EGLUtils::selectConfigForNativeWindow( | 
|  | 54 | dpy, configAttribs, window, &config); | 
|  | 55 | if (err) { | 
|  | 56 | fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); | 
|  | 57 | return 0; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 58 | } | 
| Mathias Agopian | 653870d | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 59 |  | 
|  | 60 | surface = eglCreateWindowSurface(dpy, config, window, NULL); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 61 | context = eglCreateContext(dpy, config, NULL, NULL); | 
|  | 62 | eglMakeCurrent(dpy, surface, surface, context); | 
|  | 63 | eglQuerySurface(dpy, surface, EGL_WIDTH, &w); | 
|  | 64 | eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); | 
|  | 65 |  | 
|  | 66 | printf("w=%d, h=%d\n", w, h); | 
|  | 67 |  | 
|  | 68 | glBindTexture(GL_TEXTURE_2D, 0); | 
|  | 69 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 
|  | 70 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 71 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | 
|  | 72 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 73 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 
|  | 74 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 
|  | 75 | glDisable(GL_DITHER); | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 76 | glEnable(GL_BLEND); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 77 | glEnable(GL_TEXTURE_2D); | 
|  | 78 | glColor4f(1,1,1,1); | 
|  | 79 |  | 
|  | 80 | uint32_t* t32 = (uint32_t*)malloc(512*512*4); | 
|  | 81 | for (int y=0 ; y<512 ; y++) { | 
|  | 82 | for (int x=0 ; x<512 ; x++) { | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 83 | int u = x-256; | 
|  | 84 | int v = y-256; | 
|  | 85 | if (u*u+v*v < 256*256) { | 
|  | 86 | t32[x+y*512] = 0x10FFFFFF; | 
|  | 87 | } else { | 
|  | 88 | t32[x+y*512] = 0x20FF0000; | 
|  | 89 | } | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 90 | } | 
|  | 91 | } | 
|  | 92 |  | 
|  | 93 | const GLfloat vertices[4][2] = { | 
|  | 94 | { 0,  0 }, | 
|  | 95 | { 0,  h }, | 
|  | 96 | { w,  h }, | 
|  | 97 | { w,  0 } | 
|  | 98 | }; | 
|  | 99 |  | 
|  | 100 | const GLfloat texCoords[4][2] = { | 
|  | 101 | { 0,  0 }, | 
|  | 102 | { 0,  1 }, | 
|  | 103 | { 1,  1 }, | 
|  | 104 | { 1,  0 } | 
|  | 105 | }; | 
|  | 106 |  | 
|  | 107 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32); | 
|  | 108 |  | 
|  | 109 | glViewport(0, 0, w, h); | 
|  | 110 | glMatrixMode(GL_PROJECTION); | 
|  | 111 | glLoadIdentity(); | 
|  | 112 | glOrthof(0, w, 0, h, 0, 1); | 
|  | 113 |  | 
|  | 114 | glEnableClientState(GL_VERTEX_ARRAY); | 
|  | 115 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 116 | glVertexPointer(2, GL_FLOAT, 0, vertices); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 117 | glTexCoordPointer(2, GL_FLOAT, 0, texCoords); | 
|  | 118 |  | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 119 | eglSwapInterval(dpy, 1); | 
|  | 120 |  | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 121 | glClearColor(1,0,0,0); | 
|  | 122 | glClear(GL_COLOR_BUFFER_BIT); | 
|  | 123 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
|  | 124 | eglSwapBuffers(dpy, surface); | 
|  | 125 |  | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 126 |  | 
|  | 127 | nsecs_t times[32]; | 
|  | 128 |  | 
|  | 129 | for (int c=1 ; c<32 ; c++) { | 
|  | 130 | glClear(GL_COLOR_BUFFER_BIT); | 
|  | 131 | for (int i=0 ; i<c ; i++) { | 
|  | 132 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
|  | 133 | } | 
|  | 134 | eglSwapBuffers(dpy, surface); | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 |  | 
|  | 138 | //     for (int c=31 ; c>=1 ; c--) { | 
|  | 139 | int j=0; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 140 | for (int c=1 ; c<32 ; c++) { | 
|  | 141 | glClear(GL_COLOR_BUFFER_BIT); | 
|  | 142 | nsecs_t now = systemTime(); | 
|  | 143 | for (int i=0 ; i<c ; i++) { | 
|  | 144 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
|  | 145 | } | 
|  | 146 | eglSwapBuffers(dpy, surface); | 
|  | 147 | nsecs_t t = systemTime() - now; | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 148 | times[j++] = t; | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | for (int c=1, j=0 ; c<32 ; c++, j++) { | 
|  | 152 | nsecs_t t = times[j]; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 153 | printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0); | 
|  | 154 | } | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 155 |  | 
|  | 156 |  | 
|  | 157 |  | 
|  | 158 | eglTerminate(dpy); | 
|  | 159 |  | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 160 | return 0; | 
|  | 161 | } |