blob: c814e8d440bd6929e396f23968fece7e1554fc87 [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>
29
30using namespace android;
31
32int main(int argc, char** argv)
33{
34 EGLint configAttribs[] = {
35 EGL_DEPTH_SIZE, 0,
36 EGL_NONE
37 };
38
39 EGLint numConfigs = -1, n=0;
40 EGLint majorVersion;
41 EGLint minorVersion;
42 EGLConfig config;
43 EGLContext context;
44 EGLSurface surface;
45 EGLint w, h;
46
47 EGLDisplay dpy;
48
49 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
50 eglInitialize(dpy, &majorVersion, &minorVersion);
51
52 // Get all the "potential match" configs...
53 eglGetConfigs(dpy, NULL, 0, &numConfigs);
54 EGLConfig* const configs = (EGLConfig*)malloc(sizeof(EGLConfig)*numConfigs);
55 eglChooseConfig(dpy, configAttribs, configs, numConfigs, &n);
56 config = configs[0];
57 if (n > 1) {
58 // if there is more than one candidate, go through the list
59 // and pick one that matches our framebuffer format
60 int fbSzA = 0; // should not hardcode
61 int fbSzR = 5; // should not hardcode
62 int fbSzG = 6; // should not hardcode
63 int fbSzB = 5; // should not hardcode
64 int i;
65 for (i=0 ; i<n ; i++) {
66 EGLint r,g,b,a;
67 eglGetConfigAttrib(dpy, configs[i], EGL_RED_SIZE, &r);
68 eglGetConfigAttrib(dpy, configs[i], EGL_GREEN_SIZE, &g);
69 eglGetConfigAttrib(dpy, configs[i], EGL_BLUE_SIZE, &b);
70 eglGetConfigAttrib(dpy, configs[i], EGL_ALPHA_SIZE, &a);
71 if (fbSzA == a && fbSzR == r && fbSzG == g && fbSzB == b) {
72 config = configs[i];
73 break;
74 }
75 }
76 }
77 free(configs);
78
79 surface = eglCreateWindowSurface(dpy, config,
80 android_createDisplaySurface(), NULL);
81 context = eglCreateContext(dpy, config, NULL, NULL);
82 eglMakeCurrent(dpy, surface, surface, context);
83 eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
84 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
85
86 printf("w=%d, h=%d\n", w, h);
87
88 glBindTexture(GL_TEXTURE_2D, 0);
89 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
90 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
91 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
92 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
93 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
94 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
95 glDisable(GL_DITHER);
96 glDisable(GL_BLEND);
97 glEnable(GL_TEXTURE_2D);
98 glColor4f(1,1,1,1);
99
100 uint32_t* t32 = (uint32_t*)malloc(512*512*4);
101 for (int y=0 ; y<512 ; y++) {
102 for (int x=0 ; x<512 ; x++) {
103 t32[x+y*512] = 0x10FFFFFF;
104 }
105 }
106
107 const GLfloat vertices[4][2] = {
108 { 0, 0 },
109 { 0, h },
110 { w, h },
111 { w, 0 }
112 };
113
114 const GLfloat texCoords[4][2] = {
115 { 0, 0 },
116 { 0, 1 },
117 { 1, 1 },
118 { 1, 0 }
119 };
120
121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
122
123 glViewport(0, 0, w, h);
124 glMatrixMode(GL_PROJECTION);
125 glLoadIdentity();
126 glOrthof(0, w, 0, h, 0, 1);
127
128 glEnableClientState(GL_VERTEX_ARRAY);
129 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
130 glVertexPointer(2, GL_FIXED, 0, vertices);
131 glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
132
133 glClearColor(1,0,0,0);
134 glClear(GL_COLOR_BUFFER_BIT);
135 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
136 eglSwapBuffers(dpy, surface);
137
138 for (int c=1 ; c<32 ; c++) {
139 glClear(GL_COLOR_BUFFER_BIT);
140 nsecs_t now = systemTime();
141 for (int i=0 ; i<c ; i++) {
142 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
143 }
144 eglSwapBuffers(dpy, surface);
145 nsecs_t t = systemTime() - now;
146 printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0);
147 }
148 return 0;
149}