From 10880753300b9f8290e060510aac7a9252d0813b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=AF=E6=AD=8C?= Date: Sun, 28 Apr 2024 21:32:21 +0800 Subject: [PATCH] motionevent history suuported --- src/gui/core/inputdevice.cc | 75 ++++++++++++++++++------------- src/gui/core/inputdevice.h | 2 + src/porting/common/input_linux.cc | 4 +- tests/gui/motion_tests.cc | 63 +++++++++++++------------- 4 files changed, 79 insertions(+), 65 deletions(-) diff --git a/src/gui/core/inputdevice.cc b/src/gui/core/inputdevice.cc index 1dcf91c1..ce46560e 100644 --- a/src/gui/core/inputdevice.cc +++ b/src/gui/core/inputdevice.cc @@ -325,6 +325,8 @@ TouchDevice::TouchDevice(int fd):InputDevice(fd){ mLastBits.clear(); mCurrBits.clear(); mEvent = nullptr; + mActionButton = 0; + mButtonState = 0; mDeviceInfo.addSource(SOURCE_CLASS_POINTER); LOGI("screen(%d,%d) rotation=%d [%s] X(%d,%d) Y(%d,%d) invert=%d,%d switchXY=%d",mScreenWidth, mScreenHeight, display.getRotation(),section.c_str(),mMinX,mMaxX,mMinY,mMaxY,mInvertX,mInvertY,mSwitchXY); @@ -447,7 +449,7 @@ int TouchDevice::getActionByBits(int& pointIndex){ int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value){ if(!isValidEvent(type,code,value))return -1; - int pointIndex,eventAction; + int pointIndex,action; LOGV("%lu:%04u %d,%d,%d",tv.tv_sec,tv.tv_usec,type,code,value); switch(type){ case EV_KEY: @@ -455,24 +457,24 @@ int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value switch(code){ case BTN_TOUCH : case BTN_STYLUS: - //mEvent.setActionButton(MotionEvent::BUTTON_PRIMARY); + mActionButton = MotionEvent::BUTTON_PRIMARY; if(value)mCurrBits.markBit(0);else mCurrBits.clearBit(0); if(value){ mMoveTime = mDownTime = tv.tv_sec * 1000 + tv.tv_usec/1000; - //mEvent.setButtonState(MotionEvent::BUTTON_PRIMARY); + mButtonState = MotionEvent::BUTTON_PRIMARY; }else{ mMoveTime = tv.tv_sec * 1000 + tv.tv_usec/1000; - //mEvent.setButtonState(mEvent.getButtonState()&(~MotionEvent::BUTTON_PRIMARY)); + mButtonState &= ~MotionEvent::BUTTON_PRIMARY; } break; case BTN_0: case BTN_STYLUS2: - /*mEvent.setActionButton(MotionEvent::BUTTON_SECONDARY); + mActionButton = MotionEvent::BUTTON_SECONDARY; if(value) - mEvent.setButtonState(MotionEvent::BUTTON_SECONDARY); + mButtonState = MotionEvent::BUTTON_SECONDARY; else - mEvent.setButtonState(mEvent.getButtonState()&(~MotionEvent::BUTTON_SECONDARY)); - break;*/ + mButtonState &= ~MotionEvent::BUTTON_SECONDARY; + break; case BTN_TOOL_FINGER:break; }break; case EV_ABS: @@ -492,8 +494,7 @@ int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value switch(code){ case SYN_MT_REPORT:break; case SYN_REPORT: - eventAction = getActionByBits(pointIndex); - LOGD_IF(eventAction!=2,"mask=%08x,%08x eventAction=%d pointIndex=%d",mLastBits.value,mCurrBits.value,eventAction,pointIndex); + action = getActionByBits(pointIndex); mMoveTime =(tv.tv_sec * 1000LL + tv.tv_usec/1000); { int pointerCount = 0; @@ -504,29 +505,39 @@ int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value props [pointerCount] = p.second.prop; pointerCount ++; } - if(mEvent!=nullptr)mEvent->recycle(); - mEvent = MotionEvent::obtain(mMoveTime,mMoveTime, - eventAction|(pointIndex<getX(pointIndex),mEvent->getY(pointIndex)); - if( eventAction == MotionEvent::ACTION_MOVE ) { - MotionEvent*last = mEvents.size() ? (MotionEvent*)mEvents.back() : nullptr; - if(0&&last&&(last->getAction()==MotionEvent::ACTION_MOVE)&&(mMoveTime-last->getEventTime()<20)){ - //the same positioned moveing ,skip this event - mEvents.pop_back(); - mEvents.push_back(MotionEvent::obtain(last->getDownTime(),last->getEventTime(), - last->getAction(),mEvent->getX(),mEvent->getY(),last->getMetaState())); - last->recycle(); - LOGV("%lld,%lld,%d events",mMoveTime,last->getEventTime(),mEvents.size()); - break; - } + if( (mEvent==nullptr)||(mEvent && (action!=MotionEvent::ACTION_MOVE)) ){ + if(mEvent) mEvent->recycle(); + mEvent = MotionEvent::obtain(mMoveTime,mMoveTime, + action|(pointIndex<setActionButton(mActionButton); + }else { +#if 0 + MotionEvent*ne = MotionEvent::obtain(*mEvent); + mEvent->recycle(); + mEvent = ne; + mEvent->addSample(mMoveTime,coords); +#else + MotionEvent*ne = mEvents.size()?(MotionEvent*)mEvents.back():nullptr; + if(ne&&ne->getActionMasked()==MotionEvent::ACTION_MOVE){ + mEvent->addSample(mMoveTime,coords); + goto CLEAR_END; + }else{ + ne = MotionEvent::obtain(*mEvent); + mEvent->recycle(); + mEvent = ne; + mEvent->addSample(mMoveTime,coords); + } +#endif + } + mEvent->setAction(action|(pointIndex<getX(pointIndex),mEvent->getY(pointIndex)); if( mLastBits.count() > mCurrBits.count() ){ const uint32_t pointerIndex = BitSet32::firstMarkedBit(mLastBits.value^mCurrBits.value); - LOGV("clearbits %d %08x,%08x",pointerIndex,mLastBits.value,mCurrBits.value); + LOGD("clearbits %d %08x,%08x",pointerIndex,mLastBits.value,mCurrBits.value); mCurrBits.clearBit(pointIndex); auto it = mTrack2Slot.find(pointerIndex); if( it != mTrack2Slot.end() )mTrack2Slot.erase(it); @@ -540,6 +551,7 @@ int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value MotionEvent*e = MotionEvent::obtain(*mEvent); mEvents.push_back(e); } +CLEAR_END: mLastBits.value = mCurrBits.value; if( (mDeviceClasses&INPUT_DEVICE_CLASS_TOUCH_MT) && (mTypeB==false) ){ mCurrBits.clear();//only typeA @@ -649,8 +661,7 @@ static void appendInputDeviceConfigurationFileRelativePath(std::string& path, } std::string getInputDeviceConfigurationFilePathByName(const std::string& name,const std::string&type) { - // Search system repository. - std::string path; + std::string path;// Search system repository. struct stat st; // Treblized input device config files will be located /odm/usr or /vendor/usr. const char *rootsForPartition[] {"/odm", "/vendor", getenv("ANDROID_ROOT")}; diff --git a/src/gui/core/inputdevice.h b/src/gui/core/inputdevice.h index 4c8c19bc..475f6be4 100644 --- a/src/gui/core/inputdevice.h +++ b/src/gui/core/inputdevice.h @@ -238,6 +238,8 @@ protected: int32_t mLastDownX,mLastDownY; int32_t mMinX,mMaxX; int32_t mMinY,mMaxY; + int32_t mActionButton; + int32_t mButtonState; bool mSwitchXY; bool mInvertX; bool mInvertY; diff --git a/src/porting/common/input_linux.cc b/src/porting/common/input_linux.cc index 01f16ec4..51c1dcff 100644 --- a/src/porting/common/input_linux.cc +++ b/src/porting/common/input_linux.cc @@ -129,12 +129,12 @@ INT InputGetDeviceInfo(int device,INPUTDEVICEINFO*devinfo) { strcpy(devinfo->name,"Touch-Inject"); devinfo->vendor = INJECTDEV_TOUCH>>16; devinfo->product= INJECTDEV_TOUCH&0xFF; -#if 0 +#if 1 SET_BIT(devinfo->keyBitMask,BTN_TOUCH); SET_BIT(devinfo->absBitMask,ABS_X); SET_BIT(devinfo->absBitMask,ABS_Y); #else - SET_BIT(devinfo->keyBitMask,BTN_TOUCH); + //SET_BIT(devinfo->keyBitMask,BTN_TOUCH); SET_BIT(devinfo->absBitMask,ABS_MT_POSITION_X); SET_BIT(devinfo->absBitMask,ABS_MT_POSITION_Y); #endif diff --git a/tests/gui/motion_tests.cc b/tests/gui/motion_tests.cc index b8dc127c..d69693be 100644 --- a/tests/gui/motion_tests.cc +++ b/tests/gui/motion_tests.cc @@ -82,28 +82,28 @@ TEST_F(EVENT,MT){ {EV_SYN,SYN_REPORT,0}, {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_MOVE - {EV_ABS,ABS_MT_POSITION_X ,14}, - {EV_ABS,ABS_MT_POSITION_Y ,20}, - {EV_SYN,SYN_MT_REPORT,0}, - {EV_SYN,SYN_REPORT,0}, - - {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_DOWN finger 0 - {EV_ABS,ABS_MT_POSITION_X ,14}, - {EV_ABS,ABS_MT_POSITION_Y ,20}, - {EV_SYN,SYN_MT_REPORT,0}, - {EV_ABS,ABS_MT_TRACKING_ID,46},//ACTION_POINTER_DOWN finger 1 - {EV_ABS,ABS_MT_POSITION_X ,10}, - {EV_ABS,ABS_MT_POSITION_Y ,200}, + {EV_ABS,ABS_MT_POSITION_X ,20}, + {EV_ABS,ABS_MT_POSITION_Y ,30}, {EV_SYN,SYN_MT_REPORT,0}, {EV_SYN,SYN_REPORT,0}, {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_DOWN finger 0 - {EV_ABS,ABS_MT_POSITION_X ,14}, - {EV_ABS,ABS_MT_POSITION_Y ,20}, + {EV_ABS,ABS_MT_POSITION_X ,20}, + {EV_ABS,ABS_MT_POSITION_Y ,30}, {EV_SYN,SYN_MT_REPORT,0}, {EV_ABS,ABS_MT_TRACKING_ID,46},//ACTION_POINTER_DOWN finger 1 - {EV_ABS,ABS_MT_POSITION_X ,10}, - {EV_ABS,ABS_MT_POSITION_Y ,200}, + {EV_ABS,ABS_MT_POSITION_X ,40}, + {EV_ABS,ABS_MT_POSITION_Y ,100}, + {EV_SYN,SYN_MT_REPORT,0}, + {EV_SYN,SYN_REPORT,0}, + + {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_DOWN finger 0 + {EV_ABS,ABS_MT_POSITION_X ,20}, + {EV_ABS,ABS_MT_POSITION_Y ,30}, + {EV_SYN,SYN_MT_REPORT,0}, + {EV_ABS,ABS_MT_TRACKING_ID,46},//ACTION_POINTER_DOWN finger 1 + {EV_ABS,ABS_MT_POSITION_X ,40}, + {EV_ABS,ABS_MT_POSITION_Y ,100}, {EV_SYN,SYN_MT_REPORT,0}, {EV_ABS,ABS_MT_TRACKING_ID,47},//ACTION_POINTER_DOWN finger 2 {EV_ABS,ABS_MT_POSITION_X ,200}, @@ -112,41 +112,41 @@ TEST_F(EVENT,MT){ {EV_SYN,SYN_REPORT,0}, {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_UP finger 2 - {EV_ABS,ABS_MT_POSITION_X ,16}, - {EV_ABS,ABS_MT_POSITION_Y ,20}, + {EV_ABS,ABS_MT_POSITION_X ,20}, + {EV_ABS,ABS_MT_POSITION_Y ,30}, {EV_SYN,SYN_MT_REPORT,0}, {EV_ABS,ABS_MT_TRACKING_ID,46}, - {EV_ABS,ABS_MT_POSITION_X ,6}, - {EV_ABS,ABS_MT_POSITION_Y ,200}, + {EV_ABS,ABS_MT_POSITION_X ,40}, + {EV_ABS,ABS_MT_POSITION_Y ,100}, {EV_SYN,SYN_MT_REPORT,0}, //{EV_ABS,ABS_MT_TRACKING_ID,-1}, {EV_SYN,SYN_REPORT,0}, #if 10//2 moveevents {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_UP finger 2 - {EV_ABS,ABS_MT_POSITION_X ,18}, - {EV_ABS,ABS_MT_POSITION_Y ,20}, + {EV_ABS,ABS_MT_POSITION_X ,20}, + {EV_ABS,ABS_MT_POSITION_Y ,30}, {EV_SYN,SYN_MT_REPORT,0}, {EV_ABS,ABS_MT_TRACKING_ID,46}, - {EV_ABS,ABS_MT_POSITION_X ,8}, - {EV_ABS,ABS_MT_POSITION_Y ,200}, + {EV_ABS,ABS_MT_POSITION_X ,40}, + {EV_ABS,ABS_MT_POSITION_Y ,100}, {EV_SYN,SYN_MT_REPORT,0}, //{EV_ABS,ABS_MT_TRACKING_ID,-1}, {EV_SYN,SYN_REPORT,0}, - {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_UP finger 2 - {EV_ABS,ABS_MT_POSITION_X ,19}, - {EV_ABS,ABS_MT_POSITION_Y ,20}, + {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_MOVE finger 1 + {EV_ABS,ABS_MT_POSITION_X ,20}, + {EV_ABS,ABS_MT_POSITION_Y ,30}, {EV_SYN,SYN_MT_REPORT,0}, {EV_ABS,ABS_MT_TRACKING_ID,46}, - {EV_ABS,ABS_MT_POSITION_X ,10}, - {EV_ABS,ABS_MT_POSITION_Y ,200}, + {EV_ABS,ABS_MT_POSITION_X ,60}, + {EV_ABS,ABS_MT_POSITION_Y ,120}, {EV_SYN,SYN_MT_REPORT,0}, //{EV_ABS,ABS_MT_TRACKING_ID,-1}, {EV_SYN,SYN_REPORT,0}, #endif {EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_UP finger 1 - {EV_ABS,ABS_MT_POSITION_X ,18}, - {EV_ABS,ABS_MT_POSITION_Y ,20}, + {EV_ABS,ABS_MT_POSITION_X ,20}, + {EV_ABS,ABS_MT_POSITION_Y ,30}, {EV_SYN,SYN_MT_REPORT,0}, //{EV_ABS,ABS_MT_TRACKING_ID,-1}, {EV_SYN,SYN_MT_REPORT,0}, @@ -155,6 +155,7 @@ TEST_F(EVENT,MT){ {EV_ABS,ABS_MT_TRACKING_ID,-1}, {EV_SYN,SYN_MT_REPORT,0}, {EV_SYN,SYN_REPORT,0}, + }; for(int i=0;i