Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: ui/gl/gl_surface_ozone.cc

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

Powered by Google App Engine
This is Rietveld 408576698