-
Notifications
You must be signed in to change notification settings - Fork 0
/
native_frameworks.patch
129 lines (122 loc) · 3.78 KB
/
native_frameworks.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
From 86c0d5c668079fa6f0882aa0c29d78a9467a0591 Mon Sep 17 00:00:00 2001
From: Alex Hoffman <[email protected]>
Date: Fri, 28 Feb 2020 16:36:00 +0100
Subject: [PATCH] Initial EGL modifications
---
opengl/include/EGL/EGLsyslog.h | 21 +++++++++++
opengl/libs/EGL/eglApi.cpp | 68 +++++++++++++++++++++++++++++++++-
2 files changed, 88 insertions(+), 1 deletion(-)
create mode 100644 opengl/include/EGL/EGLsyslog.h
diff --git a/opengl/include/EGL/EGLsyslog.h b/opengl/include/EGL/EGLsyslog.h
new file mode 100644
index 000000000..b7f961aa1
--- /dev/null
+++ b/opengl/include/EGL/EGLsyslog.h
@@ -0,0 +1,21 @@
+#ifndef __EGLSYSLOG_H__
+#define __EGLSYSLOG_H__
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+#define OPENGL_TARGET_FPS 30
+
+#define EGL_SYSLOGGER_NAME "EGLSyslogger"
+#define EGL_SYSLOGGER_DEV "/dev/" EGL_SYSLOGGER_NAME
+#define IOCTL_EGL_LOG_FRAME _IOW('g', 1, struct EGLLogFrame *)
+
+#define EGL_IOCTL_LOGGING
+#define LIMIT_FRAME_PERIOD
+
+struct EGLLogFrame {
+ uint64_t frame_ts;
+ uint64_t inter_frame_period;
+};
+
+#endif // __EGLSYSLOG_H__
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index 0cd8b0235..a6d110fd0 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -54,6 +54,9 @@
#include "egl_tls.h"
#include "egldefs.h"
+#include "EGL/EGLsyslog.h"
+// #include <pthread.h>
+
using namespace android;
// This extension has not been ratified yet, so can't be shipped.
@@ -1155,9 +1158,72 @@ EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw,
}
}
+#ifdef EGL_IOCTL_LOGGING
+static void *eglLogFrame(void *log_frame)
+{
+ static int IOctl_fd;
+ struct EGLLogFrame *lf = (struct EGLLogFrame *)log_frame;
+
+ //TODO can fd be just opened once?
+ IOctl_fd = open(EGL_SYSLOGGER_DEV, O_RDWR);
+
+ if(IOctl_fd > 0)
+ ioctl(IOctl_fd, IOCTL_EGL_LOG_FRAME, lf);
+
+ close(IOctl_fd);
+ free(lf);
+ pthread_exit(NULL);
+
+ return NULL;
+}
+#endif //EGL_IOCTL_LOGGING
+
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
{
- return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0);
+ static uint64_t target_frame_period = 1e9/OPENGL_TARGET_FPS;
+ static uint64_t prev_frame_dur = 0, req_sleep_dur = 0;
+ static EGLBoolean first_run = EGL_FALSE;
+ static timespec last_frame_time = {0}, cur_frame_time = {0};
+ static pthread_t IOctl_thread;
+
+ EGLBoolean ret = eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0);
+
+ //Limiting FPS
+ // Get current frame's timestamp
+ clock_gettime(CLOCK_MONOTONIC, &cur_frame_time);
+ // Get duration of prev frame
+
+ if(first_run){
+ prev_frame_dur =
+ ((uint64_t)cur_frame_time.tv_sec * (uint64_t)1.0e9 + (uint64_t) cur_frame_time.tv_nsec)
+ - ((uint64_t)last_frame_time.tv_sec * (uint64_t)1.0e9 + (uint64_t) last_frame_time.tv_nsec);
+
+#ifdef EGL_IOCTL_LOGGING
+ struct EGLLogFrame *lf =
+ (struct EGLLogFrame *)malloc(sizeof(struct EGLLogFrame));
+ lf->frame_ts = (uint64_t)cur_frame_time.tv_sec * (uint64_t)1.0e9 +
+ (uint64_t)cur_frame_time.tv_nsec;
+ lf->inter_frame_period = prev_frame_dur;
+
+ if(!pthread_create(&IOctl_thread, NULL, eglLogFrame, lf))
+ pthread_detach(IOctl_thread);
+
+#endif //EGL_IOCTL_LOGGING
+
+#ifdef LIMIT_FRAME_PERIOD
+ if(prev_frame_dur < target_frame_period){
+ //Need to delay frame to limit to target
+ req_sleep_dur = (target_frame_period - prev_frame_dur) / 1e3; // uSecs
+ usleep(req_sleep_dur);
+ } else
+ req_sleep_dur = 0;
+#endif //LIMIT_FRAME_PERIOD
+ }
+
+ last_frame_time = cur_frame_time;
+
+ first_run = EGL_TRUE;
+ return ret;
}
EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface,
--
2.25.0