| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ash/display/mirror_window_controller.h" | 5 #include "ash/display/mirror_window_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #if defined(USE_X11) | 9 #if defined(USE_X11) |
| 10 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/Xlib.h> | 11 #include <X11/Xlib.h> |
| 11 #include <X11/extensions/XInput2.h> | |
| 12 | 12 |
| 13 // Xlib.h defines RootWindow. | 13 // Xlib.h defines RootWindow. |
| 14 #undef RootWindow | 14 #undef RootWindow |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include "ash/display/cursor_window_controller.h" | 17 #include "ash/display/cursor_window_controller.h" |
| 18 #include "ash/display/display_info.h" | 18 #include "ash/display/display_info.h" |
| 19 #include "ash/display/display_manager.h" | 19 #include "ash/display/display_manager.h" |
| 20 #include "ash/display/root_window_transformers.h" | 20 #include "ash/display/root_window_transformers.h" |
| 21 #include "ash/display/screen_position_controller.h" | 21 #include "ash/display/screen_position_controller.h" |
| 22 #include "ash/display/window_tree_host_manager.h" | 22 #include "ash/display/window_tree_host_manager.h" |
| 23 #include "ash/host/ash_window_tree_host.h" | 23 #include "ash/host/ash_window_tree_host.h" |
| 24 #include "ash/host/ash_window_tree_host_init_params.h" | 24 #include "ash/host/ash_window_tree_host_init_params.h" |
| 25 #include "ash/host/root_window_transformer.h" | 25 #include "ash/host/root_window_transformer.h" |
| 26 #include "ash/root_window_settings.h" | 26 #include "ash/root_window_settings.h" |
| 27 #include "ash/shell.h" | 27 #include "ash/shell.h" |
| 28 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 29 #include "base/thread_task_runner_handle.h" | 29 #include "base/thread_task_runner_handle.h" |
| 30 #include "ui/aura/client/capture_client.h" | 30 #include "ui/aura/client/capture_client.h" |
| 31 #include "ui/aura/env.h" | 31 #include "ui/aura/env.h" |
| 32 #include "ui/aura/window_delegate.h" | 32 #include "ui/aura/window_delegate.h" |
| 33 #include "ui/aura/window_event_dispatcher.h" | 33 #include "ui/aura/window_event_dispatcher.h" |
| 34 #include "ui/aura/window_tree_host.h" | 34 #include "ui/aura/window_tree_host.h" |
| 35 #include "ui/base/layout.h" | 35 #include "ui/base/layout.h" |
| 36 #include "ui/compositor/reflector.h" | 36 #include "ui/compositor/reflector.h" |
| 37 #include "ui/display/manager/display_layout.h" | 37 #include "ui/display/manager/display_layout.h" |
| 38 #include "ui/display/screen.h" |
| 38 #include "ui/gfx/canvas.h" | 39 #include "ui/gfx/canvas.h" |
| 39 #include "ui/gfx/native_widget_types.h" | 40 #include "ui/gfx/native_widget_types.h" |
| 40 #include "ui/gfx/screen.h" | |
| 41 | 41 |
| 42 #if defined(USE_X11) | 42 #if defined(USE_X11) |
| 43 #include "ui/gfx/x/x11_types.h" // nogncheck | 43 #include "ui/gfx/x/x11_types.h" // nogncheck |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 namespace ash { | 46 namespace ash { |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 #if defined(USE_X11) | 49 #if defined(USE_X11) |
| 50 // Mirror window shouldn't handle input events. | 50 // Mirror window shouldn't handle input events. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 65 class MirroringScreenPositionClient | 65 class MirroringScreenPositionClient |
| 66 : public aura::client::ScreenPositionClient { | 66 : public aura::client::ScreenPositionClient { |
| 67 public: | 67 public: |
| 68 explicit MirroringScreenPositionClient(MirrorWindowController* controller) | 68 explicit MirroringScreenPositionClient(MirrorWindowController* controller) |
| 69 : controller_(controller) {} | 69 : controller_(controller) {} |
| 70 | 70 |
| 71 void ConvertPointToScreen(const aura::Window* window, | 71 void ConvertPointToScreen(const aura::Window* window, |
| 72 gfx::Point* point) override { | 72 gfx::Point* point) override { |
| 73 const aura::Window* root = window->GetRootWindow(); | 73 const aura::Window* root = window->GetRootWindow(); |
| 74 aura::Window::ConvertPointToTarget(window, root, point); | 74 aura::Window::ConvertPointToTarget(window, root, point); |
| 75 const gfx::Display& display = controller_->GetDisplayForRootWindow(root); | 75 const display::Display& display = |
| 76 controller_->GetDisplayForRootWindow(root); |
| 76 const gfx::Point display_origin = display.bounds().origin(); | 77 const gfx::Point display_origin = display.bounds().origin(); |
| 77 point->Offset(display_origin.x(), display_origin.y()); | 78 point->Offset(display_origin.x(), display_origin.y()); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void ConvertPointFromScreen(const aura::Window* window, | 81 void ConvertPointFromScreen(const aura::Window* window, |
| 81 gfx::Point* point) override { | 82 gfx::Point* point) override { |
| 82 const aura::Window* root = window->GetRootWindow(); | 83 const aura::Window* root = window->GetRootWindow(); |
| 83 const gfx::Display& display = controller_->GetDisplayForRootWindow(root); | 84 const display::Display& display = |
| 85 controller_->GetDisplayForRootWindow(root); |
| 84 const gfx::Point display_origin = display.bounds().origin(); | 86 const gfx::Point display_origin = display.bounds().origin(); |
| 85 point->Offset(-display_origin.x(), -display_origin.y()); | 87 point->Offset(-display_origin.x(), -display_origin.y()); |
| 86 aura::Window::ConvertPointToTarget(root, window, point); | 88 aura::Window::ConvertPointToTarget(root, window, point); |
| 87 } | 89 } |
| 88 | 90 |
| 89 void ConvertHostPointToScreen(aura::Window* root_window, | 91 void ConvertHostPointToScreen(aura::Window* root_window, |
| 90 gfx::Point* point) override { | 92 gfx::Point* point) override { |
| 91 aura::Window* not_used; | 93 aura::Window* not_used; |
| 92 ScreenPositionController::ConvertHostPointToRelativeToRootWindow( | 94 ScreenPositionController::ConvertHostPointToRelativeToRootWindow( |
| 93 root_window, controller_->GetAllRootWindows(), point, ¬_used); | 95 root_window, controller_->GetAllRootWindows(), point, ¬_used); |
| 94 ConvertPointToScreen(root_window, point); | 96 ConvertPointToScreen(root_window, point); |
| 95 } | 97 } |
| 96 | 98 |
| 97 void SetBounds(aura::Window* window, | 99 void SetBounds(aura::Window* window, |
| 98 const gfx::Rect& bounds, | 100 const gfx::Rect& bounds, |
| 99 const gfx::Display& display) override { | 101 const display::Display& display) override { |
| 100 NOTREACHED(); | 102 NOTREACHED(); |
| 101 } | 103 } |
| 102 | 104 |
| 103 private: | 105 private: |
| 104 MirrorWindowController* controller_; // not owned. | 106 MirrorWindowController* controller_; // not owned. |
| 105 | 107 |
| 106 DISALLOW_COPY_AND_ASSIGN(MirroringScreenPositionClient); | 108 DISALLOW_COPY_AND_ASSIGN(MirroringScreenPositionClient); |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 class NoneCaptureClient : public aura::client::CaptureClient { | 111 class NoneCaptureClient : public aura::client::CaptureClient { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 157 |
| 156 MirrorWindowController::~MirrorWindowController() { | 158 MirrorWindowController::~MirrorWindowController() { |
| 157 // Make sure the root window gets deleted before cursor_window_delegate. | 159 // Make sure the root window gets deleted before cursor_window_delegate. |
| 158 Close(false); | 160 Close(false); |
| 159 } | 161 } |
| 160 | 162 |
| 161 void MirrorWindowController::UpdateWindow( | 163 void MirrorWindowController::UpdateWindow( |
| 162 const std::vector<DisplayInfo>& display_info_list) { | 164 const std::vector<DisplayInfo>& display_info_list) { |
| 163 static int mirror_host_count = 0; | 165 static int mirror_host_count = 0; |
| 164 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 166 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 165 const gfx::Display& primary = gfx::Screen::GetScreen()->GetPrimaryDisplay(); | 167 const display::Display& primary = |
| 168 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 166 const DisplayInfo& source_display_info = | 169 const DisplayInfo& source_display_info = |
| 167 display_manager->GetDisplayInfo(primary.id()); | 170 display_manager->GetDisplayInfo(primary.id()); |
| 168 | 171 |
| 169 multi_display_mode_ = GetCurrentMultiDisplayMode(); | 172 multi_display_mode_ = GetCurrentMultiDisplayMode(); |
| 170 | 173 |
| 171 for (const DisplayInfo& display_info : display_info_list) { | 174 for (const DisplayInfo& display_info : display_info_list) { |
| 172 std::unique_ptr<RootWindowTransformer> transformer; | 175 std::unique_ptr<RootWindowTransformer> transformer; |
| 173 if (display_manager->IsInMirrorMode()) { | 176 if (display_manager->IsInMirrorMode()) { |
| 174 transformer.reset(CreateRootWindowTransformerForMirroredDisplay( | 177 transformer.reset(CreateRootWindowTransformerForMirroredDisplay( |
| 175 source_display_info, display_info)); | 178 source_display_info, display_info)); |
| 176 } else if (display_manager->IsInUnifiedMode()) { | 179 } else if (display_manager->IsInUnifiedMode()) { |
| 177 gfx::Display display = | 180 display::Display display = |
| 178 display_manager->GetMirroringDisplayById(display_info.id()); | 181 display_manager->GetMirroringDisplayById(display_info.id()); |
| 179 transformer.reset(CreateRootWindowTransformerForUnifiedDesktop( | 182 transformer.reset(CreateRootWindowTransformerForUnifiedDesktop( |
| 180 primary.bounds(), display)); | 183 primary.bounds(), display)); |
| 181 } else { | 184 } else { |
| 182 NOTREACHED(); | 185 NOTREACHED(); |
| 183 } | 186 } |
| 184 | 187 |
| 185 if (mirroring_host_info_map_.find(display_info.id()) == | 188 if (mirroring_host_info_map_.find(display_info.id()) == |
| 186 mirroring_host_info_map_.end()) { | 189 mirroring_host_info_map_.end()) { |
| 187 AshWindowTreeHostInitParams init_params; | 190 AshWindowTreeHostInitParams init_params; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 210 DisableInput(host->GetAcceleratedWidget()); | 213 DisableInput(host->GetAcceleratedWidget()); |
| 211 #endif | 214 #endif |
| 212 | 215 |
| 213 #if defined(OS_CHROMEOS) | 216 #if defined(OS_CHROMEOS) |
| 214 if (display_manager->IsInUnifiedMode()) { | 217 if (display_manager->IsInUnifiedMode()) { |
| 215 host_info->ash_host->ConfineCursorToRootWindow(); | 218 host_info->ash_host->ConfineCursorToRootWindow(); |
| 216 AshWindowTreeHost* unified_ash_host = | 219 AshWindowTreeHost* unified_ash_host = |
| 217 Shell::GetInstance() | 220 Shell::GetInstance() |
| 218 ->window_tree_host_manager() | 221 ->window_tree_host_manager() |
| 219 ->GetAshWindowTreeHostForDisplayId( | 222 ->GetAshWindowTreeHostForDisplayId( |
| 220 gfx::Screen::GetScreen()->GetPrimaryDisplay().id()); | 223 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
| 221 unified_ash_host->RegisterMirroringHost(host_info->ash_host.get()); | 224 unified_ash_host->RegisterMirroringHost(host_info->ash_host.get()); |
| 222 aura::client::SetScreenPositionClient(host->window(), | 225 aura::client::SetScreenPositionClient(host->window(), |
| 223 screen_position_client_.get()); | 226 screen_position_client_.get()); |
| 224 } | 227 } |
| 225 #endif | 228 #endif |
| 226 | 229 |
| 227 aura::client::SetCaptureClient(host->window(), new NoneCaptureClient()); | 230 aura::client::SetCaptureClient(host->window(), new NoneCaptureClient()); |
| 228 host->Show(); | 231 host->Show(); |
| 229 | 232 |
| 230 aura::Window* mirror_window = host_info->mirror_window = | 233 aura::Window* mirror_window = host_info->mirror_window = |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 aura::Window* MirrorWindowController::GetWindow() { | 323 aura::Window* MirrorWindowController::GetWindow() { |
| 321 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 324 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 322 if (!display_manager->IsInMirrorMode() || mirroring_host_info_map_.empty()) | 325 if (!display_manager->IsInMirrorMode() || mirroring_host_info_map_.empty()) |
| 323 return nullptr; | 326 return nullptr; |
| 324 DCHECK_EQ(1U, mirroring_host_info_map_.size()); | 327 DCHECK_EQ(1U, mirroring_host_info_map_.size()); |
| 325 return mirroring_host_info_map_.begin() | 328 return mirroring_host_info_map_.begin() |
| 326 ->second->ash_host->AsWindowTreeHost() | 329 ->second->ash_host->AsWindowTreeHost() |
| 327 ->window(); | 330 ->window(); |
| 328 } | 331 } |
| 329 | 332 |
| 330 gfx::Display MirrorWindowController::GetDisplayForRootWindow( | 333 display::Display MirrorWindowController::GetDisplayForRootWindow( |
| 331 const aura::Window* root) const { | 334 const aura::Window* root) const { |
| 332 for (const auto& pair : mirroring_host_info_map_) { | 335 for (const auto& pair : mirroring_host_info_map_) { |
| 333 if (pair.second->ash_host->AsWindowTreeHost()->window() == root) { | 336 if (pair.second->ash_host->AsWindowTreeHost()->window() == root) { |
| 334 // Sanity check to catch an error early. | 337 // Sanity check to catch an error early. |
| 335 int64_t id = pair.first; | 338 int64_t id = pair.first; |
| 336 const display::DisplayList& list = | 339 const display::DisplayList& list = |
| 337 Shell::GetInstance() | 340 Shell::GetInstance() |
| 338 ->display_manager() | 341 ->display_manager() |
| 339 ->software_mirroring_display_list(); | 342 ->software_mirroring_display_list(); |
| 340 auto iter = std::find_if( | 343 auto iter = std::find_if( |
| 341 list.begin(), list.end(), | 344 list.begin(), list.end(), |
| 342 [id](const gfx::Display& display) { return display.id() == id; }); | 345 [id](const display::Display& display) { return display.id() == id; }); |
| 343 DCHECK(iter != list.end()); | 346 DCHECK(iter != list.end()); |
| 344 if (iter != list.end()) | 347 if (iter != list.end()) |
| 345 return *iter; | 348 return *iter; |
| 346 } | 349 } |
| 347 } | 350 } |
| 348 return gfx::Display(); | 351 return display::Display(); |
| 349 } | 352 } |
| 350 | 353 |
| 351 AshWindowTreeHost* MirrorWindowController::GetAshWindowTreeHostForDisplayId( | 354 AshWindowTreeHost* MirrorWindowController::GetAshWindowTreeHostForDisplayId( |
| 352 int64_t id) { | 355 int64_t id) { |
| 353 CHECK_EQ(1u, mirroring_host_info_map_.count(id)); | 356 CHECK_EQ(1u, mirroring_host_info_map_.count(id)); |
| 354 return mirroring_host_info_map_[id]->ash_host.get(); | 357 return mirroring_host_info_map_[id]->ash_host.get(); |
| 355 } | 358 } |
| 356 | 359 |
| 357 aura::Window::Windows MirrorWindowController::GetAllRootWindows() const { | 360 aura::Window::Windows MirrorWindowController::GetAllRootWindows() const { |
| 358 aura::Window::Windows root_windows; | 361 aura::Window::Windows root_windows; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 380 // EventProcessor may be accessed after this call if the mirroring window | 383 // EventProcessor may be accessed after this call if the mirroring window |
| 381 // was deleted as a result of input event (e.g. shortcut), so don't delete | 384 // was deleted as a result of input event (e.g. shortcut), so don't delete |
| 382 // now. | 385 // now. |
| 383 if (delay_host_deletion) | 386 if (delay_host_deletion) |
| 384 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, host_info); | 387 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, host_info); |
| 385 else | 388 else |
| 386 delete host_info; | 389 delete host_info; |
| 387 } | 390 } |
| 388 | 391 |
| 389 } // namespace ash | 392 } // namespace ash |
| OLD | NEW |