supoort xorg mode to disable refresh rate
This commit is contained in:
parent
f42638d022
commit
4e271b7943
6
Makefile
6
Makefile
|
@ -7,4 +7,8 @@ build:
|
|||
cmake -B build
|
||||
|
||||
t: compile
|
||||
sudo ./build/bin/SimpleEs
|
||||
DISPLAY=:0 ./build/bin/TriangleEsDemo
|
||||
|
||||
|
||||
dt: compile
|
||||
DISPLAY=:0 gdb ./build/bin/TriangleEsDemo
|
|
@ -16,7 +16,8 @@
|
|||
#include <threads.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "GLES2/gl2.h"
|
||||
|
@ -25,7 +26,7 @@
|
|||
#include "EGL/egl.h"
|
||||
#include "EGL/eglext.h"
|
||||
|
||||
// #define XORG_SHOW
|
||||
#define XORG_SHOW
|
||||
|
||||
#include <libdrm/drm.h>
|
||||
|
||||
|
@ -396,14 +397,14 @@ static int matchConfigToVisual(EGLDisplay display, EGLint visualId, EGLConfig* c
|
|||
int retId = -1;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
PRINT_CONFIG(display, configs[i], EGL_SURFACE_TYPE);
|
||||
// PRINT_CONFIG(display, configs[i], EGL_SAMPLES);
|
||||
// PRINT_CONFIG(display, configs[i], EGL_RENDERABLE_TYPE);
|
||||
|
||||
if (!eglGetConfigAttrib(display, configs[i], EGL_NATIVE_VISUAL_ID, &id))
|
||||
continue;
|
||||
|
||||
// printf("visualid: 0x%x, str:%.*s\n", id, 4, &id);
|
||||
// PRINT_CONFIG(display, configs[i], EGL_SURFACE_TYPE);
|
||||
// PRINT_CONFIG(display, configs[i], EGL_MAX_SWAP_INTERVAL);
|
||||
// PRINT_CONFIG(display, configs[i], EGL_MIN_SWAP_INTERVAL);
|
||||
// printf("visualid: 0x%x, str:%.*s\n=====================\n", id, 4, &id);
|
||||
if (id == visualId) {
|
||||
retId = i;
|
||||
break;
|
||||
|
@ -415,7 +416,8 @@ static int matchConfigToVisual(EGLDisplay display, EGLint visualId, EGLConfig* c
|
|||
|
||||
int init(void)
|
||||
{
|
||||
|
||||
EGLint count = 0;
|
||||
EGLint numConfigs = 0;
|
||||
|
||||
#ifdef XORG_SHOW
|
||||
x_display = XOpenDisplay (NULL);
|
||||
|
@ -427,16 +429,14 @@ int init(void)
|
|||
|
||||
XSetWindowAttributes swa;
|
||||
swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | StructureNotifyMask;
|
||||
swa.override_redirect = True;
|
||||
win = XCreateWindow ( // create a window with the provided parameters
|
||||
x_display, root,
|
||||
0, 0, 1000, 1000, 0,
|
||||
CopyFromParent, InputOutput,
|
||||
CopyFromParent, CWEventMask,
|
||||
CopyFromParent,
|
||||
CWEventMask | CWOverrideRedirect,
|
||||
&swa );
|
||||
|
||||
XSetWindowAttributes xattr;
|
||||
xattr.override_redirect = False;
|
||||
XChangeWindowAttributes( x_display, win, CWOverrideRedirect, &xattr );
|
||||
|
||||
XMapWindow ( x_display , win); // make the window visible on the screen
|
||||
XStoreName ( x_display , win , "GL test"); // give the window a name
|
||||
|
@ -464,8 +464,6 @@ int init(void)
|
|||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint count = 0;
|
||||
EGLint numConfigs = 0;
|
||||
eglGetConfigs(egldisplay, NULL, 0, &count);
|
||||
EGLConfig* configs = malloc(count * sizeof(EGLConfig));
|
||||
|
||||
|
@ -508,6 +506,10 @@ int init(void)
|
|||
eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext);
|
||||
ASSERT_EQ(eglGetError(), EGL_SUCCESS);
|
||||
|
||||
// disable refresh rate limit
|
||||
if (!eglSwapInterval || !eglSwapInterval(egldisplay, 0)) {
|
||||
printf("Failed to set swap interval. Results may be bounded above by refresh rate.\n");
|
||||
}
|
||||
|
||||
print_glinfo();
|
||||
|
||||
|
@ -641,6 +643,11 @@ void init_signal() {
|
|||
signal(SIGINT, handle_sig);
|
||||
}
|
||||
|
||||
long GetNowMillis() {
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return t.tv_sec*1000 + t.tv_usec/1000;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
|
@ -661,6 +668,7 @@ int main (void)
|
|||
thrd_t thr;
|
||||
thrd_create(&thr, event_handle, NULL);
|
||||
|
||||
long lastTime = GetNowMillis();
|
||||
unsigned int framenum = 0;
|
||||
while (!g_stop) {
|
||||
render(width, height, framenum);
|
||||
|
@ -670,11 +678,13 @@ int main (void)
|
|||
gbm_mode_set();
|
||||
#endif
|
||||
|
||||
usleep(1*1000);
|
||||
//usleep(1*1000);
|
||||
framenum++;
|
||||
|
||||
if (!(framenum%100)) {
|
||||
printf("frame num:%d\n", framenum);
|
||||
long now = GetNowMillis();
|
||||
printf("frame num:%d, fps: %.1f\n", framenum, 100/((now-lastTime)/1000.0));
|
||||
lastTime = now;
|
||||
}
|
||||
if (framenum > 100000) {
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user