File: | tools/cafe-session-check-accelerated-gles-helper.c |
Warning: | line 222, column 25 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- mode:c; c-basic-offset: 8; indent-tabs-mode: nil; -*- */ |
2 | /* |
3 | * |
4 | * Copyright (C) 2016 Endless Mobile, Inc |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | * |
20 | * Author: |
21 | * Cosimo Cecchi <cosimo@endlessm.com> |
22 | */ |
23 | |
24 | /* for strcasestr */ |
25 | #define _GNU_SOURCE |
26 | |
27 | #include <config.h> |
28 | |
29 | #include <ctk/ctk.h> |
30 | #include <locale.h> |
31 | #include <stdlib.h> |
32 | #include <string.h> |
33 | |
34 | #ifdef CDK_WINDOWING_X11 |
35 | #define GL_GLEXT_PROTOTYPES |
36 | |
37 | #include <cdk/cdkx.h> |
38 | #include <GLES2/gl2.h> |
39 | #include <GLES2/gl2ext.h> |
40 | #include <EGL/egl.h> |
41 | #include <EGL/eglext.h> |
42 | #endif |
43 | |
44 | #include "cafe-session-check-accelerated-common.h" |
45 | |
46 | #ifdef CDK_WINDOWING_X11 |
47 | static EGLDisplay |
48 | get_display (void *native) |
49 | { |
50 | EGLDisplay dpy = NULL((void*)0); |
51 | const char *client_exts = eglQueryString (NULL((void*)0), EGL_EXTENSIONS0x3055); |
52 | |
53 | if (g_strstr_len (client_exts, -1, "EGL_KHR_platform_base")) { |
54 | PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = |
55 | (void *) eglGetProcAddress ("eglGetPlatformDisplay"); |
56 | |
57 | if (get_platform_display) |
58 | dpy = get_platform_display (EGL_PLATFORM_X11_KHR0x31D5, native, NULL((void*)0)); |
59 | |
60 | if (dpy) |
61 | return dpy; |
62 | } |
63 | |
64 | if (g_strstr_len (client_exts, -1, "EGL_EXT_platform_base")) { |
65 | PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = |
66 | (void *) eglGetProcAddress ("eglGetPlatformDisplayEXT"); |
67 | |
68 | if (get_platform_display) |
69 | dpy = get_platform_display (EGL_PLATFORM_X11_KHR0x31D5, native, NULL((void*)0)); |
70 | |
71 | if (dpy) |
72 | return dpy; |
73 | } |
74 | |
75 | return eglGetDisplay ((EGLNativeDisplayType) native); |
76 | } |
77 | |
78 | static char * |
79 | get_gles_renderer (void) |
80 | { |
81 | /* Select GLESv2 config */ |
82 | EGLint attribs[] = { |
83 | EGL_RENDERABLE_TYPE0x3040, EGL_OPENGL_ES2_BIT0x0004, |
84 | EGL_RED_SIZE0x3024, 1, |
85 | EGL_GREEN_SIZE0x3023, 1, |
86 | EGL_BLUE_SIZE0x3022, 1, |
87 | EGL_NONE0x3038 |
88 | }; |
89 | |
90 | EGLint ctx_attribs[] = { |
91 | EGL_CONTEXT_CLIENT_VERSION0x3098, 2, |
92 | EGL_NONE0x3038 |
93 | }; |
94 | |
95 | gboolean egl_inited = FALSE(0); |
96 | CdkDisplay *cdk_dpy; |
97 | Display *display; |
98 | Window win = None0L; |
99 | EGLContext egl_ctx = NULL((void*)0); |
100 | EGLDisplay egl_dpy = NULL((void*)0); |
101 | EGLSurface egl_surf = NULL((void*)0); |
102 | char *renderer = NULL((void*)0); |
103 | |
104 | cdk_dpy = cdk_display_get_default (); |
105 | cdk_x11_display_error_trap_push (cdk_dpy); |
106 | display = CDK_DISPLAY_XDISPLAY (cdk_dpy)(cdk_x11_display_get_xdisplay (cdk_dpy)); |
107 | egl_dpy = get_display (display); |
108 | if (!egl_dpy) { |
109 | g_warning ("eglGetDisplay() failed"); |
110 | goto out; |
111 | } |
112 | |
113 | EGLint egl_major, egl_minor; |
114 | if (!eglInitialize (egl_dpy, &egl_major, &egl_minor)) { |
115 | g_warning ("eglInitialize() failed"); |
116 | goto out; |
117 | } |
118 | |
119 | egl_inited = TRUE(!(0)); |
120 | |
121 | EGLint num_configs; |
122 | EGLConfig config; |
123 | if (!eglChooseConfig (egl_dpy, attribs, &config, 1, &num_configs)) { |
124 | g_warning ("Failed to get EGL configuration"); |
125 | goto out; |
126 | } |
127 | |
128 | EGLint vid; |
129 | if (!eglGetConfigAttrib (egl_dpy, config, EGL_NATIVE_VISUAL_ID0x302E, &vid)) { |
130 | g_warning ("Failed to get EGL visual"); |
131 | goto out; |
132 | } |
133 | |
134 | /* The X window visual must match the EGL config */ |
135 | XVisualInfo *vis_info, vis_template; |
136 | int num_visuals; |
137 | vis_template.visualid = vid; |
138 | vis_info = XGetVisualInfo (display, VisualIDMask0x1, &vis_template, &num_visuals); |
139 | if (!vis_info) { |
140 | g_warning ("Failed to get X visual"); |
141 | goto out; |
142 | } |
143 | |
144 | XSetWindowAttributes attr; |
145 | attr.colormap = XCreateColormap (display, DefaultRootWindow (display)((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay )(display))->default_screen)])->root), |
146 | vis_info->visual, AllocNone0); |
147 | win = XCreateWindow (display, DefaultRootWindow (display)((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay )(display))->default_screen)])->root), |
148 | 0, 0, /* x, y */ |
149 | 1, 1, /* width, height */ |
150 | 0, /* border_width */ |
151 | vis_info->depth, InputOutput1, |
152 | vis_info->visual, CWColormap(1L<<13), &attr); |
153 | XFree (vis_info); |
154 | |
155 | eglBindAPI (EGL_OPENGL_ES_API0x30A0); |
156 | |
157 | egl_ctx = eglCreateContext (egl_dpy, config, EGL_NO_CONTEXT((EGLContext) (0)), ctx_attribs); |
158 | if (!egl_ctx) { |
159 | g_warning ("Failed to create EGL context"); |
160 | goto out; |
161 | } |
162 | |
163 | egl_surf = eglCreateWindowSurface (egl_dpy, config, win, NULL((void*)0)); |
164 | if (!egl_surf) { |
165 | g_warning ("Failed to create EGL surface"); |
166 | goto out; |
167 | } |
168 | |
169 | if (!eglMakeCurrent (egl_dpy, egl_surf, egl_surf, egl_ctx)) { |
170 | g_warning ("eglMakeCurrent() failed"); |
171 | goto out; |
172 | } |
173 | |
174 | renderer = g_strdup ((const char *) glGetString (GL_RENDERER))g_strdup_inline ((const char *) glGetString (0x1F01)); |
175 | |
176 | out: |
177 | if (egl_ctx) |
178 | eglDestroyContext (egl_dpy, egl_ctx); |
179 | if (egl_surf) |
180 | eglDestroySurface (egl_dpy, egl_surf); |
181 | if (egl_inited) |
182 | eglTerminate (egl_dpy); |
183 | if (win != None0L) |
184 | XDestroyWindow (display, win); |
185 | |
186 | cdk_x11_display_error_trap_pop_ignored (cdk_dpy); |
187 | return renderer; |
188 | } |
189 | #endif |
190 | |
191 | static gboolean print_renderer = FALSE(0); |
192 | |
193 | static const GOptionEntry entries[] = { |
194 | { "print-renderer", 'p', 0, G_OPTION_ARG_NONE, &print_renderer, "Print EGL renderer name", NULL((void*)0) }, |
195 | { NULL((void*)0) }, |
196 | }; |
197 | |
198 | int |
199 | main (int argc, |
200 | char **argv) |
201 | { |
202 | GOptionContext *context; |
203 | int ret = HELPER_NO_ACCEL1; |
204 | GError *error = NULL((void*)0); |
205 | |
206 | setlocale (LC_ALL6, ""); |
207 | |
208 | context = g_option_context_new (NULL((void*)0)); |
209 | g_option_context_add_group (context, ctk_get_option_group (TRUE(!(0)))); |
210 | g_option_context_add_main_entries (context, entries, NULL((void*)0)); |
211 | |
212 | if (!g_option_context_parse (context, &argc, &argv, &error)) { |
213 | g_error ("Can't parse command line: %s\n", error->message); |
214 | g_error_free (error); |
215 | goto out; |
216 | } |
217 | |
218 | #ifdef CDK_WINDOWING_X11 |
219 | char *renderer = get_gles_renderer (); |
220 | if (renderer != NULL((void*)0)) { |
221 | if (print_renderer) |
222 | g_print ("%s", renderer); |
This statement is never executed | |
223 | if (strcasestr (renderer, "llvmpipe")) |
224 | ret = HELPER_SOFTWARE_RENDERING2; |
225 | else |
226 | ret = HELPER_ACCEL0; |
227 | } |
228 | #endif |
229 | |
230 | out: |
231 | return ret; |
232 | } |