| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.h" | 5 #include "ui/gl/gl_surface.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "ui/gl/gl_surface_osmesa.h" | 25 #include "ui/gl/gl_surface_osmesa.h" |
| 26 #include "ui/gl/gl_surface_overlay.h" | 26 #include "ui/gl/gl_surface_overlay.h" |
| 27 #include "ui/gl/gl_surface_stub.h" | 27 #include "ui/gl/gl_surface_stub.h" |
| 28 #include "ui/gl/scoped_binders.h" | 28 #include "ui/gl/scoped_binders.h" |
| 29 #include "ui/gl/scoped_make_current.h" | 29 #include "ui/gl/scoped_make_current.h" |
| 30 #include "ui/ozone/public/native_pixmap.h" | 30 #include "ui/ozone/public/native_pixmap.h" |
| 31 #include "ui/ozone/public/ozone_platform.h" | 31 #include "ui/ozone/public/ozone_platform.h" |
| 32 #include "ui/ozone/public/surface_factory_ozone.h" | 32 #include "ui/ozone/public/surface_factory_ozone.h" |
| 33 #include "ui/ozone/public/surface_ozone_egl.h" | 33 #include "ui/ozone/public/surface_ozone_egl.h" |
| 34 | 34 |
| 35 #if defined(USE_GLX) |
| 36 #include <X11/Xlib.h> |
| 37 |
| 38 #include "ui/events/platform/x11/x11_event_source_libevent.h" |
| 39 #include "ui/gl/gl_surface_glx.h" |
| 40 #endif |
| 41 |
| 35 using gl::GLImage; | 42 using gl::GLImage; |
| 36 | 43 |
| 37 namespace gfx { | 44 namespace gfx { |
| 38 | 45 |
| 39 namespace { | 46 namespace { |
| 40 | 47 |
| 41 // Helper function for base::Bind to create callback to eglChooseConfig. | 48 // Helper function for base::Bind to create callback to eglChooseConfig. |
| 42 bool EglChooseConfig(EGLDisplay display, | 49 bool EglChooseConfig(EGLDisplay display, |
| 43 const int32_t* attribs, | 50 const int32_t* attribs, |
| 44 EGLConfig* configs, | 51 EGLConfig* configs, |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return false; | 640 return false; |
| 634 images_[i] = image; | 641 images_[i] = image; |
| 635 // Bind image to texture. | 642 // Bind image to texture. |
| 636 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); | 643 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); |
| 637 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) | 644 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) |
| 638 return false; | 645 return false; |
| 639 } | 646 } |
| 640 return true; | 647 return true; |
| 641 } | 648 } |
| 642 | 649 |
| 650 #if defined(USE_GLX) |
| 651 |
| 652 // Ozone specific implementation of GLX surface. Registers as XEventDispatcher |
| 653 // to handle XEvents. |
| 654 class GL_EXPORT NativeViewGLSurfaceGLXOzone : public NativeViewGLSurfaceGLX, |
| 655 public ui::XEventDispatcher { |
| 656 public: |
| 657 explicit NativeViewGLSurfaceGLXOzone(gfx::AcceleratedWidget window); |
| 658 |
| 659 // XEventDispatcher implementation: |
| 660 bool DispatchXEvent(XEvent* xevent) override; |
| 661 |
| 662 protected: |
| 663 ~NativeViewGLSurfaceGLXOzone() override; |
| 664 |
| 665 // NativeViewGLSurfaceGLX implementation: |
| 666 void RegisterEvents() override; |
| 667 void UnregisterEvents() override; |
| 668 |
| 669 private: |
| 670 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLXOzone); |
| 671 }; |
| 672 |
| 673 NativeViewGLSurfaceGLXOzone::NativeViewGLSurfaceGLXOzone( |
| 674 gfx::AcceleratedWidget window) |
| 675 : NativeViewGLSurfaceGLX(window) {} |
| 676 |
| 677 bool NativeViewGLSurfaceGLXOzone::DispatchXEvent(XEvent* event) { |
| 678 if (!CanHandleEvent(event)) |
| 679 return false; |
| 680 |
| 681 ForwardExposeEvent(event); |
| 682 return true; |
| 683 } |
| 684 |
| 685 NativeViewGLSurfaceGLXOzone::~NativeViewGLSurfaceGLXOzone() { |
| 686 Destroy(); |
| 687 } |
| 688 |
| 689 void NativeViewGLSurfaceGLXOzone::RegisterEvents() { |
| 690 ui::X11EventSourceLibevent* event_source = |
| 691 ui::X11EventSourceLibevent::GetInstance(); |
| 692 // Can be nullptr in tests, when we don't care about Exposes. |
| 693 if (event_source) { |
| 694 XSelectInput(gfx::GetXDisplay(), window(), ExposureMask); |
| 695 event_source->AddXEventDispatcher(this); |
| 696 } |
| 697 } |
| 698 |
| 699 void NativeViewGLSurfaceGLXOzone::UnregisterEvents() { |
| 700 ui::X11EventSourceLibevent* event_source = |
| 701 ui::X11EventSourceLibevent::GetInstance(); |
| 702 if (event_source) |
| 703 event_source->RemoveXEventDispatcher(this); |
| 704 } |
| 705 |
| 706 #endif // defined(USE_GLX) |
| 707 |
| 643 scoped_refptr<GLSurface> CreateViewGLSurfaceOzone( | 708 scoped_refptr<GLSurface> CreateViewGLSurfaceOzone( |
| 644 gfx::AcceleratedWidget window) { | 709 gfx::AcceleratedWidget window) { |
| 645 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 710 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 646 ui::OzonePlatform::GetInstance() | 711 ui::OzonePlatform::GetInstance() |
| 647 ->GetSurfaceFactoryOzone() | 712 ->GetSurfaceFactoryOzone() |
| 648 ->CreateEGLSurfaceForWidget(window); | 713 ->CreateEGLSurfaceForWidget(window); |
| 649 if (!surface_ozone) | 714 if (!surface_ozone) |
| 650 return nullptr; | 715 return nullptr; |
| 651 scoped_refptr<GLSurface> surface = | 716 scoped_refptr<GLSurface> surface = |
| 652 new GLSurfaceOzoneEGL(std::move(surface_ozone), window); | 717 new GLSurfaceOzoneEGL(std::move(surface_ozone), window); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 668 if (!surface->Initialize()) | 733 if (!surface->Initialize()) |
| 669 return nullptr; | 734 return nullptr; |
| 670 return surface; | 735 return surface; |
| 671 } | 736 } |
| 672 | 737 |
| 673 } // namespace | 738 } // namespace |
| 674 | 739 |
| 675 // static | 740 // static |
| 676 bool GLSurface::InitializeOneOffInternal() { | 741 bool GLSurface::InitializeOneOffInternal() { |
| 677 switch (GetGLImplementation()) { | 742 switch (GetGLImplementation()) { |
| 743 #if defined(USE_GLX) |
| 744 case kGLImplementationDesktopGL: |
| 745 if (!GLSurfaceGLX::InitializeOneOff()) { |
| 746 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; |
| 747 return false; |
| 748 } |
| 749 |
| 750 return true; |
| 751 #endif |
| 678 case kGLImplementationEGLGLES2: | 752 case kGLImplementationEGLGLES2: |
| 679 if (!GLSurfaceEGL::InitializeOneOff()) { | 753 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 680 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 754 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 681 return false; | 755 return false; |
| 682 } | 756 } |
| 683 | 757 |
| 684 return true; | 758 return true; |
| 685 case kGLImplementationOSMesaGL: | 759 case kGLImplementationOSMesaGL: |
| 686 case kGLImplementationMockGL: | 760 case kGLImplementationMockGL: |
| 687 return true; | 761 return true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 707 if (surface->Initialize()) | 781 if (surface->Initialize()) |
| 708 return surface; | 782 return surface; |
| 709 } | 783 } |
| 710 | 784 |
| 711 return nullptr; | 785 return nullptr; |
| 712 } | 786 } |
| 713 | 787 |
| 714 // static | 788 // static |
| 715 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 789 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 716 gfx::AcceleratedWidget window) { | 790 gfx::AcceleratedWidget window) { |
| 791 #if defined(USE_GLX) |
| 792 if (GetGLImplementation() == kGLImplementationDesktopGL) { |
| 793 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLXOzone(window)); |
| 794 if (!surface->Initialize()) |
| 795 return nullptr; |
| 796 return surface; |
| 797 } |
| 798 #endif |
| 717 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 799 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 718 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 800 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 719 if (!surface->Initialize()) | 801 if (!surface->Initialize()) |
| 720 return nullptr; | 802 return nullptr; |
| 721 return surface; | 803 return surface; |
| 722 } | 804 } |
| 723 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 805 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 724 if (window != kNullAcceleratedWidget) { | 806 if (window != kNullAcceleratedWidget) { |
| 725 scoped_refptr<GLSurface> surface; | 807 scoped_refptr<GLSurface> surface; |
| 726 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) | 808 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) |
| 727 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); | 809 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); |
| 728 if (!surface) | 810 if (!surface) |
| 729 surface = CreateViewGLSurfaceOzone(window); | 811 surface = CreateViewGLSurfaceOzone(window); |
| 730 return surface; | 812 return surface; |
| 731 } else { | 813 } else { |
| 732 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | 814 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| 733 if (surface->Initialize()) | 815 if (surface->Initialize()) |
| 734 return surface; | 816 return surface; |
| 735 } | 817 } |
| 736 return nullptr; | 818 return nullptr; |
| 737 } | 819 } |
| 738 | 820 |
| 739 // static | 821 // static |
| 740 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | 822 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
| 741 const gfx::Size& size) { | 823 const gfx::Size& size) { |
| 742 switch (GetGLImplementation()) { | 824 switch (GetGLImplementation()) { |
| 825 #if defined(USE_GLX) |
| 826 case kGLImplementationDesktopGL: { |
| 827 scoped_refptr<GLSurface> surface( |
| 828 new UnmappedNativeViewGLSurfaceGLX(size)); |
| 829 if (!surface->Initialize()) |
| 830 return nullptr; |
| 831 |
| 832 return surface; |
| 833 } |
| 834 #endif |
| 743 case kGLImplementationOSMesaGL: { | 835 case kGLImplementationOSMesaGL: { |
| 744 scoped_refptr<GLSurface> surface( | 836 scoped_refptr<GLSurface> surface( |
| 745 new GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, size)); | 837 new GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, size)); |
| 746 if (!surface->Initialize()) | 838 if (!surface->Initialize()) |
| 747 return nullptr; | 839 return nullptr; |
| 748 | 840 |
| 749 return surface; | 841 return surface; |
| 750 } | 842 } |
| 751 case kGLImplementationEGLGLES2: { | 843 case kGLImplementationEGLGLES2: { |
| 752 scoped_refptr<GLSurface> surface; | 844 scoped_refptr<GLSurface> surface; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 769 } | 861 } |
| 770 } | 862 } |
| 771 | 863 |
| 772 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 864 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 773 return ui::OzonePlatform::GetInstance() | 865 return ui::OzonePlatform::GetInstance() |
| 774 ->GetSurfaceFactoryOzone() | 866 ->GetSurfaceFactoryOzone() |
| 775 ->GetNativeDisplay(); | 867 ->GetNativeDisplay(); |
| 776 } | 868 } |
| 777 | 869 |
| 778 } // namespace gfx | 870 } // namespace gfx |
| OLD | NEW |