blob: 2db63d7835f6a4d59dc528ba49ad44ed2e3f97af [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>
Andy McFadden6ef57d72014-03-05 15:06:53 -080028#include <WindowSurface.h>
29#include <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
Andy McFadden6ef57d72014-03-05 15:06:53 -080048 WindowSurface windowSurface;
49 EGLNativeWindowType window = windowSurface.getSurface();
Mathias Agopian1d3bcd62009-08-10 16:48:22 -070050
Mathias Agopian591018a2009-08-04 13:43:35 -070051 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
52 eglInitialize(dpy, &majorVersion, &minorVersion);
Mathias Agopian653870d2009-08-06 16:25:37 -070053
Mathias Agopian653870d2009-08-06 16:25:37 -070054 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;
Mathias Agopian591018a2009-08-04 13:43:35 -070059 }
Mathias Agopian653870d2009-08-06 16:25:37 -070060
61 surface = eglCreateWindowSurface(dpy, config, window, NULL);
Mathias Agopian591018a2009-08-04 13:43:35 -070062 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
67 printf("w=%d, h=%d\n", w, h);
68
69 glBindTexture(GL_TEXTURE_2D, 0);
70 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
71 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Mathias Agopian1c3561e2009-08-05 17:38:49 -070072 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
73 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
Mathias Agopian591018a2009-08-04 13:43:35 -070074 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
75 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
76 glDisable(GL_DITHER);
Mathias Agopian1c3561e2009-08-05 17:38:49 -070077 glEnable(GL_BLEND);
Mathias Agopian591018a2009-08-04 13:43:35 -070078 glEnable(GL_TEXTURE_2D);
79 glColor4f(1,1,1,1);
80
81 uint32_t* t32 = (uint32_t*)malloc(512*512*4);
82 for (int y=0 ; y<512 ; y++) {
83 for (int x=0 ; x<512 ; x++) {
Mathias Agopian1c3561e2009-08-05 17:38:49 -070084 int u = x-256;
85 int v = y-256;
86 if (u*u+v*v < 256*256) {
87 t32[x+y*512] = 0x10FFFFFF;
88 } else {
89 t32[x+y*512] = 0x20FF0000;
90 }
Mathias Agopian591018a2009-08-04 13:43:35 -070091 }
92 }
93
Chih-Hung Hsieh3bded912014-12-11 10:39:59 -080094 const GLfloat fh = h;
95 const GLfloat fw = w;
Mathias Agopian591018a2009-08-04 13:43:35 -070096 const GLfloat vertices[4][2] = {
Chih-Hung Hsieh3bded912014-12-11 10:39:59 -080097 { 0, 0 },
98 { 0, fh },
99 { fw, fh },
100 { fw, 0 }
Mathias Agopian591018a2009-08-04 13:43:35 -0700101 };
102
103 const GLfloat texCoords[4][2] = {
104 { 0, 0 },
105 { 0, 1 },
106 { 1, 1 },
107 { 1, 0 }
108 };
109
110 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
111
112 glViewport(0, 0, w, h);
113 glMatrixMode(GL_PROJECTION);
114 glLoadIdentity();
115 glOrthof(0, w, 0, h, 0, 1);
116
117 glEnableClientState(GL_VERTEX_ARRAY);
118 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700119 glVertexPointer(2, GL_FLOAT, 0, vertices);
Mathias Agopian591018a2009-08-04 13:43:35 -0700120 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
121
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700122 eglSwapInterval(dpy, 1);
123
Mathias Agopian591018a2009-08-04 13:43:35 -0700124 glClearColor(1,0,0,0);
125 glClear(GL_COLOR_BUFFER_BIT);
126 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
127 eglSwapBuffers(dpy, surface);
128
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700129
130 nsecs_t times[32];
131
132 for (int c=1 ; c<32 ; c++) {
133 glClear(GL_COLOR_BUFFER_BIT);
134 for (int i=0 ; i<c ; i++) {
135 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
136 }
137 eglSwapBuffers(dpy, surface);
138 }
139
140
141 // for (int c=31 ; c>=1 ; c--) {
142 int j=0;
Mathias Agopian591018a2009-08-04 13:43:35 -0700143 for (int c=1 ; c<32 ; c++) {
144 glClear(GL_COLOR_BUFFER_BIT);
145 nsecs_t now = systemTime();
146 for (int i=0 ; i<c ; i++) {
147 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
148 }
149 eglSwapBuffers(dpy, surface);
150 nsecs_t t = systemTime() - now;
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700151 times[j++] = t;
152 }
153
154 for (int c=1, j=0 ; c<32 ; c++, j++) {
155 nsecs_t t = times[j];
Mathias Agopian591018a2009-08-04 13:43:35 -0700156 printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0);
157 }
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700158
159
160
161 eglTerminate(dpy);
162
Mathias Agopian591018a2009-08-04 13:43:35 -0700163 return 0;
164}