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 #include "ui/gfx/gl/egl_util.h" |
| 11 |
| 12 #if defined(USE_WAYLAND) |
| 13 #include "ui/wayland/wayland_display.h" |
| 14 #include <EGL/egl.h> |
| 15 #include <EGL/eglext.h> |
| 16 #else |
10 #include "third_party/angle/include/EGL/egl.h" | 17 #include "third_party/angle/include/EGL/egl.h" |
11 #include "third_party/angle/include/EGL/eglext.h" | 18 #include "third_party/angle/include/EGL/eglext.h" |
12 #include "ui/gfx/gl/egl_util.h" | 19 #endif |
13 | 20 |
14 // This header must come after the above third-party include, as | 21 // This header must come after the above third-party include, as |
15 // it brings in #defines that cause conflicts. | 22 // it brings in #defines that cause conflicts. |
16 #include "ui/gfx/gl/gl_bindings.h" | 23 #include "ui/gfx/gl/gl_bindings.h" |
17 | 24 |
18 #if defined(USE_X11) | 25 #if defined(USE_X11) && !defined(USE_WAYLAND) |
19 extern "C" { | 26 extern "C" { |
20 #include <X11/Xlib.h> | 27 #include <X11/Xlib.h> |
21 } | 28 } |
22 #endif | 29 #endif |
23 | 30 |
24 namespace gfx { | 31 namespace gfx { |
25 | 32 |
26 namespace { | 33 namespace { |
27 EGLConfig g_config; | 34 EGLConfig g_config; |
28 EGLDisplay g_display; | 35 EGLDisplay g_display; |
29 EGLNativeDisplayType g_native_display; | 36 EGLNativeDisplayType g_native_display; |
30 EGLConfig g_software_config; | 37 EGLConfig g_software_config; |
31 EGLDisplay g_software_display; | 38 EGLDisplay g_software_display; |
32 EGLNativeDisplayType g_software_native_display; | 39 EGLNativeDisplayType g_software_native_display; |
33 } | 40 } |
34 | 41 |
35 GLSurfaceEGL::GLSurfaceEGL() { | 42 GLSurfaceEGL::GLSurfaceEGL() { |
36 } | 43 } |
37 | 44 |
38 GLSurfaceEGL::~GLSurfaceEGL() { | 45 GLSurfaceEGL::~GLSurfaceEGL() { |
39 } | 46 } |
40 | 47 |
41 bool GLSurfaceEGL::InitializeOneOff() { | 48 bool GLSurfaceEGL::InitializeOneOff() { |
42 static bool initialized = false; | 49 static bool initialized = false; |
43 if (initialized) | 50 if (initialized) |
44 return true; | 51 return true; |
45 | 52 |
46 #if defined(USE_X11) | 53 #if defined(USE_WAYLAND) |
| 54 g_native_display = ui::WaylandDisplay::Connect(NULL)->display(); |
| 55 #elif defined(USE_X11) |
47 g_native_display = XOpenDisplay(NULL); | 56 g_native_display = XOpenDisplay(NULL); |
48 #else | 57 #else |
49 g_native_display = EGL_DEFAULT_DISPLAY; | 58 g_native_display = EGL_DEFAULT_DISPLAY; |
50 #endif | 59 #endif |
51 g_display = eglGetDisplay(g_native_display); | 60 g_display = eglGetDisplay(g_native_display); |
52 if (!g_display) { | 61 if (!g_display) { |
53 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); | 62 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); |
54 return false; | 63 return false; |
55 } | 64 } |
56 | 65 |
57 if (!eglInitialize(g_display, NULL, NULL)) { | 66 if (!eglInitialize(g_display, NULL, NULL)) { |
58 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); | 67 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); |
59 return false; | 68 return false; |
60 } | 69 } |
61 | 70 |
62 // Choose an EGL configuration. | 71 // Choose an EGL configuration. |
63 static const EGLint kConfigAttribs[] = { | 72 static const EGLint kConfigAttribs[] = { |
64 EGL_BUFFER_SIZE, 32, | 73 EGL_BUFFER_SIZE, 32, |
65 EGL_ALPHA_SIZE, 8, | 74 EGL_ALPHA_SIZE, 8, |
66 EGL_BLUE_SIZE, 8, | 75 EGL_BLUE_SIZE, 8, |
67 EGL_GREEN_SIZE, 8, | 76 EGL_GREEN_SIZE, 8, |
68 EGL_RED_SIZE, 8, | 77 EGL_RED_SIZE, 8, |
69 EGL_DEPTH_SIZE, 16, | 78 EGL_DEPTH_SIZE, 16, |
70 EGL_STENCIL_SIZE, 8, | 79 EGL_STENCIL_SIZE, 8, |
71 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 80 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
72 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | 81 EGL_SURFACE_TYPE, EGL_WINDOW_BIT |
| 82 #if defined(USE_WAYLAND) |
| 83 | EGL_PIXMAP_BIT, |
| 84 #else |
| 85 | EGL_PBUFFER_BIT, |
| 86 #endif |
73 EGL_NONE | 87 EGL_NONE |
74 }; | 88 }; |
75 | 89 |
76 EGLint num_configs; | 90 EGLint num_configs; |
77 if (!eglChooseConfig(g_display, | 91 if (!eglChooseConfig(g_display, |
78 kConfigAttribs, | 92 kConfigAttribs, |
79 NULL, | 93 NULL, |
80 0, | 94 0, |
81 &num_configs)) { | 95 &num_configs)) { |
82 LOG(ERROR) << "eglChooseConfig failed failed with error " | 96 LOG(ERROR) << "eglChooseConfig failed failed with error " |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 310 |
297 gfx::Size PbufferGLSurfaceEGL::GetSize() { | 311 gfx::Size PbufferGLSurfaceEGL::GetSize() { |
298 return size_; | 312 return size_; |
299 } | 313 } |
300 | 314 |
301 EGLSurface PbufferGLSurfaceEGL::GetHandle() { | 315 EGLSurface PbufferGLSurfaceEGL::GetHandle() { |
302 return surface_; | 316 return surface_; |
303 } | 317 } |
304 | 318 |
305 } // namespace gfx | 319 } // namespace gfx |
OLD | NEW |