Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: client/deps/glbench/src/egl_stuff.cc

Issue 1219003: Store GLXFBConfig and get X visual ID from it. (Closed)
Patch Set: Don't redeclare variables. Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | client/deps/glbench/src/glx_stuff.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <EGL/egl.h> 5 #include <EGL/egl.h>
6 6
7 #include "base/logging.h"
7 #include "main.h" 8 #include "main.h"
8 #include "xlib_window.h" 9 #include "xlib_window.h"
9 10
10 11
11 static EGLDisplay egl_display = NULL; 12 static EGLDisplay egl_display = NULL;
12 static EGLConfig egl_config = NULL; 13 static EGLConfig egl_config = NULL;
13 static EGLSurface egl_surface = NULL; 14 static EGLSurface egl_surface = NULL;
14 static EGLContext egl_context = NULL; 15 static EGLContext egl_context = NULL;
15 16
16 #define CHECK_EGL() do { \ 17 #define CHECK_EGL() do { \
17 if (eglGetError() != EGL_SUCCESS) return false; \ 18 if (eglGetError() != EGL_SUCCESS) return false; \
18 } while (0) 19 } while (0)
19 20
20 bool Init() { 21 bool Init() {
21 if (!XlibInit()) 22 if (!XlibInit())
22 return false; 23 return false;
23 24
24 EGLNativeWindowType native_window = 25 EGLNativeWindowType native_window =
25 static_cast<EGLNativeWindowType>(g_xlib_window); 26 static_cast<EGLNativeWindowType>(g_xlib_window);
26 egl_surface = eglCreateWindowSurface(egl_display, egl_config, 27 egl_surface = eglCreateWindowSurface(egl_display, egl_config,
27 native_window, NULL); 28 native_window, NULL);
28 CHECK_EGL(); 29 CHECK_EGL();
29 return true; 30 return true;
30 } 31 }
31 32
32 VisualID GetVisualID() { 33 XVisualInfo* GetXVisual() {
33 EGLint attribs[] = { 34 if (!egl_config) {
34 EGL_RED_SIZE, 1, 35 EGLint attribs[] = {
35 EGL_GREEN_SIZE, 1, 36 EGL_RED_SIZE, 1,
36 EGL_BLUE_SIZE, 1, 37 EGL_GREEN_SIZE, 1,
37 EGL_DEPTH_SIZE, 1, 38 EGL_BLUE_SIZE, 1,
38 EGL_STENCIL_SIZE, 1, 39 EGL_DEPTH_SIZE, 1,
39 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 40 EGL_STENCIL_SIZE, 1,
40 EGL_NONE 41 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
41 }; 42 EGL_NONE
43 };
42 44
43 EGLNativeDisplayType native_display = 45 EGLNativeDisplayType native_display =
44 static_cast<EGLNativeDisplayType>(g_xlib_display); 46 static_cast<EGLNativeDisplayType>(g_xlib_display);
45 47
46 EGLDisplay egl_display = eglGetDisplay(native_display); 48 egl_display = eglGetDisplay(native_display);
47 CHECK_EGL(); 49 CHECK_EGL();
48 50
49 eglInitialize(egl_display, NULL, NULL); 51 eglInitialize(egl_display, NULL, NULL);
50 CHECK_EGL(); 52 CHECK_EGL();
51 53
52 EGLint num_configs = -1; 54 EGLint num_configs = -1;
53 eglGetConfigs(egl_display, NULL, 0, &num_configs); 55 eglGetConfigs(egl_display, NULL, 0, &num_configs);
54 CHECK_EGL(); 56 CHECK_EGL();
55 57
56 EGLConfig egl_config; 58 eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_configs);
57 eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_configs); 59 CHECK_EGL();
58 CHECK_EGL(); 60 }
59 61
60 EGLint visual_id; 62 EGLint visual_id;
61 eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &visual_id); 63 eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &visual_id);
62 CHECK_EGL(); 64 CHECK_EGL();
63 65
64 return static_cast<VisualID>(visual_id); 66 XVisualInfo vinfo_template;
67 vinfo_template.visualid = static_cast<VisualID>(visual_id);
68 int nitems = 0;
69 XVisualInfo* ret = XGetVisualInfo(g_xlib_display, VisualIDMask,
70 &vinfo_template, &nitems);
71 CHECK(nitems == 1);
72 return ret;
65 } 73 }
66 74
67 bool InitContext() { 75 bool InitContext() {
68 EGLContext egl_context = eglCreateContext(egl_display, egl_config, 76 EGLContext egl_context = eglCreateContext(egl_display, egl_config,
69 NULL, NULL); 77 NULL, NULL);
70 CHECK_EGL(); 78 CHECK_EGL();
71 79
72 eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context); 80 eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
73 CHECK_EGL(); 81 CHECK_EGL();
74 82
(...skipping 16 matching lines...) Expand all
91 eglTerminate(egl_display); 99 eglTerminate(egl_display);
92 } 100 }
93 101
94 void SwapBuffers() { 102 void SwapBuffers() {
95 eglSwapBuffers(egl_display, egl_surface); 103 eglSwapBuffers(egl_display, egl_surface);
96 } 104 }
97 105
98 bool SwapInterval(int interval) { 106 bool SwapInterval(int interval) {
99 return eglSwapInterval(egl_display, interval) == EGL_TRUE; 107 return eglSwapInterval(egl_display, interval) == EGL_TRUE;
100 } 108 }
OLDNEW
« no previous file with comments | « no previous file | client/deps/glbench/src/glx_stuff.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698