| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 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::UpdateTouchRadius( |
| 128 const DisplayInfo& display) const { |
| 129 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 130 device_manager->UpdateTouchRadiusScale( |
| 131 display.touch_device_id(), |
| 132 GetTouchResolutionScale(display, |
| 133 FindTouchscreenById(display.touch_device_id()))); |
| 134 } |
| 135 |
| 136 void TouchTransformerController::UpdateTouchTransform( |
| 137 int64_t target_display_id, |
| 138 const DisplayInfo& touch_display, |
| 139 const DisplayInfo& target_display) const { |
| 140 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 141 gfx::Size fb_size = |
| 142 Shell::GetInstance()->display_configurator()->framebuffer_size(); |
| 143 device_manager->UpdateTouchInfoForDisplay( |
| 144 target_display_id, touch_display.touch_device_id(), |
| 145 GetTouchTransform(target_display, touch_display, |
| 146 FindTouchscreenById(touch_display.touch_device_id()), |
| 147 fb_size)); |
| 148 } |
| 149 |
| 127 void TouchTransformerController::UpdateTouchTransformer() const { | 150 void TouchTransformerController::UpdateTouchTransformer() const { |
| 128 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); | 151 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); |
| 129 device_manager->ClearTouchDeviceAssociations(); | 152 device_manager->ClearTouchDeviceAssociations(); |
| 130 | 153 |
| 131 // Display IDs and DisplayInfo for mirror or extended mode. | 154 // Display IDs and DisplayInfo for mirror or extended mode. |
| 132 int64 display1_id = gfx::Display::kInvalidDisplayID; | 155 int64 display1_id = gfx::Display::kInvalidDisplayID; |
| 133 int64 display2_id = gfx::Display::kInvalidDisplayID; | 156 int64 display2_id = gfx::Display::kInvalidDisplayID; |
| 134 DisplayInfo display1; | 157 DisplayInfo display1; |
| 135 DisplayInfo display2; | 158 DisplayInfo display2; |
| 136 // Display ID and DisplayInfo for single display mode. | 159 // Display ID and DisplayInfo for single display mode. |
| 137 int64 single_display_id = gfx::Display::kInvalidDisplayID; | 160 int64 single_display_id = gfx::Display::kInvalidDisplayID; |
| 138 DisplayInfo single_display; | 161 DisplayInfo single_display; |
| 139 | 162 |
| 140 DisplayController* display_controller = | 163 DisplayController* display_controller = |
| 141 Shell::GetInstance()->display_controller(); | 164 Shell::GetInstance()->display_controller(); |
| 142 DisplayManager* display_manager = GetDisplayManager(); | 165 DisplayManager* display_manager = GetDisplayManager(); |
| 143 if (display_manager->num_connected_displays() == 0) { | 166 if (display_manager->num_connected_displays() == 0) { |
| 144 return; | 167 return; |
| 145 } else if (display_manager->num_connected_displays() == 1 || | 168 } else if (display_manager->num_connected_displays() == 1 || |
| 146 display_manager->IsInUnifiedMode()) { | 169 display_manager->IsInUnifiedMode()) { |
| 147 single_display_id = display_manager->first_display_id(); | 170 single_display_id = display_manager->first_display_id(); |
| 148 DCHECK(single_display_id != gfx::Display::kInvalidDisplayID); | 171 DCHECK(single_display_id != gfx::Display::kInvalidDisplayID); |
| 149 single_display = display_manager->GetDisplayInfo(single_display_id); | 172 single_display = display_manager->GetDisplayInfo(single_display_id); |
| 150 device_manager->UpdateTouchRadiusScale( | 173 UpdateTouchRadius(single_display); |
| 151 single_display.touch_device_id(), | |
| 152 GetTouchResolutionScale( | |
| 153 single_display, | |
| 154 FindTouchscreenById(single_display.touch_device_id()))); | |
| 155 } else { | 174 } else { |
| 156 DisplayIdPair id_pair = display_manager->GetCurrentDisplayIdPair(); | 175 DisplayIdPair id_pair = display_manager->GetCurrentDisplayIdPair(); |
| 157 display1_id = id_pair.first; | 176 display1_id = id_pair.first; |
| 158 display2_id = id_pair.second; | 177 display2_id = id_pair.second; |
| 159 DCHECK(display1_id != gfx::Display::kInvalidDisplayID && | 178 DCHECK(display1_id != gfx::Display::kInvalidDisplayID && |
| 160 display2_id != gfx::Display::kInvalidDisplayID); | 179 display2_id != gfx::Display::kInvalidDisplayID); |
| 161 display1 = display_manager->GetDisplayInfo(display1_id); | 180 display1 = display_manager->GetDisplayInfo(display1_id); |
| 162 display2 = display_manager->GetDisplayInfo(display2_id); | 181 display2 = display_manager->GetDisplayInfo(display2_id); |
| 163 device_manager->UpdateTouchRadiusScale( | 182 UpdateTouchRadius(display1); |
| 164 display1.touch_device_id(), | 183 UpdateTouchRadius(display2); |
| 165 GetTouchResolutionScale( | |
| 166 display1, | |
| 167 FindTouchscreenById(display1.touch_device_id()))); | |
| 168 device_manager->UpdateTouchRadiusScale( | |
| 169 display2.touch_device_id(), | |
| 170 GetTouchResolutionScale( | |
| 171 display2, | |
| 172 FindTouchscreenById(display2.touch_device_id()))); | |
| 173 } | 184 } |
| 174 | 185 |
| 175 gfx::Size fb_size = | 186 gfx::Size fb_size = |
| 176 Shell::GetInstance()->display_configurator()->framebuffer_size(); | 187 Shell::GetInstance()->display_configurator()->framebuffer_size(); |
| 177 | 188 |
| 178 if (display_manager->IsInMirrorMode()) { | 189 if (display_manager->IsInMirrorMode()) { |
| 190 int64_t primary_display_id = display_controller->GetPrimaryDisplayId(); |
| 179 if (GetDisplayManager()->SoftwareMirroringEnabled()) { | 191 if (GetDisplayManager()->SoftwareMirroringEnabled()) { |
| 180 // In extended but software mirroring mode, there is a WindowTreeHost for | 192 // In extended but software mirroring mode, there is a WindowTreeHost for |
| 181 // each display, but all touches are forwarded to the primary root | 193 // each display, but all touches are forwarded to the primary root |
| 182 // window's WindowTreeHost. | 194 // window's WindowTreeHost. |
| 183 DisplayInfo target_display = | 195 DisplayInfo target_display = |
| 184 display_controller->GetPrimaryDisplayId() == display1_id ? display1 | 196 primary_display_id == display1_id ? display1 : display2; |
| 185 : display2; | 197 UpdateTouchTransform(target_display.id(), display1, target_display); |
| 186 device_manager->UpdateTouchInfoForDisplay( | 198 UpdateTouchTransform(target_display.id(), display2, target_display); |
| 187 target_display.id(), display1.touch_device_id(), | |
| 188 GetTouchTransform(target_display, display1, | |
| 189 FindTouchscreenById(display1.touch_device_id()), | |
| 190 fb_size)); | |
| 191 device_manager->UpdateTouchInfoForDisplay( | |
| 192 target_display.id(), display2.touch_device_id(), | |
| 193 GetTouchTransform(target_display, display2, | |
| 194 FindTouchscreenById(display2.touch_device_id()), | |
| 195 fb_size)); | |
| 196 } else { | 199 } else { |
| 197 // In mirror mode, there is just one WindowTreeHost and two displays. Make | 200 // In mirror mode, there is just one WindowTreeHost and two displays. Make |
| 198 // the WindowTreeHost accept touch events from both displays. | 201 // the WindowTreeHost accept touch events from both displays. |
| 199 int64 primary_display_id = display_controller->GetPrimaryDisplayId(); | 202 UpdateTouchTransform(primary_display_id, display1, display1); |
| 200 device_manager->UpdateTouchInfoForDisplay( | 203 UpdateTouchTransform(primary_display_id, display2, display2); |
| 201 primary_display_id, display1.touch_device_id(), | |
| 202 GetTouchTransform(display1, display1, | |
| 203 FindTouchscreenById(display1.touch_device_id()), | |
| 204 fb_size)); | |
| 205 device_manager->UpdateTouchInfoForDisplay( | |
| 206 primary_display_id, display2.touch_device_id(), | |
| 207 GetTouchTransform(display2, display2, | |
| 208 FindTouchscreenById(display2.touch_device_id()), | |
| 209 fb_size)); | |
| 210 } | 204 } |
| 211 return; | 205 return; |
| 212 } | 206 } |
| 213 | 207 |
| 214 if (display_manager->num_connected_displays() > 1) { | 208 if (display_manager->num_connected_displays() > 1) { |
| 215 // In actual extended mode, each display is associated with one | 209 // In actual extended mode, each display is associated with one |
| 216 // WindowTreeHost. | 210 // WindowTreeHost. |
| 217 device_manager->UpdateTouchInfoForDisplay( | 211 UpdateTouchTransform(display1_id, display1, display1); |
| 218 display1_id, display1.touch_device_id(), | 212 UpdateTouchTransform(display2_id, display2, display2); |
| 219 GetTouchTransform(display1, display1, | |
| 220 FindTouchscreenById(display1.touch_device_id()), | |
| 221 fb_size)); | |
| 222 device_manager->UpdateTouchInfoForDisplay( | |
| 223 display2_id, display2.touch_device_id(), | |
| 224 GetTouchTransform(display2, display2, | |
| 225 FindTouchscreenById(display2.touch_device_id()), | |
| 226 fb_size)); | |
| 227 return; | 213 return; |
| 228 } | 214 } |
| 229 | 215 |
| 230 // Single display mode. The WindowTreeHost has one associated display id. | 216 // Single display mode. The WindowTreeHost has one associated display id. |
| 231 device_manager->UpdateTouchInfoForDisplay( | 217 UpdateTouchTransform(single_display_id, single_display, single_display); |
| 232 single_display_id, single_display.touch_device_id(), | |
| 233 GetTouchTransform(single_display, single_display, | |
| 234 FindTouchscreenById(single_display.touch_device_id()), | |
| 235 fb_size)); | |
| 236 } | 218 } |
| 237 | 219 |
| 238 void TouchTransformerController::OnDisplaysInitialized() { | 220 void TouchTransformerController::OnDisplaysInitialized() { |
| 239 UpdateTouchTransformer(); | 221 UpdateTouchTransformer(); |
| 240 } | 222 } |
| 241 | 223 |
| 242 void TouchTransformerController::OnDisplayConfigurationChanged() { | 224 void TouchTransformerController::OnDisplayConfigurationChanged() { |
| 243 UpdateTouchTransformer(); | 225 UpdateTouchTransformer(); |
| 244 } | 226 } |
| 245 | 227 |
| 246 } // namespace ash | 228 } // namespace ash |
| OLD | NEW |