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

Side by Side Diff: ui/ozone/platform/wayland/wayland_surface_factory.cc

Issue 2313353003: Ozone/Wayland: Move to newer APIs and improve GPU initialization (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « ui/ozone/platform/wayland/wayland_surface_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/platform/wayland/wayland_connection.h" 17 #include "ui/ozone/platform/wayland/wayland_connection.h"
17 #include "ui/ozone/platform/wayland/wayland_object.h" 18 #include "ui/ozone/platform/wayland/wayland_object.h"
18 #include "ui/ozone/platform/wayland/wayland_window.h" 19 #include "ui/ozone/platform/wayland/wayland_window.h"
19 #include "ui/ozone/public/surface_ozone_canvas.h" 20 #include "ui/ozone/public/surface_ozone_canvas.h"
20 21
21 #if defined(USE_WAYLAND_EGL) 22 #if defined(USE_WAYLAND_EGL)
22 #include "ui/ozone/platform/wayland/gl_surface_wayland.h" 23 #include "ui/ozone/platform/wayland/gl_surface_wayland.h"
23 #endif 24 #endif
24 25
25 namespace ui { 26 namespace ui {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 120 }
120 121
121 std::unique_ptr<gfx::VSyncProvider> 122 std::unique_ptr<gfx::VSyncProvider>
122 WaylandCanvasSurface::CreateVSyncProvider() { 123 WaylandCanvasSurface::CreateVSyncProvider() {
123 // TODO(forney): This can be implemented with information from frame 124 // TODO(forney): This can be implemented with information from frame
124 // callbacks, and possibly output refresh rate. 125 // callbacks, and possibly output refresh rate.
125 NOTIMPLEMENTED(); 126 NOTIMPLEMENTED();
126 return nullptr; 127 return nullptr;
127 } 128 }
128 129
129 WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection) 130 namespace {
130 : connection_(connection) {}
131 131
132 WaylandSurfaceFactory::~WaylandSurfaceFactory() {} 132 class GLOzoneEGLWayland : public GLOzoneEGL {
133 public:
134 GLOzoneEGLWayland(WaylandConnection* connection) : connection_(connection) {}
135 ~GLOzoneEGLWayland() override {}
133 136
134 scoped_refptr<gl::GLSurface> WaylandSurfaceFactory::CreateViewGLSurface( 137 scoped_refptr<gl::GLSurface> CreateViewGLSurface(
135 gl::GLImplementation implementation, 138 gfx::AcceleratedWidget widget) override;
139
140 scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface(
141 const gfx::Size& size) override;
142
143 protected:
144 intptr_t GetNativeDisplay() override;
145 bool LoadGLES2Bindings() override;
146
147 private:
148 WaylandConnection* connection_;
149
150 DISALLOW_COPY_AND_ASSIGN(GLOzoneEGLWayland);
151 };
152
153 scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateViewGLSurface(
136 gfx::AcceleratedWidget widget) { 154 gfx::AcceleratedWidget widget) {
137 if (implementation != gl::kGLImplementationEGLGLES2) {
138 NOTREACHED();
139 return nullptr;
140 }
141
142 #if defined(USE_WAYLAND_EGL) 155 #if defined(USE_WAYLAND_EGL)
156 DCHECK(connection_);
143 WaylandWindow* window = connection_->GetWindow(widget); 157 WaylandWindow* window = connection_->GetWindow(widget);
144 DCHECK(window); 158 DCHECK(window);
145 // The wl_egl_window needs to be created before the GLSurface so it can be 159 // The wl_egl_window needs to be created before the GLSurface so it can be
146 // used in the GLSurface constructor. 160 // used in the GLSurface constructor.
147 auto egl_window = CreateWaylandEglWindow(window); 161 auto egl_window = CreateWaylandEglWindow(window);
148 if (!egl_window) 162 if (!egl_window)
149 return nullptr; 163 return nullptr;
150 return gl::InitializeGLSurface(new GLSurfaceWayland(std::move(egl_window))); 164 return gl::InitializeGLSurface(new GLSurfaceWayland(std::move(egl_window)));
151 #else 165 #else
152 return nullptr; 166 return nullptr;
153 #endif 167 #endif
154 } 168 }
155 169
156 scoped_refptr<gl::GLSurface> WaylandSurfaceFactory::CreateOffscreenGLSurface( 170 scoped_refptr<gl::GLSurface> GLOzoneEGLWayland::CreateOffscreenGLSurface(
157 gl::GLImplementation implementation,
158 const gfx::Size& size) { 171 const gfx::Size& size) {
159 if (implementation != gl::kGLImplementationEGLGLES2) {
160 NOTREACHED();
161 return nullptr;
162 }
163
164 #if defined(USE_WAYLAND_EGL) 172 #if defined(USE_WAYLAND_EGL)
165 return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size)); 173 return gl::InitializeGLSurface(new gl::PbufferGLSurfaceEGL(size));
166 #else 174 #else
167 return nullptr; 175 return nullptr;
168 #endif 176 #endif
169 } 177 }
170 178
171 intptr_t WaylandSurfaceFactory::GetNativeDisplay() { 179 intptr_t GLOzoneEGLWayland::GetNativeDisplay() {
172 return reinterpret_cast<intptr_t>(connection_->display()); 180 return reinterpret_cast<intptr_t>(connection_->display());
173 } 181 }
174 182
175 bool WaylandSurfaceFactory::LoadEGLGLES2Bindings() { 183 bool GLOzoneEGLWayland::LoadGLES2Bindings() {
176 #if defined(USE_WAYLAND_EGL) 184 #if defined(USE_WAYLAND_EGL)
177 if (!connection_)
178 return false;
179 setenv("EGL_PLATFORM", "wayland", 0); 185 setenv("EGL_PLATFORM", "wayland", 0);
180 return LoadDefaultEGLGLES2Bindings(); 186 return LoadDefaultEGLGLES2Bindings();
181 #else 187 #else
182 return false; 188 return false;
183 #endif 189 #endif
184 } 190 }
185 191
192 } // namespace
193
194 WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandConnection* connection)
195 : connection_(connection) {
196 if (connection_)
197 egl_implementation_.reset(new GLOzoneEGLWayland(connection_));
198 }
199
200 WaylandSurfaceFactory::~WaylandSurfaceFactory() {}
201
186 std::unique_ptr<SurfaceOzoneCanvas> 202 std::unique_ptr<SurfaceOzoneCanvas>
187 WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { 203 WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) {
204 if (!connection_)
205 return nullptr;
188 WaylandWindow* window = connection_->GetWindow(widget); 206 WaylandWindow* window = connection_->GetWindow(widget);
189 DCHECK(window); 207 DCHECK(window);
190 return base::MakeUnique<WaylandCanvasSurface>(connection_, window); 208 return base::MakeUnique<WaylandCanvasSurface>(connection_, window);
191 } 209 }
192 210
211 std::vector<gl::GLImplementation>
212 WaylandSurfaceFactory::GetAllowedGLImplementations() {
213 std::vector<gl::GLImplementation> impls;
214 impls.push_back(gl::kGLImplementationEGLGLES2);
215 return impls;
216 }
217
218 GLOzone* WaylandSurfaceFactory::GetGLOzone(
219 gl::GLImplementation implementation) {
220 switch (implementation) {
221 case gl::kGLImplementationEGLGLES2:
222 return egl_implementation_.get();
223 default:
224 return nullptr;
225 }
226 }
227
193 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmap( 228 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmap(
194 gfx::AcceleratedWidget widget, 229 gfx::AcceleratedWidget widget,
195 gfx::Size size, 230 gfx::Size size,
196 gfx::BufferFormat format, 231 gfx::BufferFormat format,
197 gfx::BufferUsage usage) { 232 gfx::BufferUsage usage) {
198 NOTIMPLEMENTED(); 233 NOTIMPLEMENTED();
199 return nullptr; 234 return nullptr;
200 } 235 }
201 236
202 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmapFromHandle( 237 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmapFromHandle(
203 gfx::AcceleratedWidget widget, 238 gfx::AcceleratedWidget widget,
204 gfx::Size size, 239 gfx::Size size,
205 gfx::BufferFormat format, 240 gfx::BufferFormat format,
206 const gfx::NativePixmapHandle& handle) { 241 const gfx::NativePixmapHandle& handle) {
207 NOTIMPLEMENTED(); 242 NOTIMPLEMENTED();
208 return nullptr; 243 return nullptr;
209 } 244 }
210 245
211 } // namespace ui 246 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/wayland_surface_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698