Home | History | Annotate | Download | only in finish
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <stdlib.h>
     18 #include <stdio.h>
     19 #include <time.h>
     20 #include <sched.h>
     21 #include <sys/resource.h>
     22 
     23 #include <EGL/egl.h>
     24 #include <GLES/gl.h>
     25 #include <GLES/glext.h>
     26 
     27 #include <utils/Timers.h>
     28 
     29 #include <ui/FramebufferNativeWindow.h>
     30 #include "EGLUtils.h"
     31 
     32 using namespace android;
     33 
     34 int main(int argc, char** argv)
     35 {
     36     EGLint configAttribs[] = {
     37          EGL_DEPTH_SIZE, 0,
     38          EGL_NONE
     39      };
     40 
     41      EGLint majorVersion;
     42      EGLint minorVersion;
     43      EGLContext context;
     44      EGLConfig config;
     45      EGLSurface surface;
     46      EGLint w, h;
     47      EGLDisplay dpy;
     48 
     49      EGLNativeWindowType window = android_createDisplaySurface();
     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      GLint dim = w<h ? w : h;
     67 
     68      glBindTexture(GL_TEXTURE_2D, 0);
     69      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     70      glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     71      glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     72      glEnable(GL_TEXTURE_2D);
     73      glColor4f(1,1,1,1);
     74      glDisable(GL_DITHER);
     75      glShadeModel(GL_FLAT);
     76 
     77      long long now, t;
     78      int i;
     79 
     80      char* texels = (char*)malloc(512*512*2);
     81      memset(texels,0xFF,512*512*2);
     82 
     83      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
     84              512, 512, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, texels);
     85 
     86      char* dst = (char*)malloc(320*480*2);
     87      memset(dst, 0, 320*480*2);
     88      printf("307200 bytes memcpy\n");
     89      for (i=0 ; i<4 ; i++) {
     90          now = systemTime();
     91          memcpy(dst, texels, 320*480*2);
     92          t = systemTime();
     93          printf("memcpy() time = %llu us\n", (t-now)/1000);
     94          fflush(stdout);
     95      }
     96      free(dst);
     97 
     98      free(texels);
     99 
    100      setpriority(PRIO_PROCESS, 0, -20);
    101 
    102      printf("512x512 unmodified texture, 512x512 blit:\n");
    103      glClear(GL_COLOR_BUFFER_BIT);
    104      for (i=0 ; i<4 ; i++) {
    105          GLint crop[4] = { 0, 512, 512, -512 };
    106          glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
    107          now = systemTime();
    108          glDrawTexiOES(0, 0, 0, 512, 512);
    109          glFinish();
    110          t = systemTime();
    111          printf("glFinish() time = %llu us\n", (t-now)/1000);
    112          fflush(stdout);
    113          eglSwapBuffers(dpy, surface);
    114      }
    115 
    116      printf("512x512 unmodified texture, 1x1 blit:\n");
    117      glClear(GL_COLOR_BUFFER_BIT);
    118      for (i=0 ; i<4 ; i++) {
    119          GLint crop[4] = { 0, 1, 1, -1 };
    120          glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
    121          now = systemTime();
    122          glDrawTexiOES(0, 0, 0, 1, 1);
    123          glFinish();
    124          t = systemTime();
    125          printf("glFinish() time = %llu us\n", (t-now)/1000);
    126          fflush(stdout);
    127          eglSwapBuffers(dpy, surface);
    128      }
    129 
    130      printf("512x512 unmodified texture, 512x512 blit (x2):\n");
    131      glClear(GL_COLOR_BUFFER_BIT);
    132      for (i=0 ; i<4 ; i++) {
    133          GLint crop[4] = { 0, 512, 512, -512 };
    134          glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
    135          now = systemTime();
    136          glDrawTexiOES(0, 0, 0, 512, 512);
    137          glDrawTexiOES(0, 0, 0, 512, 512);
    138          glFinish();
    139          t = systemTime();
    140          printf("glFinish() time = %llu us\n", (t-now)/1000);
    141          fflush(stdout);
    142          eglSwapBuffers(dpy, surface);
    143      }
    144 
    145      printf("512x512 unmodified texture, 1x1 blit (x2):\n");
    146      glClear(GL_COLOR_BUFFER_BIT);
    147      for (i=0 ; i<4 ; i++) {
    148          GLint crop[4] = { 0, 1, 1, -1 };
    149          glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
    150          now = systemTime();
    151          glDrawTexiOES(0, 0, 0, 1, 1);
    152          glDrawTexiOES(0, 0, 0, 1, 1);
    153          glFinish();
    154          t = systemTime();
    155          printf("glFinish() time = %llu us\n", (t-now)/1000);
    156          fflush(stdout);
    157          eglSwapBuffers(dpy, surface);
    158      }
    159 
    160 
    161      printf("512x512 (1x1 texel MODIFIED texture), 512x512 blit:\n");
    162      glClear(GL_COLOR_BUFFER_BIT);
    163      for (i=0 ; i<4 ; i++) {
    164          uint16_t green = 0x7E0;
    165          GLint crop[4] = { 0, 512, 512, -512 };
    166          glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
    167          glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &green);
    168          now = systemTime();
    169          glDrawTexiOES(0, 0, 0, 512, 512);
    170          glFinish();
    171          t = systemTime();
    172          printf("glFinish() time = %llu us\n", (t-now)/1000);
    173          fflush(stdout);
    174          eglSwapBuffers(dpy, surface);
    175      }
    176 
    177 
    178      int16_t texel = 0xF800;
    179      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
    180              1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &texel);
    181 
    182      printf("1x1 unmodified texture, 1x1 blit:\n");
    183      glClear(GL_COLOR_BUFFER_BIT);
    184      for (i=0 ; i<4 ; i++) {
    185          GLint crop[4] = { 0, 1, 1, -1 };
    186          glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
    187          now = systemTime();
    188          glDrawTexiOES(0, 0, 0, 1, 1);
    189          glFinish();
    190          t = systemTime();
    191          printf("glFinish() time = %llu us\n", (t-now)/1000);
    192          eglSwapBuffers(dpy, surface);
    193      }
    194 
    195      printf("1x1 unmodified texture, 512x512 blit:\n");
    196      glClear(GL_COLOR_BUFFER_BIT);
    197      for (i=0 ; i<4 ; i++) {
    198          GLint crop[4] = { 0, 1, 1, -1 };
    199          glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
    200          now = systemTime();
    201          glDrawTexiOES(0, 0, 0, 512, 512);
    202          glFinish();
    203          t = systemTime();
    204          printf("glFinish() time = %llu us\n", (t-now)/1000);
    205          fflush(stdout);
    206          eglSwapBuffers(dpy, surface);
    207      }
    208 
    209      printf("1x1 (1x1 texel MODIFIED texture), 512x512 blit:\n");
    210      glClear(GL_COLOR_BUFFER_BIT);
    211      for (i=0 ; i<4 ; i++) {
    212          uint16_t green = 0x7E0;
    213          GLint crop[4] = { 0, 1, 1, -1 };
    214          glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
    215          glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &green);
    216          now = systemTime();
    217          glDrawTexiOES(0, 0, 0, 1, 1);
    218          glFinish();
    219          t = systemTime();
    220          printf("glFinish() time = %llu us\n", (t-now)/1000);
    221          fflush(stdout);
    222          eglSwapBuffers(dpy, surface);
    223      }
    224 
    225      return 0;
    226 }
    227