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