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