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/platform/wayland/wayland_connection.h" | 16 #include "ui/ozone/platform/wayland/wayland_connection.h" |
17 #include "ui/ozone/platform/wayland/wayland_object.h" | 17 #include "ui/ozone/platform/wayland/wayland_object.h" |
18 #include "ui/ozone/platform/wayland/wayland_window.h" | 18 #include "ui/ozone/platform/wayland/wayland_window.h" |
19 #include "ui/ozone/public/surface_ozone_canvas.h" | 19 #include "ui/ozone/public/surface_ozone_canvas.h" |
20 #include "ui/ozone/public/surface_ozone_egl.h" | 20 #include "ui/ozone/public/surface_ozone_egl.h" |
21 | 21 |
22 #if defined(USE_WAYLAND_EGL) | 22 #if defined(USE_WAYLAND_EGL) |
23 #include "ui/ozone/platform/wayland/wayland_egl_surface.h" | 23 #include "ui/ozone/platform/wayland/gl_surface_wayland.h" |
24 #endif | 24 #endif |
25 | 25 |
26 namespace ui { | 26 namespace ui { |
27 | 27 |
28 static void DeleteSharedMemory(void* pixels, void* context) { | 28 static void DeleteSharedMemory(void* pixels, void* context) { |
29 delete static_cast<base::SharedMemory*>(context); | 29 delete static_cast<base::SharedMemory*>(context); |
30 } | 30 } |
31 | 31 |
32 class WaylandCanvasSurface : public SurfaceOzoneCanvas { | 32 class WaylandCanvasSurface : public SurfaceOzoneCanvas { |
33 public: | 33 public: |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // callbacks, and possibly output refresh rate. | 125 // callbacks, and possibly output refresh rate. |
126 NOTIMPLEMENTED(); | 126 NOTIMPLEMENTED(); |
127 return nullptr; | 127 return nullptr; |
128 } | 128 } |
129 | 129 |
130 WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection) | 130 WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection) |
131 : connection_(connection) {} | 131 : connection_(connection) {} |
132 | 132 |
133 WaylandSurfaceFactory::~WaylandSurfaceFactory() {} | 133 WaylandSurfaceFactory::~WaylandSurfaceFactory() {} |
134 | 134 |
| 135 scoped_refptr<gl::GLSurface> WaylandSurfaceFactory::CreateViewGLSurface( |
| 136 gl::GLImplementation implementation, |
| 137 gfx::AcceleratedWidget widget) { |
| 138 if (implementation != gl::kGLImplementationEGLGLES2) { |
| 139 NOTREACHED(); |
| 140 return nullptr; |
| 141 } |
| 142 |
| 143 #if defined(USE_WAYLAND_EGL) |
| 144 WaylandWindow* window = connection_->GetWindow(widget); |
| 145 DCHECK(window); |
| 146 // The wl_egl_window needs to be created before the GLSurface so it can be |
| 147 // used in the GLSurface constructor. |
| 148 auto egl_window = CreateWaylandEglWindow(window); |
| 149 if (!egl_window) |
| 150 return nullptr; |
| 151 return gl::InitializeGLSurface(new GLSurfaceWayland(std::move(egl_window))); |
| 152 #else |
| 153 return nullptr; |
| 154 #endif |
| 155 } |
| 156 |
| 157 scoped_refptr<gl::GLSurface> WaylandSurfaceFactory::CreateOffscreenGLSurface( |
| 158 gl::GLImplementation implementation, |
| 159 const gfx::Size& size) { |
| 160 if (implementation != gl::kGLImplementationEGLGLES2) { |
| 161 NOTREACHED(); |
| 162 return nullptr; |
| 163 } |
| 164 |
| 165 #if defined(USE_WAYLAND_EGL) |
| 166 return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size)); |
| 167 #else |
| 168 return nullptr; |
| 169 #endif |
| 170 } |
| 171 |
135 intptr_t WaylandSurfaceFactory::GetNativeDisplay() { | 172 intptr_t WaylandSurfaceFactory::GetNativeDisplay() { |
136 return reinterpret_cast<intptr_t>(connection_->display()); | 173 return reinterpret_cast<intptr_t>(connection_->display()); |
137 } | 174 } |
138 | 175 |
139 bool WaylandSurfaceFactory::LoadEGLGLES2Bindings( | 176 bool WaylandSurfaceFactory::LoadEGLGLES2Bindings( |
140 AddGLLibraryCallback add_gl_library, | 177 AddGLLibraryCallback add_gl_library, |
141 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 178 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
142 #if defined(USE_WAYLAND_EGL) | 179 #if defined(USE_WAYLAND_EGL) |
143 if (!connection_) | 180 if (!connection_) |
144 return false; | 181 return false; |
145 setenv("EGL_PLATFORM", "wayland", 0); | 182 setenv("EGL_PLATFORM", "wayland", 0); |
146 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); | 183 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); |
147 #else | 184 #else |
148 return false; | 185 return false; |
149 #endif | 186 #endif |
150 } | 187 } |
151 | 188 |
152 std::unique_ptr<SurfaceOzoneCanvas> | 189 std::unique_ptr<SurfaceOzoneCanvas> |
153 WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { | 190 WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { |
154 WaylandWindow* window = connection_->GetWindow(widget); | 191 WaylandWindow* window = connection_->GetWindow(widget); |
155 DCHECK(window); | 192 DCHECK(window); |
156 return base::WrapUnique(new WaylandCanvasSurface(connection_, window)); | 193 return base::WrapUnique(new WaylandCanvasSurface(connection_, window)); |
157 } | 194 } |
158 | 195 |
159 std::unique_ptr<SurfaceOzoneEGL> | |
160 WaylandSurfaceFactory::CreateEGLSurfaceForWidget( | |
161 gfx::AcceleratedWidget widget) { | |
162 #if defined(USE_WAYLAND_EGL) | |
163 WaylandWindow* window = connection_->GetWindow(widget); | |
164 DCHECK(window); | |
165 auto surface = base::WrapUnique( | |
166 new WaylandEGLSurface(window, window->GetBounds().size())); | |
167 if (!surface->Initialize()) | |
168 return nullptr; | |
169 return std::move(surface); | |
170 #else | |
171 return nullptr; | |
172 #endif | |
173 } | |
174 | |
175 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmap( | 196 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmap( |
176 gfx::AcceleratedWidget widget, | 197 gfx::AcceleratedWidget widget, |
177 gfx::Size size, | 198 gfx::Size size, |
178 gfx::BufferFormat format, | 199 gfx::BufferFormat format, |
179 gfx::BufferUsage usage) { | 200 gfx::BufferUsage usage) { |
180 NOTIMPLEMENTED(); | 201 NOTIMPLEMENTED(); |
181 return nullptr; | 202 return nullptr; |
182 } | 203 } |
183 | 204 |
184 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmapFromHandle( | 205 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmapFromHandle( |
185 gfx::AcceleratedWidget widget, | 206 gfx::AcceleratedWidget widget, |
186 gfx::Size size, | 207 gfx::Size size, |
187 gfx::BufferFormat format, | 208 gfx::BufferFormat format, |
188 const gfx::NativePixmapHandle& handle) { | 209 const gfx::NativePixmapHandle& handle) { |
189 NOTIMPLEMENTED(); | 210 NOTIMPLEMENTED(); |
190 return nullptr; | 211 return nullptr; |
191 } | 212 } |
192 | 213 |
193 } // namespace ui | 214 } // namespace ui |
OLD | NEW |