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

Side by Side Diff: ui/base/touch/touch_factory.cc

Issue 8070003: touchui: Convert XI2 MT tracking id to slot id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/touch/touch_factory.h ('k') | views/events/event_x.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/base/touch/touch_factory.h" 5 #include "ui/base/touch/touch_factory.h"
6 6
7 #include <X11/cursorfont.h> 7 #include <X11/cursorfont.h>
8 #include <X11/extensions/XInput.h> 8 #include <X11/extensions/XInput.h>
9 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
10 #include <X11/extensions/XIproto.h> 10 #include <X11/extensions/XIproto.h>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // static 128 // static
129 TouchFactory* TouchFactory::GetInstance() { 129 TouchFactory* TouchFactory::GetInstance() {
130 return Singleton<TouchFactory>::get(); 130 return Singleton<TouchFactory>::get();
131 } 131 }
132 132
133 TouchFactory::TouchFactory() 133 TouchFactory::TouchFactory()
134 : is_cursor_visible_(true), 134 : is_cursor_visible_(true),
135 keep_mouse_cursor_(false), 135 keep_mouse_cursor_(false),
136 cursor_timer_(), 136 cursor_timer_(),
137 pointer_device_lookup_(), 137 pointer_device_lookup_(),
138 touch_device_list_(),
138 #if defined(USE_XI2_MT) 139 #if defined(USE_XI2_MT)
139 touch_device_list_() { 140 min_available_slot_(0),
140 #else 141 #endif
141 touch_device_list_(),
142 slots_used_() { 142 slots_used_() {
143 #endif
144 #if defined(TOUCH_UI) 143 #if defined(TOUCH_UI)
145 if (!base::MessagePumpForUI::HasXInput2()) 144 if (!base::MessagePumpForUI::HasXInput2())
146 return; 145 return;
147 #endif 146 #endif
148 147
149 char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 148 char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
150 XColor black; 149 XColor black;
151 black.red = black.green = black.blue = 0; 150 black.red = black.green = black.blue = 0;
152 Display* display = ui::GetXDisplay(); 151 Display* display = ui::GetXDisplay();
153 Pixmap blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), 152 Pixmap blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 touch_device_lookup_[deviceid] : false; 327 touch_device_lookup_[deviceid] : false;
329 } 328 }
330 329
331 bool TouchFactory::IsRealTouchDevice(unsigned int deviceid) const { 330 bool TouchFactory::IsRealTouchDevice(unsigned int deviceid) const {
332 return (deviceid < touch_device_lookup_.size() && 331 return (deviceid < touch_device_lookup_.size() &&
333 touch_device_lookup_[deviceid]) ? 332 touch_device_lookup_[deviceid]) ?
334 touch_device_list_.find(deviceid)->second : 333 touch_device_list_.find(deviceid)->second :
335 false; 334 false;
336 } 335 }
337 336
338 #if !defined(USE_XI2_MT) 337 #if defined(USE_XI2_MT)
338 int TouchFactory::GetSlotForTrackingID(uint32 tracking_id) {
339 TrackingIdMap::iterator itr = tracking_id_map_.find(tracking_id);
340 if (itr != tracking_id_map_.end())
341 return itr->second;
342
343 int slot = min_available_slot_;
344 if (slot == kMaxTouchPoints) {
345 LOG(ERROR) << "Could not find available slot for touch point";
346 return 0;
347 }
348 SetSlotUsed(slot, true);
349 tracking_id_map_.insert(std::make_pair(tracking_id, slot));
350
351 // Updates the minium available slot ID
352 while (++min_available_slot_ < kMaxTouchPoints &&
353 IsSlotUsed(min_available_slot_))
354 continue;
355
356 return slot;
357 }
358
359 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) {
360 TrackingIdMap::iterator itr = tracking_id_map_.find(tracking_id);
361 if (itr != tracking_id_map_.end()) {
362 int slot = itr->second;
363 SetSlotUsed(slot, false);
364 tracking_id_map_.erase(itr);
365 if (slot < min_available_slot_)
366 min_available_slot_ = slot;
367 } else {
368 NOTREACHED() << "Cannot find slot mapping to tracking ID " << tracking_id;
369 }
370 }
371 #endif
372
339 bool TouchFactory::IsSlotUsed(int slot) const { 373 bool TouchFactory::IsSlotUsed(int slot) const {
340 CHECK_LT(slot, kMaxTouchPoints); 374 CHECK_LT(slot, kMaxTouchPoints);
341 return slots_used_[slot]; 375 return slots_used_[slot];
342 } 376 }
343 377
344 void TouchFactory::SetSlotUsed(int slot, bool used) { 378 void TouchFactory::SetSlotUsed(int slot, bool used) {
345 CHECK_LT(slot, kMaxTouchPoints); 379 CHECK_LT(slot, kMaxTouchPoints);
346 slots_used_[slot] = used; 380 slots_used_[slot] = used;
347 } 381 }
348 #endif
349 382
350 bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) { 383 bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) {
351 #if defined(TOUCH_UI) 384 #if defined(TOUCH_UI)
352 if (!base::MessagePumpForUI::HasXInput2() || 385 if (!base::MessagePumpForUI::HasXInput2() ||
353 touch_device_list_.empty()) 386 touch_device_list_.empty())
354 return true; 387 return true;
355 #endif 388 #endif
356 389
357 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; 390 unsigned char mask[XIMaskLen(XI_LASTEVENT)];
358 bool success = true; 391 bool success = true;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 float* max) { 534 float* max) {
502 if (valuator_lookup_[deviceid][tp] >= 0) { 535 if (valuator_lookup_[deviceid][tp] >= 0) {
503 *min = touch_param_min_[deviceid][tp]; 536 *min = touch_param_min_[deviceid][tp];
504 *max = touch_param_max_[deviceid][tp]; 537 *max = touch_param_max_[deviceid][tp];
505 return true; 538 return true;
506 } 539 }
507 return false; 540 return false;
508 } 541 }
509 542
510 } // namespace ui 543 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/touch/touch_factory.h ('k') | views/events/event_x.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698