blob: a0f4bc4663e52a28b5ce1d6138b0322ef3efc956 [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 Agopian870b8aa2012-02-24 16:42:46 -080027#include "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 Agopian1d3bcd62009-08-10 16:48:22 -070047
48 EGLNativeWindowType window = android_createDisplaySurface();
49
Mathias Agopian0928e312009-08-07 16:38:10 -070050 dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Mathias Agopian7dddeac2011-08-15 14:56:38 -070051 eglInitialize(dpy, &majorVersion, &minorVersion);
Mathias Agopian0928e312009-08-07 16:38:10 -070052 eglGetConfigs(dpy, NULL, 0, &numConfigs);
53 printf("# configs = %d\n", numConfigs);
Mathias Agopian1c3561e2009-08-05 17:38:49 -070054
Mathias Agopian0928e312009-08-07 16:38:10 -070055 status_t err = EGLUtils::selectConfigForNativeWindow(
56 dpy, configAttribs, window, &config);
57 if (err) {
Mathias Agopian7dddeac2011-08-15 14:56:38 -070058 fprintf(stderr, "error: %s", EGLUtils::strerror(eglGetError()));
59 eglTerminate(dpy);
Mathias Agopian0928e312009-08-07 16:38:10 -070060 return 0;
61 }
Mathias Agopian1c3561e2009-08-05 17:38:49 -070062
Mathias Agopian7dddeac2011-08-15 14:56:38 -070063 EGLint r,g,b,a, vid;
Mathias Agopian0928e312009-08-07 16:38:10 -070064 eglGetConfigAttrib(dpy, config, EGL_RED_SIZE, &r);
65 eglGetConfigAttrib(dpy, config, EGL_GREEN_SIZE, &g);
66 eglGetConfigAttrib(dpy, config, EGL_BLUE_SIZE, &b);
67 eglGetConfigAttrib(dpy, config, EGL_ALPHA_SIZE, &a);
Mathias Agopian7dddeac2011-08-15 14:56:38 -070068 eglGetConfigAttrib(dpy, config, EGL_NATIVE_VISUAL_ID, &vid);
Mathias Agopian1c3561e2009-08-05 17:38:49 -070069
Mathias Agopian0928e312009-08-07 16:38:10 -070070 surface = eglCreateWindowSurface(dpy, config, window, NULL);
71 if (surface == EGL_NO_SURFACE) {
72 EGLint err = eglGetError();
Mathias Agopian7dddeac2011-08-15 14:56:38 -070073 fprintf(stderr, "error: %s, config=%p, format = %d-%d-%d-%d, visual-id = %d\n",
74 EGLUtils::strerror(err), config, r,g,b,a, vid);
75 eglTerminate(dpy);
Mathias Agopian0928e312009-08-07 16:38:10 -070076 return 0;
77 } else {
Mathias Agopian7dddeac2011-08-15 14:56:38 -070078 printf("config=%p, format = %d-%d-%d-%d, visual-id = %d\n",
79 config, r,g,b,a, vid);
Mathias Agopian0928e312009-08-07 16:38:10 -070080 }
81
82 context = eglCreateContext(dpy, config, NULL, NULL);
83 eglMakeCurrent(dpy, surface, surface, context);
84 eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
85 eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
86
87 printf("w=%d, h=%d\n", w, h);
88
89 glDisable(GL_DITHER);
90 glEnable(GL_BLEND);
91
92 glViewport(0, 0, w, h);
93 glOrthof(0, w, 0, h, 0, 1);
94
95 eglSwapInterval(dpy, 1);
96
97 glClearColor(1,0,0,0);
98 glClear(GL_COLOR_BUFFER_BIT);
99 eglSwapBuffers(dpy, surface);
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700100
101
Mathias Agopian0928e312009-08-07 16:38:10 -0700102 int time = 10;
103 printf("screen should flash red/green quickly for %d s...\n", time);
104
105 int c = 0;
106 nsecs_t start = systemTime();
107 nsecs_t t;
108 do {
109 glClearColor(1,0,0,0);
110 glClear(GL_COLOR_BUFFER_BIT);
111 eglSwapBuffers(dpy, surface);
112 glClearColor(0,1,0,0);
113 glClear(GL_COLOR_BUFFER_BIT);
114 eglSwapBuffers(dpy, surface);
115 t = systemTime() - start;
116 c += 2;
117 } while (int(ns2s(t))<=time);
118
119 double p = (double(t) / c) / 1000000000.0;
120 printf("refresh-rate is %f fps (%f ms)\n", 1.0f/p, p*1000.0);
121
122 eglTerminate(dpy);
123
124 return 0;
Mathias Agopian1c3561e2009-08-05 17:38:49 -0700125}