Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(901)

Side by Side Diff: ui/gl/gl_surface_egl.cc

Issue 17265006: wayland patch for inspection Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gl/gl_surface_egl.h ('k') | ui/gl/gl_surface_wayland.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 10 matching lines...) Expand all
21 #if defined(USE_X11) 21 #if defined(USE_X11)
22 extern "C" { 22 extern "C" {
23 #include <X11/Xlib.h> 23 #include <X11/Xlib.h>
24 } 24 }
25 #endif 25 #endif
26 26
27 #if defined (USE_OZONE) 27 #if defined (USE_OZONE)
28 #include "ui/base/ozone/surface_factory_ozone.h" 28 #include "ui/base/ozone/surface_factory_ozone.h"
29 #endif 29 #endif
30 30
31 #if defined(USE_WAYLAND)
32 #include "ui/wayland/wayland_display.h"
33 #include "ui/wayland/wayland_window.h"
34 #include <wayland-egl.h>
35 #endif
36
31 using ui::GetLastEGLErrorString; 37 using ui::GetLastEGLErrorString;
32 38
33 namespace gfx { 39 namespace gfx {
34 40
35 namespace { 41 namespace {
36 42
37 EGLConfig g_config; 43 EGLConfig g_config;
38 EGLDisplay g_display; 44 EGLDisplay g_display;
39 EGLNativeDisplayType g_native_display; 45 EGLNativeDisplayType g_native_display;
40 EGLConfig g_software_config; 46 EGLConfig g_software_config;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 93
88 bool GLSurfaceEGL::InitializeOneOff() { 94 bool GLSurfaceEGL::InitializeOneOff() {
89 static bool initialized = false; 95 static bool initialized = false;
90 if (initialized) 96 if (initialized)
91 return true; 97 return true;
92 98
93 #if defined (USE_OZONE) 99 #if defined (USE_OZONE)
94 ui::SurfaceFactoryOzone::GetInstance()->InitializeHardware(); 100 ui::SurfaceFactoryOzone::GetInstance()->InitializeHardware();
95 #endif 101 #endif
96 102
97 #if defined(USE_X11) 103 #if defined(USE_WAYLAND)
104 g_native_display = ui::WaylandDisplay::GetDisplay()->display();
105 #elif defined(USE_X11)
98 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay(); 106 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay();
99 #else 107 #else
100 g_native_display = EGL_DEFAULT_DISPLAY; 108 g_native_display = EGL_DEFAULT_DISPLAY;
101 #endif 109 #endif
102 g_display = eglGetDisplay(g_native_display); 110 g_display = eglGetDisplay(g_native_display);
103 if (!g_display) { 111 if (!g_display) {
104 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); 112 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString();
105 return false; 113 return false;
106 } 114 }
107 115
108 if (!eglInitialize(g_display, NULL, NULL)) { 116 if (!eglInitialize(g_display, NULL, NULL)) {
109 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); 117 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString();
110 return false; 118 return false;
111 } 119 }
112 120
113 // Choose an EGL configuration. 121 // Choose an EGL configuration.
114 // On X this is only used for PBuffer surfaces. 122 // On X this is only used for PBuffer surfaces.
115 static const EGLint kConfigAttribs[] = { 123 static const EGLint kConfigAttribs[] = {
116 EGL_BUFFER_SIZE, 32, 124 EGL_BUFFER_SIZE, 32,
117 EGL_ALPHA_SIZE, 8, 125 EGL_ALPHA_SIZE, 8,
118 EGL_BLUE_SIZE, 8, 126 EGL_BLUE_SIZE, 8,
119 EGL_GREEN_SIZE, 8, 127 EGL_GREEN_SIZE, 8,
120 EGL_RED_SIZE, 8, 128 EGL_RED_SIZE, 8,
121 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 129 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
122 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, 130 EGL_SURFACE_TYPE,
131 #if defined(USE_WAYLAND)
132 EGL_WINDOW_BIT,
133 #else
134 EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
135 #endif
123 EGL_NONE 136 EGL_NONE
124 }; 137 };
125 138
126 EGLint num_configs; 139 EGLint num_configs;
127 if (!eglChooseConfig(g_display, 140 if (!eglChooseConfig(g_display,
128 kConfigAttribs, 141 kConfigAttribs,
129 NULL, 142 NULL,
130 0, 143 0,
131 &num_configs)) { 144 &num_configs)) {
132 LOG(ERROR) << "eglChooseConfig failed with error " 145 LOG(ERROR) << "eglChooseConfig failed with error "
(...skipping 18 matching lines...) Expand all
151 164
152 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); 165 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS);
153 g_egl_create_context_robustness_supported = 166 g_egl_create_context_robustness_supported =
154 HasEGLExtension("EGL_EXT_create_context_robustness"); 167 HasEGLExtension("EGL_EXT_create_context_robustness");
155 g_egl_sync_control_supported = 168 g_egl_sync_control_supported =
156 HasEGLExtension("EGL_CHROMIUM_sync_control"); 169 HasEGLExtension("EGL_CHROMIUM_sync_control");
157 170
158 initialized = true; 171 initialized = true;
159 172
160 #if defined(USE_X11) || defined(OS_ANDROID) \ 173 #if defined(USE_X11) || defined(OS_ANDROID) \
161 || defined(USE_OZONE) 174 || defined(USE_OZONE) || defined(USE_WAYLAND)
162 return true; 175 return true;
163 #else 176 #else
164 g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE; 177 g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE;
165 #endif 178 #endif
166 g_software_display = eglGetDisplay(g_software_native_display); 179 g_software_display = eglGetDisplay(g_software_native_display);
167 if (!g_software_display) { 180 if (!g_software_display) {
168 return true; 181 return true;
169 } 182 }
170 183
171 if (!eglInitialize(g_software_display, NULL, NULL)) { 184 if (!eglInitialize(g_software_display, NULL, NULL)) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 273
261 static const EGLint egl_window_attributes_sub_buffer[] = { 274 static const EGLint egl_window_attributes_sub_buffer[] = {
262 EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_TRUE, 275 EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_TRUE,
263 EGL_NONE 276 EGL_NONE
264 }; 277 };
265 278
266 // Create a surface for the native window. 279 // Create a surface for the native window.
267 surface_ = eglCreateWindowSurface( 280 surface_ = eglCreateWindowSurface(
268 GetDisplay(), 281 GetDisplay(),
269 GetConfig(), 282 GetConfig(),
283 #if defined(USE_WAYLAND)
284 window_->egl_window(),
285 #else
270 window_, 286 window_,
287 #endif
271 gfx::g_driver_egl.ext.b_EGL_NV_post_sub_buffer ? 288 gfx::g_driver_egl.ext.b_EGL_NV_post_sub_buffer ?
272 egl_window_attributes_sub_buffer : 289 egl_window_attributes_sub_buffer :
273 NULL); 290 NULL);
274 291
275 if (!surface_) { 292 if (!surface_) {
276 LOG(ERROR) << "eglCreateWindowSurface failed with error " 293 LOG(ERROR) << "eglCreateWindowSurface failed with error "
277 << GetLastEGLErrorString(); 294 << GetLastEGLErrorString();
278 Destroy(); 295 Destroy();
279 return false; 296 return false;
280 } 297 }
(...skipping 16 matching lines...) Expand all
297 if (surface_) { 314 if (surface_) {
298 if (!eglDestroySurface(GetDisplay(), surface_)) { 315 if (!eglDestroySurface(GetDisplay(), surface_)) {
299 LOG(ERROR) << "eglDestroySurface failed with error " 316 LOG(ERROR) << "eglDestroySurface failed with error "
300 << GetLastEGLErrorString(); 317 << GetLastEGLErrorString();
301 } 318 }
302 surface_ = NULL; 319 surface_ = NULL;
303 } 320 }
304 } 321 }
305 322
306 EGLConfig NativeViewGLSurfaceEGL::GetConfig() { 323 EGLConfig NativeViewGLSurfaceEGL::GetConfig() {
307 #if !defined(USE_X11) 324 #if !defined(USE_X11) || defined(USE_WAYLAND)
308 return software_ ? g_software_config : g_config; 325 return software_ ? g_software_config : g_config;
309 #else 326 #else
310 if (!config_) { 327 if (!config_) {
311 // Get a config compatible with the window 328 // Get a config compatible with the window
312 DCHECK(window_); 329 DCHECK(window_);
313 XWindowAttributes win_attribs; 330 XWindowAttributes win_attribs;
314 if (!XGetWindowAttributes(GetNativeDisplay(), window_, &win_attribs)) { 331 if (!XGetWindowAttributes(GetNativeDisplay(), window_, &win_attribs)) {
315 return NULL; 332 return NULL;
316 } 333 }
317 334
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 bool NativeViewGLSurfaceEGL::IsOffscreen() { 400 bool NativeViewGLSurfaceEGL::IsOffscreen() {
384 return false; 401 return false;
385 } 402 }
386 403
387 bool NativeViewGLSurfaceEGL::SwapBuffers() { 404 bool NativeViewGLSurfaceEGL::SwapBuffers() {
388 if (!eglSwapBuffers(GetDisplay(), surface_)) { 405 if (!eglSwapBuffers(GetDisplay(), surface_)) {
389 DVLOG(1) << "eglSwapBuffers failed with error " 406 DVLOG(1) << "eglSwapBuffers failed with error "
390 << GetLastEGLErrorString(); 407 << GetLastEGLErrorString();
391 return false; 408 return false;
392 } 409 }
393
394 return true; 410 return true;
395 } 411 }
396 412
397 gfx::Size NativeViewGLSurfaceEGL::GetSize() { 413 gfx::Size NativeViewGLSurfaceEGL::GetSize() {
398 EGLint width; 414 EGLint width;
399 EGLint height; 415 EGLint height;
400 if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) || 416 if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) ||
401 !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) { 417 !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) {
402 NOTREACHED() << "eglQuerySurface failed with error " 418 NOTREACHED() << "eglQuerySurface failed with error "
403 << GetLastEGLErrorString(); 419 << GetLastEGLErrorString();
404 return gfx::Size(); 420 return gfx::Size();
405 } 421 }
406 422
407 return gfx::Size(width, height); 423 return gfx::Size(width, height);
408 } 424 }
409 425
410 bool NativeViewGLSurfaceEGL::Resize(const gfx::Size& size) { 426 bool NativeViewGLSurfaceEGL::Resize(const gfx::Size& size) {
427 #if defined(USE_WAYLAND)
428 window_->ScheduleResize(size.width(), size.height());
429 #endif
411 if (size == GetSize()) 430 if (size == GetSize())
412 return true; 431 return true;
413 432
414 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; 433 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current;
415 GLContext* current_context = GLContext::GetCurrent(); 434 GLContext* current_context = GLContext::GetCurrent();
416 bool was_current = 435 bool was_current =
417 current_context && current_context->IsCurrent(this); 436 current_context && current_context->IsCurrent(this);
418 if (was_current) { 437 if (was_current) {
419 scoped_make_current.reset( 438 scoped_make_current.reset(
420 new ui::ScopedMakeCurrent(current_context, this)); 439 new ui::ScopedMakeCurrent(current_context, this));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 LOG(ERROR) << "Trying to create surface with invalid display."; 513 LOG(ERROR) << "Trying to create surface with invalid display.";
495 return false; 514 return false;
496 } 515 }
497 516
498 if (size_.GetArea() == 0) { 517 if (size_.GetArea() == 0) {
499 LOG(ERROR) << "Error: surface has zero area " 518 LOG(ERROR) << "Error: surface has zero area "
500 << size_.width() << " x " << size_.height(); 519 << size_.width() << " x " << size_.height();
501 return false; 520 return false;
502 } 521 }
503 522
523 #if defined(USE_WAYLAND)
524 wsurf_ = ui::WaylandDisplay::GetDisplay()->CreateSurface();
525 wwindow_ = wl_egl_window_create(wsurf_, size_.width(), size_.height());
526 EGLSurface new_surface = eglCreateWindowSurface(GetDisplay(),
527 GetConfig(),
528 wwindow_,
529 NULL);
530 #else
504 // Allocate the new pbuffer surface before freeing the old one to ensure 531 // Allocate the new pbuffer surface before freeing the old one to ensure
505 // they have different addresses. If they have the same address then a 532 // they have different addresses. If they have the same address then a
506 // future call to MakeCurrent might early out because it appears the current 533 // future call to MakeCurrent might early out because it appears the current
507 // context and surface have not changed. 534 // context and surface have not changed.
508 const EGLint pbuffer_attribs[] = { 535 const EGLint pbuffer_attribs[] = {
509 EGL_WIDTH, size_.width(), 536 EGL_WIDTH, size_.width(),
510 EGL_HEIGHT, size_.height(), 537 EGL_HEIGHT, size_.height(),
511 EGL_NONE 538 EGL_NONE
512 }; 539 };
513 540
514 EGLSurface new_surface = eglCreatePbufferSurface(display, 541 EGLSurface new_surface = eglCreatePbufferSurface(display,
515 GetConfig(), 542 GetConfig(),
516 pbuffer_attribs); 543 pbuffer_attribs);
544 #endif
517 if (!new_surface) { 545 if (!new_surface) {
518 LOG(ERROR) << "eglCreatePbufferSurface failed with error " 546 LOG(ERROR) << "eglCreatePbufferSurface failed with error "
519 << GetLastEGLErrorString(); 547 << GetLastEGLErrorString();
520 return false; 548 return false;
521 } 549 }
522 550
523 if (old_surface) 551 if (old_surface)
524 eglDestroySurface(display, old_surface); 552 eglDestroySurface(display, old_surface);
525 553
526 surface_ = new_surface; 554 surface_ = new_surface;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 } 692 }
665 default: 693 default:
666 NOTREACHED(); 694 NOTREACHED();
667 return NULL; 695 return NULL;
668 } 696 }
669 } 697 }
670 698
671 #endif 699 #endif
672 700
673 } // namespace gfx 701 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_surface_egl.h ('k') | ui/gl/gl_surface_wayland.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698