OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gl/gl_surface_egl.h" | 5 #include "ui/gl/gl_surface_egl.h" |
6 | 6 |
7 #if defined(OS_ANDROID) | 7 #if defined(OS_ANDROID) |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
9 #endif | 9 #endif |
10 | 10 |
| 11 #include "base/command_line.h" |
11 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gl/egl_util.h" | 18 #include "ui/gl/egl_util.h" |
18 #include "ui/gl/gl_context.h" | 19 #include "ui/gl/gl_context.h" |
19 #include "ui/gl/gl_implementation.h" | 20 #include "ui/gl/gl_implementation.h" |
20 #include "ui/gl/gl_surface_stub.h" | 21 #include "ui/gl/gl_surface_stub.h" |
21 #include "ui/gl/gl_switches.h" | 22 #include "ui/gl/gl_switches.h" |
22 #include "ui/gl/scoped_make_current.h" | 23 #include "ui/gl/scoped_make_current.h" |
23 #include "ui/gl/sync_control_vsync_provider.h" | 24 #include "ui/gl/sync_control_vsync_provider.h" |
24 | 25 |
25 #if defined(USE_X11) | 26 #if defined(USE_X11) |
26 extern "C" { | 27 extern "C" { |
27 #include <X11/Xlib.h> | 28 #include <X11/Xlib.h> |
28 } | 29 } |
29 #endif | 30 #endif |
30 | 31 |
31 #if defined (USE_OZONE) | 32 #if defined (USE_OZONE) |
32 #include "ui/ozone/public/surface_factory_ozone.h" | 33 #include "ui/ozone/public/surface_factory_ozone.h" |
33 #endif | 34 #endif |
34 | 35 |
35 #if !defined(EGL_FIXED_SIZE_ANGLE) | 36 #if !defined(EGL_FIXED_SIZE_ANGLE) |
36 #define EGL_FIXED_SIZE_ANGLE 0x3201 | 37 #define EGL_FIXED_SIZE_ANGLE 0x3201 |
37 #endif | 38 #endif |
38 | 39 |
| 40 #if defined(OS_WIN) |
| 41 // From ANGLE's egl/eglext.h. |
| 42 #if !defined(EGL_PLATFORM_ANGLE_ANGLE) |
| 43 #define EGL_PLATFORM_ANGLE_ANGLE 0x3201 |
| 44 #endif |
| 45 #if !defined(EGL_PLATFORM_ANGLE_TYPE_ANGLE) |
| 46 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3202 |
| 47 #endif |
| 48 #if !defined(EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE) |
| 49 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE 0x3206 |
| 50 #endif |
| 51 #endif // defined(OS_WIN) |
| 52 |
39 using ui::GetLastEGLErrorString; | 53 using ui::GetLastEGLErrorString; |
40 | 54 |
41 namespace gfx { | 55 namespace gfx { |
42 | 56 |
43 namespace { | 57 namespace { |
44 | 58 |
45 EGLConfig g_config; | 59 EGLConfig g_config; |
46 EGLDisplay g_display; | 60 EGLDisplay g_display; |
47 EGLNativeDisplayType g_native_display; | 61 EGLNativeDisplayType g_native_display; |
48 | 62 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } // namespace | 105 } // namespace |
92 | 106 |
93 GLSurfaceEGL::GLSurfaceEGL() {} | 107 GLSurfaceEGL::GLSurfaceEGL() {} |
94 | 108 |
95 bool GLSurfaceEGL::InitializeOneOff() { | 109 bool GLSurfaceEGL::InitializeOneOff() { |
96 static bool initialized = false; | 110 static bool initialized = false; |
97 if (initialized) | 111 if (initialized) |
98 return true; | 112 return true; |
99 | 113 |
100 g_native_display = GetPlatformDefaultEGLNativeDisplay(); | 114 g_native_display = GetPlatformDefaultEGLNativeDisplay(); |
| 115 |
| 116 #if defined(OS_WIN) |
| 117 g_display = GetPlatformDisplay(g_native_display); |
| 118 #else |
101 g_display = eglGetDisplay(g_native_display); | 119 g_display = eglGetDisplay(g_native_display); |
| 120 #endif |
| 121 |
102 if (!g_display) { | 122 if (!g_display) { |
103 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); | 123 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); |
104 return false; | 124 return false; |
105 } | 125 } |
106 | 126 |
107 if (!eglInitialize(g_display, NULL, NULL)) { | 127 if (!eglInitialize(g_display, NULL, NULL)) { |
108 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); | 128 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); |
109 return false; | 129 return false; |
110 } | 130 } |
111 | 131 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() { | 241 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() { |
222 return g_egl_create_context_robustness_supported; | 242 return g_egl_create_context_robustness_supported; |
223 } | 243 } |
224 | 244 |
225 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { | 245 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { |
226 return g_egl_surfaceless_context_supported; | 246 return g_egl_surfaceless_context_supported; |
227 } | 247 } |
228 | 248 |
229 GLSurfaceEGL::~GLSurfaceEGL() {} | 249 GLSurfaceEGL::~GLSurfaceEGL() {} |
230 | 250 |
| 251 #if defined(OS_WIN) |
| 252 static const EGLint kDisplayAttribsWarp[] { |
| 253 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
| 254 EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE, |
| 255 EGL_NONE |
| 256 }; |
| 257 |
| 258 // static |
| 259 EGLDisplay GLSurfaceEGL::GetPlatformDisplay( |
| 260 EGLNativeDisplayType native_display) { |
| 261 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp)) { |
| 262 // Check for availability of WARP via ANGLE extension. |
| 263 bool supports_warp = false; |
| 264 const char* no_display_extensions = eglQueryString(EGL_NO_DISPLAY, |
| 265 EGL_EXTENSIONS); |
| 266 // If EGL_EXT_client_extensions not supported this call to eglQueryString |
| 267 // will return NULL. |
| 268 if (no_display_extensions) |
| 269 supports_warp = |
| 270 ExtensionsContain(no_display_extensions, "ANGLE_platform_angle") && |
| 271 ExtensionsContain(no_display_extensions, "ANGLE_platform_angle_d3d"); |
| 272 |
| 273 if (!supports_warp) |
| 274 return NULL; |
| 275 |
| 276 return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, native_display, |
| 277 kDisplayAttribsWarp); |
| 278 } |
| 279 |
| 280 return eglGetDisplay(native_display); |
| 281 } |
| 282 #endif |
| 283 |
231 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) | 284 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) |
232 : window_(window), | 285 : window_(window), |
233 surface_(NULL), | 286 surface_(NULL), |
234 supports_post_sub_buffer_(false), | 287 supports_post_sub_buffer_(false), |
235 config_(NULL), | 288 config_(NULL), |
236 size_(1, 1) { | 289 size_(1, 1) { |
237 #if defined(OS_ANDROID) | 290 #if defined(OS_ANDROID) |
238 if (window) | 291 if (window) |
239 ANativeWindow_acquire(window); | 292 ANativeWindow_acquire(window); |
240 #endif | 293 #endif |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 701 } |
649 | 702 |
650 void* SurfacelessEGL::GetShareHandle() { | 703 void* SurfacelessEGL::GetShareHandle() { |
651 return NULL; | 704 return NULL; |
652 } | 705 } |
653 | 706 |
654 SurfacelessEGL::~SurfacelessEGL() { | 707 SurfacelessEGL::~SurfacelessEGL() { |
655 } | 708 } |
656 | 709 |
657 } // namespace gfx | 710 } // namespace gfx |
OLD | NEW |