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 <ui/FramebufferNativeWindow.h>
     29 #include <ui/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      EGLNativeWindowType window = android_createDisplaySurface();
     49 
     50      dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     51      eglInitialize(dpy, &majorVersion, &minorVersion);
     52 
     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;
     58      }
     59 
     60      surface = eglCreateWindowSurface(dpy, config, window, NULL);
     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);
     71      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     72      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     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);
     76      glEnable(GL_BLEND);
     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++) {
     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              }
     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);
    116      glVertexPointer(2, GL_FLOAT, 0, vertices);
    117      glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    118 
    119      eglSwapInterval(dpy, 1);
    120 
    121      glClearColor(1,0,0,0);
    122      glClear(GL_COLOR_BUFFER_BIT);
    123      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    124      eglSwapBuffers(dpy, surface);
    125 
    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;
    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;
    148          times[j++] = t;
    149      }
    150 
    151      for (int c=1, j=0 ; c<32 ; c++, j++) {
    152          nsecs_t t = times[j];
    153          printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0);
    154      }
    155 
    156 
    157 
    158      eglTerminate(dpy);
    159 
    160      return 0;
    161 }
    162