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

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

Issue 611423002: [WIP][Ozone] Support external touchscreens (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ozone-touchscreen
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
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 25 matching lines...) Expand all
36 double TouchTransformerController::GetTouchResolutionScale( 36 double TouchTransformerController::GetTouchResolutionScale(
37 const DisplayInfo& touch_display) const { 37 const DisplayInfo& touch_display) const {
38 if (touch_display.touch_device_id() == 0) 38 if (touch_display.touch_device_id() == 0)
39 return 1.0; 39 return 1.0;
40 40
41 double min_x, max_x; 41 double min_x, max_x;
42 double min_y, max_y; 42 double min_y, max_y;
43 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange( 43 if (!ui::DeviceDataManagerX11::GetInstance()->GetDataRange(
44 touch_display.touch_device_id(), 44 touch_display.touch_device_id(),
45 ui::DeviceDataManagerX11::DT_TOUCH_POSITION_X, 45 ui::DeviceDataManagerX11::DT_TOUCH_POSITION_X,
46 &min_x, &max_x) || 46 &min_x,
47 &max_x) ||
47 !ui::DeviceDataManagerX11::GetInstance()->GetDataRange( 48 !ui::DeviceDataManagerX11::GetInstance()->GetDataRange(
48 touch_display.touch_device_id(), 49 touch_display.touch_device_id(),
49 ui::DeviceDataManagerX11::DT_TOUCH_POSITION_Y, 50 ui::DeviceDataManagerX11::DT_TOUCH_POSITION_Y,
50 &min_y, &max_y)) { 51 &min_y,
52 &max_y)) {
51 return 1.0; 53 return 1.0;
52 } 54 }
53 55
54 double width = touch_display.bounds_in_native().width(); 56 double width = touch_display.bounds_in_native().width();
55 double height = touch_display.bounds_in_native().height(); 57 double height = touch_display.bounds_in_native().height();
56 58
57 if (max_x == 0.0 || max_y == 0.0 || width == 0.0 || height == 0.0) 59 if (max_x == 0.0 || max_y == 0.0 || width == 0.0 || height == 0.0)
58 return 1.0; 60 return 1.0;
59 61
60 // [0, max_x] -> touchscreen width = max_x + 1 62 // [0, max_x] -> touchscreen width = max_x + 1
61 // [0, max_y] -> touchscreen height = max_y + 1 63 // [0, max_y] -> touchscreen height = max_y + 1
62 max_x += 1.0; 64 max_x += 1.0;
63 max_y += 1.0; 65 max_y += 1.0;
64 66
65 double ratio = std::sqrt((width * height) / (max_x * max_y)); 67 double ratio = std::sqrt((width * height) / (max_x * max_y));
66 68
67 VLOG(2) << "Screen width/height: " << width << "/" << height 69 VLOG(2) << "Screen width/height: " << width << "/" << height
68 << ", Touchscreen width/height: " << max_x << "/" << max_y 70 << ", Touchscreen width/height: " << max_x << "/" << max_y
69 << ", Touch radius scale ratio: " << ratio; 71 << ", Touch radius scale ratio: " << ratio;
70 return ratio; 72 return ratio;
71 } 73 }
72 74
73 // This function computes the extended mode TouchTransformer for 75 // This function computes the extended mode TouchTransformer for
74 // |touch_display|. The TouchTransformer maps the touch event position 76 // |touch_display|. The TouchTransformer maps the touch event position
75 // from framebuffer size to the display size. 77 // from framebuffer size to the display size.
76 gfx::Transform 78 gfx::Transform TouchTransformerController::GetExtendedModeTouchTransformer(
77 TouchTransformerController::GetExtendedModeTouchTransformer( 79 const DisplayInfo& touch_display,
78 const DisplayInfo& touch_display, const gfx::Size& fb_size) const { 80 const gfx::Size& fb_size) const {
79 gfx::Transform ctm; 81 gfx::Transform ctm;
80 if (touch_display.touch_device_id() == 0 || 82 if (touch_display.touch_device_id() == 0 || fb_size.width() == 0.0 ||
81 fb_size.width() == 0.0 ||
82 fb_size.height() == 0.0) 83 fb_size.height() == 0.0)
83 return ctm; 84 return ctm;
84 float width = touch_display.bounds_in_native().width(); 85 float width = touch_display.bounds_in_native().width();
85 float height = touch_display.bounds_in_native().height(); 86 float height = touch_display.bounds_in_native().height();
86 ctm.Scale(width / fb_size.width(), height / fb_size.height()); 87 ctm.Scale(width / fb_size.width(), height / fb_size.height());
87 return ctm; 88 return ctm;
88 } 89 }
89 90
90 bool TouchTransformerController::ShouldComputeMirrorModeTouchTransformer( 91 bool TouchTransformerController::ShouldComputeMirrorModeTouchTransformer(
91 const DisplayInfo& touch_display) const { 92 const DisplayInfo& touch_display) const {
(...skipping 23 matching lines...) Expand all
115 gfx::Transform ctm; 116 gfx::Transform ctm;
116 if (!ShouldComputeMirrorModeTouchTransformer(touch_display)) 117 if (!ShouldComputeMirrorModeTouchTransformer(touch_display))
117 return ctm; 118 return ctm;
118 119
119 float mirror_width = touch_display.bounds_in_native().width(); 120 float mirror_width = touch_display.bounds_in_native().width();
120 float mirror_height = touch_display.bounds_in_native().height(); 121 float mirror_height = touch_display.bounds_in_native().height();
121 gfx::Size native_mode_size = touch_display.GetNativeModeSize(); 122 gfx::Size native_mode_size = touch_display.GetNativeModeSize();
122 float native_width = native_mode_size.width(); 123 float native_width = native_mode_size.width();
123 float native_height = native_mode_size.height(); 124 float native_height = native_mode_size.height();
124 125
125 if (native_height == 0.0 || mirror_height == 0.0 || 126 if (native_height == 0.0 || mirror_height == 0.0 || native_width == 0.0 ||
126 native_width == 0.0 || mirror_width == 0.0) 127 mirror_width == 0.0)
127 return ctm; 128 return ctm;
128 129
129 float native_ar = native_width / native_height; 130 float native_ar = native_width / native_height;
130 float mirror_ar = mirror_width / mirror_height; 131 float mirror_ar = mirror_width / mirror_height;
131 132
132 if (mirror_ar > native_ar) { // Letterboxing 133 if (mirror_ar > native_ar) { // Letterboxing
133 // Translate before scale. 134 // Translate before scale.
134 ctm.Translate(0.0, (1.0 - mirror_ar / native_ar) * 0.5 * mirror_height); 135 ctm.Translate(0.0, (1.0 - mirror_ar / native_ar) * 0.5 * mirror_height);
135 ctm.Scale(1.0, mirror_ar / native_ar); 136 ctm.Scale(1.0, mirror_ar / native_ar);
136 return ctm; 137 return ctm;
137 } 138 }
138 139
139 if (native_ar > mirror_ar) { // Pillarboxing 140 if (native_ar > mirror_ar) { // Pillarboxing
140 // Translate before scale. 141 // Translate before scale.
141 ctm.Translate((1.0 - native_ar / mirror_ar) * 0.5 * mirror_width, 0.0); 142 ctm.Translate((1.0 - native_ar / mirror_ar) * 0.5 * mirror_width, 0.0);
142 ctm.Scale(native_ar / mirror_ar, 1.0); 143 ctm.Scale(native_ar / mirror_ar, 1.0);
143 return ctm; 144 return ctm;
144 } 145 }
145 146
146 return ctm; // Same aspect ratio - return identity 147 return ctm; // Same aspect ratio - return identity
147 } 148 }
148 149
149 TouchTransformerController::TouchTransformerController() : 150 TouchTransformerController::TouchTransformerController()
150 force_compute_mirror_mode_touch_transformer_ (false) { 151 : force_compute_mirror_mode_touch_transformer_(false) {
151 Shell::GetInstance()->display_controller()->AddObserver(this); 152 Shell::GetInstance()->display_controller()->AddObserver(this);
152 } 153 }
153 154
154 TouchTransformerController::~TouchTransformerController() { 155 TouchTransformerController::~TouchTransformerController() {
155 Shell::GetInstance()->display_controller()->RemoveObserver(this); 156 Shell::GetInstance()->display_controller()->RemoveObserver(this);
156 } 157 }
157 158
158 void TouchTransformerController::UpdateTouchTransformer() const { 159 void TouchTransformerController::UpdateTouchTransformer() const {
159 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance(); 160 ui::DeviceDataManager* device_manager = ui::DeviceDataManager::GetInstance();
160 device_manager->ClearTouchTransformerRecord(); 161 device_manager->ClearTouchTransformerRecord();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 display2.touch_device_id(), 213 display2.touch_device_id(),
213 GetMirrorModeTouchTransformer(display2)); 214 GetMirrorModeTouchTransformer(display2));
214 return; 215 return;
215 } 216 }
216 217
217 if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) { 218 if (display_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED) {
218 gfx::Size fb_size = 219 gfx::Size fb_size =
219 Shell::GetInstance()->display_configurator()->framebuffer_size(); 220 Shell::GetInstance()->display_configurator()->framebuffer_size();
220 // In extended but software mirroring mode, ther is only one X root window 221 // In extended but software mirroring mode, ther is only one X root window
221 // that associates with both displays. 222 // that associates with both displays.
222 if (GetDisplayManager()->software_mirroring_enabled()) { 223 if (GetDisplayManager()->software_mirroring_enabled()) {
223 aura::Window* root = display_controller->GetPrimaryRootWindow(); 224 aura::Window* root = display_controller->GetPrimaryRootWindow();
224 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID( 225 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID(
225 display1_id, display2_id); 226 display1_id, display2_id);
226 DisplayInfo source_display = 227 DisplayInfo source_display =
227 gfx::Display::InternalDisplayId() == display1_id ? 228 gfx::Display::InternalDisplayId() == display1_id ? display1
228 display1 : display2; 229 : display2;
229 // Mapping from framebuffer size to the source display's native 230 // Mapping from framebuffer size to the source display's native
230 // resolution. 231 // resolution.
231 device_manager->UpdateTouchInfoForDisplay( 232 device_manager->UpdateTouchInfoForDisplay(
232 display1_id, 233 display1_id,
233 display1.touch_device_id(), 234 display1.touch_device_id(),
234 GetExtendedModeTouchTransformer(source_display, fb_size)); 235 GetExtendedModeTouchTransformer(source_display, fb_size));
235 device_manager->UpdateTouchInfoForDisplay( 236 device_manager->UpdateTouchInfoForDisplay(
236 display2_id, 237 display2_id,
237 display2.touch_device_id(), 238 display2.touch_device_id(),
238 GetExtendedModeTouchTransformer(source_display, fb_size)); 239 GetExtendedModeTouchTransformer(source_display, fb_size));
(...skipping 19 matching lines...) Expand all
258 GetExtendedModeTouchTransformer(display2, fb_size)); 259 GetExtendedModeTouchTransformer(display2, fb_size));
259 } 260 }
260 return; 261 return;
261 } 262 }
262 263
263 // Single display mode. The root window has one associated display id. 264 // Single display mode. The root window has one associated display id.
264 aura::Window* root = 265 aura::Window* root =
265 display_controller->GetRootWindowForDisplayId(single_display.id()); 266 display_controller->GetRootWindowForDisplayId(single_display.id());
266 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID( 267 RootWindowController::ForWindow(root)->ash_host()->UpdateDisplayID(
267 single_display.id(), gfx::Display::kInvalidDisplayID); 268 single_display.id(), gfx::Display::kInvalidDisplayID);
268 device_manager->UpdateTouchInfoForDisplay(single_display_id, 269 device_manager->UpdateTouchInfoForDisplay(
269 single_display.touch_device_id(), 270 single_display_id, single_display.touch_device_id(), gfx::Transform());
270 gfx::Transform());
271 } 271 }
272 272
273 void TouchTransformerController::OnDisplaysInitialized() { 273 void TouchTransformerController::OnDisplaysInitialized() {
274 UpdateTouchTransformer(); 274 UpdateTouchTransformer();
275 } 275 }
276 276
277 void TouchTransformerController::OnDisplayConfigurationChanged() { 277 void TouchTransformerController::OnDisplayConfigurationChanged() {
278 UpdateTouchTransformer(); 278 UpdateTouchTransformer();
279 } 279 }
280 280
281 } // namespace ash 281 } // namespace ash
OLDNEW
« no previous file with comments | « ash/touch/touch_transformer_controller_ozone.cc ('k') | ui/events/ozone/evdev/touch_event_converter_evdev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698