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(OS_ANDROID) | 10 #if !defined(OS_ANDROID) |
11 #include "third_party/angle/include/EGL/egl.h" | 11 #include "third_party/angle/include/EGL/egl.h" |
12 #include "third_party/angle/include/EGL/eglext.h" | 12 #include "third_party/angle/include/EGL/eglext.h" |
13 #endif | 13 #endif |
14 #include "ui/gfx/gl/egl_util.h" | 14 #include "ui/gfx/gl/egl_util.h" |
15 | 15 |
16 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
17 #include <EGL/egl.h> | 17 #include <EGL/egl.h> |
18 #endif | 18 #endif |
19 | 19 |
20 // This header must come after the above third-party include, as | 20 // This header must come after the above third-party include, as |
21 // it brings in #defines that cause conflicts. | 21 // it brings in #defines that cause conflicts. |
22 #include "ui/gfx/gl/gl_bindings.h" | 22 #include "ui/gfx/gl/gl_bindings.h" |
23 | 23 |
24 #if defined(USE_X11) && !defined(USE_WAYLAND) | 24 #if defined(USE_X11) && !defined(USE_WAYLAND) |
25 extern "C" { | 25 extern "C" { |
26 #include <X11/Xlib.h> | 26 #include <X11/Xlib.h> |
27 } | 27 } |
| 28 #include "ui/base/x/x11_util.h" |
28 #endif | 29 #endif |
29 | 30 |
30 #if defined(USE_WAYLAND) | 31 #if defined(USE_WAYLAND) |
31 #include "ui/wayland/wayland_display.h" | 32 #include "ui/wayland/wayland_display.h" |
32 #endif | 33 #endif |
33 | 34 |
34 namespace gfx { | 35 namespace gfx { |
35 | 36 |
36 namespace { | 37 namespace { |
37 EGLConfig g_config; | 38 EGLConfig g_config; |
38 EGLDisplay g_display; | 39 EGLDisplay g_display; |
39 EGLNativeDisplayType g_native_display; | |
40 EGLConfig g_software_config; | 40 EGLConfig g_software_config; |
41 EGLDisplay g_software_display; | 41 EGLDisplay g_software_display; |
42 EGLNativeDisplayType g_software_native_display; | 42 EGLNativeDisplayType g_software_native_display; |
43 } | 43 } |
44 | 44 |
45 GLSurfaceEGL::GLSurfaceEGL() : software_(false) { | 45 GLSurfaceEGL::GLSurfaceEGL() : software_(false) { |
46 } | 46 } |
47 | 47 |
48 GLSurfaceEGL::~GLSurfaceEGL() { | 48 GLSurfaceEGL::~GLSurfaceEGL() { |
49 } | 49 } |
50 | 50 |
| 51 // static |
51 bool GLSurfaceEGL::InitializeOneOff() { | 52 bool GLSurfaceEGL::InitializeOneOff() { |
52 static bool initialized = false; | 53 static bool initialized = false; |
53 if (initialized) | 54 if (initialized) |
54 return true; | 55 return true; |
55 | 56 |
56 #if defined(USE_WAYLAND) | 57 g_display = eglGetDisplay(GetNativeDisplay()); |
57 g_native_display = ui::WaylandDisplay::Connect(NULL)->display(); | |
58 #elif defined(USE_X11) | |
59 g_native_display = XOpenDisplay(NULL); | |
60 #else | |
61 g_native_display = EGL_DEFAULT_DISPLAY; | |
62 #endif | |
63 g_display = eglGetDisplay(g_native_display); | |
64 if (!g_display) { | 58 if (!g_display) { |
65 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); | 59 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); |
66 return false; | 60 return false; |
67 } | 61 } |
68 | 62 |
69 if (!eglInitialize(g_display, NULL, NULL)) { | 63 if (!eglInitialize(g_display, NULL, NULL)) { |
70 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); | 64 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); |
71 return false; | 65 return false; |
72 } | 66 } |
73 | 67 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 151 } |
158 | 152 |
159 EGLDisplay GLSurfaceEGL::GetDisplay() { | 153 EGLDisplay GLSurfaceEGL::GetDisplay() { |
160 return software_ ? g_software_display : g_display; | 154 return software_ ? g_software_display : g_display; |
161 } | 155 } |
162 | 156 |
163 EGLConfig GLSurfaceEGL::GetConfig() { | 157 EGLConfig GLSurfaceEGL::GetConfig() { |
164 return software_ ? g_software_config : g_config; | 158 return software_ ? g_software_config : g_config; |
165 } | 159 } |
166 | 160 |
| 161 // static |
167 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { | 162 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { |
168 return g_display; | 163 return g_display; |
169 } | 164 } |
170 | 165 |
| 166 // static |
171 EGLDisplay GLSurfaceEGL::GetSoftwareDisplay() { | 167 EGLDisplay GLSurfaceEGL::GetSoftwareDisplay() { |
172 return g_software_display; | 168 return g_software_display; |
173 } | 169 } |
174 | 170 |
| 171 // static |
175 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { | 172 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { |
176 return g_native_display; | 173 #if defined(USE_WAYLAND) |
| 174 static EGLNativeDisplayType native_display = NULL; |
| 175 if (!native_display) |
| 176 native_display = ui::WaylandDisplay::Connect(NULL)->display(); |
| 177 return native_display; |
| 178 #elif defined(USE_X11) |
| 179 return ui::GetXDisplay(); |
| 180 #else |
| 181 return EGL_DEFAULT_DISPLAY; |
| 182 #endif |
177 } | 183 } |
178 | 184 |
179 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(bool software, | 185 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(bool software, |
180 gfx::PluginWindowHandle window) | 186 gfx::PluginWindowHandle window) |
181 : window_(window), | 187 : window_(window), |
182 surface_(NULL), | 188 surface_(NULL), |
183 supports_post_sub_buffer_(false) | 189 supports_post_sub_buffer_(false) |
184 { | 190 { |
185 software_ = software; | 191 software_ = software; |
186 } | 192 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, | 387 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, |
382 &handle)) { | 388 &handle)) { |
383 return NULL; | 389 return NULL; |
384 } | 390 } |
385 | 391 |
386 return handle; | 392 return handle; |
387 #endif | 393 #endif |
388 } | 394 } |
389 | 395 |
390 } // namespace gfx | 396 } // namespace gfx |
OLD | NEW |