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" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ui/aura/window_tree_host.h" | 12 #include "ui/aura/window_tree_host.h" |
13 #include "ui/display/chromeos/display_configurator.h" | 13 #include "ui/display/chromeos/display_configurator.h" |
14 #include "ui/display/types/chromeos/display_snapshot.h" | 14 #include "ui/display/types/chromeos/display_snapshot.h" |
15 #include "ui/events/device_data_manager.h" | 15 #include "ui/events/device_data_manager.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 DisplayManager* GetDisplayManager() { | 21 DisplayManager* GetDisplayManager() { |
22 return Shell::GetInstance()->display_manager(); | 22 return Shell::GetInstance()->display_manager(); |
23 } | 23 } |
24 | 24 |
25 gfx::Size GetNativeModeSize(const DisplayInfo& display) { | |
26 const std::vector<DisplayMode>& modes = display.display_modes(); | |
27 for (size_t i = 0; i < modes.size(); ++i) { | |
28 if (modes[i].native) { | |
Daniel Erat
2014/06/17 21:59:18
nit: remove these curly brackets
dnicoara
2014/06/20 17:01:05
Done.
| |
29 return modes[i].size; | |
30 } | |
31 } | |
32 | |
33 return gfx::Size(); | |
34 } | |
35 | |
25 } // namespace | 36 } // namespace |
26 | 37 |
27 // This function computes the extended mode TouchTransformer for | 38 // This function computes the extended mode TouchTransformer for |
28 // |touch_display|. The TouchTransformer maps the touch event position | 39 // |touch_display|. The TouchTransformer maps the touch event position |
29 // from framebuffer size to the display size. | 40 // from framebuffer size to the display size. |
30 gfx::Transform | 41 gfx::Transform |
31 TouchTransformerController::GetExtendedModeTouchTransformer( | 42 TouchTransformerController::GetExtendedModeTouchTransformer( |
32 const DisplayInfo& touch_display, const gfx::Size& fb_size) const { | 43 const DisplayInfo& touch_display, const gfx::Size& fb_size) const { |
33 gfx::Transform ctm; | 44 gfx::Transform ctm; |
34 if (touch_display.touch_device_id() == 0 || | 45 if (touch_display.touch_device_id() == 0 || |
35 fb_size.width() == 0.0 || | 46 fb_size.width() == 0.0 || |
36 fb_size.height() == 0.0) | 47 fb_size.height() == 0.0) |
37 return ctm; | 48 return ctm; |
38 float width = touch_display.bounds_in_native().width(); | 49 float width = touch_display.bounds_in_native().width(); |
39 float height = touch_display.bounds_in_native().height(); | 50 float height = touch_display.bounds_in_native().height(); |
40 ctm.Scale(width / fb_size.width(), height / fb_size.height()); | 51 ctm.Scale(width / fb_size.width(), height / fb_size.height()); |
41 return ctm; | 52 return ctm; |
42 } | 53 } |
43 | 54 |
44 bool TouchTransformerController::ShouldComputeMirrorModeTouchTransformer( | 55 bool TouchTransformerController::ShouldComputeMirrorModeTouchTransformer( |
45 const DisplayInfo& touch_display) const { | 56 const DisplayInfo& touch_display) const { |
46 if (force_compute_mirror_mode_touch_transformer_) | 57 if (force_compute_mirror_mode_touch_transformer_) |
47 return true; | 58 return true; |
48 | 59 |
49 if (touch_display.touch_device_id() == 0) | 60 if (touch_display.touch_device_id() == 0) |
50 return false; | 61 return false; |
51 | 62 |
52 const ui::DisplayConfigurator::DisplayState* state = NULL; | 63 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
53 const std::vector<ui::DisplayConfigurator::DisplayState>& cached_displays = | 64 const std::vector<gfx::Display>& displays = display_manager->displays(); |
54 Shell::GetInstance()->display_configurator()->cached_displays(); | 65 const DisplayInfo* info = NULL; |
55 for (size_t i = 0; i < cached_displays.size(); i++) { | 66 for (size_t i = 0; i < displays.size(); i++) { |
56 if (cached_displays[i].touch_device_id == touch_display.touch_device_id()) { | 67 const DisplayInfo& current_info = |
57 state = &cached_displays[i]; | 68 display_manager->GetDisplayInfo(displays[i].id()); |
69 if (current_info.touch_device_id() == touch_display.touch_device_id()) { | |
70 info = ¤t_info; | |
58 break; | 71 break; |
59 } | 72 } |
60 } | 73 } |
61 | 74 |
62 if (!state || state->mirror_mode == state->display->native_mode() || | 75 if (!info || info->size_in_pixel() == GetNativeModeSize(*info) || |
63 !state->display->is_aspect_preserving_scaling()) { | 76 !info->is_aspect_preserving_scaling()) { |
64 return false; | 77 return false; |
65 } | 78 } |
66 return true; | 79 return true; |
67 } | 80 } |
68 | 81 |
69 // This function computes the mirror mode TouchTransformer for |touch_display|. | 82 // This function computes the mirror mode TouchTransformer for |touch_display|. |
70 // When internal monitor is applied a resolution that does not have | 83 // When internal monitor is applied a resolution that does not have |
71 // the same aspect ratio as its native resolution, there would be | 84 // the same aspect ratio as its native resolution, there would be |
72 // blank regions in the letterboxing/pillarboxing mode. | 85 // blank regions in the letterboxing/pillarboxing mode. |
73 // The TouchTransformer will make sure the touch events on the blank region | 86 // The TouchTransformer will make sure the touch events on the blank region |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 | 233 |
221 void TouchTransformerController::OnDisplaysInitialized() { | 234 void TouchTransformerController::OnDisplaysInitialized() { |
222 UpdateTouchTransformer(); | 235 UpdateTouchTransformer(); |
223 } | 236 } |
224 | 237 |
225 void TouchTransformerController::OnDisplayConfigurationChanged() { | 238 void TouchTransformerController::OnDisplayConfigurationChanged() { |
226 UpdateTouchTransformer(); | 239 UpdateTouchTransformer(); |
227 } | 240 } |
228 | 241 |
229 } // namespace ash | 242 } // namespace ash |
OLD | NEW |