blob: 80a6c21b4e4945d09abecb679219b5c1e4e0d18c [file] [log] [blame]
Mathias Agopian1c3561e2009-08-05 17:38:49 -07001/*
Mathias Agopian0928e312009-08-07 16:38:10 -07002 **
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 */
Mathias Agopian1c3561e2009-08-05 17:38:49 -070017
18#include <stdlib.h>
19#include <stdio.h>
20
21#include <EGL/egl.h>
22#include <GLES/gl.h>
23#include <GLES/glext.h>
24
25#include <utils/StopWatch.h>
26#include <ui/FramebufferNativeWindow.h>
Mathias Agopian6cf50a72009-08-06 16:05:39 -070027#include <ui/EGLUtils.h>
Mathias Agopian1c3561e2009-08-05 17:38:49 -070028
29using namespace android;
30
31int main(int argc, char** argv)
32{
33 EGLint configAttribs[] = {
Mathias Agopian0928e312009-08-07 16:38:10 -070034 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
35 EGL_NONE
36 };
Mathias Agopian1c3561e2009-08-05 17:38:49 -070037
Mathias Agopian0928e312009-08-07 16:38:10 -070038 EGLint majorVersion;
39 EGLint minorVersion;
40 EGLContext context;
41 EGLConfig config;
42 EGLint numConfigs=0;
43 EGLSurface surface;
44 EGLint w, h;
45 EGLDisplay dpy;
Mathias Agopian6cf50a72009-08-06 16:05:39 -070046
Mathias Agopian0928e312009-08-07 16:38:10 -070047 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
48 eglInitialize(dpy, 0 ,0) ;//&majorVersion, &minorVersion);
49 eglGetConfigs(dpy, NULL, 0, &numConfigs);
50 printf("# configs = %d\n", numConfigs);
51
52 EGLNativeWindowType window = android_createDisplaySurface();
Mathias Agopian1c3561e2009-08-05 17:38:49 -070053
Mathias Agopian0928e312009-08-07 16:38:10 -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;
59 }
Mathias Agopian1c3561e2009-08-05 17:38:49 -070060
Mathias Agopian0928e312009-08-07 16:38:10 -070061 EGLint r,g,b,a;
62 eglGetConfigAttrib(dpy, config, EGL_RED_SIZE, &r);
63 eglGetConfigAttrib(dpy, config, EGL_GREEN_SIZE, &g);
64 eglGetConfigAttrib(dpy, config, EGL_BLUE_SIZE, &b);
65 eglGetConfigAttrib(dpy, config, EGL_ALPHA_SIZE, &a);
Mathias Agopian1c3561e2009-08-05 17:38:49 -070066
Mathias Agopian0928e312009-08-07 16:38:10 -070067 surface = eglCreateWindowSurface(dpy, config, window, NULL);
68 if (surface == EGL_NO_SURFACE) {
69 EGLint err = eglGetError();
70 fprintf(stderr, "%s, config=%p, format = %d-%d-%d-%d\n",
71 EGLUtils::strerror(err), config, r,g,b,a);
72 return 0;
73 } else {
74 printf("config=%p, format = %d-%d-%d-%d\n", config, r,g,b,a);
75 }
76
77 context = eglCreateContext(dpy, config, NULL, NULL);
78 eglMakeCurrent(dpy, surface, surface, context);
79 eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
80 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
81
82 printf("w=%d, h=%d\n", w, h);
83
84 glDisable(GL_DITHER);
85 glEnable(GL_BLEND);
86
87 glViewport(0, 0, w, h);
88 glOrthof(0, w, 0, h, 0, 1);
89
90 eglSwapInterval(dpy, 1);
91
92 glClearColor(1,0,0,0);
93 glClear(GL_COLOR_BUFFER_BIT);
94 eglSwapBuffers(dpy, surface);
Mathias Agopian1c3561e2009-08-05 17:38:49 -070095
96
Mathias Agopian0928e312009-08-07 16:38:10 -070097 int time = 10;
98 printf("screen should flash red/green quickly for %d s...\n", time);
99
100 int c = 0;
101 nsecs_t start = systemTime();
102 nsecs_t t;
103 do {
104 glClearColor(1,0,0,0);
105 glClear(GL_COLOR_BUFFER_BIT);
106 eglSwapBuffers(dpy, surface);
107 glClearColor(0,1,0,0);
108 glClear(GL_COLOR_BUFFER_BIT);
109 eglSwapBuffers(dpy, surface);
110 t = systemTime() - start;
111 c += 2;
112 } while (int(ns2s(t))<=time);
113
114 double p = (double(t) / c) / 1000000000.0;
115 printf("refresh-rate is %f fps (%f ms)\n", 1.0f/p, p*1000.0);
116
117 eglTerminate(dpy);
118
119 return 0;
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700120}