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

Side by Side Diff: chromeos/display/touchscreen_delegate_x11.cc

Issue 187073002: Refactoring display configuration state to allow generic state objects (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
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 "chromeos/display/touchscreen_delegate_x11.h" 5 #include "chromeos/display/touchscreen_delegate_x11.h"
6 6
7 #include <X11/extensions/XInput.h> 7 #include <X11/extensions/XInput.h>
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 9
10 #include <cmath> 10 #include <cmath>
11 #include <set> 11 #include <set>
12 12
13 #include "base/message_loop/message_pump_x11.h" 13 #include "base/message_loop/message_pump_x11.h"
14 #include "ui/display/chromeos/display_mode.h"
15 #include "ui/display/chromeos/display_snapshot.h"
14 16
15 namespace chromeos { 17 namespace chromeos {
16 18
17 TouchscreenDelegateX11::TouchscreenDelegateX11() 19 TouchscreenDelegateX11::TouchscreenDelegateX11()
18 : display_(base::MessagePumpX11::GetDefaultXDisplay()) {} 20 : display_(base::MessagePumpX11::GetDefaultXDisplay()) {}
19 21
20 TouchscreenDelegateX11::~TouchscreenDelegateX11() {} 22 TouchscreenDelegateX11::~TouchscreenDelegateX11() {}
21 23
22 void TouchscreenDelegateX11::AssociateTouchscreens( 24 void TouchscreenDelegateX11::AssociateTouchscreens(
23 std::vector<OutputConfigurator::OutputSnapshot>* outputs) { 25 std::vector<OutputConfigurator::InternalDisplayState>* outputs) {
24 int ndevices = 0; 26 int ndevices = 0;
25 Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False); 27 Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False);
26 Atom valuator_y = XInternAtom(display_, "Abs MT Position Y", False); 28 Atom valuator_y = XInternAtom(display_, "Abs MT Position Y", False);
27 if (valuator_x == None || valuator_y == None) 29 if (valuator_x == None || valuator_y == None)
28 return; 30 return;
29 31
30 std::set<int> no_match_touchscreen; 32 std::set<int> no_match_touchscreen;
31 XIDeviceInfo* info = XIQueryDevice(display_, XIAllDevices, &ndevices); 33 XIDeviceInfo* info = XIQueryDevice(display_, XIAllDevices, &ndevices);
32 for (int i = 0; i < ndevices; i++) { 34 for (int i = 0; i < ndevices; i++) {
33 if (!info[i].enabled || info[i].use != XIFloatingSlave) 35 if (!info[i].enabled || info[i].use != XIFloatingSlave)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 is_direct_touch = touch_info->mode == XIDirectTouch; 67 is_direct_touch = touch_info->mode == XIDirectTouch;
66 } 68 }
67 #endif 69 #endif
68 } 70 }
69 71
70 // Touchscreens should have absolute X and Y axes, 72 // Touchscreens should have absolute X and Y axes,
71 // and be direct touch devices. 73 // and be direct touch devices.
72 if (width > 0.0 && height > 0.0 && is_direct_touch) { 74 if (width > 0.0 && height > 0.0 && is_direct_touch) {
73 size_t k = 0; 75 size_t k = 0;
74 for (; k < outputs->size(); k++) { 76 for (; k < outputs->size(); k++) {
75 OutputConfigurator::OutputSnapshot* output = &(*outputs)[k]; 77 OutputConfigurator::InternalDisplayState* output = &(*outputs)[k];
76 if (output->native_mode == None || output->touch_device_id != None) 78 if (output->touch_device_id != None)
77 continue; 79 continue;
78 80
79 const OutputConfigurator::ModeInfo* mode_info = 81 const ui::DisplayMode* mode_info = output->display->native_mode();
80 OutputConfigurator::GetModeInfo(*output, output->native_mode);
81 if (!mode_info) 82 if (!mode_info)
82 continue; 83 continue;
83 84
84 // Allow 1 pixel difference between screen and touchscreen 85 // Allow 1 pixel difference between screen and touchscreen
85 // resolutions. Because in some cases for monitor resolution 86 // resolutions. Because in some cases for monitor resolution
86 // 1024x768 touchscreen's resolution would be 1024x768, but for 87 // 1024x768 touchscreen's resolution would be 1024x768, but for
87 // some 1023x767. It really depends on touchscreen's firmware 88 // some 1023x767. It really depends on touchscreen's firmware
88 // configuration. 89 // configuration.
89 if (std::abs(mode_info->width - width) <= 1.0 && 90 if (std::abs(mode_info->size().width() - width) <= 1.0 &&
90 std::abs(mode_info->height - height) <= 1.0) { 91 std::abs(mode_info->size().height() - height) <= 1.0) {
91 output->touch_device_id = info[i].deviceid; 92 output->touch_device_id = info[i].deviceid;
92 93
93 VLOG(2) << "Found touchscreen for output #" << k 94 VLOG(2) << "Found touchscreen for output #" << k
94 << " id " << output->touch_device_id 95 << " id " << output->touch_device_id
95 << " width " << width 96 << " width " << width
96 << " height " << height; 97 << " height " << height;
97 break; 98 break;
98 } 99 }
99 } 100 }
100 101
101 if (k == outputs->size()) { 102 if (k == outputs->size()) {
102 no_match_touchscreen.insert(info[i].deviceid); 103 no_match_touchscreen.insert(info[i].deviceid);
103 VLOG(2) << "No matching output for touchscreen" 104 VLOG(2) << "No matching output for touchscreen"
104 << " id " << info[i].deviceid 105 << " id " << info[i].deviceid
105 << " width " << width 106 << " width " << width
106 << " height " << height; 107 << " height " << height;
107 } 108 }
108 109
109 } 110 }
110 } 111 }
111 112
112 // Sometimes we can't find a matching screen for the touchscreen, e.g. 113 // Sometimes we can't find a matching screen for the touchscreen, e.g.
113 // due to the touchscreen's reporting range having no correlation with the 114 // due to the touchscreen's reporting range having no correlation with the
114 // screen's resolution. In this case, we arbitrarily assign unmatched 115 // screen's resolution. In this case, we arbitrarily assign unmatched
115 // touchscreens to unmatched screens. 116 // touchscreens to unmatched screens.
116 for (std::set<int>::iterator it = no_match_touchscreen.begin(); 117 for (std::set<int>::iterator it = no_match_touchscreen.begin();
117 it != no_match_touchscreen.end(); 118 it != no_match_touchscreen.end();
118 it++) { 119 it++) {
119 for (size_t i = 0; i < outputs->size(); i++) { 120 for (size_t i = 0; i < outputs->size(); i++) {
120 if ((*outputs)[i].type != ui::OUTPUT_TYPE_INTERNAL && 121 if ((*outputs)[i].display->type() != ui::OUTPUT_TYPE_INTERNAL &&
121 (*outputs)[i].native_mode != None && 122 (*outputs)[i].display->native_mode() != NULL &&
122 (*outputs)[i].touch_device_id == None) { 123 (*outputs)[i].touch_device_id == None) {
123 (*outputs)[i].touch_device_id = *it; 124 (*outputs)[i].touch_device_id = *it;
124 VLOG(2) << "Arbitrarily matching touchscreen " 125 VLOG(2) << "Arbitrarily matching touchscreen "
125 << (*outputs)[i].touch_device_id << " to output #" << i; 126 << (*outputs)[i].touch_device_id << " to output #" << i;
126 break; 127 break;
127 } 128 }
128 } 129 }
129 } 130 }
130 131
131 XIFreeDeviceInfo(info); 132 XIFreeDeviceInfo(info);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 format, 166 format,
166 PropModeReplace, 167 PropModeReplace,
167 reinterpret_cast<unsigned char*>(value), 168 reinterpret_cast<unsigned char*>(value),
168 9); 169 9);
169 } 170 }
170 } 171 }
171 XIFreeDeviceInfo(info); 172 XIFreeDeviceInfo(info);
172 } 173 }
173 174
174 } // namespace chromeos 175 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698