Since we never actually read more than one mouse_movement at a time and we only
ever wait for reports on demand, there's no need for buffering at all. This removes some unnecessary copying and ring buffer overhead, the ring buffer will now in fact not be created at all. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41864 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
4787582ad1
commit
23249681ab
@ -25,7 +25,7 @@
|
|||||||
MouseProtocolHandler::MouseProtocolHandler(HIDReport &report,
|
MouseProtocolHandler::MouseProtocolHandler(HIDReport &report,
|
||||||
HIDReportItem &xAxis, HIDReportItem &yAxis)
|
HIDReportItem &xAxis, HIDReportItem &yAxis)
|
||||||
:
|
:
|
||||||
ProtocolHandler(report.Device(), "input/mouse/usb/", 512),
|
ProtocolHandler(report.Device(), "input/mouse/usb/", 0),
|
||||||
fReport(report),
|
fReport(report),
|
||||||
fXAxis(xAxis),
|
fXAxis(xAxis),
|
||||||
fYAxis(yAxis),
|
fYAxis(yAxis),
|
||||||
@ -106,24 +106,29 @@ MouseProtocolHandler::AddHandlers(HIDDevice &device, HIDCollection &collection,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
MouseProtocolHandler::Control(uint32 *cookie, uint32 op, void *buffer, size_t length)
|
MouseProtocolHandler::Control(uint32 *cookie, uint32 op, void *buffer,
|
||||||
|
size_t length)
|
||||||
{
|
{
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case MS_READ:
|
case MS_READ:
|
||||||
while (RingBufferReadable() == 0) {
|
{
|
||||||
status_t result = _ReadReport();
|
if (length < sizeof(mouse_movement))
|
||||||
if (result != B_OK)
|
return B_BUFFER_OVERFLOW;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
status_t result = _ReadReport(buffer);
|
||||||
|
if (result != B_INTERRUPTED)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return RingBufferRead(buffer, sizeof(mouse_movement));
|
|
||||||
|
|
||||||
case MS_NUM_EVENTS:
|
case MS_NUM_EVENTS:
|
||||||
{
|
{
|
||||||
int32 count = RingBufferReadable() / sizeof(mouse_movement);
|
if (fReport.Device()->IsRemoved())
|
||||||
if (count == 0 && fReport.Device()->IsRemoved())
|
|
||||||
return B_DEV_NOT_READY;
|
return B_DEV_NOT_READY;
|
||||||
return count;
|
|
||||||
|
// we are always on demand, so 0 queued events
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MS_SET_CLICKSPEED:
|
case MS_SET_CLICKSPEED:
|
||||||
@ -140,7 +145,7 @@ MouseProtocolHandler::Control(uint32 *cookie, uint32 op, void *buffer, size_t le
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
MouseProtocolHandler::_ReadReport()
|
MouseProtocolHandler::_ReadReport(void *buffer)
|
||||||
{
|
{
|
||||||
status_t result = fReport.WaitForReport(B_INFINITE_TIMEOUT);
|
status_t result = fReport.WaitForReport(B_INFINITE_TIMEOUT);
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
@ -156,19 +161,19 @@ MouseProtocolHandler::_ReadReport()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// signal that we simply want to try again
|
// signal that we simply want to try again
|
||||||
return B_OK;
|
return B_INTERRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse_movement info;
|
mouse_movement *info = (mouse_movement *)buffer;
|
||||||
memset(&info, 0, sizeof(info));
|
memset(info, 0, sizeof(mouse_movement));
|
||||||
|
|
||||||
if (fXAxis.Extract() == B_OK && fXAxis.Valid())
|
if (fXAxis.Extract() == B_OK && fXAxis.Valid())
|
||||||
info.xdelta = fXAxis.Data();
|
info->xdelta = fXAxis.Data();
|
||||||
if (fYAxis.Extract() == B_OK && fYAxis.Valid())
|
if (fYAxis.Extract() == B_OK && fYAxis.Valid())
|
||||||
info.ydelta = -fYAxis.Data();
|
info->ydelta = -fYAxis.Data();
|
||||||
|
|
||||||
if (fWheel != NULL && fWheel->Extract() == B_OK && fWheel->Valid())
|
if (fWheel != NULL && fWheel->Extract() == B_OK && fWheel->Valid())
|
||||||
info.wheel_ydelta = -fWheel->Data();
|
info->wheel_ydelta = -fWheel->Data();
|
||||||
|
|
||||||
for (uint32 i = 0; i < B_MAX_MOUSE_BUTTONS; i++) {
|
for (uint32 i = 0; i < B_MAX_MOUSE_BUTTONS; i++) {
|
||||||
HIDReportItem *button = fButtons[i];
|
HIDReportItem *button = fButtons[i];
|
||||||
@ -176,14 +181,14 @@ MouseProtocolHandler::_ReadReport()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (button->Extract() == B_OK && button->Valid())
|
if (button->Extract() == B_OK && button->Valid())
|
||||||
info.buttons |= (button->Data() & 1) << (button->UsageID() - 1);
|
info->buttons |= (button->Data() & 1) << (button->UsageID() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fReport.DoneProcessing();
|
fReport.DoneProcessing();
|
||||||
TRACE("got mouse report\n");
|
TRACE("got mouse report\n");
|
||||||
|
|
||||||
bigtime_t timestamp = system_time();
|
bigtime_t timestamp = system_time();
|
||||||
if (info.buttons != 0) {
|
if (info->buttons != 0) {
|
||||||
if (fLastButtons == 0) {
|
if (fLastButtons == 0) {
|
||||||
if (fLastClickTime + fClickSpeed > timestamp)
|
if (fLastClickTime + fClickSpeed > timestamp)
|
||||||
fClickCount++;
|
fClickCount++;
|
||||||
@ -192,10 +197,10 @@ MouseProtocolHandler::_ReadReport()
|
|||||||
}
|
}
|
||||||
|
|
||||||
fLastClickTime = timestamp;
|
fLastClickTime = timestamp;
|
||||||
info.clicks = fClickCount;
|
info->clicks = fClickCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
fLastButtons = info.buttons;
|
fLastButtons = info->buttons;
|
||||||
info.timestamp = timestamp;
|
info->timestamp = timestamp;
|
||||||
return RingBufferWrite(&info, sizeof(mouse_movement));
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,8 @@ public:
|
|||||||
size_t length);
|
size_t length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _ReadReport();
|
status_t _ReadReport(void *buffer);
|
||||||
|
|
||||||
private:
|
|
||||||
HIDReport & fReport;
|
HIDReport & fReport;
|
||||||
|
|
||||||
HIDReportItem & fXAxis;
|
HIDReportItem & fXAxis;
|
||||||
|
Loading…
Reference in New Issue
Block a user