11c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian/* 20928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** 30928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** Copyright 2006, The Android Open Source Project 40928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** 50928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** Licensed under the Apache License, Version 2.0 (the "License"); 60928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** you may not use this file except in compliance with the License. 70928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** You may obtain a copy of the License at 80928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** 90928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** http://www.apache.org/licenses/LICENSE-2.0 100928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** 110928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** Unless required by applicable law or agreed to in writing, software 120928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** distributed under the License is distributed on an "AS IS" BASIS, 130928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 140928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** See the License for the specific language governing permissions and 150928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian ** limitations under the License. 160928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian */ 171c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 181c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian#include <stdlib.h> 191c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian#include <stdio.h> 201c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 211c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian#include <EGL/egl.h> 221c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian#include <GLES/gl.h> 231c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian#include <GLES/glext.h> 241c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 251c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian#include <utils/StopWatch.h> 261c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian#include <ui/FramebufferNativeWindow.h> 27870b8aa15cb5c722b5d8eb7726eaa5f1a7c23d69Mathias Agopian#include "EGLUtils.h" 281c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 291c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopianusing namespace android; 301c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian 311c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopianint main(int argc, char** argv) 321c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian{ 331c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian EGLint configAttribs[] = { 340928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 350928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGL_NONE 360928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian }; 370928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 380928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLint majorVersion; 390928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLint minorVersion; 400928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLContext context; 410928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLConfig config; 420928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLint numConfigs=0; 430928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLSurface surface; 440928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLint w, h; 450928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLDisplay dpy; 460928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 471d3bcd6e217e7ef177287d06f6fdf6149f453830Mathias Agopian 481d3bcd6e217e7ef177287d06f6fdf6149f453830Mathias Agopian EGLNativeWindowType window = android_createDisplaySurface(); 491d3bcd6e217e7ef177287d06f6fdf6149f453830Mathias Agopian 500928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 517dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian eglInitialize(dpy, &majorVersion, &minorVersion); 520928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglGetConfigs(dpy, NULL, 0, &numConfigs); 530928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian printf("# configs = %d\n", numConfigs); 540928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 550928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian status_t err = EGLUtils::selectConfigForNativeWindow( 560928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian dpy, configAttribs, window, &config); 570928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian if (err) { 587dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian fprintf(stderr, "error: %s", EGLUtils::strerror(eglGetError())); 597dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian eglTerminate(dpy); 600928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian return 0; 610928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian } 620928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 637dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian EGLint r,g,b,a, vid; 640928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglGetConfigAttrib(dpy, config, EGL_RED_SIZE, &r); 650928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglGetConfigAttrib(dpy, config, EGL_GREEN_SIZE, &g); 660928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglGetConfigAttrib(dpy, config, EGL_BLUE_SIZE, &b); 670928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglGetConfigAttrib(dpy, config, EGL_ALPHA_SIZE, &a); 687dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian eglGetConfigAttrib(dpy, config, EGL_NATIVE_VISUAL_ID, &vid); 690928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 700928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian surface = eglCreateWindowSurface(dpy, config, window, NULL); 710928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian if (surface == EGL_NO_SURFACE) { 720928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian EGLint err = eglGetError(); 737dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian fprintf(stderr, "error: %s, config=%p, format = %d-%d-%d-%d, visual-id = %d\n", 747dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian EGLUtils::strerror(err), config, r,g,b,a, vid); 757dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian eglTerminate(dpy); 760928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian return 0; 770928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian } else { 787dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian printf("config=%p, format = %d-%d-%d-%d, visual-id = %d\n", 797dddeac97122170f71151dfdd7934c4d207c679bMathias Agopian config, r,g,b,a, vid); 800928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian } 810928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 820928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian context = eglCreateContext(dpy, config, NULL, NULL); 830928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglMakeCurrent(dpy, surface, surface, context); 840928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglQuerySurface(dpy, surface, EGL_WIDTH, &w); 850928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglQuerySurface(dpy, surface, EGL_HEIGHT, &h); 860928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 870928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian printf("w=%d, h=%d\n", w, h); 880928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 890928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glDisable(GL_DITHER); 900928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glEnable(GL_BLEND); 910928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 920928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glViewport(0, 0, w, h); 930928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glOrthof(0, w, 0, h, 0, 1); 940928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 950928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglSwapInterval(dpy, 1); 960928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 970928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glClearColor(1,0,0,0); 980928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glClear(GL_COLOR_BUFFER_BIT); 990928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglSwapBuffers(dpy, surface); 1000928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 1010928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 1020928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian int time = 10; 1030928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian printf("screen should flash red/green quickly for %d s...\n", time); 1040928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 1050928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian int c = 0; 1060928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian nsecs_t start = systemTime(); 1070928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian nsecs_t t; 1080928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian do { 1090928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glClearColor(1,0,0,0); 1100928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glClear(GL_COLOR_BUFFER_BIT); 1110928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglSwapBuffers(dpy, surface); 1120928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glClearColor(0,1,0,0); 1130928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian glClear(GL_COLOR_BUFFER_BIT); 1140928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglSwapBuffers(dpy, surface); 1150928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian t = systemTime() - start; 1160928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian c += 2; 1170928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian } while (int(ns2s(t))<=time); 1180928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 1190928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian double p = (double(t) / c) / 1000000000.0; 1200928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian printf("refresh-rate is %f fps (%f ms)\n", 1.0f/p, p*1000.0); 1210928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 1220928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian eglTerminate(dpy); 1230928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian 1240928e31cc7a9ec7367a68796fcaa9c52959216a5Mathias Agopian return 0; 1251c3561e8d862d8fd27f8e843a18f251b9d9500b4Mathias Agopian} 126