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