OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 "ui/gfx/gl/gl_surface_egl.h" | 5 #include "ui/gfx/gl/gl_surface_egl.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #if defined(USE_WAYLAND) | |
11 #include "ui/wayland/wayland_display.h" | |
12 #include <EGL/egl.h> | |
13 #else | |
10 #include "third_party/angle/include/EGL/egl.h" | 14 #include "third_party/angle/include/EGL/egl.h" |
15 #endif | |
11 #include "ui/gfx/gl/egl_util.h" | 16 #include "ui/gfx/gl/egl_util.h" |
12 | 17 |
13 // This header must come after the above third-party include, as | 18 // This header must come after the above third-party include, as |
14 // it brings in #defines that cause conflicts. | 19 // it brings in #defines that cause conflicts. |
15 #include "ui/gfx/gl/gl_bindings.h" | 20 #include "ui/gfx/gl/gl_bindings.h" |
16 | 21 |
17 #if defined(USE_X11) | 22 #if defined(USE_X11) && !defined(USE_WAYLAND) |
jonathan.backer
2011/07/26 14:56:27
Is it consistent to have USE_X11 and USE_WAYLAND d
| |
18 extern "C" { | 23 extern "C" { |
19 #include <X11/Xlib.h> | 24 #include <X11/Xlib.h> |
20 } | 25 } |
21 #endif | 26 #endif |
22 | 27 |
23 namespace gfx { | 28 namespace gfx { |
24 | 29 |
25 namespace { | 30 namespace { |
26 EGLConfig g_config; | 31 EGLConfig g_config; |
27 EGLDisplay g_display; | 32 EGLDisplay g_display; |
28 EGLNativeDisplayType g_native_display; | 33 EGLNativeDisplayType g_native_display; |
29 } | 34 } |
30 | 35 |
31 GLSurfaceEGL::GLSurfaceEGL() { | 36 GLSurfaceEGL::GLSurfaceEGL() { |
32 } | 37 } |
33 | 38 |
34 GLSurfaceEGL::~GLSurfaceEGL() { | 39 GLSurfaceEGL::~GLSurfaceEGL() { |
35 } | 40 } |
36 | 41 |
37 bool GLSurfaceEGL::InitializeOneOff() { | 42 bool GLSurfaceEGL::InitializeOneOff() { |
38 static bool initialized = false; | 43 static bool initialized = false; |
39 if (initialized) | 44 if (initialized) |
40 return true; | 45 return true; |
41 | 46 |
42 #if defined(USE_X11) | 47 #if defined(USE_WAYLAND) |
48 g_native_display = WaylandDisplay::Connect(NULL)->GetNativeDisplay(); | |
49 #elif defined(USE_X11) | |
43 g_native_display = XOpenDisplay(NULL); | 50 g_native_display = XOpenDisplay(NULL); |
44 #else | 51 #else |
45 g_native_display = EGL_DEFAULT_DISPLAY; | 52 g_native_display = EGL_DEFAULT_DISPLAY; |
46 #endif | 53 #endif |
47 g_display = eglGetDisplay(g_native_display); | 54 g_display = eglGetDisplay(g_native_display); |
48 if (!g_display) { | 55 if (!g_display) { |
49 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); | 56 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); |
50 return false; | 57 return false; |
51 } | 58 } |
52 | 59 |
53 if (!eglInitialize(g_display, NULL, NULL)) { | 60 if (!eglInitialize(g_display, NULL, NULL)) { |
54 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); | 61 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); |
55 return false; | 62 return false; |
56 } | 63 } |
57 | 64 |
58 // Choose an EGL configuration. | 65 // Choose an EGL configuration. |
59 static const EGLint kConfigAttribs[] = { | 66 static const EGLint kConfigAttribs[] = { |
60 EGL_BUFFER_SIZE, 32, | 67 EGL_BUFFER_SIZE, 32, |
61 EGL_ALPHA_SIZE, 8, | 68 EGL_ALPHA_SIZE, 8, |
62 EGL_BLUE_SIZE, 8, | 69 EGL_BLUE_SIZE, 8, |
63 EGL_GREEN_SIZE, 8, | 70 EGL_GREEN_SIZE, 8, |
64 EGL_RED_SIZE, 8, | 71 EGL_RED_SIZE, 8, |
65 EGL_DEPTH_SIZE, 16, | 72 EGL_DEPTH_SIZE, 16, |
66 EGL_STENCIL_SIZE, 8, | 73 EGL_STENCIL_SIZE, 8, |
67 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 74 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
68 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | 75 EGL_SURFACE_TYPE, EGL_WINDOW_BIT |
76 #if defined(USE_WAYLAND) | |
77 | EGL_PIXMAP_BIT, | |
78 #else | |
79 | EGL_PBUFFER_BIT, | |
80 #endif | |
69 EGL_NONE | 81 EGL_NONE |
70 }; | 82 }; |
71 | 83 |
72 EGLint num_configs; | 84 EGLint num_configs; |
73 if (!eglChooseConfig(g_display, | 85 if (!eglChooseConfig(g_display, |
74 kConfigAttribs, | 86 kConfigAttribs, |
75 NULL, | 87 NULL, |
76 0, | 88 0, |
77 &num_configs)) { | 89 &num_configs)) { |
78 LOG(ERROR) << "eglChooseConfig failed failed with error " | 90 LOG(ERROR) << "eglChooseConfig failed failed with error " |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 | 248 |
237 gfx::Size PbufferGLSurfaceEGL::GetSize() { | 249 gfx::Size PbufferGLSurfaceEGL::GetSize() { |
238 return size_; | 250 return size_; |
239 } | 251 } |
240 | 252 |
241 EGLSurface PbufferGLSurfaceEGL::GetHandle() { | 253 EGLSurface PbufferGLSurfaceEGL::GetHandle() { |
242 return surface_; | 254 return surface_; |
243 } | 255 } |
244 | 256 |
245 } // namespace gfx | 257 } // namespace gfx |
OLD | NEW |