| OLD | NEW |
| 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 "main.h" | 7 #include "main.h" |
| 8 #include "xlib_window.h" | 8 #include "xlib_window.h" |
| 9 | 9 |
| 10 | 10 |
| 11 static EGLDisplay egl_display = NULL; | 11 static EGLDisplay egl_display = NULL; |
| 12 static EGLConfig egl_config = NULL; | 12 static EGLConfig egl_config = NULL; |
| 13 static EGLSurface egl_surface = NULL; | 13 static EGLSurface egl_surface = NULL; |
| 14 static EGLContext egl_context = NULL; | 14 static EGLContext egl_context = NULL; |
| 15 | 15 |
| 16 #define CHECK_EGL() do { \ | 16 #define CHECK_EGL() do { \ |
| 17 if (eglGetError() != EGL_SUCCESS) return false; \ | 17 if (eglGetError() != EGL_SUCCESS) return false; \ |
| 18 } while (0) | 18 } while (0) |
| 19 | 19 |
| 20 bool Init() { | 20 bool Init() { |
| 21 if (!XlibInit()) | 21 if (!XlibInit()) |
| 22 return false; | 22 return false; |
| 23 | 23 |
| 24 EGLNativeWindowType native_window = |
| 25 static_cast<EGLNativeWindowType>(xlib_window); |
| 26 egl_surface = eglCreateWindowSurface(egl_display, egl_config, |
| 27 native_window, NULL); |
| 28 CHECK_EGL(); |
| 29 return true; |
| 30 } |
| 31 |
| 32 VisualID GetVisualID() { |
| 24 EGLint attribs[] = { | 33 EGLint attribs[] = { |
| 25 EGL_RED_SIZE, 5, | 34 EGL_RED_SIZE, 1, |
| 26 EGL_GREEN_SIZE, 6, | 35 EGL_GREEN_SIZE, 1, |
| 27 EGL_BLUE_SIZE, 5, | 36 EGL_BLUE_SIZE, 1, |
| 28 EGL_DEPTH_SIZE, 16, | 37 EGL_DEPTH_SIZE, 1, |
| 29 EGL_STENCIL_SIZE, 0, | 38 EGL_STENCIL_SIZE, 1, |
| 30 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, | 39 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 31 EGL_NONE | 40 EGL_NONE |
| 32 }; | 41 }; |
| 33 | 42 |
| 34 EGLNativeDisplayType native_display = | 43 EGLNativeDisplayType native_display = |
| 35 static_cast<EGLNativeDisplayType>(xlib_display); | 44 static_cast<EGLNativeDisplayType>(xlib_display); |
| 36 EGLNativeWindowType native_window = | |
| 37 static_cast<EGLNativeWindowType>(xlib_window); | |
| 38 | 45 |
| 39 EGLDisplay egl_display = eglGetDisplay(native_display); | 46 EGLDisplay egl_display = eglGetDisplay(native_display); |
| 40 CHECK_EGL(); | 47 CHECK_EGL(); |
| 41 | 48 |
| 42 eglInitialize(egl_display, NULL, NULL); | 49 eglInitialize(egl_display, NULL, NULL); |
| 43 CHECK_EGL(); | 50 CHECK_EGL(); |
| 44 | 51 |
| 45 EGLint num_configs = -1; | 52 EGLint num_configs = -1; |
| 46 eglGetConfigs(egl_display, NULL, 0, &num_configs); | 53 eglGetConfigs(egl_display, NULL, 0, &num_configs); |
| 47 CHECK_EGL(); | 54 CHECK_EGL(); |
| 48 | 55 |
| 49 EGLConfig egl_config; | 56 EGLConfig egl_config; |
| 50 eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_configs); | 57 eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_configs); |
| 51 CHECK_EGL(); | 58 CHECK_EGL(); |
| 52 | 59 |
| 53 egl_surface = eglCreateWindowSurface(egl_display, egl_config, | 60 EGLint visual_id; |
| 54 native_window, NULL); | 61 eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &visual_id); |
| 55 CHECK_EGL(); | 62 CHECK_EGL(); |
| 56 return true; | 63 |
| 64 return static_cast<VisualID>(visual_id); |
| 57 } | 65 } |
| 58 | 66 |
| 59 bool InitContext() { | 67 bool InitContext() { |
| 60 EGLContext egl_context = eglCreateContext(egl_display, egl_config, | 68 EGLContext egl_context = eglCreateContext(egl_display, egl_config, |
| 61 NULL, NULL); | 69 NULL, NULL); |
| 62 CHECK_EGL(); | 70 CHECK_EGL(); |
| 63 | 71 |
| 64 eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context); | 72 eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context); |
| 65 CHECK_EGL(); | 73 CHECK_EGL(); |
| 66 | 74 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 void TerminateGL() { | 89 void TerminateGL() { |
| 82 eglDestroySurface(egl_display, egl_surface); | 90 eglDestroySurface(egl_display, egl_surface); |
| 83 eglTerminate(egl_display); | 91 eglTerminate(egl_display); |
| 84 } | 92 } |
| 85 | 93 |
| 86 void SwapBuffers() { | 94 void SwapBuffers() { |
| 87 eglSwapBuffers(egl_display, egl_surface); | 95 eglSwapBuffers(egl_display, egl_surface); |
| 88 } | 96 } |
| 89 | 97 |
| 90 bool SwapInterval(int interval) { | 98 bool SwapInterval(int interval) { |
| 91 return eglSwapInterval(interval) == EGL_TRUE; | 99 return eglSwapInterval(egl_display, interval) == EGL_TRUE; |
| 92 } | 100 } |
| OLD | NEW |