| 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> | 10 #include <memory> |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 // See https://crbug.com/326995. | 513 // See https://crbug.com/326995. |
| 514 XSetWindowAttributes swa; | 514 XSetWindowAttributes swa; |
| 515 memset(&swa, 0, sizeof(swa)); | 515 memset(&swa, 0, sizeof(swa)); |
| 516 swa.background_pixmap = 0; | 516 swa.background_pixmap = 0; |
| 517 swa.bit_gravity = NorthWestGravity; | 517 swa.bit_gravity = NorthWestGravity; |
| 518 window_ = XCreateWindow(g_display, parent_window_, 0, 0, size_.width(), | 518 window_ = XCreateWindow(g_display, parent_window_, 0, 0, size_.width(), |
| 519 size_.height(), 0, CopyFromParent, InputOutput, | 519 size_.height(), 0, CopyFromParent, InputOutput, |
| 520 CopyFromParent, CWBackPixmap | CWBitGravity, &swa); | 520 CopyFromParent, CWBackPixmap | CWBitGravity, &swa); |
| 521 XMapWindow(g_display, window_); | 521 XMapWindow(g_display, window_); |
| 522 | 522 |
| 523 ui::PlatformEventSource* event_source = | 523 RegisterEvents(); |
| 524 ui::PlatformEventSource::GetInstance(); | |
| 525 // Can be nullptr in tests, when we don't care about Exposes. | |
| 526 if (event_source) { | |
| 527 XSelectInput(g_display, window_, ExposureMask); | |
| 528 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | |
| 529 } | |
| 530 XFlush(g_display); | 524 XFlush(g_display); |
| 531 | 525 |
| 532 GetConfig(); | 526 GetConfig(); |
| 533 DCHECK(config_); | 527 DCHECK(config_); |
| 534 glx_window_ = glXCreateWindow(g_display, config_, window_, NULL); | 528 glx_window_ = glXCreateWindow(g_display, config_, window_, NULL); |
| 535 | 529 |
| 536 if (g_glx_oml_sync_control_supported) { | 530 if (g_glx_oml_sync_control_supported) { |
| 537 vsync_provider_.reset(new OMLSyncControlVSyncProvider(glx_window_)); | 531 vsync_provider_.reset(new OMLSyncControlVSyncProvider(glx_window_)); |
| 538 } else if (g_glx_sgi_video_sync_supported) { | 532 } else if (g_glx_sgi_video_sync_supported) { |
| 539 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(parent_window_)); | 533 vsync_provider_.reset(new SGIVideoSyncVSyncProvider(parent_window_)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 553 return true; | 547 return true; |
| 554 } | 548 } |
| 555 | 549 |
| 556 void NativeViewGLSurfaceGLX::Destroy() { | 550 void NativeViewGLSurfaceGLX::Destroy() { |
| 557 vsync_provider_.reset(); | 551 vsync_provider_.reset(); |
| 558 if (glx_window_) { | 552 if (glx_window_) { |
| 559 glXDestroyWindow(g_display, glx_window_); | 553 glXDestroyWindow(g_display, glx_window_); |
| 560 glx_window_ = 0; | 554 glx_window_ = 0; |
| 561 } | 555 } |
| 562 if (window_) { | 556 if (window_) { |
| 563 ui::PlatformEventSource* event_source = | 557 UnregisterEvents(); |
| 564 ui::PlatformEventSource::GetInstance(); | |
| 565 if (event_source) | |
| 566 event_source->RemovePlatformEventDispatcher(this); | |
| 567 XDestroyWindow(g_display, window_); | 558 XDestroyWindow(g_display, window_); |
| 568 window_ = 0; | 559 window_ = 0; |
| 569 XFlush(g_display); | 560 XFlush(g_display); |
| 570 } | 561 } |
| 571 } | 562 } |
| 572 | 563 |
| 573 bool NativeViewGLSurfaceGLX::CanDispatchEvent(const ui::PlatformEvent& event) { | |
| 574 return event->type == Expose && event->xexpose.window == window_; | |
| 575 } | |
| 576 | |
| 577 uint32_t NativeViewGLSurfaceGLX::DispatchEvent(const ui::PlatformEvent& event) { | |
| 578 XEvent forwarded_event = *event; | |
| 579 forwarded_event.xexpose.window = parent_window_; | |
| 580 XSendEvent(g_display, parent_window_, False, ExposureMask, &forwarded_event); | |
| 581 XFlush(g_display); | |
| 582 return ui::POST_DISPATCH_STOP_PROPAGATION; | |
| 583 } | |
| 584 | |
| 585 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size, | 564 bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size, |
| 586 float scale_factor, | 565 float scale_factor, |
| 587 bool has_alpha) { | 566 bool has_alpha) { |
| 588 size_ = size; | 567 size_ = size; |
| 589 glXWaitGL(); | 568 glXWaitGL(); |
| 590 XResizeWindow(g_display, window_, size.width(), size.height()); | 569 XResizeWindow(g_display, window_, size.width(), size.height()); |
| 591 glXWaitX(); | 570 glXWaitX(); |
| 592 return true; | 571 return true; |
| 593 } | 572 } |
| 594 | 573 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 } | 611 } |
| 633 | 612 |
| 634 gfx::VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { | 613 gfx::VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { |
| 635 return vsync_provider_.get(); | 614 return vsync_provider_.get(); |
| 636 } | 615 } |
| 637 | 616 |
| 638 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { | 617 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { |
| 639 Destroy(); | 618 Destroy(); |
| 640 } | 619 } |
| 641 | 620 |
| 621 void NativeViewGLSurfaceGLX::ForwardExposeEvent(XEvent* event) { |
| 622 XEvent forwarded_event = *event; |
| 623 forwarded_event.xexpose.window = parent_window_; |
| 624 XSendEvent(g_display, parent_window_, False, ExposureMask, &forwarded_event); |
| 625 XFlush(g_display); |
| 626 } |
| 627 |
| 628 bool NativeViewGLSurfaceGLX::CanHandleEvent(XEvent* event) { |
| 629 return event->type == Expose && |
| 630 event->xexpose.window == static_cast<Window>(window_); |
| 631 } |
| 632 |
| 642 UnmappedNativeViewGLSurfaceGLX::UnmappedNativeViewGLSurfaceGLX( | 633 UnmappedNativeViewGLSurfaceGLX::UnmappedNativeViewGLSurfaceGLX( |
| 643 const gfx::Size& size) | 634 const gfx::Size& size) |
| 644 : size_(size), config_(nullptr), window_(0), glx_window_(0) { | 635 : size_(size), config_(nullptr), window_(0), glx_window_(0) { |
| 645 // Ensure that we don't create a window with zero size. | 636 // Ensure that we don't create a window with zero size. |
| 646 if (size_.GetArea() == 0) | 637 if (size_.GetArea() == 0) |
| 647 size_.SetSize(1, 1); | 638 size_.SetSize(1, 1); |
| 648 } | 639 } |
| 649 | 640 |
| 650 bool UnmappedNativeViewGLSurfaceGLX::Initialize(GLSurface::Format format) { | 641 bool UnmappedNativeViewGLSurfaceGLX::Initialize(GLSurface::Format format) { |
| 651 DCHECK(!window_); | 642 DCHECK(!window_); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 if (!config_) | 689 if (!config_) |
| 699 config_ = GetConfigForWindow(g_display, window_); | 690 config_ = GetConfigForWindow(g_display, window_); |
| 700 return config_; | 691 return config_; |
| 701 } | 692 } |
| 702 | 693 |
| 703 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { | 694 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { |
| 704 Destroy(); | 695 Destroy(); |
| 705 } | 696 } |
| 706 | 697 |
| 707 } // namespace gl | 698 } // namespace gl |
| OLD | NEW |