Home | History | Annotate | Download | only in fillrate
      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 <WindowSurface.h>
     29 #include <EGLUtils.h>
     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 
     40      EGLint majorVersion;
     41      EGLint minorVersion;
     42      EGLContext context;
     43      EGLConfig config;
     44      EGLSurface surface;
     45      EGLint w, h;
     46      EGLDisplay dpy;
     47 
     48      WindowSurface windowSurface;
     49      EGLNativeWindowType window = windowSurface.getSurface();
     50 
     51      dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     52      eglInitialize(dpy, &majorVersion, &minorVersion);
     53 
     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;
     59      }
     60 
     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);
     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);
     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);
     76      glDisable(GL_DITHER);
     77      glEnable(GL_BLEND);
     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++) {
     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              }
     91          }
     92      }
     93 
     94      const GLfloat fh = h;
     95      const GLfloat fw = w;
     96      const GLfloat vertices[4][2] = {
     97              { 0,   0  },
     98              { 0,   fh },
     99              { fw,  fh },
    100              { fw,  0  }
    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);
    119      glVertexPointer(2, GL_FLOAT, 0, vertices);
    120      glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    121 
    122      eglSwapInterval(dpy, 1);
    123 
    124      glClearColor(1,0,0,0);
    125      glClear(GL_COLOR_BUFFER_BIT);
    126      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    127      eglSwapBuffers(dpy, surface);
    128 
    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;
    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;
    151          times[j++] = t;
    152      }
    153 
    154      for (int c=1, j=0 ; c<32 ; c++, j++) {
    155          nsecs_t t = times[j];
    156          printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0);
    157      }
    158 
    159 
    160 
    161      eglTerminate(dpy);
    162 
    163      return 0;
    164 }
    165