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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 bool TouchTransformerController::ShouldComputeMirrorModeTouchTransformer( | 90 bool TouchTransformerController::ShouldComputeMirrorModeTouchTransformer( |
91 const DisplayInfo& touch_display) const { | 91 const DisplayInfo& touch_display) const { |
92 if (force_compute_mirror_mode_touch_transformer_) | 92 if (force_compute_mirror_mode_touch_transformer_) |
93 return true; | 93 return true; |
94 | 94 |
95 if (touch_display.touch_device_id() == 0) | 95 if (touch_display.touch_device_id() == 0) |
96 return false; | 96 return false; |
97 | 97 |
98 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 98 if (touch_display.size_in_pixel() == touch_display.GetNativeModeSize() || |
99 const std::vector<gfx::Display>& displays = display_manager->displays(); | 99 !touch_display.is_aspect_preserving_scaling()) { |
100 const DisplayInfo* info = NULL; | 100 return false; |
101 for (size_t i = 0; i < displays.size(); i++) { | |
102 const DisplayInfo& current_info = | |
103 display_manager->GetDisplayInfo(displays[i].id()); | |
104 if (current_info.touch_device_id() == touch_display.touch_device_id()) { | |
105 info = ¤t_info; | |
106 break; | |
107 } | |
108 } | 101 } |
109 | 102 |
110 if (!info || info->size_in_pixel() == info->GetNativeModeSize() || | |
111 !info->is_aspect_preserving_scaling()) { | |
112 return false; | |
113 } | |
114 return true; | 103 return true; |
115 } | 104 } |
116 | 105 |
117 // This function computes the mirror mode TouchTransformer for |touch_display|. | 106 // This function computes the mirror mode TouchTransformer for |touch_display|. |
118 // When internal monitor is applied a resolution that does not have | 107 // When internal monitor is applied a resolution that does not have |
119 // the same aspect ratio as its native resolution, there would be | 108 // the same aspect ratio as its native resolution, there would be |
120 // blank regions in the letterboxing/pillarboxing mode. | 109 // blank regions in the letterboxing/pillarboxing mode. |
121 // The TouchTransformer will make sure the touch events on the blank region | 110 // The TouchTransformer will make sure the touch events on the blank region |
122 // have negative coordinates and touch events within the chrome region | 111 // have negative coordinates and touch events within the chrome region |
123 // have the correct positive coordinates. | 112 // have the correct positive coordinates. |
124 gfx::Transform TouchTransformerController::GetMirrorModeTouchTransformer( | 113 gfx::Transform TouchTransformerController::GetMirrorModeTouchTransformer( |
125 const DisplayInfo& touch_display) const { | 114 const DisplayInfo& touch_display) const { |
126 gfx::Transform ctm; | 115 gfx::Transform ctm; |
127 if (!ShouldComputeMirrorModeTouchTransformer(touch_display)) | 116 if (!ShouldComputeMirrorModeTouchTransformer(touch_display)) |
128 return ctm; | 117 return ctm; |
129 | 118 |
130 float mirror_width = touch_display.bounds_in_native().width(); | 119 float mirror_width = touch_display.bounds_in_native().width(); |
131 float mirror_height = touch_display.bounds_in_native().height(); | 120 float mirror_height = touch_display.bounds_in_native().height(); |
132 float native_width = 0; | 121 gfx::Size native_mode_size = touch_display.GetNativeModeSize(); |
133 float native_height = 0; | 122 float native_width = native_mode_size.width(); |
134 | 123 float native_height = native_mode_size.height(); |
135 std::vector<DisplayMode> modes = touch_display.display_modes(); | |
136 for (size_t i = 0; i < modes.size(); i++) { | |
137 if (modes[i].native) { | |
138 native_width = modes[i].size.width(); | |
139 native_height = modes[i].size.height(); | |
140 break; | |
141 } | |
142 } | |
143 | 124 |
144 if (native_height == 0.0 || mirror_height == 0.0 || | 125 if (native_height == 0.0 || mirror_height == 0.0 || |
145 native_width == 0.0 || mirror_width == 0.0) | 126 native_width == 0.0 || mirror_width == 0.0) |
146 return ctm; | 127 return ctm; |
147 | 128 |
148 float native_ar = static_cast<float>(native_width) / | 129 float native_ar = native_width / native_height; |
149 static_cast<float>(native_height); | 130 float mirror_ar = mirror_width / mirror_height; |
150 float mirror_ar = static_cast<float>(mirror_width) / | |
151 static_cast<float>(mirror_height); | |
152 | 131 |
153 if (mirror_ar > native_ar) { // Letterboxing | 132 if (mirror_ar > native_ar) { // Letterboxing |
154 // Translate before scale. | 133 // Translate before scale. |
155 ctm.Translate(0.0, (1.0 - mirror_ar / native_ar) * 0.5 * mirror_height); | 134 ctm.Translate(0.0, (1.0 - mirror_ar / native_ar) * 0.5 * mirror_height); |
156 ctm.Scale(1.0, mirror_ar / native_ar); | 135 ctm.Scale(1.0, mirror_ar / native_ar); |
157 return ctm; | 136 return ctm; |
158 } | 137 } |
159 | 138 |
160 if (native_ar > mirror_ar) { // Pillarboxing | 139 if (native_ar > mirror_ar) { // Pillarboxing |
161 // Translate before scale. | 140 // Translate before scale. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 272 |
294 void TouchTransformerController::OnDisplaysInitialized() { | 273 void TouchTransformerController::OnDisplaysInitialized() { |
295 UpdateTouchTransformer(); | 274 UpdateTouchTransformer(); |
296 } | 275 } |
297 | 276 |
298 void TouchTransformerController::OnDisplayConfigurationChanged() { | 277 void TouchTransformerController::OnDisplayConfigurationChanged() { |
299 UpdateTouchTransformer(); | 278 UpdateTouchTransformer(); |
300 } | 279 } |
301 | 280 |
302 } // namespace ash | 281 } // namespace ash |
OLD | NEW |