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

Side by Side Diff: ui/ozone/demo/ozone_demo.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
« no previous file with comments | « ui/ozone/common/stub_overlay_manager.cc ('k') | ui/ozone/demo/software_renderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <utility> 5 #include <utility>
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "ui/display/types/display_snapshot.h" 15 #include "ui/display/types/display_snapshot.h"
15 #include "ui/display/types/native_display_delegate.h" 16 #include "ui/display/types/native_display_delegate.h"
16 #include "ui/display/types/native_display_observer.h" 17 #include "ui/display/types/native_display_observer.h"
17 #include "ui/events/event.h" 18 #include "ui/events/event.h"
18 #include "ui/events/keycodes/dom/dom_code.h" 19 #include "ui/events/keycodes/dom/dom_code.h"
19 #include "ui/events/ozone/layout/keyboard_layout_engine.h" 20 #include "ui/events/ozone/layout/keyboard_layout_engine.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 public: 55 public:
55 enum RendererType { 56 enum RendererType {
56 GL, 57 GL,
57 SOFTWARE, 58 SOFTWARE,
58 }; 59 };
59 60
60 RendererFactory(); 61 RendererFactory();
61 ~RendererFactory(); 62 ~RendererFactory();
62 63
63 bool Initialize(); 64 bool Initialize();
64 scoped_ptr<ui::Renderer> CreateRenderer(gfx::AcceleratedWidget widget, 65 std::unique_ptr<ui::Renderer> CreateRenderer(gfx::AcceleratedWidget widget,
65 const gfx::Size& size); 66 const gfx::Size& size);
66 67
67 private: 68 private:
68 RendererType type_ = SOFTWARE; 69 RendererType type_ = SOFTWARE;
69 70
70 // Helper for applications that do GL on main thread. 71 // Helper for applications that do GL on main thread.
71 ui::OzoneGpuTestHelper gpu_helper_; 72 ui::OzoneGpuTestHelper gpu_helper_;
72 73
73 DISALLOW_COPY_AND_ASSIGN(RendererFactory); 74 DISALLOW_COPY_AND_ASSIGN(RendererFactory);
74 }; 75 };
75 76
76 class WindowManager : public ui::NativeDisplayObserver { 77 class WindowManager : public ui::NativeDisplayObserver {
77 public: 78 public:
78 WindowManager(const base::Closure& quit_closure); 79 WindowManager(const base::Closure& quit_closure);
79 ~WindowManager() override; 80 ~WindowManager() override;
80 81
81 void Quit(); 82 void Quit();
82 83
83 void AddWindow(DemoWindow* window); 84 void AddWindow(DemoWindow* window);
84 void RemoveWindow(DemoWindow* window); 85 void RemoveWindow(DemoWindow* window);
85 86
86 private: 87 private:
87 void OnDisplaysAquired(const std::vector<ui::DisplaySnapshot*>& displays); 88 void OnDisplaysAquired(const std::vector<ui::DisplaySnapshot*>& displays);
88 void OnDisplayConfigured(const gfx::Rect& bounds, bool success); 89 void OnDisplayConfigured(const gfx::Rect& bounds, bool success);
89 90
90 // ui::NativeDisplayDelegate: 91 // ui::NativeDisplayDelegate:
91 void OnConfigurationChanged() override; 92 void OnConfigurationChanged() override;
92 93
93 scoped_ptr<ui::NativeDisplayDelegate> delegate_; 94 std::unique_ptr<ui::NativeDisplayDelegate> delegate_;
94 base::Closure quit_closure_; 95 base::Closure quit_closure_;
95 RendererFactory renderer_factory_; 96 RendererFactory renderer_factory_;
96 std::vector<scoped_ptr<DemoWindow>> windows_; 97 std::vector<std::unique_ptr<DemoWindow>> windows_;
97 98
98 // Flags used to keep track of the current state of display configuration. 99 // Flags used to keep track of the current state of display configuration.
99 // 100 //
100 // True if configuring the displays. In this case a new display configuration 101 // True if configuring the displays. In this case a new display configuration
101 // isn't started. 102 // isn't started.
102 bool is_configuring_ = false; 103 bool is_configuring_ = false;
103 104
104 // If |is_configuring_| is true and another display configuration event 105 // If |is_configuring_| is true and another display configuration event
105 // happens, the event is deferred. This is set to true and a display 106 // happens, the event is deferred. This is set to true and a display
106 // configuration will be scheduled after the current one finishes. 107 // configuration will be scheduled after the current one finishes.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // initialize the GPU resources via a posted task. 168 // initialize the GPU resources via a posted task.
168 void StartOnGpu() { 169 void StartOnGpu() {
169 renderer_ = 170 renderer_ =
170 renderer_factory_->CreateRenderer(GetAcceleratedWidget(), GetSize()); 171 renderer_factory_->CreateRenderer(GetAcceleratedWidget(), GetSize());
171 renderer_->Initialize(); 172 renderer_->Initialize();
172 } 173 }
173 174
174 WindowManager* window_manager_; // Not owned. 175 WindowManager* window_manager_; // Not owned.
175 RendererFactory* renderer_factory_; // Not owned. 176 RendererFactory* renderer_factory_; // Not owned.
176 177
177 scoped_ptr<ui::Renderer> renderer_; 178 std::unique_ptr<ui::Renderer> renderer_;
178 179
179 // Window-related state. 180 // Window-related state.
180 scoped_ptr<ui::PlatformWindow> platform_window_; 181 std::unique_ptr<ui::PlatformWindow> platform_window_;
181 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; 182 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
182 183
183 base::WeakPtrFactory<DemoWindow> weak_ptr_factory_; 184 base::WeakPtrFactory<DemoWindow> weak_ptr_factory_;
184 185
185 DISALLOW_COPY_AND_ASSIGN(DemoWindow); 186 DISALLOW_COPY_AND_ASSIGN(DemoWindow);
186 }; 187 };
187 188
188 /////////////////////////////////////////////////////////////////////////////// 189 ///////////////////////////////////////////////////////////////////////////////
189 // RendererFactory implementation: 190 // RendererFactory implementation:
190 191
(...skipping 10 matching lines...) Expand all
201 gpu_helper_.Initialize(base::ThreadTaskRunnerHandle::Get(), 202 gpu_helper_.Initialize(base::ThreadTaskRunnerHandle::Get(),
202 base::ThreadTaskRunnerHandle::Get())) { 203 base::ThreadTaskRunnerHandle::Get())) {
203 type_ = GL; 204 type_ = GL;
204 } else { 205 } else {
205 type_ = SOFTWARE; 206 type_ = SOFTWARE;
206 } 207 }
207 208
208 return true; 209 return true;
209 } 210 }
210 211
211 scoped_ptr<ui::Renderer> RendererFactory::CreateRenderer( 212 std::unique_ptr<ui::Renderer> RendererFactory::CreateRenderer(
212 gfx::AcceleratedWidget widget, 213 gfx::AcceleratedWidget widget,
213 const gfx::Size& size) { 214 const gfx::Size& size) {
214 switch (type_) { 215 switch (type_) {
215 case GL: { 216 case GL: {
216 scoped_refptr<gfx::GLSurface> surface = CreateGLSurface(widget); 217 scoped_refptr<gfx::GLSurface> surface = CreateGLSurface(widget);
217 if (!surface) 218 if (!surface)
218 LOG(FATAL) << "Failed to create GL surface"; 219 LOG(FATAL) << "Failed to create GL surface";
219 if (surface->IsSurfaceless()) 220 if (surface->IsSurfaceless())
220 return make_scoped_ptr( 221 return base::WrapUnique(
221 new ui::SurfacelessGlRenderer(widget, surface, size)); 222 new ui::SurfacelessGlRenderer(widget, surface, size));
222 else 223 else
223 return make_scoped_ptr(new ui::GlRenderer(widget, surface, size)); 224 return base::WrapUnique(new ui::GlRenderer(widget, surface, size));
224 } 225 }
225 case SOFTWARE: 226 case SOFTWARE:
226 return make_scoped_ptr(new ui::SoftwareRenderer(widget, size)); 227 return base::WrapUnique(new ui::SoftwareRenderer(widget, size));
227 } 228 }
228 229
229 return nullptr; 230 return nullptr;
230 } 231 }
231 232
232 /////////////////////////////////////////////////////////////////////////////// 233 ///////////////////////////////////////////////////////////////////////////////
233 // WindowManager implementation: 234 // WindowManager implementation:
234 235
235 WindowManager::WindowManager(const base::Closure& quit_closure) 236 WindowManager::WindowManager(const base::Closure& quit_closure)
236 : delegate_( 237 : delegate_(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 if (should_configure_) { 304 if (should_configure_) {
304 should_configure_ = false; 305 should_configure_ = false;
305 base::ThreadTaskRunnerHandle::Get()->PostTask( 306 base::ThreadTaskRunnerHandle::Get()->PostTask(
306 FROM_HERE, base::Bind(&WindowManager::OnConfigurationChanged, 307 FROM_HERE, base::Bind(&WindowManager::OnConfigurationChanged,
307 base::Unretained(this))); 308 base::Unretained(this)));
308 } 309 }
309 } 310 }
310 311
311 void WindowManager::OnDisplayConfigured(const gfx::Rect& bounds, bool success) { 312 void WindowManager::OnDisplayConfigured(const gfx::Rect& bounds, bool success) {
312 if (success) { 313 if (success) {
313 scoped_ptr<DemoWindow> window( 314 std::unique_ptr<DemoWindow> window(
314 new DemoWindow(this, &renderer_factory_, bounds)); 315 new DemoWindow(this, &renderer_factory_, bounds));
315 window->Start(); 316 window->Start();
316 windows_.push_back(std::move(window)); 317 windows_.push_back(std::move(window));
317 } else { 318 } else {
318 LOG(ERROR) << "Failed to configure display at " << bounds.ToString(); 319 LOG(ERROR) << "Failed to configure display at " << bounds.ToString();
319 } 320 }
320 } 321 }
321 322
322 int main(int argc, char** argv) { 323 int main(int argc, char** argv) {
323 base::CommandLine::Init(argc, argv); 324 base::CommandLine::Init(argc, argv);
(...skipping 12 matching lines...) Expand all
336 ->SetCurrentLayoutByName("us"); 337 ->SetCurrentLayoutByName("us");
337 338
338 base::RunLoop run_loop; 339 base::RunLoop run_loop;
339 340
340 WindowManager window_manager(run_loop.QuitClosure()); 341 WindowManager window_manager(run_loop.QuitClosure());
341 342
342 run_loop.Run(); 343 run_loop.Run();
343 344
344 return 0; 345 return 0;
345 } 346 }
OLDNEW
« no previous file with comments | « ui/ozone/common/stub_overlay_manager.cc ('k') | ui/ozone/demo/software_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698