| 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> | 
| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 28 | #include <WindowSurface.h> | 
 | 29 | #include <EGLUtils.h> | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 30 |  | 
 | 31 | using namespace android; | 
 | 32 |  | 
| Kalle Raita | 9c93848 | 2017-06-26 16:15:06 -0700 | [diff] [blame] | 33 | int main(int /*argc*/, char** /*argv*/) | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 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 |  | 
| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 48 |      WindowSurface windowSurface; | 
 | 49 |      EGLNativeWindowType window = windowSurface.getSurface(); | 
| Mathias Agopian | 1d3bcd6 | 2009-08-10 16:48:22 -0700 | [diff] [blame] | 50 |       | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 51 |      dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 
 | 52 |      eglInitialize(dpy, &majorVersion, &minorVersion); | 
| Mathias Agopian | 653870d | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 53 |            | 
| Mathias Agopian | 653870d | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 54 |      status_t err = EGLUtils::selectConfigForNativeWindow( | 
 | 55 |              dpy, configAttribs, window, &config); | 
 | 56 |      if (err) { | 
 | 57 |          fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n"); | 
 | 58 |          return 0; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 59 |      } | 
| Mathias Agopian | 653870d | 2009-08-06 16:25:37 -0700 | [diff] [blame] | 60 |  | 
 | 61 |      surface = eglCreateWindowSurface(dpy, config, window, NULL); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 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); | 
 | 66 |       | 
 | 67 |      printf("w=%d, h=%d\n", w, h); | 
 | 68 |       | 
 | 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); | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 72 |      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | 
 | 73 |      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 74 |      glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 
 | 75 |      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 
 | 76 |      glDisable(GL_DITHER); | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 77 |      glEnable(GL_BLEND); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 78 |      glEnable(GL_TEXTURE_2D); | 
 | 79 |      glColor4f(1,1,1,1); | 
 | 80 |  | 
 | 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++) { | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 84 |              int u = x-256; | 
 | 85 |              int v = y-256; | 
 | 86 |              if (u*u+v*v < 256*256) { | 
 | 87 |                  t32[x+y*512] = 0x10FFFFFF; | 
 | 88 |              } else { | 
 | 89 |                  t32[x+y*512] = 0x20FF0000; | 
 | 90 |              } | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 91 |          } | 
 | 92 |      } | 
 | 93 |  | 
| Chih-Hung Hsieh | 3bded91 | 2014-12-11 10:39:59 -0800 | [diff] [blame] | 94 |      const GLfloat fh = h; | 
 | 95 |      const GLfloat fw = w; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 96 |      const GLfloat vertices[4][2] = { | 
| Chih-Hung Hsieh | 3bded91 | 2014-12-11 10:39:59 -0800 | [diff] [blame] | 97 |              { 0,   0  }, | 
 | 98 |              { 0,   fh }, | 
 | 99 |              { fw,  fh }, | 
 | 100 |              { fw,  0  } | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 101 |      }; | 
 | 102 |  | 
 | 103 |      const GLfloat texCoords[4][2] = { | 
 | 104 |              { 0,  0 }, | 
 | 105 |              { 0,  1 }, | 
 | 106 |              { 1,  1 }, | 
 | 107 |              { 1,  0 } | 
 | 108 |      }; | 
 | 109 |  | 
 | 110 |      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32); | 
 | 111 |  | 
 | 112 |      glViewport(0, 0, w, h); | 
 | 113 |      glMatrixMode(GL_PROJECTION); | 
 | 114 |      glLoadIdentity(); | 
 | 115 |      glOrthof(0, w, 0, h, 0, 1); | 
 | 116 |  | 
 | 117 |      glEnableClientState(GL_VERTEX_ARRAY); | 
 | 118 |      glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 119 |      glVertexPointer(2, GL_FLOAT, 0, vertices); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 120 |      glTexCoordPointer(2, GL_FLOAT, 0, texCoords); | 
 | 121 |  | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 122 |      eglSwapInterval(dpy, 1); | 
 | 123 |  | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 124 |      glClearColor(1,0,0,0); | 
 | 125 |      glClear(GL_COLOR_BUFFER_BIT); | 
 | 126 |      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);  | 
 | 127 |      eglSwapBuffers(dpy, surface); | 
 | 128 |       | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 129 |  | 
 | 130 |      nsecs_t times[32]; | 
 | 131 |  | 
 | 132 |      for (int c=1 ; c<32 ; c++) { | 
 | 133 |          glClear(GL_COLOR_BUFFER_BIT); | 
 | 134 |          for (int i=0 ; i<c ; i++) { | 
 | 135 |              glDrawArrays(GL_TRIANGLE_FAN, 0, 4);  | 
 | 136 |          } | 
 | 137 |          eglSwapBuffers(dpy, surface); | 
 | 138 |      } | 
 | 139 |  | 
 | 140 |  | 
 | 141 |      //     for (int c=31 ; c>=1 ; c--) { | 
 | 142 |      int j=0; | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 143 |      for (int c=1 ; c<32 ; c++) { | 
 | 144 |          glClear(GL_COLOR_BUFFER_BIT); | 
 | 145 |          nsecs_t now = systemTime(); | 
 | 146 |          for (int i=0 ; i<c ; i++) { | 
 | 147 |              glDrawArrays(GL_TRIANGLE_FAN, 0, 4);  | 
 | 148 |          } | 
 | 149 |          eglSwapBuffers(dpy, surface); | 
 | 150 |          nsecs_t t = systemTime() - now; | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 151 |          times[j++] = t; | 
 | 152 |      } | 
 | 153 |  | 
 | 154 |      for (int c=1, j=0 ; c<32 ; c++, j++) { | 
 | 155 |          nsecs_t t = times[j]; | 
| Kalle Raita | 9c93848 | 2017-06-26 16:15:06 -0700 | [diff] [blame] | 156 |          printf("%ld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0); | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 157 |      } | 
| Mathias Agopian | 1c3561e | 2009-08-05 17:38:49 -0700 | [diff] [blame] | 158 |  | 
 | 159 |  | 
 | 160 |         | 
 | 161 |      eglTerminate(dpy); | 
 | 162 |       | 
| Mathias Agopian | 591018a | 2009-08-04 13:43:35 -0700 | [diff] [blame] | 163 |      return 0; | 
 | 164 | } |