| 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 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 images_[i]->Destroy(true); | 653 images_[i]->Destroy(true); |
| 647 images_[i] = image; | 654 images_[i] = image; |
| 648 // Bind image to texture. | 655 // Bind image to texture. |
| 649 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); | 656 ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); |
| 650 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) | 657 if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) |
| 651 return false; | 658 return false; |
| 652 } | 659 } |
| 653 return true; | 660 return true; |
| 654 } | 661 } |
| 655 | 662 |
| 663 #if defined(USE_GLX) |
| 664 |
| 665 // Ozone specific implementation of GLX surface. Registers as XEventDispatcher |
| 666 // to handle XEvents. |
| 667 class GL_EXPORT NativeViewGLSurfaceGLXOzone : public NativeViewGLSurfaceGLX, |
| 668 public ui::XEventDispatcher { |
| 669 public: |
| 670 explicit NativeViewGLSurfaceGLXOzone(gfx::AcceleratedWidget window); |
| 671 |
| 672 // XEventDispatcher implementation: |
| 673 bool DispatchXEvent(XEvent* xevent) override; |
| 674 |
| 675 protected: |
| 676 ~NativeViewGLSurfaceGLXOzone() override; |
| 677 |
| 678 // NativeViewGLSurfaceGLX implementation: |
| 679 void RegisterEvents() override; |
| 680 void UnregisterEvents() override; |
| 681 |
| 682 private: |
| 683 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLXOzone); |
| 684 }; |
| 685 |
| 686 NativeViewGLSurfaceGLXOzone::NativeViewGLSurfaceGLXOzone( |
| 687 gfx::AcceleratedWidget window) |
| 688 : NativeViewGLSurfaceGLX(window) {} |
| 689 |
| 690 bool NativeViewGLSurfaceGLXOzone::DispatchXEvent(XEvent* event) { |
| 691 if (!CanHandleEvent(event)) |
| 692 return false; |
| 693 |
| 694 ForwardExposeEvent(event); |
| 695 return true; |
| 696 } |
| 697 |
| 698 NativeViewGLSurfaceGLXOzone::~NativeViewGLSurfaceGLXOzone() { |
| 699 Destroy(); |
| 700 } |
| 701 |
| 702 void NativeViewGLSurfaceGLXOzone::RegisterEvents() { |
| 703 ui::X11EventSourceLibevent* event_source = |
| 704 ui::X11EventSourceLibevent::GetInstance(); |
| 705 // Can be nullptr in tests, when we don't care about Exposes. |
| 706 if (event_source) { |
| 707 XSelectInput(gfx::GetXDisplay(), window(), ExposureMask); |
| 708 event_source->AddXEventDispatcher(this); |
| 709 } |
| 710 } |
| 711 |
| 712 void NativeViewGLSurfaceGLXOzone::UnregisterEvents() { |
| 713 ui::X11EventSourceLibevent* event_source = |
| 714 ui::X11EventSourceLibevent::GetInstance(); |
| 715 if (event_source) |
| 716 event_source->RemoveXEventDispatcher(this); |
| 717 } |
| 718 |
| 719 #endif // defined(USE_GLX) |
| 720 |
| 656 scoped_refptr<GLSurface> CreateViewGLSurfaceOzone( | 721 scoped_refptr<GLSurface> CreateViewGLSurfaceOzone( |
| 657 gfx::AcceleratedWidget window) { | 722 gfx::AcceleratedWidget window) { |
| 658 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 723 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 659 ui::OzonePlatform::GetInstance() | 724 ui::OzonePlatform::GetInstance() |
| 660 ->GetSurfaceFactoryOzone() | 725 ->GetSurfaceFactoryOzone() |
| 661 ->CreateEGLSurfaceForWidget(window); | 726 ->CreateEGLSurfaceForWidget(window); |
| 662 if (!surface_ozone) | 727 if (!surface_ozone) |
| 663 return nullptr; | 728 return nullptr; |
| 664 scoped_refptr<GLSurface> surface = | 729 scoped_refptr<GLSurface> surface = |
| 665 new GLSurfaceOzoneEGL(std::move(surface_ozone), window); | 730 new GLSurfaceOzoneEGL(std::move(surface_ozone), window); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 681 if (!surface->Initialize()) | 746 if (!surface->Initialize()) |
| 682 return nullptr; | 747 return nullptr; |
| 683 return surface; | 748 return surface; |
| 684 } | 749 } |
| 685 | 750 |
| 686 } // namespace | 751 } // namespace |
| 687 | 752 |
| 688 // static | 753 // static |
| 689 bool GLSurface::InitializeOneOffInternal() { | 754 bool GLSurface::InitializeOneOffInternal() { |
| 690 switch (GetGLImplementation()) { | 755 switch (GetGLImplementation()) { |
| 756 #if defined(USE_GLX) |
| 757 case kGLImplementationDesktopGL: |
| 758 if (!GLSurfaceGLX::InitializeOneOff()) { |
| 759 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; |
| 760 return false; |
| 761 } |
| 762 |
| 763 return true; |
| 764 #endif |
| 691 case kGLImplementationEGLGLES2: | 765 case kGLImplementationEGLGLES2: |
| 692 if (!GLSurfaceEGL::InitializeOneOff()) { | 766 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 693 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 767 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 694 return false; | 768 return false; |
| 695 } | 769 } |
| 696 | 770 |
| 697 return true; | 771 return true; |
| 698 case kGLImplementationOSMesaGL: | 772 case kGLImplementationOSMesaGL: |
| 699 case kGLImplementationMockGL: | 773 case kGLImplementationMockGL: |
| 700 return true; | 774 return true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 720 if (surface->Initialize()) | 794 if (surface->Initialize()) |
| 721 return surface; | 795 return surface; |
| 722 } | 796 } |
| 723 | 797 |
| 724 return nullptr; | 798 return nullptr; |
| 725 } | 799 } |
| 726 | 800 |
| 727 // static | 801 // static |
| 728 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 802 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 729 gfx::AcceleratedWidget window) { | 803 gfx::AcceleratedWidget window) { |
| 804 #if defined(USE_GLX) |
| 805 if (GetGLImplementation() == kGLImplementationDesktopGL) { |
| 806 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLXOzone(window)); |
| 807 if (!surface->Initialize()) |
| 808 return nullptr; |
| 809 return surface; |
| 810 } |
| 811 #endif |
| 730 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 812 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 731 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 813 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 732 if (!surface->Initialize()) | 814 if (!surface->Initialize()) |
| 733 return nullptr; | 815 return nullptr; |
| 734 return surface; | 816 return surface; |
| 735 } | 817 } |
| 736 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 818 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 737 if (window != kNullAcceleratedWidget) { | 819 if (window != kNullAcceleratedWidget) { |
| 738 scoped_refptr<GLSurface> surface; | 820 scoped_refptr<GLSurface> surface; |
| 739 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) | 821 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) |
| 740 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); | 822 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); |
| 741 if (!surface) | 823 if (!surface) |
| 742 surface = CreateViewGLSurfaceOzone(window); | 824 surface = CreateViewGLSurfaceOzone(window); |
| 743 return surface; | 825 return surface; |
| 744 } else { | 826 } else { |
| 745 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | 827 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| 746 if (surface->Initialize()) | 828 if (surface->Initialize()) |
| 747 return surface; | 829 return surface; |
| 748 } | 830 } |
| 749 return nullptr; | 831 return nullptr; |
| 750 } | 832 } |
| 751 | 833 |
| 752 // static | 834 // static |
| 753 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | 835 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
| 754 const gfx::Size& size) { | 836 const gfx::Size& size) { |
| 755 switch (GetGLImplementation()) { | 837 switch (GetGLImplementation()) { |
| 838 #if defined(USE_GLX) |
| 839 case kGLImplementationDesktopGL: { |
| 840 scoped_refptr<GLSurface> surface( |
| 841 new UnmappedNativeViewGLSurfaceGLX(size)); |
| 842 if (!surface->Initialize()) |
| 843 return nullptr; |
| 844 |
| 845 return surface; |
| 846 } |
| 847 #endif |
| 756 case kGLImplementationOSMesaGL: { | 848 case kGLImplementationOSMesaGL: { |
| 757 scoped_refptr<GLSurface> surface( | 849 scoped_refptr<GLSurface> surface( |
| 758 new GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, size)); | 850 new GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, size)); |
| 759 if (!surface->Initialize()) | 851 if (!surface->Initialize()) |
| 760 return nullptr; | 852 return nullptr; |
| 761 | 853 |
| 762 return surface; | 854 return surface; |
| 763 } | 855 } |
| 764 case kGLImplementationEGLGLES2: { | 856 case kGLImplementationEGLGLES2: { |
| 765 scoped_refptr<GLSurface> surface; | 857 scoped_refptr<GLSurface> surface; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 782 } | 874 } |
| 783 } | 875 } |
| 784 | 876 |
| 785 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 877 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 786 return ui::OzonePlatform::GetInstance() | 878 return ui::OzonePlatform::GetInstance() |
| 787 ->GetSurfaceFactoryOzone() | 879 ->GetSurfaceFactoryOzone() |
| 788 ->GetNativeDisplay(); | 880 ->GetNativeDisplay(); |
| 789 } | 881 } |
| 790 | 882 |
| 791 } // namespace gfx | 883 } // namespace gfx |
| OLD | NEW |