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/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "ui/gl/egl_util.h" | 15 #include "ui/gl/egl_util.h" |
16 #include "ui/gl/gl_context.h" | 16 #include "ui/gl/gl_context.h" |
17 | 17 |
18 #if defined(USE_X11) | 18 #if defined(USE_X11) |
19 extern "C" { | 19 extern "C" { |
20 #include <X11/Xlib.h> | 20 #include <X11/Xlib.h> |
21 } | 21 } |
22 #endif | 22 #endif |
23 | 23 |
24 #if defined(USE_NATIVE_SURFACE_LINUX) | |
25 #include "ui/base/linux/native_surface_linux_factory.h" | |
26 #endif | |
27 | |
24 using ui::GetLastEGLErrorString; | 28 using ui::GetLastEGLErrorString; |
25 | 29 |
26 namespace gfx { | 30 namespace gfx { |
27 | 31 |
28 namespace { | 32 namespace { |
29 | 33 |
30 EGLConfig g_config; | 34 EGLConfig g_config; |
31 EGLDisplay g_display; | 35 EGLDisplay g_display; |
32 EGLNativeDisplayType g_native_display; | 36 EGLNativeDisplayType g_native_display; |
33 EGLConfig g_software_config; | 37 EGLConfig g_software_config; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 } | 143 } |
140 | 144 |
141 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); | 145 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
142 g_egl_create_context_robustness_supported = | 146 g_egl_create_context_robustness_supported = |
143 HasEGLExtension("EGL_EXT_create_context_robustness"); | 147 HasEGLExtension("EGL_EXT_create_context_robustness"); |
144 g_egl_sync_control_supported = | 148 g_egl_sync_control_supported = |
145 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 149 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
146 | 150 |
147 initialized = true; | 151 initialized = true; |
148 | 152 |
149 #if defined(USE_X11) || defined(OS_ANDROID) | 153 #if defined(USE_X11) || defined(OS_ANDROID) || defined(USE_NATIVE_SURFACE_LINUX ) |
jonathan.backer
2013/04/30 12:41:20
nit: use a \ to wrap?
rjkroege
2013/05/06 18:46:24
Done.
| |
150 return true; | 154 return true; |
151 #else | 155 #else |
152 g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE; | 156 g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE; |
153 #endif | 157 #endif |
154 g_software_display = eglGetDisplay(g_software_native_display); | 158 g_software_display = eglGetDisplay(g_software_native_display); |
155 if (!g_software_display) { | 159 if (!g_software_display) { |
156 return true; | 160 return true; |
157 } | 161 } |
158 | 162 |
159 if (!eglInitialize(g_software_display, NULL, NULL)) { | 163 if (!eglInitialize(g_software_display, NULL, NULL)) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 220 |
217 GLSurfaceEGL::~GLSurfaceEGL() {} | 221 GLSurfaceEGL::~GLSurfaceEGL() {} |
218 | 222 |
219 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(bool software, | 223 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(bool software, |
220 gfx::AcceleratedWidget window) | 224 gfx::AcceleratedWidget window) |
221 : window_(window), | 225 : window_(window), |
222 surface_(NULL), | 226 surface_(NULL), |
223 supports_post_sub_buffer_(false), | 227 supports_post_sub_buffer_(false), |
224 config_(NULL) { | 228 config_(NULL) { |
225 software_ = software; | 229 software_ = software; |
230 | |
226 #if defined(OS_ANDROID) | 231 #if defined(OS_ANDROID) |
227 if (window) | 232 if (window) |
228 ANativeWindow_acquire(window); | 233 ANativeWindow_acquire(window); |
229 #endif | 234 #endif |
230 } | 235 } |
231 | 236 |
232 bool NativeViewGLSurfaceEGL::Initialize() { | 237 bool NativeViewGLSurfaceEGL::Initialize() { |
233 DCHECK(!surface_); | 238 DCHECK(!surface_); |
234 | 239 |
235 if (window_ == kNullAcceleratedWidget) { | 240 if (window_ == kNullAcceleratedWidget) { |
(...skipping 13 matching lines...) Expand all Loading... | |
249 | 254 |
250 // Create a surface for the native window. | 255 // Create a surface for the native window. |
251 surface_ = eglCreateWindowSurface( | 256 surface_ = eglCreateWindowSurface( |
252 GetDisplay(), | 257 GetDisplay(), |
253 GetConfig(), | 258 GetConfig(), |
254 window_, | 259 window_, |
255 gfx::g_driver_egl.ext.b_EGL_NV_post_sub_buffer ? | 260 gfx::g_driver_egl.ext.b_EGL_NV_post_sub_buffer ? |
256 egl_window_attributes_sub_buffer : | 261 egl_window_attributes_sub_buffer : |
257 NULL); | 262 NULL); |
258 | 263 |
264 #if defined(USE_NATIVE_SURFACE_LINUX) | |
265 eglSurfaceAttrib(GetDisplay(), surface_, | |
266 EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED); | |
267 #endif | |
268 | |
259 if (!surface_) { | 269 if (!surface_) { |
260 LOG(ERROR) << "eglCreateWindowSurface failed with error " | 270 LOG(ERROR) << "eglCreateWindowSurface failed with error " |
261 << GetLastEGLErrorString(); | 271 << GetLastEGLErrorString(); |
262 Destroy(); | 272 Destroy(); |
263 return false; | 273 return false; |
264 } | 274 } |
265 | 275 |
266 EGLint surfaceVal; | 276 EGLint surfaceVal; |
267 EGLBoolean retVal = eglQuerySurface(GetDisplay(), | 277 EGLBoolean retVal = eglQuerySurface(GetDisplay(), |
268 surface_, | 278 surface_, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 return gfx::Size(); | 397 return gfx::Size(); |
388 } | 398 } |
389 | 399 |
390 return gfx::Size(width, height); | 400 return gfx::Size(width, height); |
391 } | 401 } |
392 | 402 |
393 bool NativeViewGLSurfaceEGL::Resize(const gfx::Size& size) { | 403 bool NativeViewGLSurfaceEGL::Resize(const gfx::Size& size) { |
394 if (size == GetSize()) | 404 if (size == GetSize()) |
395 return true; | 405 return true; |
396 | 406 |
407 #if defined(USE_NATIVE_SURFACE_LINUX) | |
408 ui::NativeSurfaceLinuxFactory *nslf = | |
409 ui::NativeSurfaceLinuxFactory::GetInstance(); | |
410 if (!nslf->AcceleratedWidgetCanBeResized(window_)) { | |
411 LOG(ERROR) << "desired size for GL surface does not match native size"; | |
412 LOG(ERROR) << "desired size: " << size.width() << "x" << size.height(); | |
413 LOG(ERROR) << "native size: " << GetSize().width() << "x" | |
414 << GetSize().height(); | |
415 return true; | |
416 } | |
417 #endif | |
418 | |
397 GLContext* current_context = GLContext::GetCurrent(); | 419 GLContext* current_context = GLContext::GetCurrent(); |
398 bool was_current = current_context && current_context->IsCurrent(this); | 420 bool was_current = current_context && current_context->IsCurrent(this); |
399 if (was_current) | 421 if (was_current) |
400 current_context->ReleaseCurrent(this); | 422 current_context->ReleaseCurrent(this); |
401 | 423 |
402 Destroy(); | 424 Destroy(); |
403 | 425 |
404 if (!Initialize()) { | 426 if (!Initialize()) { |
405 LOG(ERROR) << "Failed to resize pbuffer."; | 427 LOG(ERROR) << "Failed to resize pbuffer."; |
406 return false; | 428 return false; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 | 601 |
580 return handle; | 602 return handle; |
581 #endif | 603 #endif |
582 } | 604 } |
583 | 605 |
584 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { | 606 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { |
585 Destroy(); | 607 Destroy(); |
586 } | 608 } |
587 | 609 |
588 } // namespace gfx | 610 } // namespace gfx |
OLD | NEW |