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 #if defined(USE_X11) | 7 #if defined(USE_X11) |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 // Xlib.h defines RootWindow. | 10 // Xlib.h defines RootWindow. |
11 #undef RootWindow | 11 #undef RootWindow |
12 #endif | 12 #endif |
13 | 13 |
14 #include "ash/display/cursor_window_controller.h" | 14 #include "ash/display/cursor_window_controller.h" |
15 #include "ash/display/display_controller.h" | 15 #include "ash/display/display_controller.h" |
16 #include "ash/display/display_info.h" | 16 #include "ash/display/display_info.h" |
17 #include "ash/display/display_manager.h" | 17 #include "ash/display/display_manager.h" |
18 #include "ash/display/root_window_transformers.h" | 18 #include "ash/display/root_window_transformers.h" |
19 #include "ash/host/window_tree_host_factory.h" | 19 #include "ash/host/ash_window_tree_host.h" |
| 20 #include "ash/host/root_window_transformer.h" |
20 #include "ash/root_window_settings.h" | 21 #include "ash/root_window_settings.h" |
21 #include "ash/shell.h" | 22 #include "ash/shell.h" |
22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
23 #include "ui/aura/client/capture_client.h" | 24 #include "ui/aura/client/capture_client.h" |
24 #include "ui/aura/root_window_transformer.h" | |
25 #include "ui/aura/window_delegate.h" | 25 #include "ui/aura/window_delegate.h" |
26 #include "ui/aura/window_event_dispatcher.h" | 26 #include "ui/aura/window_event_dispatcher.h" |
| 27 #include "ui/aura/window_tree_host.h" |
27 #include "ui/base/layout.h" | 28 #include "ui/base/layout.h" |
28 #include "ui/compositor/reflector.h" | 29 #include "ui/compositor/reflector.h" |
29 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
30 #include "ui/gfx/native_widget_types.h" | 31 #include "ui/gfx/native_widget_types.h" |
31 | 32 |
32 #if defined(USE_X11) | 33 #if defined(USE_X11) |
33 #include "ui/gfx/x/x11_types.h" | 34 #include "ui/gfx/x/x11_types.h" |
34 #endif | 35 #endif |
35 | 36 |
36 namespace ash { | 37 namespace ash { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 74 |
74 MirrorWindowController::MirrorWindowController() {} | 75 MirrorWindowController::MirrorWindowController() {} |
75 | 76 |
76 MirrorWindowController::~MirrorWindowController() { | 77 MirrorWindowController::~MirrorWindowController() { |
77 // Make sure the root window gets deleted before cursor_window_delegate. | 78 // Make sure the root window gets deleted before cursor_window_delegate. |
78 Close(); | 79 Close(); |
79 } | 80 } |
80 | 81 |
81 void MirrorWindowController::UpdateWindow(const DisplayInfo& display_info) { | 82 void MirrorWindowController::UpdateWindow(const DisplayInfo& display_info) { |
82 static int mirror_host_count = 0; | 83 static int mirror_host_count = 0; |
83 | 84 aura::WindowTreeHost* host = NULL; |
84 if (!host_.get()) { | 85 if (!ash_host_.get()) { |
85 const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); | 86 const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); |
86 host_.reset(Shell::GetInstance()->window_tree_host_factory()-> | 87 ash_host_.reset(AshWindowTreeHost::Create(bounds_in_native)); |
87 CreateWindowTreeHost(bounds_in_native)); | 88 host = ash_host_->AsWindowTreeHost(); |
88 host_->window()->SetName( | 89 host->window()->SetName( |
89 base::StringPrintf("MirrorRootWindow-%d", mirror_host_count++)); | 90 base::StringPrintf("MirrorRootWindow-%d", mirror_host_count++)); |
90 host_->compositor()->SetBackgroundColor(SK_ColorBLACK); | 91 host->compositor()->SetBackgroundColor(SK_ColorBLACK); |
91 // No need to remove the observer because the DisplayController outlives the | 92 // No need to remove the observer because the DisplayController outlives the |
92 // host. | 93 // host. |
93 host_->AddObserver(Shell::GetInstance()->display_controller()); | 94 host->AddObserver(Shell::GetInstance()->display_controller()); |
94 host_->AddObserver(this); | 95 host->AddObserver(this); |
95 // TODO(oshima): TouchHUD is using idkey. | 96 // TODO(oshima): TouchHUD is using idkey. |
96 InitRootWindowSettings(host_->window())->display_id = display_info.id(); | 97 InitRootWindowSettings(host->window())->display_id = display_info.id(); |
97 host_->InitHost(); | 98 host->InitHost(); |
98 #if defined(USE_X11) | 99 #if defined(USE_X11) |
99 DisableInput(host_->GetAcceleratedWidget()); | 100 DisableInput(host->GetAcceleratedWidget()); |
100 #endif | 101 #endif |
101 | 102 |
102 aura::client::SetCaptureClient(host_->window(), new NoneCaptureClient()); | 103 aura::client::SetCaptureClient(host->window(), new NoneCaptureClient()); |
103 host_->Show(); | 104 host->Show(); |
104 | 105 |
105 // TODO(oshima): Start mirroring. | 106 // TODO(oshima): Start mirroring. |
106 aura::Window* mirror_window = new aura::Window(NULL); | 107 aura::Window* mirror_window = new aura::Window(NULL); |
107 mirror_window->Init(aura::WINDOW_LAYER_TEXTURED); | 108 mirror_window->Init(aura::WINDOW_LAYER_TEXTURED); |
108 host_->window()->AddChild(mirror_window); | 109 host->window()->AddChild(mirror_window); |
109 mirror_window->SetBounds(host_->window()->bounds()); | 110 mirror_window->SetBounds(host->window()->bounds()); |
110 mirror_window->Show(); | 111 mirror_window->Show(); |
111 reflector_ = ui::ContextFactory::GetInstance()->CreateReflector( | 112 reflector_ = ui::ContextFactory::GetInstance()->CreateReflector( |
112 Shell::GetPrimaryRootWindow()->GetHost()->compositor(), | 113 Shell::GetPrimaryRootWindow()->GetHost()->compositor(), |
113 mirror_window->layer()); | 114 mirror_window->layer()); |
114 } else { | 115 } else { |
115 GetRootWindowSettings(host_->window())->display_id = display_info.id(); | 116 host = ash_host_->AsWindowTreeHost(); |
116 host_->SetBounds(display_info.bounds_in_native()); | 117 GetRootWindowSettings(host->window())->display_id = display_info.id(); |
| 118 host->SetBounds(display_info.bounds_in_native()); |
117 } | 119 } |
118 | 120 |
119 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 121 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
120 const DisplayInfo& source_display_info = display_manager->GetDisplayInfo( | 122 const DisplayInfo& source_display_info = display_manager->GetDisplayInfo( |
121 Shell::GetScreen()->GetPrimaryDisplay().id()); | 123 Shell::GetScreen()->GetPrimaryDisplay().id()); |
122 DCHECK(display_manager->IsMirrored()); | 124 DCHECK(display_manager->IsMirrored()); |
123 scoped_ptr<aura::RootWindowTransformer> transformer( | 125 scoped_ptr<RootWindowTransformer> transformer( |
124 internal::CreateRootWindowTransformerForMirroredDisplay( | 126 internal::CreateRootWindowTransformerForMirroredDisplay( |
125 source_display_info, | 127 source_display_info, |
126 display_info)); | 128 display_info)); |
127 host_->SetRootWindowTransformer(transformer.Pass()); | 129 ash_host_->SetRootWindowTransformer(transformer.Pass()); |
128 } | 130 } |
129 | 131 |
130 void MirrorWindowController::UpdateWindow() { | 132 void MirrorWindowController::UpdateWindow() { |
131 if (host_.get()) { | 133 if (ash_host_.get()) { |
132 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 134 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
133 const DisplayInfo& mirror_display_info = display_manager->GetDisplayInfo( | 135 const DisplayInfo& mirror_display_info = display_manager->GetDisplayInfo( |
134 display_manager->mirrored_display_id()); | 136 display_manager->mirrored_display_id()); |
135 UpdateWindow(mirror_display_info); | 137 UpdateWindow(mirror_display_info); |
136 } | 138 } |
137 } | 139 } |
138 | 140 |
139 void MirrorWindowController::Close() { | 141 void MirrorWindowController::Close() { |
140 if (host_.get()) { | 142 if (ash_host_.get()) { |
| 143 aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost(); |
141 ui::ContextFactory::GetInstance()->RemoveReflector(reflector_); | 144 ui::ContextFactory::GetInstance()->RemoveReflector(reflector_); |
142 reflector_ = NULL; | 145 reflector_ = NULL; |
143 NoneCaptureClient* capture_client = static_cast<NoneCaptureClient*>( | 146 NoneCaptureClient* capture_client = static_cast<NoneCaptureClient*>( |
144 aura::client::GetCaptureClient(host_->window())); | 147 aura::client::GetCaptureClient(host->window())); |
145 aura::client::SetCaptureClient(host_->window(), NULL); | 148 aura::client::SetCaptureClient(host->window(), NULL); |
146 delete capture_client; | 149 delete capture_client; |
147 | 150 |
148 host_->RemoveObserver(Shell::GetInstance()->display_controller()); | 151 host->RemoveObserver(Shell::GetInstance()->display_controller()); |
149 host_->RemoveObserver(this); | 152 host->RemoveObserver(this); |
150 host_.reset(); | 153 ash_host_.reset(); |
151 } | 154 } |
152 } | 155 } |
153 | 156 |
154 void MirrorWindowController::OnHostResized(const aura::WindowTreeHost* host) { | 157 void MirrorWindowController::OnHostResized(const aura::WindowTreeHost* host) { |
155 if (mirror_window_host_size_ == host->GetBounds().size()) | 158 if (mirror_window_host_size_ == host->GetBounds().size()) |
156 return; | 159 return; |
157 mirror_window_host_size_ = host->GetBounds().size(); | 160 mirror_window_host_size_ = host->GetBounds().size(); |
158 reflector_->OnMirroringCompositorResized(); | 161 reflector_->OnMirroringCompositorResized(); |
159 host_->SetRootWindowTransformer(CreateRootWindowTransformer().Pass()); | 162 ash_host_->SetRootWindowTransformer(CreateRootWindowTransformer().Pass()); |
160 Shell::GetInstance()->display_controller()->cursor_window_controller()-> | 163 Shell::GetInstance()->display_controller()->cursor_window_controller()-> |
161 UpdateLocation(); | 164 UpdateLocation(); |
162 } | 165 } |
163 | 166 |
164 | 167 |
165 scoped_ptr<aura::RootWindowTransformer> | 168 scoped_ptr<RootWindowTransformer> |
166 MirrorWindowController::CreateRootWindowTransformer() const { | 169 MirrorWindowController::CreateRootWindowTransformer() const { |
167 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 170 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
168 const DisplayInfo& mirror_display_info = display_manager->GetDisplayInfo( | 171 const DisplayInfo& mirror_display_info = display_manager->GetDisplayInfo( |
169 display_manager->mirrored_display_id()); | 172 display_manager->mirrored_display_id()); |
170 const DisplayInfo& source_display_info = display_manager->GetDisplayInfo( | 173 const DisplayInfo& source_display_info = display_manager->GetDisplayInfo( |
171 Shell::GetScreen()->GetPrimaryDisplay().id()); | 174 Shell::GetScreen()->GetPrimaryDisplay().id()); |
172 DCHECK(display_manager->IsMirrored()); | 175 DCHECK(display_manager->IsMirrored()); |
173 return scoped_ptr<aura::RootWindowTransformer>( | 176 return scoped_ptr<RootWindowTransformer>( |
174 internal::CreateRootWindowTransformerForMirroredDisplay( | 177 internal::CreateRootWindowTransformerForMirroredDisplay( |
175 source_display_info, | 178 source_display_info, |
176 mirror_display_info)); | 179 mirror_display_info)); |
177 } | 180 } |
178 | 181 |
179 } // namespace internal | 182 } // namespace internal |
180 } // namespace ash | 183 } // namespace ash |
OLD | NEW |