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

Side by Side Diff: components/mus/ws/display_manager.cc

Issue 1766943002: Refators display related functionality into own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 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 | « components/mus/ws/display_manager.h ('k') | components/mus/ws/display_manager_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/mus/ws/display_manager.h"
6
7 #include "components/mus/ws/display.h"
8 #include "components/mus/ws/display_manager_delegate.h"
9 #include "components/mus/ws/server_window.h"
10
11 namespace mus {
12 namespace ws {
13
14 DisplayManager::DisplayManager(DisplayManagerDelegate* delegate)
15 : delegate_(delegate), next_root_id_(0) {}
16
17 DisplayManager::~DisplayManager() {
18 DestroyAllDisplays();
19 }
20
21 void DisplayManager::AddDisplay(Display* display) {
22 DCHECK_EQ(0u, pending_displays_.count(display));
23 pending_displays_.insert(display);
24 }
25
26 void DisplayManager::DestroyDisplay(Display* display) {
27 delegate_->OnWillDestroyDisplay(display);
28
29 if (pending_displays_.count(display)) {
30 pending_displays_.erase(display);
31 } else {
32 DCHECK(displays_.count(display));
33 displays_.erase(display);
34 }
35 delete display;
36
37 // If we have no more roots left, let the app know so it can terminate.
38 // TODO(sky): move to delegate/observer.
39 if (!displays_.size() && !pending_displays_.size())
40 delegate_->OnNoMoreDisplays();
41 }
42
43 void DisplayManager::DestroyAllDisplays() {
44 while (!pending_displays_.empty())
45 DestroyDisplay(*pending_displays_.begin());
46 DCHECK(pending_displays_.empty());
47
48 while (!displays_.empty())
49 DestroyDisplay(*displays_.begin());
50 DCHECK(displays_.empty());
51 }
52
53 std::set<const Display*> DisplayManager::displays() const {
54 std::set<const Display*> ret_value(displays_.begin(), displays_.end());
55 return ret_value;
56 }
57
58 Display* DisplayManager::GetDisplayContaining(ServerWindow* window) {
59 return const_cast<Display*>(
60 static_cast<const DisplayManager*>(this)->GetDisplayContaining(window));
61 }
62
63 const Display* DisplayManager::GetDisplayContaining(
64 const ServerWindow* window) const {
65 while (window && window->parent())
66 window = window->parent();
67 for (Display* display : displays_) {
68 if (window == display->root_window())
69 return display;
70 }
71 return nullptr;
72 }
73
74 Display* DisplayManager::GetActiveDisplay() {
75 // TODO(sky): this isn't active, but first. Make it active.
76 return displays_.size() ? *displays_.begin() : nullptr;
77 }
78
79 WindowManagerAndDisplayConst DisplayManager::GetWindowManagerAndDisplay(
80 const ServerWindow* window) const {
81 const ServerWindow* last = window;
82 while (window && window->parent()) {
83 last = window;
84 window = window->parent();
85 }
86 for (Display* display : displays_) {
87 if (window == display->root_window()) {
88 WindowManagerAndDisplayConst result;
89 result.display = display;
90 result.window_manager_state =
91 display->GetWindowManagerStateWithRoot(last);
92 return result;
93 }
94 }
95 return WindowManagerAndDisplayConst();
96 }
97
98 WindowManagerAndDisplay DisplayManager::GetWindowManagerAndDisplay(
99 const ServerWindow* window) {
100 WindowManagerAndDisplayConst result_const =
101 const_cast<const DisplayManager*>(this)->GetWindowManagerAndDisplay(
102 window);
103 WindowManagerAndDisplay result;
104 result.display = const_cast<Display*>(result_const.display);
105 result.window_manager_state =
106 const_cast<WindowManagerState*>(result_const.window_manager_state);
107 return result;
108 }
109
110 WindowId DisplayManager::GetAndAdvanceNextRootId() {
111 // TODO(sky): handle wrapping!
112 const uint16_t id = next_root_id_++;
113 DCHECK_LT(id, next_root_id_);
114 return RootWindowId(id);
115 }
116
117 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) {
118 DCHECK_NE(0u, pending_displays_.count(display));
119 DCHECK_EQ(0u, displays_.count(display));
120 const bool is_first_display = displays_.empty();
121 displays_.insert(display);
122 pending_displays_.erase(display);
123 if (is_first_display)
124 delegate_->OnFirstDisplayReady();
125 }
126
127 } // namespace ws
128 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/display_manager.h ('k') | components/mus/ws/display_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698