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

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

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 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
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/shared_memory.h" 12 #include "base/memory/shared_memory.h"
12 #include "third_party/skia/include/core/SkSurface.h" 13 #include "third_party/skia/include/core/SkSurface.h"
13 #include "ui/gfx/vsync_provider.h" 14 #include "ui/gfx/vsync_provider.h"
14 #include "ui/ozone/common/egl_util.h" 15 #include "ui/ozone/common/egl_util.h"
15 #include "ui/ozone/platform/wayland/wayland_display.h" 16 #include "ui/ozone/platform/wayland/wayland_display.h"
16 #include "ui/ozone/platform/wayland/wayland_object.h" 17 #include "ui/ozone/platform/wayland/wayland_object.h"
17 #include "ui/ozone/platform/wayland/wayland_window.h" 18 #include "ui/ozone/platform/wayland/wayland_window.h"
18 #include "ui/ozone/public/surface_ozone_canvas.h" 19 #include "ui/ozone/public/surface_ozone_canvas.h"
19 #include "ui/ozone/public/surface_ozone_egl.h" 20 #include "ui/ozone/public/surface_ozone_egl.h"
20 21
21 #if defined(USE_WAYLAND_EGL) 22 #if defined(USE_WAYLAND_EGL)
22 #include "ui/ozone/platform/wayland/wayland_egl_surface.h" 23 #include "ui/ozone/platform/wayland/wayland_egl_surface.h"
23 #endif 24 #endif
24 25
25 namespace ui { 26 namespace ui {
26 27
27 static void DeleteSharedMemory(void* pixels, void* context) { 28 static void DeleteSharedMemory(void* pixels, void* context) {
28 delete static_cast<base::SharedMemory*>(context); 29 delete static_cast<base::SharedMemory*>(context);
29 } 30 }
30 31
31 class WaylandCanvasSurface : public SurfaceOzoneCanvas { 32 class WaylandCanvasSurface : public SurfaceOzoneCanvas {
32 public: 33 public:
33 WaylandCanvasSurface(WaylandDisplay* display, WaylandWindow* window_); 34 WaylandCanvasSurface(WaylandDisplay* display, WaylandWindow* window_);
34 ~WaylandCanvasSurface() override; 35 ~WaylandCanvasSurface() override;
35 36
36 // SurfaceOzoneCanvas 37 // SurfaceOzoneCanvas
37 skia::RefPtr<SkSurface> GetSurface() override; 38 skia::RefPtr<SkSurface> GetSurface() override;
38 void ResizeCanvas(const gfx::Size& viewport_size) override; 39 void ResizeCanvas(const gfx::Size& viewport_size) override;
39 void PresentCanvas(const gfx::Rect& damage) override; 40 void PresentCanvas(const gfx::Rect& damage) override;
40 scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override; 41 std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override;
41 42
42 private: 43 private:
43 WaylandDisplay* display_; 44 WaylandDisplay* display_;
44 WaylandWindow* window_; 45 WaylandWindow* window_;
45 46
46 gfx::Size size_; 47 gfx::Size size_;
47 skia::RefPtr<SkSurface> sk_surface_; 48 skia::RefPtr<SkSurface> sk_surface_;
48 wl::Object<wl_shm_pool> pool_; 49 wl::Object<wl_shm_pool> pool_;
49 wl::Object<wl_buffer> buffer_; 50 wl::Object<wl_buffer> buffer_;
50 51
51 DISALLOW_COPY_AND_ASSIGN(WaylandCanvasSurface); 52 DISALLOW_COPY_AND_ASSIGN(WaylandCanvasSurface);
52 }; 53 };
53 54
54 WaylandCanvasSurface::WaylandCanvasSurface(WaylandDisplay* display, 55 WaylandCanvasSurface::WaylandCanvasSurface(WaylandDisplay* display,
55 WaylandWindow* window) 56 WaylandWindow* window)
56 : display_(display), window_(window), size_(window->GetBounds().size()) {} 57 : display_(display), window_(window), size_(window->GetBounds().size()) {}
57 58
58 WaylandCanvasSurface::~WaylandCanvasSurface() {} 59 WaylandCanvasSurface::~WaylandCanvasSurface() {}
59 60
60 skia::RefPtr<SkSurface> WaylandCanvasSurface::GetSurface() { 61 skia::RefPtr<SkSurface> WaylandCanvasSurface::GetSurface() {
61 if (sk_surface_) 62 if (sk_surface_)
62 return sk_surface_; 63 return sk_surface_;
63 64
64 size_t length = size_.width() * size_.height() * 4; 65 size_t length = size_.width() * size_.height() * 4;
65 auto shared_memory = make_scoped_ptr(new base::SharedMemory); 66 auto shared_memory = base::WrapUnique(new base::SharedMemory);
66 if (!shared_memory->CreateAndMapAnonymous(length)) 67 if (!shared_memory->CreateAndMapAnonymous(length))
67 return nullptr; 68 return nullptr;
68 69
69 wl::Object<wl_shm_pool> pool( 70 wl::Object<wl_shm_pool> pool(
70 wl_shm_create_pool(display_->shm(), shared_memory->handle().fd, length)); 71 wl_shm_create_pool(display_->shm(), shared_memory->handle().fd, length));
71 if (!pool) 72 if (!pool)
72 return nullptr; 73 return nullptr;
73 wl::Object<wl_buffer> buffer( 74 wl::Object<wl_buffer> buffer(
74 wl_shm_pool_create_buffer(pool.get(), 0, size_.width(), size_.height(), 75 wl_shm_pool_create_buffer(pool.get(), 0, size_.width(), size_.height(),
75 size_.width() * 4, WL_SHM_FORMAT_ARGB8888)); 76 size_.width() * 4, WL_SHM_FORMAT_ARGB8888));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // compositor. Instead, we should track buffer releases and frame callbacks 110 // compositor. Instead, we should track buffer releases and frame callbacks
110 // from Wayland to ensure perfect frames (while minimizing copies). 111 // from Wayland to ensure perfect frames (while minimizing copies).
111 wl_surface* surface = window_->surface(); 112 wl_surface* surface = window_->surface();
112 wl_surface_damage(surface, damage.x(), damage.y(), damage.width(), 113 wl_surface_damage(surface, damage.x(), damage.y(), damage.width(),
113 damage.height()); 114 damage.height());
114 wl_surface_attach(surface, buffer_.get(), 0, 0); 115 wl_surface_attach(surface, buffer_.get(), 0, 0);
115 wl_surface_commit(surface); 116 wl_surface_commit(surface);
116 display_->ScheduleFlush(); 117 display_->ScheduleFlush();
117 } 118 }
118 119
119 scoped_ptr<gfx::VSyncProvider> WaylandCanvasSurface::CreateVSyncProvider() { 120 std::unique_ptr<gfx::VSyncProvider>
121 WaylandCanvasSurface::CreateVSyncProvider() {
120 // TODO(forney): This can be implemented with information from frame 122 // TODO(forney): This can be implemented with information from frame
121 // callbacks, and possibly output refresh rate. 123 // callbacks, and possibly output refresh rate.
122 NOTIMPLEMENTED(); 124 NOTIMPLEMENTED();
123 return nullptr; 125 return nullptr;
124 } 126 }
125 127
126 WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandDisplay* display) 128 WaylandSurfaceFactory::WaylandSurfaceFactory(WaylandDisplay* display)
127 : display_(display) {} 129 : display_(display) {}
128 130
129 WaylandSurfaceFactory::~WaylandSurfaceFactory() {} 131 WaylandSurfaceFactory::~WaylandSurfaceFactory() {}
130 132
131 intptr_t WaylandSurfaceFactory::GetNativeDisplay() { 133 intptr_t WaylandSurfaceFactory::GetNativeDisplay() {
132 return reinterpret_cast<intptr_t>(display_->display()); 134 return reinterpret_cast<intptr_t>(display_->display());
133 } 135 }
134 136
135 bool WaylandSurfaceFactory::LoadEGLGLES2Bindings( 137 bool WaylandSurfaceFactory::LoadEGLGLES2Bindings(
136 AddGLLibraryCallback add_gl_library, 138 AddGLLibraryCallback add_gl_library,
137 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { 139 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
138 #if defined(USE_WAYLAND_EGL) 140 #if defined(USE_WAYLAND_EGL)
139 if (!display_) 141 if (!display_)
140 return false; 142 return false;
141 setenv("EGL_PLATFORM", "wayland", 0); 143 setenv("EGL_PLATFORM", "wayland", 0);
142 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); 144 return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address);
143 #else 145 #else
144 return false; 146 return false;
145 #endif 147 #endif
146 } 148 }
147 149
148 scoped_ptr<SurfaceOzoneCanvas> WaylandSurfaceFactory::CreateCanvasForWidget( 150 std::unique_ptr<SurfaceOzoneCanvas>
149 gfx::AcceleratedWidget widget) { 151 WaylandSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) {
150 WaylandWindow* window = display_->GetWindow(widget); 152 WaylandWindow* window = display_->GetWindow(widget);
151 DCHECK(window); 153 DCHECK(window);
152 return make_scoped_ptr(new WaylandCanvasSurface(display_, window)); 154 return base::WrapUnique(new WaylandCanvasSurface(display_, window));
153 } 155 }
154 156
155 scoped_ptr<SurfaceOzoneEGL> WaylandSurfaceFactory::CreateEGLSurfaceForWidget( 157 std::unique_ptr<SurfaceOzoneEGL>
158 WaylandSurfaceFactory::CreateEGLSurfaceForWidget(
156 gfx::AcceleratedWidget widget) { 159 gfx::AcceleratedWidget widget) {
157 #if defined(USE_WAYLAND_EGL) 160 #if defined(USE_WAYLAND_EGL)
158 WaylandWindow* window = display_->GetWindow(widget); 161 WaylandWindow* window = display_->GetWindow(widget);
159 DCHECK(window); 162 DCHECK(window);
160 auto surface = make_scoped_ptr( 163 auto surface = base::WrapUnique(
161 new WaylandEGLSurface(window, window->GetBounds().size())); 164 new WaylandEGLSurface(window, window->GetBounds().size()));
162 if (!surface->Initialize()) 165 if (!surface->Initialize())
163 return nullptr; 166 return nullptr;
164 return std::move(surface); 167 return std::move(surface);
165 #else 168 #else
166 return nullptr; 169 return nullptr;
167 #endif 170 #endif
168 } 171 }
169 172
170 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmap( 173 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmap(
171 gfx::AcceleratedWidget widget, 174 gfx::AcceleratedWidget widget,
172 gfx::Size size, 175 gfx::Size size,
173 gfx::BufferFormat format, 176 gfx::BufferFormat format,
174 gfx::BufferUsage usage) { 177 gfx::BufferUsage usage) {
175 NOTIMPLEMENTED(); 178 NOTIMPLEMENTED();
176 return nullptr; 179 return nullptr;
177 } 180 }
178 181
179 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmapFromHandle( 182 scoped_refptr<NativePixmap> WaylandSurfaceFactory::CreateNativePixmapFromHandle(
180 gfx::Size size, 183 gfx::Size size,
181 gfx::BufferFormat format, 184 gfx::BufferFormat format,
182 const gfx::NativePixmapHandle& handle) { 185 const gfx::NativePixmapHandle& handle) {
183 NOTIMPLEMENTED(); 186 NOTIMPLEMENTED();
184 return nullptr; 187 return nullptr;
185 } 188 }
186 189
187 } // namespace ui 190 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/wayland_surface_factory.h ('k') | ui/ozone/platform/wayland/wayland_surface_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698