diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index b080e99..d29092d 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -177,12 +177,15 @@ size_t InputHub::GetEvents(RawEvent* buffer, size_t bufferSize) } continue; } + struct input_event readBuffer[bufferSize]; + int32_t readSize = read(eventItem.data.fd, readBuffer, sizeof(struct input_event) * capacity); + size_t count = ReadInputEvent(readSize, *GetDeviceByFdLocked(eventItem.data.fd)); Device* device = GetSupportDeviceByFd(eventItem.data.fd); if (!device) { continue; } if (eventItem.events & EPOLLIN) { - event += CollectEvent(event, capacity, bufferSize, device); + event += CollectEvent(event, capacity, device, readBuffer, count); if (capacity == 0) { pendingEventIndex_ -= 1; @@ -197,17 +200,10 @@ size_t InputHub::GetEvents(RawEvent* buffer, size_t bufferSize) return event - buffer; } -size_t InputHub::CollectEvent(RawEvent* buffer, size_t& capacity, size_t bufferSize, Device* device) +size_t InputHub::CollectEvent(RawEvent* buffer, size_t& capacity, Device* device, struct input_event readBuffer[], + const size_t count) { - struct input_event readBuffer[bufferSize]; - if (bufferSize < capacity) { - DHLOGE("capacity: %d should not lager than bufferSize: %d\n", capacity, bufferSize); - return 0; - } - int32_t readSize = read(device->fd, readBuffer, sizeof(struct input_event) * capacity); - size_t count = ReadInputEvent(readSize, *device); - - std::vector needFilted(bufferSize, false); + std::vector needFilted(capacity, false); if (device->classes == INPUT_DEVICE_CLASS_TOUCH_MT) { HandleTouchScreenEvent(readBuffer, count, needFilted, device); } diff --git a/common/include/input_hub.h b/common/include/input_hub.h index bdb948c..2514a6a 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -118,7 +118,8 @@ private: Device* device); int32_t QueryLocalTouchScreenInfo(int fd); bool CheckTouchPointRegion(struct input_event readBuffer[], const AbsInfo& absInfo, Device* device); - size_t CollectEvent(RawEvent* buffer, size_t& capacity, size_t bufferSize, Device* device); + size_t CollectEvent(RawEvent* buffer, size_t& capacity, Device* device, struct input_event readBuffer[], + const size_t count); int epollFd_; int iNotifyFd_;