| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ozone/platform/x11/x11_surface_factory.h" | 5 #include "ui/ozone/platform/x11/x11_surface_factory.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "third_party/khronos/EGL/egl.h" | 10 #include "third_party/khronos/EGL/egl.h" |
| 11 #include "ui/gfx/x/x11_types.h" | 11 #include "ui/gfx/x/x11_types.h" |
| 12 #include "ui/gl/egl_util.h" | 12 #include "ui/gl/egl_util.h" |
| 13 #include "ui/gl/gl_surface_egl.h" | 13 #include "ui/gl/gl_surface_egl.h" |
| 14 #include "ui/gl/gl_surface_osmesa_x11.h" | |
| 15 #include "ui/ozone/common/egl_util.h" | 14 #include "ui/ozone/common/egl_util.h" |
| 16 #include "ui/ozone/common/gl_ozone_egl.h" | 15 #include "ui/ozone/common/gl_ozone_egl.h" |
| 17 #include "ui/ozone/common/gl_ozone_osmesa.h" | 16 #include "ui/ozone/common/gl_ozone_osmesa.h" |
| 18 #include "ui/ozone/platform/x11/gl_ozone_glx.h" | 17 #include "ui/ozone/platform/x11/gl_ozone_glx.h" |
| 19 | 18 |
| 20 namespace ui { | 19 namespace ui { |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 // GLSurface implementation for Ozone X11 EGL. | 23 // GLSurface implementation for Ozone X11 EGL. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 XResizeWindow(gfx::GetXDisplay(), window_, size.width(), size.height()); | 116 XResizeWindow(gfx::GetXDisplay(), window_, size.width(), size.height()); |
| 118 eglWaitNative(EGL_CORE_NATIVE_ENGINE); | 117 eglWaitNative(EGL_CORE_NATIVE_ENGINE); |
| 119 | 118 |
| 120 return true; | 119 return true; |
| 121 } | 120 } |
| 122 | 121 |
| 123 GLSurfaceEGLOzoneX11::~GLSurfaceEGLOzoneX11() { | 122 GLSurfaceEGLOzoneX11::~GLSurfaceEGLOzoneX11() { |
| 124 Destroy(); | 123 Destroy(); |
| 125 } | 124 } |
| 126 | 125 |
| 127 // GLOzoneEGL implementation that draws to an XWindow. | |
| 128 class GLOzoneEGLX11 : public GLOzoneEGL { | 126 class GLOzoneEGLX11 : public GLOzoneEGL { |
| 129 public: | 127 public: |
| 130 GLOzoneEGLX11() {} | 128 GLOzoneEGLX11() {} |
| 131 ~GLOzoneEGLX11() override {} | 129 ~GLOzoneEGLX11() override {} |
| 132 | 130 |
| 133 // GLOzoneEGL: | |
| 134 scoped_refptr<gl::GLSurface> CreateViewGLSurface( | 131 scoped_refptr<gl::GLSurface> CreateViewGLSurface( |
| 135 gfx::AcceleratedWidget window) override { | 132 gfx::AcceleratedWidget window) override { |
| 136 return gl::InitializeGLSurface(new GLSurfaceEGLOzoneX11(window)); | 133 return gl::InitializeGLSurface(new GLSurfaceEGLOzoneX11(window)); |
| 137 } | 134 } |
| 138 | 135 |
| 139 scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface( | 136 scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface( |
| 140 const gfx::Size& size) override { | 137 const gfx::Size& size) override { |
| 141 return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size)); | 138 return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size)); |
| 142 } | 139 } |
| 143 | 140 |
| 144 protected: | 141 protected: |
| 145 intptr_t GetNativeDisplay() override { | 142 intptr_t GetNativeDisplay() override { |
| 146 return reinterpret_cast<intptr_t>(gfx::GetXDisplay()); | 143 return reinterpret_cast<intptr_t>(gfx::GetXDisplay()); |
| 147 } | 144 } |
| 148 | 145 |
| 149 bool LoadGLES2Bindings() override { return LoadDefaultEGLGLES2Bindings(); } | 146 bool LoadGLES2Bindings() override { return LoadDefaultEGLGLES2Bindings(); } |
| 150 | 147 |
| 151 private: | 148 private: |
| 152 DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLX11); | 149 DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLX11); |
| 153 }; | 150 }; |
| 154 | 151 |
| 155 // GLOzoneOSMesa implementation that draws to an XWindow. | |
| 156 class GLOzoneOSMesaX11 : public GLOzoneOSMesa { | |
| 157 public: | |
| 158 GLOzoneOSMesaX11() {} | |
| 159 ~GLOzoneOSMesaX11() override {} | |
| 160 | |
| 161 // GLOzoneOSMesa: | |
| 162 bool InitializeGLOneOffPlatform() override { | |
| 163 return gl::GLSurfaceOSMesaX11::InitializeOneOff(); | |
| 164 } | |
| 165 | |
| 166 scoped_refptr<gl::GLSurface> CreateViewGLSurface( | |
| 167 gfx::AcceleratedWidget window) override { | |
| 168 return gl::InitializeGLSurface(new gl::GLSurfaceOSMesaX11(window)); | |
| 169 } | |
| 170 }; | |
| 171 | |
| 172 } // namespace | 152 } // namespace |
| 173 | 153 |
| 174 X11SurfaceFactory::X11SurfaceFactory() | 154 X11SurfaceFactory::X11SurfaceFactory() |
| 175 : glx_implementation_(base::MakeUnique<GLOzoneGLX>()), | 155 : glx_implementation_(base::MakeUnique<GLOzoneGLX>()), |
| 176 egl_implementation_(base::MakeUnique<GLOzoneEGLX11>()), | 156 egl_implementation_(base::MakeUnique<GLOzoneEGLX11>()), |
| 177 osmesa_implementation_(base::MakeUnique<GLOzoneOSMesaX11>()) {} | 157 osmesa_implementation_(base::MakeUnique<GLOzoneOSMesa>()) {} |
| 178 | 158 |
| 179 X11SurfaceFactory::~X11SurfaceFactory() {} | 159 X11SurfaceFactory::~X11SurfaceFactory() {} |
| 180 | 160 |
| 181 std::vector<gl::GLImplementation> | 161 std::vector<gl::GLImplementation> |
| 182 X11SurfaceFactory::GetAllowedGLImplementations() { | 162 X11SurfaceFactory::GetAllowedGLImplementations() { |
| 183 // DesktopGL (GLX) should be the first option when crbug.com/646982 is fixed. | 163 // DesktopGL (GLX) should be the first option when crbug.com/646982 is fixed. |
| 184 return std::vector<gl::GLImplementation>{gl::kGLImplementationEGLGLES2, | 164 return std::vector<gl::GLImplementation>{gl::kGLImplementationEGLGLES2, |
| 185 gl::kGLImplementationDesktopGL, | 165 gl::kGLImplementationDesktopGL, |
| 186 gl::kGLImplementationOSMesaGL}; | 166 gl::kGLImplementationOSMesaGL}; |
| 187 } | 167 } |
| 188 | 168 |
| 189 GLOzone* X11SurfaceFactory::GetGLOzone(gl::GLImplementation implementation) { | 169 GLOzone* X11SurfaceFactory::GetGLOzone(gl::GLImplementation implementation) { |
| 190 switch (implementation) { | 170 switch (implementation) { |
| 191 case gl::kGLImplementationDesktopGL: | 171 case gl::kGLImplementationDesktopGL: |
| 192 return glx_implementation_.get(); | 172 return glx_implementation_.get(); |
| 193 case gl::kGLImplementationEGLGLES2: | 173 case gl::kGLImplementationEGLGLES2: |
| 194 return egl_implementation_.get(); | 174 return egl_implementation_.get(); |
| 195 case gl::kGLImplementationOSMesaGL: | 175 case gl::kGLImplementationOSMesaGL: |
| 196 return osmesa_implementation_.get(); | 176 return osmesa_implementation_.get(); |
| 197 default: | 177 default: |
| 198 return nullptr; | 178 return nullptr; |
| 199 } | 179 } |
| 200 } | 180 } |
| 201 | 181 |
| 202 } // namespace ui | 182 } // namespace ui |
| OLD | NEW |