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 extern "C" { | 5 extern "C" { |
6 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
7 } | 7 } |
8 | 8 |
9 #include "ui/gl/gl_surface_glx.h" | 9 #include "ui/gl/gl_surface_glx.h" |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/message_loop/message_pump_x11.h" |
17 #include "base/synchronization/cancellation_flag.h" | 18 #include "base/synchronization/cancellation_flag.h" |
18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
19 #include "base/threading/non_thread_safe.h" | 20 #include "base/threading/non_thread_safe.h" |
20 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "third_party/mesa/src/include/GL/osmesa.h" | 23 #include "third_party/mesa/src/include/GL/osmesa.h" |
23 #include "ui/base/x/x11_util.h" | 24 #include "ui/base/x/x11_util.h" |
24 #include "ui/gl/gl_bindings.h" | 25 #include "ui/gl/gl_bindings.h" |
25 #include "ui/gl/gl_implementation.h" | 26 #include "ui/gl/gl_implementation.h" |
26 #include "ui/gl/vsync_provider.h" | 27 #include "ui/gl/vsync_provider.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 if (initialized) | 309 if (initialized) |
309 return true; | 310 return true; |
310 | 311 |
311 // http://crbug.com/245466 | 312 // http://crbug.com/245466 |
312 setenv("force_s3tc_enable", "true", 1); | 313 setenv("force_s3tc_enable", "true", 1); |
313 | 314 |
314 // SGIVideoSyncProviderShim (if instantiated) will issue X commands on | 315 // SGIVideoSyncProviderShim (if instantiated) will issue X commands on |
315 // it's own thread. | 316 // it's own thread. |
316 XInitThreads(); | 317 XInitThreads(); |
317 | 318 |
318 g_display = base::MessagePumpForUI::GetDefaultXDisplay(); | 319 // XXX -- base::MessagePumpForUI is returning Gtk here -- we need to |
| 320 // make this *not* be a compile-time decision. |
| 321 g_display = //base::MessagePumpForUI::GetDefaultXDisplay(); |
| 322 base::MessagePumpX11::GetDefaultXDisplay(); |
319 if (!g_display) { | 323 if (!g_display) { |
320 LOG(ERROR) << "XOpenDisplay failed."; | 324 LOG(ERROR) << "XOpenDisplay failed."; |
321 return false; | 325 return false; |
322 } | 326 } |
323 | 327 |
324 int major, minor; | 328 int major, minor; |
325 if (!glXQueryVersion(g_display, &major, &minor)) { | 329 if (!glXQueryVersion(g_display, &major, &minor)) { |
326 LOG(ERROR) << "glxQueryVersion failed"; | 330 LOG(ERROR) << "glxQueryVersion failed"; |
327 return false; | 331 return false; |
328 } | 332 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 bool GLSurfaceGLX::IsOMLSyncControlSupported() { | 385 bool GLSurfaceGLX::IsOMLSyncControlSupported() { |
382 return g_glx_oml_sync_control_supported; | 386 return g_glx_oml_sync_control_supported; |
383 } | 387 } |
384 | 388 |
385 void* GLSurfaceGLX::GetDisplay() { | 389 void* GLSurfaceGLX::GetDisplay() { |
386 return g_display; | 390 return g_display; |
387 } | 391 } |
388 | 392 |
389 GLSurfaceGLX::~GLSurfaceGLX() {} | 393 GLSurfaceGLX::~GLSurfaceGLX() {} |
390 | 394 |
| 395 // XXX - we should just have 1 of these, not 1 per GLSurfaceGLX |
| 396 class NativeViewXExposeEventForwarder : public base::MessagePumpObserver { |
| 397 public: |
| 398 NativeViewXExposeEventForwarder(gfx::AcceleratedWidget parent_window, |
| 399 gfx::AcceleratedWidget child_window) |
| 400 : child_window_(child_window), parent_window_(parent_window) { |
| 401 base::MessagePumpX11::Current()->AddObserver(this); |
| 402 } |
| 403 |
| 404 virtual ~NativeViewXExposeEventForwarder() { |
| 405 base::MessagePumpX11::Current()->RemoveObserver(this); |
| 406 } |
| 407 |
| 408 virtual base::EventStatus WillProcessEvent( |
| 409 const base::NativeEvent& xevent) OVERRIDE { |
| 410 if (xevent->type == Expose && |
| 411 xevent->xexpose.window == child_window_) { |
| 412 XEvent forwarded_event = *xevent; |
| 413 forwarded_event.xexpose.window = parent_window_; |
| 414 XSendEvent( |
| 415 g_display, parent_window_, False, ExposureMask, &forwarded_event); |
| 416 } |
| 417 return base::EVENT_CONTINUE; |
| 418 } |
| 419 virtual void DidProcessEvent(const base::NativeEvent&) OVERRIDE { |
| 420 } |
| 421 |
| 422 private: |
| 423 gfx::AcceleratedWidget child_window_; |
| 424 gfx::AcceleratedWidget parent_window_; |
| 425 }; |
| 426 |
391 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::AcceleratedWidget window) | 427 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(gfx::AcceleratedWidget window) |
392 : window_(window), | 428 : parent_window_(window), |
| 429 window_(0), |
393 config_(NULL) { | 430 config_(NULL) { |
394 } | 431 } |
395 | 432 |
396 bool NativeViewGLSurfaceGLX::Initialize() { | 433 bool NativeViewGLSurfaceGLX::Initialize() { |
397 XWindowAttributes attributes; | 434 XWindowAttributes attributes; |
398 if (!XGetWindowAttributes(g_display, window_, &attributes)) { | 435 if (!XGetWindowAttributes(g_display, parent_window_, &attributes)) { |
399 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 436 LOG(ERROR) << "XGetWindowAttributes failed for window " |
| 437 << parent_window_ << "."; |
400 return false; | 438 return false; |
401 } | 439 } |
402 size_ = gfx::Size(attributes.width, attributes.height); | 440 size_ = gfx::Size(attributes.width, attributes.height); |
403 | 441 |
| 442 XSetWindowAttributes set_attributes = {0}; |
| 443 set_attributes.event_mask = ExposureMask; |
| 444 window_= XCreateWindow( |
| 445 g_display, parent_window_, 0, 0, attributes.width, attributes.height, 0, |
| 446 attributes.depth, InputOutput, attributes.visual, CWEventMask, |
| 447 &set_attributes); |
| 448 XMapWindow(g_display, window_); |
| 449 XFlush(g_display); |
| 450 |
404 if (g_glx_oml_sync_control_supported) | 451 if (g_glx_oml_sync_control_supported) |
405 vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_)); | 452 vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_)); |
406 else if (g_glx_sgi_video_sync_supported) | 453 else if (g_glx_sgi_video_sync_supported) |
407 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_)); | 454 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_)); |
408 | 455 |
| 456 event_forwarder_.reset( |
| 457 new NativeViewXExposeEventForwarder(parent_window_, window_)); |
| 458 |
409 return true; | 459 return true; |
410 } | 460 } |
411 | 461 |
412 void NativeViewGLSurfaceGLX::Destroy() { | 462 void NativeViewGLSurfaceGLX::Destroy() { |
| 463 event_forwarder_.reset(); |
| 464 if (window_) { |
| 465 XDestroyWindow(g_display, window_); |
| 466 XFlush(g_display); |
| 467 window_ = 0; |
| 468 } |
413 } | 469 } |
414 | 470 |
415 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) { | 471 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) { |
| 472 XResizeWindow(g_display, window_, size.width(), size.height()); |
| 473 XFlush(g_display); |
416 size_ = size; | 474 size_ = size; |
417 return true; | 475 return true; |
418 } | 476 } |
419 | 477 |
420 bool NativeViewGLSurfaceGLX::IsOffscreen() { | 478 bool NativeViewGLSurfaceGLX::IsOffscreen() { |
421 return false; | 479 return false; |
422 } | 480 } |
423 | 481 |
424 bool NativeViewGLSurfaceGLX::SwapBuffers() { | 482 bool NativeViewGLSurfaceGLX::SwapBuffers() { |
425 glXSwapBuffers(g_display, window_); | 483 glXSwapBuffers(g_display, window_); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); | 567 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); |
510 glXCopySubBufferMESA(g_display, window_, x, y, width, height); | 568 glXCopySubBufferMESA(g_display, window_, x, y, width, height); |
511 return true; | 569 return true; |
512 } | 570 } |
513 | 571 |
514 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { | 572 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { |
515 return vsync_provider_.get(); | 573 return vsync_provider_.get(); |
516 } | 574 } |
517 | 575 |
518 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() | 576 NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX() |
519 : window_(0), | 577 : parent_window_(0), |
| 578 window_(0), |
520 config_(NULL) { | 579 config_(NULL) { |
521 } | 580 } |
522 | 581 |
523 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { | 582 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { |
524 Destroy(); | 583 Destroy(); |
525 } | 584 } |
526 | 585 |
527 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) | 586 PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(const gfx::Size& size) |
528 : size_(size), | 587 : size_(size), |
529 config_(NULL), | 588 config_(NULL), |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 666 |
608 void* PbufferGLSurfaceGLX::GetConfig() { | 667 void* PbufferGLSurfaceGLX::GetConfig() { |
609 return config_; | 668 return config_; |
610 } | 669 } |
611 | 670 |
612 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { | 671 PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() { |
613 Destroy(); | 672 Destroy(); |
614 } | 673 } |
615 | 674 |
616 } // namespace gfx | 675 } // namespace gfx |
OLD | NEW |