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

Side by Side Diff: services/ui/ws/display.cc

Issue 2736943003: Start to decouple display::Display from ws::PlatformDisplay. (Closed)
Patch Set: Fix comments. Created 3 years, 9 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 | « services/ui/ws/display.h ('k') | services/ui/ws/display_manager.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/ui/ws/display.h" 5 #include "services/ui/ws/display.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "services/service_manager/public/interfaces/connector.mojom.h" 13 #include "services/service_manager/public/interfaces/connector.mojom.h"
14 #include "services/ui/common/types.h" 14 #include "services/ui/common/types.h"
15 #include "services/ui/display/viewport_metrics.h"
15 #include "services/ui/public/interfaces/cursor.mojom.h" 16 #include "services/ui/public/interfaces/cursor.mojom.h"
16 #include "services/ui/ws/display_binding.h" 17 #include "services/ui/ws/display_binding.h"
17 #include "services/ui/ws/display_manager.h" 18 #include "services/ui/ws/display_manager.h"
18 #include "services/ui/ws/focus_controller.h" 19 #include "services/ui/ws/focus_controller.h"
19 #include "services/ui/ws/platform_display.h" 20 #include "services/ui/ws/platform_display.h"
20 #include "services/ui/ws/platform_display_init_params.h"
21 #include "services/ui/ws/user_activity_monitor.h" 21 #include "services/ui/ws/user_activity_monitor.h"
22 #include "services/ui/ws/window_manager_display_root.h" 22 #include "services/ui/ws/window_manager_display_root.h"
23 #include "services/ui/ws/window_manager_state.h" 23 #include "services/ui/ws/window_manager_state.h"
24 #include "services/ui/ws/window_manager_window_tree_factory.h" 24 #include "services/ui/ws/window_manager_window_tree_factory.h"
25 #include "services/ui/ws/window_server.h" 25 #include "services/ui/ws/window_server.h"
26 #include "services/ui/ws/window_server_delegate.h" 26 #include "services/ui/ws/window_server_delegate.h"
27 #include "services/ui/ws/window_tree.h" 27 #include "services/ui/ws/window_tree.h"
28 #include "services/ui/ws/window_tree_binding.h" 28 #include "services/ui/ws/window_tree_binding.h"
29 #include "ui/base/cursor/cursor.h" 29 #include "ui/base/cursor/cursor.h"
30 #include "ui/display/screen.h"
30 31
31 namespace ui { 32 namespace ui {
32 namespace ws { 33 namespace ws {
33 34
34 Display::Display(WindowServer* window_server) 35 Display::Display(WindowServer* window_server)
35 : window_server_(window_server), last_cursor_(mojom::Cursor::CURSOR_NULL) { 36 : window_server_(window_server), last_cursor_(mojom::Cursor::CURSOR_NULL) {
36 window_server_->window_manager_window_tree_factory_set()->AddObserver(this); 37 window_server_->window_manager_window_tree_factory_set()->AddObserver(this);
37 window_server_->user_id_tracker()->AddObserver(this); 38 window_server_->user_id_tracker()->AddObserver(this);
38 } 39 }
39 40
(...skipping 13 matching lines...) Expand all
53 pair.second->window_manager_state()->OnDisplayDestroying(this); 54 pair.second->window_manager_state()->OnDisplayDestroying(this);
54 } else if (!window_manager_display_root_map_.empty()) { 55 } else if (!window_manager_display_root_map_.empty()) {
55 // If there is a |binding_| then the tree was created specifically for this 56 // If there is a |binding_| then the tree was created specifically for this
56 // display (which corresponds to a WindowTreeHost). 57 // display (which corresponds to a WindowTreeHost).
57 window_server_->DestroyTree(window_manager_display_root_map_.begin() 58 window_server_->DestroyTree(window_manager_display_root_map_.begin()
58 ->second->window_manager_state() 59 ->second->window_manager_state()
59 ->window_tree()); 60 ->window_tree());
60 } 61 }
61 } 62 }
62 63
63 void Display::Init(const PlatformDisplayInitParams& init_params, 64 void Display::Init(const display::ViewportMetrics& metrics,
64 std::unique_ptr<DisplayBinding> binding) { 65 std::unique_ptr<DisplayBinding> binding) {
65 binding_ = std::move(binding); 66 binding_ = std::move(binding);
66 display_manager()->AddDisplay(this); 67 display_manager()->AddDisplay(this);
67 68
68 CreateRootWindow(init_params.metrics.pixel_size); 69 CreateRootWindow(metrics.bounds_in_pixels.size());
69 PlatformDisplayInitParams params_copy = init_params;
70 params_copy.root_window = root_.get();
71 70
72 platform_display_ = PlatformDisplay::Create(params_copy); 71 platform_display_ = PlatformDisplay::Create(root_.get(), metrics);
73 platform_display_->Init(this); 72 platform_display_->Init(this);
74 } 73 }
75 74
76 int64_t Display::GetId() const { 75 int64_t Display::GetId() const {
77 return platform_display_->GetId(); 76 // TODO(tonikitoo): Implement a different ID for external window mode.
77 return display_.id();
78 }
79
80 void Display::SetDisplay(const display::Display& display) {
81 display_ = display;
82 }
83
84 const display::Display& Display::GetDisplay() {
85 return display_;
78 } 86 }
79 87
80 DisplayManager* Display::display_manager() { 88 DisplayManager* Display::display_manager() {
81 return window_server_->display_manager(); 89 return window_server_->display_manager();
82 } 90 }
83 91
84 const DisplayManager* Display::display_manager() const { 92 const DisplayManager* Display::display_manager() const {
85 return window_server_->display_manager(); 93 return window_server_->display_manager();
86 } 94 }
87 95
88 display::Display Display::ToDisplay() const {
89 display::Display display(GetId());
90
91 const display::ViewportMetrics& metrics =
92 platform_display_->GetViewportMetrics();
93
94 display.set_bounds(metrics.bounds);
95 display.set_work_area(metrics.work_area);
96 display.set_device_scale_factor(metrics.device_scale_factor);
97 display.set_rotation(metrics.rotation);
98 display.set_touch_support(
99 display::Display::TouchSupport::TOUCH_SUPPORT_UNKNOWN);
100
101 return display;
102 }
103
104 gfx::Size Display::GetSize() const { 96 gfx::Size Display::GetSize() const {
105 DCHECK(root_); 97 DCHECK(root_);
106 return root_->bounds().size(); 98 return root_->bounds().size();
107 } 99 }
108 100
109 ServerWindow* Display::GetRootWithId(const WindowId& id) { 101 ServerWindow* Display::GetRootWithId(const WindowId& id) {
110 if (id == root_->id()) 102 if (id == root_->id())
111 return root_.get(); 103 return root_.get();
112 for (auto& pair : window_manager_display_root_map_) { 104 for (auto& pair : window_manager_display_root_map_) {
113 if (pair.second->root()->id() == id) 105 if (pair.second->root()->id() == id)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // id works. 205 // id works.
214 window_manager_display_root_map_[service_manager::mojom::kRootUserID] = 206 window_manager_display_root_map_[service_manager::mojom::kRootUserID] =
215 display_root_ptr.get(); 207 display_root_ptr.get();
216 WindowTree* window_tree = binding_->CreateWindowTree(display_root->root()); 208 WindowTree* window_tree = binding_->CreateWindowTree(display_root->root());
217 display_root->window_manager_state_ = window_tree->window_manager_state(); 209 display_root->window_manager_state_ = window_tree->window_manager_state();
218 window_tree->window_manager_state()->AddWindowManagerDisplayRoot( 210 window_tree->window_manager_state()->AddWindowManagerDisplayRoot(
219 std::move(display_root_ptr)); 211 std::move(display_root_ptr));
220 } else { 212 } else {
221 CreateWindowManagerDisplayRootsFromFactories(); 213 CreateWindowManagerDisplayRootsFromFactories();
222 } 214 }
223 display_manager()->OnDisplayUpdate(this); 215 display_manager()->OnDisplayUpdate(display_);
224 } 216 }
225 217
226 void Display::CreateWindowManagerDisplayRootsFromFactories() { 218 void Display::CreateWindowManagerDisplayRootsFromFactories() {
227 std::vector<WindowManagerWindowTreeFactory*> factories = 219 std::vector<WindowManagerWindowTreeFactory*> factories =
228 window_server_->window_manager_window_tree_factory_set()->GetFactories(); 220 window_server_->window_manager_window_tree_factory_set()->GetFactories();
229 for (WindowManagerWindowTreeFactory* factory : factories) { 221 for (WindowManagerWindowTreeFactory* factory : factories) {
230 if (factory->window_tree()) 222 if (factory->window_tree())
231 CreateWindowManagerDisplayRootFromFactory(factory); 223 CreateWindowManagerDisplayRootFromFactory(factory);
232 } 224 }
233 } 225 }
(...skipping 23 matching lines...) Expand all
257 display_manager()->GetAndAdvanceNextRootId(), 249 display_manager()->GetAndAdvanceNextRootId(),
258 ServerWindow::Properties())); 250 ServerWindow::Properties()));
259 root_->set_event_targeting_policy( 251 root_->set_event_targeting_policy(
260 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); 252 mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
261 root_->SetBounds(gfx::Rect(size), allocator_.GenerateId()); 253 root_->SetBounds(gfx::Rect(size), allocator_.GenerateId());
262 root_->SetVisible(true); 254 root_->SetVisible(true);
263 focus_controller_ = base::MakeUnique<FocusController>(this, root_.get()); 255 focus_controller_ = base::MakeUnique<FocusController>(this, root_.get());
264 focus_controller_->AddObserver(this); 256 focus_controller_->AddObserver(this);
265 } 257 }
266 258
267 display::Display Display::GetDisplay() {
268 return ToDisplay();
269 }
270
271 ServerWindow* Display::GetRootWindow() { 259 ServerWindow* Display::GetRootWindow() {
272 return root_.get(); 260 return root_.get();
273 } 261 }
274 262
275 void Display::OnAcceleratedWidgetAvailable() { 263 void Display::OnAcceleratedWidgetAvailable() {
276 display_manager()->OnDisplayAcceleratedWidgetAvailable(this); 264 display_manager()->OnDisplayAcceleratedWidgetAvailable(this);
277 InitWindowManagerDisplayRoots(); 265 InitWindowManagerDisplayRoots();
278 } 266 }
279 267
280 bool Display::IsInHighContrastMode() { 268 bool Display::IsInHighContrastMode() {
(...skipping 11 matching lines...) Expand all
292 } 280 }
293 281
294 void Display::OnNativeCaptureLost() { 282 void Display::OnNativeCaptureLost() {
295 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); 283 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot();
296 if (display_root) 284 if (display_root)
297 display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId); 285 display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId);
298 } 286 }
299 287
300 void Display::OnViewportMetricsChanged( 288 void Display::OnViewportMetricsChanged(
301 const display::ViewportMetrics& metrics) { 289 const display::ViewportMetrics& metrics) {
302 if (root_->bounds().size() == metrics.pixel_size) 290 if (root_->bounds().size() == metrics.bounds_in_pixels.size())
303 return; 291 return;
304 292
305 gfx::Rect new_bounds(metrics.pixel_size); 293 gfx::Rect new_bounds(metrics.bounds_in_pixels.size());
306 root_->SetBounds(new_bounds, allocator_.GenerateId()); 294 root_->SetBounds(new_bounds, allocator_.GenerateId());
307 for (auto& pair : window_manager_display_root_map_) 295 for (auto& pair : window_manager_display_root_map_)
308 pair.second->root()->SetBounds(new_bounds, allocator_.GenerateId()); 296 pair.second->root()->SetBounds(new_bounds, allocator_.GenerateId());
309 } 297 }
310 298
311 ServerWindow* Display::GetActiveRootWindow() { 299 ServerWindow* Display::GetActiveRootWindow() {
312 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot(); 300 WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot();
313 if (display_root) 301 if (display_root)
314 return display_root->root(); 302 return display_root->root();
315 return nullptr; 303 return nullptr;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 381 }
394 382
395 void Display::OnWindowManagerWindowTreeFactoryReady( 383 void Display::OnWindowManagerWindowTreeFactoryReady(
396 WindowManagerWindowTreeFactory* factory) { 384 WindowManagerWindowTreeFactory* factory) {
397 if (!binding_) 385 if (!binding_)
398 CreateWindowManagerDisplayRootFromFactory(factory); 386 CreateWindowManagerDisplayRootFromFactory(factory);
399 } 387 }
400 388
401 } // namespace ws 389 } // namespace ws
402 } // namespace ui 390 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/display.h ('k') | services/ui/ws/display_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698