aboutsummaryrefslogtreecommitdiffstats
path: root/meta-xilinx-core/dynamic-layers/openembedded-layer/recipes-benchmark/glmark2/files/0002-native-state-fbdev-Add-support-for-glmark2-es2-fbdev.patch
blob: 83e5b58a037f62e8d78e1cda736a555ae295b365 (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
From f5d9664b86592dabeec33421f62eb3cfb43d7f05 Mon Sep 17 00:00:00 2001
From: Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
Date: Thu, 30 Jan 2020 14:30:06 -0800
Subject: [PATCH 2/3] native-state-fbdev: Add support for glmark2-es2-fbdev

This patch add support for mali specific fbdev backend.

Signed-off-by: Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
Upstream-status: Inappropriate [Xilinx specific]
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
---
 src/gl-state-egl.cpp       |   4 +
 src/main.cpp               |   4 +
 src/native-state-fbdev.cpp | 172 +++++++++++++++++++++++++++++++++++++
 src/native-state-fbdev.h   |  59 +++++++++++++
 src/wscript_build          |   5 ++
 wscript                    |   2 +
 6 files changed, 246 insertions(+)
 create mode 100644 src/native-state-fbdev.cpp
 create mode 100644 src/native-state-fbdev.h

Index: git/src/gl-state-egl.cpp
===================================================================
--- git.orig/src/gl-state-egl.cpp
+++ git/src/gl-state-egl.cpp
@@ -508,6 +508,7 @@ GLStateEGL::gotValidDisplay()
         return false;
     }
 
+#ifndef GLMARK2_USE_FBDEV
     char const * __restrict const supported_extensions =
         egl_query_string(EGL_NO_DISPLAY, EGL_EXTENSIONS);
 
@@ -541,6 +542,9 @@ GLStateEGL::gotValidDisplay()
         Log::debug("Falling back to eglGetDisplay()\n");
         egl_display_ = egl_get_display(native_display_);
     }
+#else
+    egl_display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+#endif
 
     if (!egl_display_) {
         Log::error("eglGetDisplay() failed with error: 0x%x\n", egl_get_error());
Index: git/src/main.cpp
===================================================================
--- git.orig/src/main.cpp
+++ git/src/main.cpp
@@ -37,6 +37,8 @@
 
 #if GLMARK2_USE_X11
 #include "native-state-x11.h"
+#elif GLMARK2_USE_FBDEV
+#include "native-state-fbdev.h"
 #elif GLMARK2_USE_DRM
 #include "native-state-drm.h"
 #elif GLMARK2_USE_GBM
@@ -160,6 +162,8 @@ main(int argc, char *argv[])
 {
 #if GLMARK2_USE_X11
     NativeStateX11 native_state;
+#elif GLMARK2_USE_FBDEV
+    NativeStateFbdev native_state;
 #elif GLMARK2_USE_DRM
     NativeStateDRM native_state;
 #elif GLMARK2_USE_GBM
Index: git/src/native-state-fbdev.cpp
===================================================================
--- /dev/null
+++ git/src/native-state-fbdev.cpp
@@ -0,0 +1,172 @@
+
+/*
+ * Copyright © 2018 Xilinx Inc
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
+ */
+
+#include <cstring>
+#include <csignal>
+#include <fcntl.h>
+#include <libudev.h>
+#include <linux/fb.h>
+#include "log.h"
+#include "native-state-fbdev.h"
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+volatile bool NativeStateFbdev::should_quit_ = false;
+
+NativeStateFbdev::~NativeStateFbdev()
+{
+    if (isvalid_fd(fd_)) {
+        close(fd_);
+        fd_ = -1;
+    }
+}
+
+bool
+NativeStateFbdev::init_display()
+{
+    struct sigaction new_action;
+
+    new_action.sa_handler = &NativeStateFbdev::quit_handler;
+    new_action.sa_flags = 0;
+    sigemptyset(&new_action.sa_mask);
+
+    sigaction(SIGINT, &new_action, NULL);
+    sigaction(SIGTERM, &new_action, NULL);
+
+    fd_ = get_fd();
+    if (!isvalid_fd(fd_)) {
+        Log::error("Failed to find a suitable FB device\n");
+        return false;
+    }
+
+    return true;
+}
+
+void*
+NativeStateFbdev::display()
+{
+    if (!isvalid_fd(fd_)) {
+        Log::error("Failed to initalize display\n");
+        return NULL;
+    }
+
+    return reinterpret_cast<void*>(fd_);
+}
+
+bool
+NativeStateFbdev::create_window(WindowProperties const& /*properties*/)
+{
+    if (!isvalid_fd(fd_)) {
+        Log::error("Failed to initalize display\n");
+	should_quit_ = true;
+        return false;
+    }
+
+    if (ioctl(fd_, FBIOGET_VSCREENINFO, &fb_info_)) {
+        Log::error("Failed to get Frame buffer info\n");
+	should_quit_ = true;
+        return false;
+    }
+    return true;
+}
+
+void*
+NativeStateFbdev::window(WindowProperties& properties)
+{
+    properties = WindowProperties(fb_info_.xres, fb_info_.yres, true, 0);
+
+    return 0;
+}
+
+void
+NativeStateFbdev::visible(bool /*visible*/)
+{
+}
+
+bool
+NativeStateFbdev::should_quit()
+{
+    return should_quit_;
+}
+
+void
+NativeStateFbdev::flip()
+{
+}
+
+void
+NativeStateFbdev::quit_handler(int /*signum*/)
+{
+    should_quit_ = true;
+}
+
+bool
+NativeStateFbdev::isvalid_fd(int fd)
+{
+    return fd >= 0;
+}
+
+int
+NativeStateFbdev::get_fd()
+{
+    std::string node_path;
+    struct fb_var_screeninfo fb_info;
+    int fd = -1, temp_fd;
+
+    Log::debug("Using Udev to detect the right fb node to use\n");
+    auto udev_cntx = udev_new();
+    auto dev_enum = udev_enumerate_new(udev_cntx);
+
+    udev_enumerate_add_match_sysname(dev_enum, "fb[0-9]*");
+    udev_enumerate_scan_devices(dev_enum);
+
+    Log::debug("Looking for the right fb node...\n");
+
+    auto entity = udev_enumerate_get_list_entry(dev_enum);
+
+    while (entity && !isvalid_fd(fd)) {
+        char const * __restrict entity_sys_path =
+	    udev_list_entry_get_name(entity);
+
+	if (entity_sys_path) {
+            struct udev_device* dev =
+	        udev_device_new_from_syspath(udev_cntx,
+					     entity_sys_path);
+	    const char * dev_node_path =
+	        udev_device_get_devnode(dev);
+
+	    temp_fd = open(dev_node_path, O_RDWR);
+
+	    if (!ioctl(temp_fd, FBIOGET_VSCREENINFO, &fb_info)) {
+                fd = temp_fd;
+		break;
+	    }
+
+	    udev_device_unref(dev);
+	}
+
+	entity = udev_list_entry_get_next(entity);
+    }
+
+    return fd;
+}
Index: git/src/native-state-fbdev.h
===================================================================
--- /dev/null
+++ git/src/native-state-fbdev.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2018 Xilinx Inc
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
+ */
+
+#ifndef GLMARK2_NATIVE_STATE_FBDEV_H_
+#define GLMARK2_NATIVE_STATE_FBDEV_H_
+
+#include <csignal>
+#include <cstring>
+#include <EGL/egl.h>
+#include <EGL/eglplatform.h>
+#include <linux/fb.h>
+#include "native-state.h"
+
+class NativeStateFbdev : public NativeState
+{
+public:
+    NativeStateFbdev() :
+        fd_(-1),
+        native_window_((EGLNativeWindowType)NULL) {}
+    ~NativeStateFbdev();
+
+    bool init_display();
+    void* display();
+    bool create_window(WindowProperties const& properties);
+    void* window(WindowProperties& properties);
+    void visible(bool v);
+    bool should_quit();
+    void flip();
+
+private:
+    int fd_;
+    struct fb_var_screeninfo fb_info_;
+    NativeWindowType native_window_;
+    static volatile bool should_quit_;
+    static void quit_handler(int signum);
+    static bool isvalid_fd(int fd);
+    static int get_fd();
+};
+
+#endif /* GLMARK2_NATIVE_STATE_FBDEV_H_ */
Index: git/src/wscript_build
===================================================================
--- git.orig/src/wscript_build
+++ git/src/wscript_build
@@ -88,6 +88,7 @@ flavor_sources = {
   'win32-glesv2': common_flavor_sources + ['native-state-win32.cpp', 'gl-state-egl.cpp'],
   'x11-gl' : common_flavor_sources + ['native-state-x11.cpp', 'gl-state-glx.cpp'],
   'x11-glesv2' : common_flavor_sources + ['native-state-x11.cpp', 'gl-state-egl.cpp'],
+  'fbdev-glesv2' :  common_flavor_sources + ['native-state-fbdev.cpp', 'gl-state-egl.cpp']
 }
 flavor_uselibs = {
   'dispmanx-glesv2' : ['glad-egl-dispmanx', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2',  'dispmanx'],
@@ -99,6 +100,7 @@ flavor_uselibs = {
   'win32-glesv2': ['glad-egl-win32', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2'],
   'x11-gl' : ['x11', 'glad-gl', 'glad-glx', 'matrix-gl', 'common-gl'],
   'x11-glesv2' : ['x11', 'glad-egl-x11', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2'],
+  'fbdev-glesv2' : ['udev', 'glad-egl-fbdev', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2']
 }
 
 flavor_defines = {
@@ -111,6 +113,7 @@ flavor_defines = {
   'win32-glesv2': ['GLMARK2_USE_WIN32', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL'],
   'x11-gl' : ['GLMARK2_USE_X11', 'GLMARK2_USE_GL', 'GLMARK2_USE_GLX'],
   'x11-glesv2' : ['GLMARK2_USE_X11', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL'],
+  'fbdev-glesv2' : ['GLMARK2_USE_FBDEV', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL']
 }
 flavor_libs = {
   'dispmanx-glesv2' : [],
@@ -144,6 +147,7 @@ flavor_sources_gen = {
   'win32-glesv2' : [],
   'x11-gl' : [],
   'x11-glesv2' : [],
+  'fbdev-glesv2' : []
 }
 egl_platform_defines = {
   'dispmanx' : ['MESA_EGL_NO_X11_HEADERS'],
@@ -151,6 +155,7 @@ egl_platform_defines = {
   'wayland' : ['WL_EGL_PLATFORM'],
   'win32' : [],
   'x11' : [],
+  'fbdev' : ['MESA_EGL_NO_X11_HEADERS']
 }
 
 includes = ['.', 'scene-ideas', 'scene-terrain'] + platform_includes
Index: git/wscript
===================================================================
--- git.orig/wscript
+++ git/wscript
@@ -17,6 +17,7 @@ FLAVORS = {
     'win32-glesv2': 'glmark2-es2',
     'x11-gl' : 'glmark2',
     'x11-glesv2' : 'glmark2-es2',
+    'fbdev-glesv2' : 'glmark2-es2-fbdev',
 }
 FLAVORS_STR = ", ".join(sorted(list(FLAVORS) + ['all-linux', 'all-win32']))
 
@@ -210,6 +211,7 @@ def configure_linux(ctx):
                 ('libdrm','drm', None, list_contains(ctx.options.flavors, 'drm')),
                 ('gbm','gbm', None, list_contains(ctx.options.flavors, 'drm')),
                 ('libudev', 'udev', None, list_contains(ctx.options.flavors, 'drm')),
+                ('libudev', 'udev', None, list_contains(ctx.options.flavors, 'fbdev')),
                 ('wayland-client','wayland-client', None, list_contains(ctx.options.flavors, 'wayland')),
                 ('wayland-cursor','wayland-cursor', None, list_contains(ctx.options.flavors, 'wayland')),
                 ('wayland-egl','wayland-egl', None, list_contains(ctx.options.flavors, 'wayland'))]