| 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
|
|
|