Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: ash/touch/touch_transformer_controller.cc

Issue 635403002: Preserve the native mode when parsing external display modes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-hotplug-in-mirror-mode
Patch Set: . Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/display/display_change_observer_chromeos_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = &current_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
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
OLDNEW
« no previous file with comments | « ash/display/display_change_observer_chromeos_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698