blob: 911d35469b1e247b451430888e6e7c3c798d5a1d [file] [log] [blame]
Mathias Agopian591018a2009-08-04 13:43:35 -07001/*
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>
Mathias Agopian653870d2009-08-06 16:25:37 -070029#include <ui/EGLUtils.h>
Mathias Agopian591018a2009-08-04 13:43:35 -070030
31using namespace android;
32
33int main(int argc, char** argv)
34{
35 EGLint configAttribs[] = {
36 EGL_DEPTH_SIZE, 0,
37 EGL_NONE
38 };
39
Mathias Agopian591018a2009-08-04 13:43:35 -070040 EGLint majorVersion;
41 EGLint minorVersion;
Mathias Agopian591018a2009-08-04 13:43:35 -070042 EGLContext context;
Mathias Agopian653870d2009-08-06 16:25:37 -070043 EGLConfig config;
Mathias Agopian591018a2009-08-04 13:43:35 -070044 EGLSurface surface;
45 EGLint w, h;
Mathias Agopian591018a2009-08-04 13:43:35 -070046 EGLDisplay dpy;
47
Mathias Agopian1d3bcd62009-08-10 16:48:22 -070048 EGLNativeWindowType window = android_createDisplaySurface();
49
Mathias Agopian591018a2009-08-04 13:43:35 -070050 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
51 eglInitialize(dpy, &majorVersion, &minorVersion);
Mathias Agopian653870d2009-08-06 16:25:37 -070052
Mathias Agopian653870d2009-08-06 16:25:37 -070053 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;
Mathias Agopian591018a2009-08-04 13:43:35 -070058 }
Mathias Agopian653870d2009-08-06 16:25:37 -070059
60 surface = eglCreateWindowSurface(dpy, config, window, NULL);
Mathias Agopian591018a2009-08-04 13:43:35 -070061 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);
Mathias Agopian1c3561e2009-08-05 17:38:49 -070071 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
72 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
Mathias Agopian591018a2009-08-04 13:43:35 -070073 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
74 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
75 glDisable(GL_DITHER);
Mathias Agopian1c3561e2009-08-05 17:38:49 -070076 glEnable(GL_BLEND);
Mathias Agopian591018a2009-08-04 13:43:35 -070077 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++) {
Mathias Agopian1c3561e2009-08-05 17:38:49 -070083 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 }
Mathias Agopian591018a2009-08-04 13:43:35 -070090 }
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);
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700116 glVertexPointer(2, GL_FLOAT, 0, vertices);
Mathias Agopian591018a2009-08-04 13:43:35 -0700117 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
118
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700119 eglSwapInterval(dpy, 1);
120
Mathias Agopian591018a2009-08-04 13:43:35 -0700121 glClearColor(1,0,0,0);
122 glClear(GL_COLOR_BUFFER_BIT);
123 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
124 eglSwapBuffers(dpy, surface);
125
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700126
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;
Mathias Agopian591018a2009-08-04 13:43:35 -0700140 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;
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700148 times[j++] = t;
149 }
150
151 for (int c=1, j=0 ; c<32 ; c++, j++) {
152 nsecs_t t = times[j];
Mathias Agopian591018a2009-08-04 13:43:35 -0700153 printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0);
154 }
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700155
156
157
158 eglTerminate(dpy);
159
Mathias Agopian591018a2009-08-04 13:43:35 -0700160 return 0;
161}