OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/touch/touch_transformer_controller.h" | 5 #include "ash/touch/touch_transformer_controller.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
9 #include "ash/host/ash_window_tree_host.h" | 9 #include "ash/host/ash_window_tree_host.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 TouchTransformerController::TouchTransformerController() { | 119 TouchTransformerController::TouchTransformerController() { |
120 Shell::GetInstance()->display_controller()->AddObserver(this); | 120 Shell::GetInstance()->display_controller()->AddObserver(this); |
121 } | 121 } |
122 | 122 |
123 TouchTransformerController::~TouchTransformerController() { | 123 TouchTransformerController::~TouchTransformerController() { |
124 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 124 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
125 } | 125 } |
126 | 126 |
127 void TouchTransformerController::UpdateTouchTransformer() const { | 127 void TouchTransformerController::UpdateTouchTransformer() const { |
128 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 128 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
129 device_manager->ClearTouchTransformerRecord(); | 129 device_manager->ClearTouchDeviceAssociations(); |
130 | 130 |
131 // Display IDs and DisplayInfo for mirror or extended mode. | 131 // Display IDs and DisplayInfo for mirror or extended mode. |
132 int64 display1_id = gfx::Display::kInvalidDisplayID; | 132 int64 display1_id = gfx::Display::kInvalidDisplayID; |
133 int64 display2_id = gfx::Display::kInvalidDisplayID; | 133 int64 display2_id = gfx::Display::kInvalidDisplayID; |
134 DisplayInfo display1; | 134 DisplayInfo display1; |
135 DisplayInfo display2; | 135 DisplayInfo display2; |
136 // Display ID and DisplayInfo for single display mode. | 136 // Display ID and DisplayInfo for single display mode. |
137 int64 single_display_id = gfx::Display::kInvalidDisplayID; | 137 int64 single_display_id = gfx::Display::kInvalidDisplayID; |
138 DisplayInfo single_display; | 138 DisplayInfo single_display; |
139 | 139 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 single_display.touch_device_id(), | 171 single_display.touch_device_id(), |
172 GetTouchResolutionScale( | 172 GetTouchResolutionScale( |
173 single_display, | 173 single_display, |
174 FindTouchscreenById(single_display.touch_device_id()))); | 174 FindTouchscreenById(single_display.touch_device_id()))); |
175 } | 175 } |
176 | 176 |
177 gfx::Size fb_size = | 177 gfx::Size fb_size = |
178 Shell::GetInstance()->display_configurator()->framebuffer_size(); | 178 Shell::GetInstance()->display_configurator()->framebuffer_size(); |
179 | 179 |
180 if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) { | 180 if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) { |
181 // In mirror mode, both displays share the same root window so | 181 // In mirror mode, there is just one WindowTreeHost and two displays. Make |
182 // both display ids are associated with the root window. | 182 // the WindowTreeHost accept touch events from both displays. |
183 aura::Window* root = display_controller->GetPrimaryRootWindow(); | 183 int64 primary_display_id = display_controller->GetPrimaryDisplayId(); |
184 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID( | |
185 display1_id, display2_id); | |
186 device_manager->UpdateTouchInfoForDisplay( | 184 device_manager->UpdateTouchInfoForDisplay( |
187 display1_id, display1.touch_device_id(), | 185 primary_display_id, display1.touch_device_id(), |
188 GetTouchTransform(display1, display1, | 186 GetTouchTransform(display1, display1, |
189 FindTouchscreenById(display1.touch_device_id()), | 187 FindTouchscreenById(display1.touch_device_id()), |
190 fb_size)); | 188 fb_size)); |
191 device_manager->UpdateTouchInfoForDisplay( | 189 device_manager->UpdateTouchInfoForDisplay( |
192 display2_id, display2.touch_device_id(), | 190 primary_display_id, display2.touch_device_id(), |
193 GetTouchTransform(display2, display2, | 191 GetTouchTransform(display2, display2, |
194 FindTouchscreenById(display2.touch_device_id()), | 192 FindTouchscreenById(display2.touch_device_id()), |
195 fb_size)); | 193 fb_size)); |
196 return; | 194 return; |
197 } | 195 } |
198 | 196 |
199 if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) { | 197 if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) { |
200 // In extended but software mirroring mode, ther is only one X root window | 198 // In extended but software mirroring mode, there is a WindowTreeHost for |
201 // that associates with both displays. | 199 // each display, but all touches are forwarded to the primary root window's |
| 200 // WindowTreeHost. |
202 if (GetDisplayManager()->software_mirroring_enabled()) { | 201 if (GetDisplayManager()->software_mirroring_enabled()) { |
203 aura::Window* root = display_controller->GetPrimaryRootWindow(); | 202 DisplayInfo target_display = |
204 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID( | |
205 display1_id, display2_id); | |
206 DisplayInfo source_display = | |
207 display_controller->GetPrimaryDisplayId() == display1_id ? display1 | 203 display_controller->GetPrimaryDisplayId() == display1_id ? display1 |
208 : display2; | 204 : display2; |
209 // Mapping from framebuffer size to the source display's native | |
210 // resolution. | |
211 device_manager->UpdateTouchInfoForDisplay( | 205 device_manager->UpdateTouchInfoForDisplay( |
212 display1_id, display1.touch_device_id(), | 206 target_display.id(), display1.touch_device_id(), |
213 GetTouchTransform(source_display, display1, | 207 GetTouchTransform(target_display, display1, |
214 FindTouchscreenById(display1.touch_device_id()), | 208 FindTouchscreenById(display1.touch_device_id()), |
215 fb_size)); | 209 fb_size)); |
216 device_manager->UpdateTouchInfoForDisplay( | 210 device_manager->UpdateTouchInfoForDisplay( |
217 display2_id, display2.touch_device_id(), | 211 target_display.id(), display2.touch_device_id(), |
218 GetTouchTransform(source_display, display2, | 212 GetTouchTransform(target_display, display2, |
219 FindTouchscreenById(display2.touch_device_id()), | 213 FindTouchscreenById(display2.touch_device_id()), |
220 fb_size)); | 214 fb_size)); |
221 } else { | 215 } else { |
222 // In actual extended mode, each display is associated with one root | 216 // In actual extended mode, each display is associated with one |
223 // window. | 217 // WindowTreeHost. |
224 aura::Window* root1 = | |
225 display_controller->GetRootWindowForDisplayId(display1_id); | |
226 aura::Window* root2 = | |
227 display_controller->GetRootWindowForDisplayId(display2_id); | |
228 RootWindowController::ForWindow(root1)->ash_host()->UpdateDisplayID( | |
229 display1_id, gfx::Display::kInvalidDisplayID); | |
230 RootWindowController::ForWindow(root2)->ash_host()->UpdateDisplayID( | |
231 display2_id, gfx::Display::kInvalidDisplayID); | |
232 // Mapping from framebuffer size to each display's native resolution. | |
233 device_manager->UpdateTouchInfoForDisplay( | 218 device_manager->UpdateTouchInfoForDisplay( |
234 display1_id, display1.touch_device_id(), | 219 display1_id, display1.touch_device_id(), |
235 GetTouchTransform(display1, display1, | 220 GetTouchTransform(display1, display1, |
236 FindTouchscreenById(display1.touch_device_id()), | 221 FindTouchscreenById(display1.touch_device_id()), |
237 fb_size)); | 222 fb_size)); |
238 device_manager->UpdateTouchInfoForDisplay( | 223 device_manager->UpdateTouchInfoForDisplay( |
239 display2_id, display2.touch_device_id(), | 224 display2_id, display2.touch_device_id(), |
240 GetTouchTransform(display2, display2, | 225 GetTouchTransform(display2, display2, |
241 FindTouchscreenById(display2.touch_device_id()), | 226 FindTouchscreenById(display2.touch_device_id()), |
242 fb_size)); | 227 fb_size)); |
243 } | 228 } |
244 return; | 229 return; |
245 } | 230 } |
246 | 231 |
247 // Single display mode. The root window has one associated display id. | 232 // Single display mode. The WindowTreeHost has one associated display id. |
248 aura::Window* root = | |
249 display_controller->GetRootWindowForDisplayId(single_display.id()); | |
250 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID( | |
251 single_display.id(), gfx::Display::kInvalidDisplayID); | |
252 device_manager->UpdateTouchInfoForDisplay( | 233 device_manager->UpdateTouchInfoForDisplay( |
253 single_display_id, single_display.touch_device_id(), | 234 single_display_id, single_display.touch_device_id(), |
254 GetTouchTransform(single_display, single_display, | 235 GetTouchTransform(single_display, single_display, |
255 FindTouchscreenById(single_display.touch_device_id()), | 236 FindTouchscreenById(single_display.touch_device_id()), |
256 fb_size)); | 237 fb_size)); |
257 } | 238 } |
258 | 239 |
259 void TouchTransformerController::OnDisplaysInitialized() { | 240 void TouchTransformerController::OnDisplaysInitialized() { |
260 UpdateTouchTransformer(); | 241 UpdateTouchTransformer(); |
261 } | 242 } |
262 | 243 |
263 void TouchTransformerController::OnDisplayConfigurationChanged() { | 244 void TouchTransformerController::OnDisplayConfigurationChanged() { |
264 UpdateTouchTransformer(); | 245 UpdateTouchTransformer(); |
265 } | 246 } |
266 | 247 |
267 } // namespace ash | 248 } // namespace ash |
OLD | NEW |