blob: cf908a0d97f7e6b5ffb4838a6f599645bd236dbe [file] [log] [blame]
Mathias Agopian1c3561e2009-08-05 17:38:49 -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 Agopian6cf50a72009-08-06 16:05:39 -070029#include <ui/EGLUtils.h>
Mathias Agopian1c3561e2009-08-05 17:38:49 -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 Agopian1c3561e2009-08-05 17:38:49 -070040 EGLint majorVersion;
41 EGLint minorVersion;
Mathias Agopian1c3561e2009-08-05 17:38:49 -070042 EGLContext context;
Mathias Agopian6cf50a72009-08-06 16:05:39 -070043 EGLConfig config;
Mathias Agopian1c3561e2009-08-05 17:38:49 -070044 EGLSurface surface;
45 EGLint w, h;
Mathias Agopian1c3561e2009-08-05 17:38:49 -070046 EGLDisplay dpy;
47
48 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
49 eglInitialize(dpy, &majorVersion, &minorVersion);
Mathias Agopian6cf50a72009-08-06 16:05:39 -070050
51 EGLNativeWindowType window = android_createDisplaySurface();
Mathias Agopian1c3561e2009-08-05 17:38:49 -070052
Mathias Agopian6cf50a72009-08-06 16:05:39 -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 Agopian1c3561e2009-08-05 17:38:49 -070058 }
Mathias Agopian6cf50a72009-08-06 16:05:39 -070059
60 surface = eglCreateWindowSurface(dpy, config, window, NULL);
Mathias Agopian1c3561e2009-08-05 17:38:49 -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 glDisable(GL_DITHER);
69 glEnable(GL_BLEND);
70
71 glViewport(0, 0, w, h);
72 glOrthof(0, w, 0, h, 0, 1);
73
74 eglSwapInterval(dpy, 1);
75
76 glClearColor(1,0,0,0);
77 glClear(GL_COLOR_BUFFER_BIT);
78 eglSwapBuffers(dpy, surface);
79
80
81 int time = 10;
82 printf("screen should flash red/green quickly for %d s...\n", time);
83
84 int c = 0;
85 nsecs_t start = systemTime();
86 nsecs_t t;
87 do {
88 glClearColor(1,0,0,0);
89 glClear(GL_COLOR_BUFFER_BIT);
90 eglSwapBuffers(dpy, surface);
91 glClearColor(0,1,0,0);
92 glClear(GL_COLOR_BUFFER_BIT);
93 eglSwapBuffers(dpy, surface);
94 t = systemTime() - start;
95 c += 2;
96 } while (int(ns2s(t))<=time);
97
98 double p = (double(t) / c) / 1000000000.0;
99 printf("refresh-rate is %f fps (%f ms)\n", 1.0f/p, p*1000.0);
100
101 eglTerminate(dpy);
102
103 return 0;
104}