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/wayland/wayland_surface_factory.h" | 5 #include "ui/ozone/platform/wayland/wayland_surface_factory.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <sys/mman.h> | 8 #include <sys/mman.h> |
9 #include <wayland-client.h> | 9 #include <wayland-client.h> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
13 #include "third_party/skia/include/core/SkSurface.h" | 13 #include "third_party/skia/include/core/SkSurface.h" |
14 #include "ui/gfx/vsync_provider.h" | 14 #include "ui/gfx/vsync_provider.h" |
15 #include "ui/ozone/common/egl_util.h" | 15 #include "ui/ozone/common/egl_util.h" |
16 #include "ui/ozone/common/gl_ozone_egl.h" | 16 #include "ui/ozone/common/gl_ozone_egl.h" |
| 17 #include "ui/ozone/common/gl_ozone_osmesa.h" |
17 #include "ui/ozone/platform/wayland/gl_surface_wayland.h" | 18 #include "ui/ozone/platform/wayland/gl_surface_wayland.h" |
18 #include "ui/ozone/platform/wayland/wayland_connection.h" | 19 #include "ui/ozone/platform/wayland/wayland_connection.h" |
19 #include "ui/ozone/platform/wayland/wayland_object.h" | 20 #include "ui/ozone/platform/wayland/wayland_object.h" |
20 #include "ui/ozone/platform/wayland/wayland_window.h" | 21 #include "ui/ozone/platform/wayland/wayland_window.h" |
21 #include "ui/ozone/public/surface_ozone_canvas.h" | 22 #include "ui/ozone/public/surface_ozone_canvas.h" |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 | 25 |
25 static void DeleteSharedMemory(void* pixels, void* context) { | 26 static void DeleteSharedMemory(void* pixels, void* context) { |
26 delete static_cast<base::SharedMemory*>(context); | 27 delete static_cast<base::SharedMemory*>(context); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // TODO(forney): This can be implemented with information from frame | 122 // TODO(forney): This can be implemented with information from frame |
122 // callbacks, and possibly output refresh rate. | 123 // callbacks, and possibly output refresh rate. |
123 NOTIMPLEMENTED(); | 124 NOTIMPLEMENTED(); |
124 return nullptr; | 125 return nullptr; |
125 } | 126 } |
126 | 127 |
127 namespace { | 128 namespace { |
128 | 129 |
129 class GLOzoneEGLWayland : public GLOzoneEGL { | 130 class GLOzoneEGLWayland : public GLOzoneEGL { |
130 public: | 131 public: |
131 GLOzoneEGLWayland(WaylandConnection* connection) : connection_(connection) {} | 132 explicit GLOzoneEGLWayland(WaylandConnection* connection) |
| 133 : connection_(connection) {} |
132 ~GLOzoneEGLWayland() override {} | 134 ~GLOzoneEGLWayland() override {} |
133 | 135 |
134 scoped_refptr<gl::GLSurface> CreateViewGLSurface( | 136 scoped_refptr<gl::GLSurface> CreateViewGLSurface( |
135 gfx::AcceleratedWidget widget) override; | 137 gfx::AcceleratedWidget widget) override; |
136 | 138 |
137 scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface( | 139 scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface( |
138 const gfx::Size& size) override; | 140 const gfx::Size& size) override; |
139 | 141 |
140 protected: | 142 protected: |
141 intptr_t GetNativeDisplay() override; | 143 intptr_t GetNativeDisplay() override; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 177 } |
176 | 178 |
177 bool GLOzoneEGLWayland::LoadGLES2Bindings() { | 179 bool GLOzoneEGLWayland::LoadGLES2Bindings() { |
178 setenv("EGL_PLATFORM", "wayland", 0); | 180 setenv("EGL_PLATFORM", "wayland", 0); |
179 return LoadDefaultEGLGLES2Bindings(); | 181 return LoadDefaultEGLGLES2Bindings(); |
180 } | 182 } |
181 | 183 |
182 } // namespace | 184 } // namespace |
183 | 185 |
184 WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection) | 186 WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection) |
185 : connection_(connection) { | 187 : connection_(connection), |
| 188 osmesa_implementation_(base::MakeUnique<GLOzoneOSMesa>()) { |
186 if (connection_) | 189 if (connection_) |
187 egl_implementation_.reset(new GLOzoneEGLWayland(connection_)); | 190 egl_implementation_ = base::MakeUnique<GLOzoneEGLWayland>(connection_); |
188 } | 191 } |
189 | 192 |
190 WaylandSurfaceFactory::~WaylandSurfaceFactory() {} | 193 WaylandSurfaceFactory::~WaylandSurfaceFactory() {} |
191 | 194 |
192 std::unique_ptr<SurfaceOzoneCanvas> | 195 std::unique_ptr<SurfaceOzoneCanvas> |
193 WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { | 196 WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { |
194 if (!connection_) | 197 if (!connection_) |
195 return nullptr; | 198 return nullptr; |
196 WaylandWindow* window = connection_->GetWindow(widget); | 199 WaylandWindow* window = connection_->GetWindow(widget); |
197 DCHECK(window); | 200 DCHECK(window); |
198 return base::MakeUnique<WaylandCanvasSurface>(connection_, window); | 201 return base::MakeUnique<WaylandCanvasSurface>(connection_, window); |
199 } | 202 } |
200 | 203 |
201 std::vector<gl::GLImplementation> | 204 std::vector<gl::GLImplementation> |
202 WaylandSurfaceFactory::GetAllowedGLImplementations() { | 205 WaylandSurfaceFactory::GetAllowedGLImplementations() { |
203 std::vector<gl::GLImplementation> impls; | 206 std::vector<gl::GLImplementation> impls; |
204 impls.push_back(gl::kGLImplementationEGLGLES2); | 207 if (egl_implementation_) |
| 208 impls.push_back(gl::kGLImplementationEGLGLES2); |
| 209 impls.push_back(gl::kGLImplementationOSMesaGL); |
205 return impls; | 210 return impls; |
206 } | 211 } |
207 | 212 |
208 GLOzone* WaylandSurfaceFactory::GetGLOzone( | 213 GLOzone* WaylandSurfaceFactory::GetGLOzone( |
209 gl::GLImplementation implementation) { | 214 gl::GLImplementation implementation) { |
210 switch (implementation) { | 215 switch (implementation) { |
211 case gl::kGLImplementationEGLGLES2: | 216 case gl::kGLImplementationEGLGLES2: |
212 return egl_implementation_.get(); | 217 return egl_implementation_.get(); |
| 218 case gl::kGLImplementationOSMesaGL: |
| 219 return osmesa_implementation_.get(); |
213 default: | 220 default: |
214 return nullptr; | 221 return nullptr; |
215 } | 222 } |
216 } | 223 } |
217 | 224 |
218 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmap( | 225 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmap( |
219 gfx::AcceleratedWidget widget, | 226 gfx::AcceleratedWidget widget, |
220 gfx::Size size, | 227 gfx::Size size, |
221 gfx::BufferFormat format, | 228 gfx::BufferFormat format, |
222 gfx::BufferUsage usage) { | 229 gfx::BufferUsage usage) { |
223 NOTIMPLEMENTED(); | 230 NOTIMPLEMENTED(); |
224 return nullptr; | 231 return nullptr; |
225 } | 232 } |
226 | 233 |
227 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmapFromHandle( | 234 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmapFromHandle( |
228 gfx::AcceleratedWidget widget, | 235 gfx::AcceleratedWidget widget, |
229 gfx::Size size, | 236 gfx::Size size, |
230 gfx::BufferFormat format, | 237 gfx::BufferFormat format, |
231 const gfx::NativePixmapHandle& handle) { | 238 const gfx::NativePixmapHandle& handle) { |
232 NOTIMPLEMENTED(); | 239 NOTIMPLEMENTED(); |
233 return nullptr; | 240 return nullptr; |
234 } | 241 } |
235 | 242 |
236 } // namespace ui | 243 } // namespace ui |
OLD | NEW |