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 #include "third_party/angle/include/EGL/egl.h" | 11 #include "third_party/angle/include/EGL/egl.h" |
11 #include "third_party/angle/include/EGL/eglext.h" | 12 #include "third_party/angle/include/EGL/eglext.h" |
13 #endif | |
12 #include "ui/gfx/gl/egl_util.h" | 14 #include "ui/gfx/gl/egl_util.h" |
13 | 15 |
16 #if defined(OS_ANDROID) | |
17 #include <EGL/egl.h> | |
18 #endif | |
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) && !defined(USE_WAYLAND) | 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 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 &g_config, | 109 &g_config, |
104 1, | 110 1, |
105 &num_configs)) { | 111 &num_configs)) { |
106 LOG(ERROR) << "eglChooseConfig failed with error " | 112 LOG(ERROR) << "eglChooseConfig failed with error " |
107 << GetLastEGLErrorString(); | 113 << GetLastEGLErrorString(); |
108 return false; | 114 return false; |
109 } | 115 } |
110 | 116 |
111 initialized = true; | 117 initialized = true; |
112 | 118 |
113 #if defined(USE_X11) | 119 #if defined(USE_X11) || defined(OS_ANDROID) |
114 return true; | 120 return true; |
115 #else | 121 #else |
116 g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE; | 122 g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE; |
117 #endif | 123 #endif |
118 g_software_display = eglGetDisplay(g_software_native_display); | 124 g_software_display = eglGetDisplay(g_software_native_display); |
119 if (!g_software_display) { | 125 if (!g_software_display) { |
120 return true; | 126 return true; |
121 } | 127 } |
122 | 128 |
123 if (!eglInitialize(g_software_display, NULL, NULL)) { | 129 if (!eglInitialize(g_software_display, NULL, NULL)) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 supports_post_sub_buffer_(false) | 183 supports_post_sub_buffer_(false) |
178 { | 184 { |
179 software_ = software; | 185 software_ = software; |
180 } | 186 } |
181 | 187 |
182 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { | 188 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { |
183 Destroy(); | 189 Destroy(); |
184 } | 190 } |
185 | 191 |
186 bool NativeViewGLSurfaceEGL::Initialize() { | 192 bool NativeViewGLSurfaceEGL::Initialize() { |
193 #if defined(OS_ANDROID) | |
jonathan.backer
2011/11/18 19:33:32
NOTREACHED()?
michaelbai
2011/11/21 18:28:58
Done.
| |
194 return false; | |
195 #else | |
187 DCHECK(!surface_); | 196 DCHECK(!surface_); |
188 | 197 |
189 if (!GetDisplay()) { | 198 if (!GetDisplay()) { |
190 LOG(ERROR) << "Trying to create surface with invalid display."; | 199 LOG(ERROR) << "Trying to create surface with invalid display."; |
191 return false; | 200 return false; |
192 } | 201 } |
193 | 202 |
194 static const EGLint egl_window_attributes_sub_buffer[] = { | 203 static const EGLint egl_window_attributes_sub_buffer[] = { |
195 EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_TRUE, | 204 EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_TRUE, |
196 EGL_NONE | 205 EGL_NONE |
(...skipping 15 matching lines...) Expand all Loading... | |
212 } | 221 } |
213 | 222 |
214 EGLint surfaceVal; | 223 EGLint surfaceVal; |
215 EGLBoolean retVal = eglQuerySurface(GetDisplay(), | 224 EGLBoolean retVal = eglQuerySurface(GetDisplay(), |
216 surface_, | 225 surface_, |
217 EGL_POST_SUB_BUFFER_SUPPORTED_NV, | 226 EGL_POST_SUB_BUFFER_SUPPORTED_NV, |
218 &surfaceVal); | 227 &surfaceVal); |
219 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE; | 228 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE; |
220 | 229 |
221 return true; | 230 return true; |
231 #endif | |
222 } | 232 } |
223 | 233 |
224 void NativeViewGLSurfaceEGL::Destroy() { | 234 void NativeViewGLSurfaceEGL::Destroy() { |
225 if (surface_) { | 235 if (surface_) { |
226 if (!eglDestroySurface(GetDisplay(), surface_)) { | 236 if (!eglDestroySurface(GetDisplay(), surface_)) { |
227 LOG(ERROR) << "eglDestroySurface failed with error " | 237 LOG(ERROR) << "eglDestroySurface failed with error " |
228 << GetLastEGLErrorString(); | 238 << GetLastEGLErrorString(); |
229 } | 239 } |
230 surface_ = NULL; | 240 surface_ = NULL; |
231 } | 241 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 Destroy(); | 354 Destroy(); |
345 size_ = size; | 355 size_ = size; |
346 return Initialize(); | 356 return Initialize(); |
347 } | 357 } |
348 | 358 |
349 EGLSurface PbufferGLSurfaceEGL::GetHandle() { | 359 EGLSurface PbufferGLSurfaceEGL::GetHandle() { |
350 return surface_; | 360 return surface_; |
351 } | 361 } |
352 | 362 |
353 void* PbufferGLSurfaceEGL::GetShareHandle() { | 363 void* PbufferGLSurfaceEGL::GetShareHandle() { |
364 #if defined(OS_ANDROID) | |
jonathan.backer
2011/11/18 19:33:32
NOTREACHED()?
michaelbai
2011/11/21 18:28:58
Done.
| |
365 return NULL; | |
366 #else | |
354 const char* extensions = eglQueryString(g_display, EGL_EXTENSIONS); | 367 const char* extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
355 if (!strstr(extensions, "EGL_ANGLE_query_surface_pointer")) | 368 if (!strstr(extensions, "EGL_ANGLE_query_surface_pointer")) |
356 return NULL; | 369 return NULL; |
357 | 370 |
358 void* handle; | 371 void* handle; |
359 if (!eglQuerySurfacePointerANGLE(g_display, | 372 if (!eglQuerySurfacePointerANGLE(g_display, |
360 GetHandle(), | 373 GetHandle(), |
361 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, | 374 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, |
362 &handle)) { | 375 &handle)) { |
363 return NULL; | 376 return NULL; |
364 } | 377 } |
365 | 378 |
366 return handle; | 379 return handle; |
380 #endif | |
367 } | 381 } |
368 | 382 |
369 } // namespace gfx | 383 } // namespace gfx |
OLD | NEW |