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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/ws/display_manager.cc
diff --git a/components/mus/ws/display_manager.cc b/components/mus/ws/display_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8fda170f29fe4129e310b7f043578d4cdbda1462
--- /dev/null
+++ b/components/mus/ws/display_manager.cc
@@ -0,0 +1,128 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/mus/ws/display_manager.h"
+
+#include "components/mus/ws/display.h"
+#include "components/mus/ws/display_manager_delegate.h"
+#include "components/mus/ws/server_window.h"
+
+namespace mus {
+namespace ws {
+
+DisplayManager::DisplayManager(DisplayManagerDelegate* delegate)
+ : delegate_(delegate), next_root_id_(0) {}
+
+DisplayManager::~DisplayManager() {
+ DestroyAllDisplays();
+}
+
+void DisplayManager::AddDisplay(Display* display) {
+ DCHECK_EQ(0u, pending_displays_.count(display));
+ pending_displays_.insert(display);
+}
+
+void DisplayManager::DestroyDisplay(Display* display) {
+ delegate_->OnWillDestroyDisplay(display);
+
+ if (pending_displays_.count(display)) {
+ pending_displays_.erase(display);
+ } else {
+ DCHECK(displays_.count(display));
+ displays_.erase(display);
+ }
+ delete display;
+
+ // If we have no more roots left, let the app know so it can terminate.
+ // TODO(sky): move to delegate/observer.
+ if (!displays_.size() && !pending_displays_.size())
+ delegate_->OnNoMoreDisplays();
+}
+
+void DisplayManager::DestroyAllDisplays() {
+ while (!pending_displays_.empty())
+ DestroyDisplay(*pending_displays_.begin());
+ DCHECK(pending_displays_.empty());
+
+ while (!displays_.empty())
+ DestroyDisplay(*displays_.begin());
+ DCHECK(displays_.empty());
+}
+
+std::set<const Display*> DisplayManager::displays() const {
+ std::set<const Display*> ret_value(displays_.begin(), displays_.end());
+ return ret_value;
+}
+
+Display* DisplayManager::GetDisplayContaining(ServerWindow* window) {
+ return const_cast<Display*>(
+ static_cast<const DisplayManager*>(this)->GetDisplayContaining(window));
+}
+
+const Display* DisplayManager::GetDisplayContaining(
+ const ServerWindow* window) const {
+ while (window && window->parent())
+ window = window->parent();
+ for (Display* display : displays_) {
+ if (window == display->root_window())
+ return display;
+ }
+ return nullptr;
+}
+
+Display* DisplayManager::GetActiveDisplay() {
+ // TODO(sky): this isn't active, but first. Make it active.
+ return displays_.size() ? *displays_.begin() : nullptr;
+}
+
+WindowManagerAndDisplayConst DisplayManager::GetWindowManagerAndDisplay(
+ const ServerWindow* window) const {
+ const ServerWindow* last = window;
+ while (window && window->parent()) {
+ last = window;
+ window = window->parent();
+ }
+ for (Display* display : displays_) {
+ if (window == display->root_window()) {
+ WindowManagerAndDisplayConst result;
+ result.display = display;
+ result.window_manager_state =
+ display->GetWindowManagerStateWithRoot(last);
+ return result;
+ }
+ }
+ return WindowManagerAndDisplayConst();
+}
+
+WindowManagerAndDisplay DisplayManager::GetWindowManagerAndDisplay(
+ const ServerWindow* window) {
+ WindowManagerAndDisplayConst result_const =
+ const_cast<const DisplayManager*>(this)->GetWindowManagerAndDisplay(
+ window);
+ WindowManagerAndDisplay result;
+ result.display = const_cast<Display*>(result_const.display);
+ result.window_manager_state =
+ const_cast<WindowManagerState*>(result_const.window_manager_state);
+ return result;
+}
+
+WindowId DisplayManager::GetAndAdvanceNextRootId() {
+ // TODO(sky): handle wrapping!
+ const uint16_t id = next_root_id_++;
+ DCHECK_LT(id, next_root_id_);
+ return RootWindowId(id);
+}
+
+void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) {
+ DCHECK_NE(0u, pending_displays_.count(display));
+ DCHECK_EQ(0u, displays_.count(display));
+ const bool is_first_display = displays_.empty();
+ displays_.insert(display);
+ pending_displays_.erase(display);
+ if (is_first_display)
+ delegate_->OnFirstDisplayReady();
+}
+
+} // namespace ws
+} // namespace mus
« 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