The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 28 | long long systemTime() |
| 29 | { |
| 30 | struct timespec t; |
| 31 | t.tv_sec = t.tv_nsec = 0; |
| 32 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 33 | return (long long)(t.tv_sec)*1000000000LL + t.tv_nsec; |
| 34 | } |
| 35 | |
| 36 | int main(int argc, char** argv) |
| 37 | { |
| 38 | EGLint s_configAttribs[] = { |
| 39 | EGL_RED_SIZE, 5, |
| 40 | EGL_GREEN_SIZE, 6, |
| 41 | EGL_BLUE_SIZE, 5, |
| 42 | EGL_NONE |
| 43 | }; |
| 44 | |
| 45 | EGLint numConfigs = -1; |
| 46 | EGLint majorVersion; |
| 47 | EGLint minorVersion; |
| 48 | EGLConfig config; |
| 49 | EGLContext context; |
| 50 | EGLSurface surface; |
| 51 | EGLint w, h; |
| 52 | |
| 53 | EGLDisplay dpy; |
| 54 | |
| 55 | dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 56 | eglInitialize(dpy, &majorVersion, &minorVersion); |
| 57 | eglChooseConfig(dpy, s_configAttribs, &config, 1, &numConfigs); |
| 58 | surface = eglCreateWindowSurface(dpy, config, |
| 59 | android_createDisplaySurface(), NULL); |
| 60 | context = eglCreateContext(dpy, config, NULL, NULL); |
| 61 | eglMakeCurrent(dpy, surface, surface, context); |
| 62 | eglQuerySurface(dpy, surface, EGL_WIDTH, &w); |
| 63 | eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); |
| 64 | GLint dim = w<h ? w : h; |
| 65 | |
| 66 | glBindTexture(GL_TEXTURE_2D, 0); |
| 67 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 68 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 69 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 70 | glEnable(GL_TEXTURE_2D); |
| 71 | glColor4f(1,1,1,1); |
| 72 | glDisable(GL_DITHER); |
| 73 | glShadeModel(GL_FLAT); |
| 74 | |
| 75 | long long now, t; |
| 76 | int i; |
| 77 | |
| 78 | char* texels = malloc(512*512*2); |
| 79 | memset(texels,0xFF,512*512*2); |
| 80 | |
| 81 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, |
| 82 | 512, 512, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, texels); |
| 83 | |
| 84 | char* dst = malloc(320*480*2); |
| 85 | memset(dst, 0, 320*480*2); |
| 86 | printf("307200 bytes memcpy\n"); |
| 87 | for (i=0 ; i<4 ; i++) { |
| 88 | now = systemTime(); |
| 89 | memcpy(dst, texels, 320*480*2); |
| 90 | t = systemTime(); |
| 91 | printf("memcpy() time = %llu us\n", (t-now)/1000); |
| 92 | fflush(stdout); |
| 93 | } |
| 94 | free(dst); |
| 95 | |
| 96 | free(texels); |
| 97 | |
| 98 | setpriority(PRIO_PROCESS, 0, -20); |
| 99 | |
| 100 | printf("512x512 unmodified texture, 512x512 blit:\n"); |
| 101 | glClear(GL_COLOR_BUFFER_BIT); |
| 102 | for (i=0 ; i<4 ; i++) { |
| 103 | GLint crop[4] = { 0, 512, 512, -512 }; |
| 104 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 105 | now = systemTime(); |
| 106 | glDrawTexiOES(0, 0, 0, 512, 512); |
| 107 | glFinish(); |
| 108 | t = systemTime(); |
| 109 | printf("glFinish() time = %llu us\n", (t-now)/1000); |
| 110 | fflush(stdout); |
| 111 | eglSwapBuffers(dpy, surface); |
| 112 | } |
| 113 | |
| 114 | printf("512x512 unmodified texture, 1x1 blit:\n"); |
| 115 | glClear(GL_COLOR_BUFFER_BIT); |
| 116 | for (i=0 ; i<4 ; i++) { |
| 117 | GLint crop[4] = { 0, 1, 1, -1 }; |
| 118 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 119 | now = systemTime(); |
| 120 | glDrawTexiOES(0, 0, 0, 1, 1); |
| 121 | glFinish(); |
| 122 | t = systemTime(); |
| 123 | printf("glFinish() time = %llu us\n", (t-now)/1000); |
| 124 | fflush(stdout); |
| 125 | eglSwapBuffers(dpy, surface); |
| 126 | } |
| 127 | |
| 128 | printf("512x512 unmodified texture, 512x512 blit (x2):\n"); |
| 129 | glClear(GL_COLOR_BUFFER_BIT); |
| 130 | for (i=0 ; i<4 ; i++) { |
| 131 | GLint crop[4] = { 0, 512, 512, -512 }; |
| 132 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 133 | now = systemTime(); |
| 134 | glDrawTexiOES(0, 0, 0, 512, 512); |
| 135 | glDrawTexiOES(0, 0, 0, 512, 512); |
| 136 | glFinish(); |
| 137 | t = systemTime(); |
| 138 | printf("glFinish() time = %llu us\n", (t-now)/1000); |
| 139 | fflush(stdout); |
| 140 | eglSwapBuffers(dpy, surface); |
| 141 | } |
| 142 | |
| 143 | printf("512x512 unmodified texture, 1x1 blit (x2):\n"); |
| 144 | glClear(GL_COLOR_BUFFER_BIT); |
| 145 | for (i=0 ; i<4 ; i++) { |
| 146 | GLint crop[4] = { 0, 1, 1, -1 }; |
| 147 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 148 | now = systemTime(); |
| 149 | glDrawTexiOES(0, 0, 0, 1, 1); |
| 150 | glDrawTexiOES(0, 0, 0, 1, 1); |
| 151 | glFinish(); |
| 152 | t = systemTime(); |
| 153 | printf("glFinish() time = %llu us\n", (t-now)/1000); |
| 154 | fflush(stdout); |
| 155 | eglSwapBuffers(dpy, surface); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | printf("512x512 (1x1 texel MODIFIED texture), 512x512 blit:\n"); |
| 160 | glClear(GL_COLOR_BUFFER_BIT); |
| 161 | for (i=0 ; i<4 ; i++) { |
| 162 | uint16_t green = 0x7E0; |
| 163 | GLint crop[4] = { 0, 512, 512, -512 }; |
| 164 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 165 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &green); |
| 166 | now = systemTime(); |
| 167 | glDrawTexiOES(0, 0, 0, 512, 512); |
| 168 | glFinish(); |
| 169 | t = systemTime(); |
| 170 | printf("glFinish() time = %llu us\n", (t-now)/1000); |
| 171 | fflush(stdout); |
| 172 | eglSwapBuffers(dpy, surface); |
| 173 | } |
| 174 | |
| 175 | |
| 176 | int16_t texel = 0xF800; |
| 177 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, |
| 178 | 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &texel); |
| 179 | |
| 180 | printf("1x1 unmodified texture, 1x1 blit:\n"); |
| 181 | glClear(GL_COLOR_BUFFER_BIT); |
| 182 | for (i=0 ; i<4 ; i++) { |
| 183 | GLint crop[4] = { 0, 1, 1, -1 }; |
| 184 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 185 | now = systemTime(); |
| 186 | glDrawTexiOES(0, 0, 0, 1, 1); |
| 187 | glFinish(); |
| 188 | t = systemTime(); |
| 189 | printf("glFinish() time = %llu us\n", (t-now)/1000); |
| 190 | eglSwapBuffers(dpy, surface); |
| 191 | } |
| 192 | |
| 193 | printf("1x1 unmodified texture, 512x512 blit:\n"); |
| 194 | glClear(GL_COLOR_BUFFER_BIT); |
| 195 | for (i=0 ; i<4 ; i++) { |
| 196 | GLint crop[4] = { 0, 1, 1, -1 }; |
| 197 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 198 | now = systemTime(); |
| 199 | glDrawTexiOES(0, 0, 0, 512, 512); |
| 200 | glFinish(); |
| 201 | t = systemTime(); |
| 202 | printf("glFinish() time = %llu us\n", (t-now)/1000); |
| 203 | fflush(stdout); |
| 204 | eglSwapBuffers(dpy, surface); |
| 205 | } |
| 206 | |
| 207 | printf("1x1 (1x1 texel MODIFIED texture), 512x512 blit:\n"); |
| 208 | glClear(GL_COLOR_BUFFER_BIT); |
| 209 | for (i=0 ; i<4 ; i++) { |
| 210 | uint16_t green = 0x7E0; |
| 211 | GLint crop[4] = { 0, 1, 1, -1 }; |
| 212 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 213 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &green); |
| 214 | now = systemTime(); |
| 215 | glDrawTexiOES(0, 0, 0, 1, 1); |
| 216 | glFinish(); |
| 217 | t = systemTime(); |
| 218 | printf("glFinish() time = %llu us\n", (t-now)/1000); |
| 219 | fflush(stdout); |
| 220 | eglSwapBuffers(dpy, surface); |
| 221 | } |
| 222 | |
| 223 | return 0; |
| 224 | } |