| 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_glx.h" | 5 #include "ui/gl/gl_surface_glx.h" |
| 6 | 6 |
| 7 extern "C" { | 7 extern "C" { |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 } | 9 } |
| 10 #include <memory> | |
| 11 | 10 |
| 12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 13 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 14 #include "base/logging.h" | 13 #include "base/logging.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 19 #include "base/synchronization/cancellation_flag.h" | 18 #include "base/synchronization/cancellation_flag.h" |
| 20 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 21 #include "base/threading/non_thread_safe.h" | 20 #include "base/threading/non_thread_safe.h" |
| 22 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 25 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
| 26 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 27 #include "ui/events/platform/platform_event_source.h" | |
| 28 #include "ui/gfx/x/x11_connection.h" | 26 #include "ui/gfx/x/x11_connection.h" |
| 29 #include "ui/gfx/x/x11_types.h" | 27 #include "ui/gfx/x/x11_types.h" |
| 30 #include "ui/gl/gl_bindings.h" | 28 #include "ui/gl/gl_bindings.h" |
| 31 #include "ui/gl/gl_implementation.h" | 29 #include "ui/gl/gl_implementation.h" |
| 32 #include "ui/gl/sync_control_vsync_provider.h" | 30 #include "ui/gl/sync_control_vsync_provider.h" |
| 33 | 31 |
| 34 namespace gl { | 32 namespace gl { |
| 35 | 33 |
| 36 namespace { | 34 namespace { |
| 37 | 35 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 // See https://crbug.com/326995. | 478 // See https://crbug.com/326995. |
| 481 XSetWindowAttributes swa; | 479 XSetWindowAttributes swa; |
| 482 memset(&swa, 0, sizeof(swa)); | 480 memset(&swa, 0, sizeof(swa)); |
| 483 swa.background_pixmap = 0; | 481 swa.background_pixmap = 0; |
| 484 swa.bit_gravity = NorthWestGravity; | 482 swa.bit_gravity = NorthWestGravity; |
| 485 window_ = XCreateWindow(g_display, parent_window_, 0, 0, size_.width(), | 483 window_ = XCreateWindow(g_display, parent_window_, 0, 0, size_.width(), |
| 486 size_.height(), 0, CopyFromParent, InputOutput, | 484 size_.height(), 0, CopyFromParent, InputOutput, |
| 487 CopyFromParent, CWBackPixmap | CWBitGravity, &swa); | 485 CopyFromParent, CWBackPixmap | CWBitGravity, &swa); |
| 488 XMapWindow(g_display, window_); | 486 XMapWindow(g_display, window_); |
| 489 | 487 |
| 490 ui::PlatformEventSource* event_source = | 488 RegisterEvents(); |
| 491 ui::PlatformEventSource::GetInstance(); | |
| 492 // Can be nullptr in tests, when we don't care about Exposes. | |
| 493 if (event_source) { | |
| 494 XSelectInput(g_display, window_, ExposureMask); | |
| 495 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | |
| 496 } | |
| 497 XFlush(g_display); | 489 XFlush(g_display); |
| 498 | 490 |
| 499 GetConfig(); | 491 GetConfig(); |
| 500 DCHECK(config_); | 492 DCHECK(config_); |
| 501 glx_window_ = glXCreateWindow(g_display, config_, window_, NULL); | 493 glx_window_ = glXCreateWindow(g_display, config_, window_, NULL); |
| 502 | 494 |
| 503 if (g_glx_oml_sync_control_supported) { | 495 if (g_glx_oml_sync_control_supported) { |
| 504 vsync_provider_.reset(new OMLSyncControlVSyncProvider(glx_window_)); | 496 vsync_provider_.reset(new OMLSyncControlVSyncProvider(glx_window_)); |
| 505 } else if (g_glx_sgi_video_sync_supported) { | 497 } else if (g_glx_sgi_video_sync_supported) { |
| 506 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(config_, glx_window_)); | 498 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(config_, glx_window_)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 520 return true; | 512 return true; |
| 521 } | 513 } |
| 522 | 514 |
| 523 void NativeViewGLSurfaceGLX::Destroy() { | 515 void NativeViewGLSurfaceGLX::Destroy() { |
| 524 vsync_provider_.reset(); | 516 vsync_provider_.reset(); |
| 525 if (glx_window_) { | 517 if (glx_window_) { |
| 526 glXDestroyWindow(g_display, glx_window_); | 518 glXDestroyWindow(g_display, glx_window_); |
| 527 glx_window_ = 0; | 519 glx_window_ = 0; |
| 528 } | 520 } |
| 529 if (window_) { | 521 if (window_) { |
| 530 ui::PlatformEventSource* event_source = | 522 UnregisterEvents(); |
| 531 ui::PlatformEventSource::GetInstance(); | |
| 532 if (event_source) | |
| 533 event_source->RemovePlatformEventDispatcher(this); | |
| 534 XDestroyWindow(g_display, window_); | 523 XDestroyWindow(g_display, window_); |
| 535 window_ = 0; | 524 window_ = 0; |
| 536 XFlush(g_display); | 525 XFlush(g_display); |
| 537 } | 526 } |
| 538 } | 527 } |
| 539 | 528 |
| 540 bool NativeViewGLSurfaceGLX::CanDispatchEvent(const ui::PlatformEvent& event) { | |
| 541 return event->type == Expose && event->xexpose.window == window_; | |
| 542 } | |
| 543 | |
| 544 uint32_t NativeViewGLSurfaceGLX::DispatchEvent(const ui::PlatformEvent& event) { | |
| 545 XEvent forwarded_event = *event; | |
| 546 forwarded_event.xexpose.window = parent_window_; | |
| 547 XSendEvent(g_display, parent_window_, False, ExposureMask, | |
| 548 &forwarded_event); | |
| 549 XFlush(g_display); | |
| 550 return ui::POST_DISPATCH_STOP_PROPAGATION; | |
| 551 } | |
| 552 | |
| 553 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size, | 529 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size, |
| 554 float scale_factor, | 530 float scale_factor, |
| 555 bool has_alpha) { | 531 bool has_alpha) { |
| 556 size_ = size; | 532 size_ = size; |
| 557 glXWaitGL(); | 533 glXWaitGL(); |
| 558 XResizeWindow(g_display, window_, size.width(), size.height()); | 534 XResizeWindow(g_display, window_, size.width(), size.height()); |
| 559 glXWaitX(); | 535 glXWaitX(); |
| 560 return true; | 536 return true; |
| 561 } | 537 } |
| 562 | 538 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 577 } |
| 602 | 578 |
| 603 gfx::VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { | 579 gfx::VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { |
| 604 return vsync_provider_.get(); | 580 return vsync_provider_.get(); |
| 605 } | 581 } |
| 606 | 582 |
| 607 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { | 583 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { |
| 608 Destroy(); | 584 Destroy(); |
| 609 } | 585 } |
| 610 | 586 |
| 587 void NativeViewGLSurfaceGLX::ForwardExposeEvent(XEvent* event) { |
| 588 XEvent forwarded_event = *event; |
| 589 forwarded_event.xexpose.window = parent_window_; |
| 590 XSendEvent(g_display, parent_window_, False, ExposureMask, &forwarded_event); |
| 591 XFlush(g_display); |
| 592 } |
| 593 |
| 594 bool NativeViewGLSurfaceGLX::CanHandleEvent(XEvent* event) { |
| 595 return event->type == Expose && |
| 596 event->xexpose.window == static_cast<Window>(window_); |
| 597 } |
| 598 |
| 611 UnmappedNativeViewGLSurfaceGLX::UnmappedNativeViewGLSurfaceGLX( | 599 UnmappedNativeViewGLSurfaceGLX::UnmappedNativeViewGLSurfaceGLX( |
| 612 const gfx::Size& size) | 600 const gfx::Size& size) |
| 613 : size_(size), config_(nullptr), window_(0), glx_window_(0) { | 601 : size_(size), config_(nullptr), window_(0), glx_window_(0) { |
| 614 // Ensure that we don't create a window with zero size. | 602 // Ensure that we don't create a window with zero size. |
| 615 if (size_.GetArea() == 0) | 603 if (size_.GetArea() == 0) |
| 616 size_.SetSize(1, 1); | 604 size_.SetSize(1, 1); |
| 617 } | 605 } |
| 618 | 606 |
| 619 bool UnmappedNativeViewGLSurfaceGLX::Initialize(GLSurface::Format format) { | 607 bool UnmappedNativeViewGLSurfaceGLX::Initialize(GLSurface::Format format) { |
| 620 DCHECK(!window_); | 608 DCHECK(!window_); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 if (!config_) | 655 if (!config_) |
| 668 config_ = GetConfigForWindow(g_display, window_); | 656 config_ = GetConfigForWindow(g_display, window_); |
| 669 return config_; | 657 return config_; |
| 670 } | 658 } |
| 671 | 659 |
| 672 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { | 660 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { |
| 673 Destroy(); | 661 Destroy(); |
| 674 } | 662 } |
| 675 | 663 |
| 676 } // namespace gl | 664 } // namespace gl |
| OLD | NEW |