mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-29 18:59:14 +08:00
add motionevent.MultiTouch TypeA/B and Single Touch testcase.
This commit is contained in:
parent
837d9c4e0d
commit
32b56a5f8f
@ -65,7 +65,7 @@ public:
|
||||
maxY = std::max(y,maxY);
|
||||
}
|
||||
}
|
||||
invalidate(minX,minY,maxX-minX+1,maxY-minY+1);
|
||||
invalidate(minX-R,minY-R,maxX-minX+R+R,maxY-minY+R+R);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
@ -98,7 +98,7 @@ int main(int argc,const char*argv[]){
|
||||
w->invalidate();
|
||||
Runnable run;
|
||||
run=[](){sendEvents();};
|
||||
w->postDelayed(run,5000);
|
||||
//w->postDelayed(run,5000);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ InputDevice::InputDevice(int fdev){
|
||||
// with the ABS_MT range. Try to confirm that the device really is a touch screen.
|
||||
if (TEST_BIT(BTN_TOUCH, devInfos.keyBitMask) || !haveGamepadButtons) {
|
||||
mDeviceClasses |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
|
||||
oss<<"MTouch";
|
||||
oss<<"MTouch";
|
||||
}
|
||||
// Is this an old style single-touch driver?
|
||||
} else if ( TEST_BIT(ABS_X, devInfos.absBitMask) && TEST_BIT(ABS_Y, devInfos.absBitMask) ) {
|
||||
@ -293,7 +293,7 @@ int KeyDevice::putRawEvent(const struct timeval&tv,int type,int code,int value){
|
||||
|
||||
TouchDevice::TouchDevice(int fd):InputDevice(fd){
|
||||
mTypeB = false;
|
||||
mTrackID = mSlotID = 0;
|
||||
mTrackID = mSlotID = -1;
|
||||
#define ISRANGEVALID(range) (range&&(range->max-range->min))
|
||||
const InputDeviceInfo::MotionRange*rangeX = mDeviceInfo.getMotionRange(ABS_X,0);
|
||||
Display display = WindowManager::getInstance().getDefaultDisplay();
|
||||
@ -326,6 +326,9 @@ TouchDevice::TouchDevice(int fd):InputDevice(fd){
|
||||
mEvent = nullptr;
|
||||
mActionButton = 0;
|
||||
mButtonState = 0;
|
||||
mPointerCoords.resize(16);
|
||||
mPointerProps.resize(16);
|
||||
mCoord.clear();mProp.clear();
|
||||
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);
|
||||
@ -372,6 +375,7 @@ void TouchDevice::setAxisValue(int raw_axis,int value,bool isRelative){
|
||||
}else if(mScreenWidth != mTPWidth){
|
||||
value = (value * mScreenWidth)/mTPWidth;
|
||||
}
|
||||
mCoord.setAxisValue(axis,value);
|
||||
break;
|
||||
case MotionEvent::AXIS_Y:
|
||||
switch(rotation){
|
||||
@ -387,43 +391,46 @@ void TouchDevice::setAxisValue(int raw_axis,int value,bool isRelative){
|
||||
axis= MotionEvent::AXIS_X;
|
||||
}else{
|
||||
value = (value * mScreenHeight)/mTPHeight;
|
||||
}
|
||||
}mCoord.setAxisValue(axis,value);
|
||||
break;
|
||||
case MotionEvent::AXIS_PRESSURE:
|
||||
mCoord.setAxisValue(axis,value);break;
|
||||
default:/*MotionEvent::AXIS_Z:*/break;
|
||||
}/*endof switch(axis)*/
|
||||
switch(raw_axis){
|
||||
case ABS_X ... ABS_Z :{
|
||||
mSlotID = 0 ; mTrackID = 0;
|
||||
if(mPointMAP.size()==0)mPointMAP.insert({mSlotID,{}});
|
||||
auto it = mPointMAP.begin();
|
||||
it->second.coord.setAxisValue(axis,value);
|
||||
}
|
||||
break;
|
||||
case ABS_X ... ABS_Z :
|
||||
mSlotID = 0 ; mTrackID = 0;
|
||||
mDeviceClasses&=~INPUT_DEVICE_CLASS_TOUCH_MT;
|
||||
//mCurrBits.markBit(0);
|
||||
break;
|
||||
case ABS_MT_POSITION_X...ABS_MT_POSITION_Y:
|
||||
mDeviceClasses|=INPUT_DEVICE_CLASS_TOUCH_MT;
|
||||
break;
|
||||
case ABS_MT_SLOT:
|
||||
mTypeB = true; mCurrBits.markBit(value);
|
||||
break;
|
||||
case ABS_MT_TRACKING_ID:{
|
||||
mProp.id = value;
|
||||
auto it = mTrack2Slot.find(value);/*value is trackid*/
|
||||
if( (it == mTrack2Slot.end()) && (value!=-1) ){
|
||||
mSlotID = mTrack2Slot.size();
|
||||
mCurrBits.markBit(mSlotID);
|
||||
it = mTrack2Slot.insert({value,mSlotID}).first;
|
||||
mPointMAP.insert({mSlotID,{}});
|
||||
mPointerProps[mSlotID].id = value;
|
||||
LOGV("TRACKID=%d %08x,%08x",value,mLastBits.value,mCurrBits.value);
|
||||
}else if(value==-1){
|
||||
const uint32_t pointerIndex = BitSet32::firstMarkedBit(mLastBits.value^mCurrBits.value);
|
||||
LOGV("clearbits %d %08x,%08x",pointerIndex,mLastBits.value,mCurrBits.value);
|
||||
mCurrBits.clearBit(pointerIndex);
|
||||
auto it = mTrack2Slot.find(value);
|
||||
if(it!=mTrack2Slot.end())mTrack2Slot.erase(it);
|
||||
//auto it = mTrack2Slot.find(value);
|
||||
//if(it!=mTrack2Slot.end())mTrack2Slot.erase(it);
|
||||
}
|
||||
if(value!=-1){
|
||||
mSlotID = it->second;
|
||||
mTrackID= value;
|
||||
}
|
||||
}break;
|
||||
default:if(raw_axis!=ABS_MT_TRACKING_ID){
|
||||
auto it = mPointMAP.find(mSlotID);
|
||||
it->second.prop.id = mTrackID;
|
||||
it->second.coord.setAxisValue(axis,value);
|
||||
}
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -446,9 +453,25 @@ int TouchDevice::getActionByBits(int& pointIndex){
|
||||
return MotionEvent::ACTION_MOVE;
|
||||
}
|
||||
|
||||
static std::string printEvent(MotionEvent*e){
|
||||
std::ostringstream oss;
|
||||
oss<<"MotionEvent::Acion="<<e->getActionMasked()<<" Index="<<e->getActionIndex();
|
||||
oss<<" ("<<e->getX()<<","<<e->getY()<<"}"<<" historySize="<<e->getHistorySize();
|
||||
for(int i=0;i<e->getPointerCount();i++){
|
||||
oss<<std::endl<<" Pointer["<<i<<"].id="<<e->getPointerId(i)<<" ";
|
||||
oss<<"("<<e->getX(i)<<","<<e->getY(i)<<") {";
|
||||
for(int j=0;j<e->getHistorySize();j++){
|
||||
oss<<"("<<e->getHistoricalRawX(i,j)<<","<<e->getHistoricalRawX(i,j)<<")";
|
||||
}
|
||||
oss<<"}";
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value){
|
||||
int pointerCount,pointIndex,action;
|
||||
MotionEvent*lastEvent;
|
||||
if(!isValidEvent(type,code,value))return -1;
|
||||
int pointIndex,action;
|
||||
LOGV("%lu:%04u %d,%d,%d",tv.tv_sec,tv.tv_usec,type,code,value);
|
||||
switch(type){
|
||||
case EV_KEY:
|
||||
@ -478,71 +501,69 @@ int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value
|
||||
}break;
|
||||
case EV_ABS:
|
||||
switch(code){
|
||||
case ABS_X ... ABS_Z : setAxisValue(code,value,false) ; break;
|
||||
case ABS_MT_SLOT : mTypeB = true; mCurrBits.markBit(value); break;
|
||||
case ABS_MT_TOUCH_MAJOR...ABS_MT_TOOL_Y:/*for all MT Events*/
|
||||
case ABS_X ... ABS_Z :
|
||||
case ABS_MT_TOUCH_MAJOR...ABS_MT_TOOL_Y:
|
||||
setAxisValue(code,value,false);break;
|
||||
}break;
|
||||
case EV_REL:
|
||||
switch(code){
|
||||
case REL_X:
|
||||
case REL_Y://LOGD("EV_REL code %x,%x",code,value);
|
||||
case REL_Z:setAxisValue(code,value,true);break;
|
||||
if((code>=REL_X)&&(code<=REL_Z)){
|
||||
setAxisValue(code,value,true);
|
||||
}break;
|
||||
case EV_SYN:
|
||||
switch(code){
|
||||
case SYN_MT_REPORT:break;
|
||||
case SYN_MT_REPORT:
|
||||
if(!mCoord.isEmpty()){
|
||||
auto it = mTrack2Slot.find(mProp.id);
|
||||
int slot = (it!=mTrack2Slot.end())?it->second:0;
|
||||
LOGD("track %d' slot=%d mTrack2Slot.size=%d",mProp.id,slot,mTrack2Slot.size());
|
||||
mPointerProps [slot] = mProp;
|
||||
mPointerCoords[slot] = mCoord;
|
||||
}break;
|
||||
case SYN_REPORT:
|
||||
if(!mCoord.isEmpty()&&(mProp.id==-1)){
|
||||
//mCurrBits.value = mLastBits.value;
|
||||
mProp.id = mTrackID;
|
||||
mPointerProps[0] = mProp;
|
||||
mPointerCoords[0]= mCoord;
|
||||
}
|
||||
action = getActionByBits(pointIndex);
|
||||
mMoveTime =(tv.tv_sec * 1000LL + tv.tv_usec/1000);
|
||||
{
|
||||
int pointerCount = 0;
|
||||
PointerCoords coords[16];
|
||||
PointerProperties props[16];
|
||||
for(auto p:mPointMAP){
|
||||
coords[pointerCount] = p.second.coord;
|
||||
props [pointerCount] = p.second.prop;
|
||||
pointerCount ++;
|
||||
}
|
||||
if( (mEvent==nullptr)||(action!=MotionEvent::ACTION_MOVE) ){
|
||||
if(mEvent) mEvent->recycle();
|
||||
mEvent = MotionEvent::obtain(mMoveTime,mMoveTime,action,pointerCount,
|
||||
props,coords, 0/*metaState*/,mButtonState,.0,.0/*x/yPrecision*/,
|
||||
getId()/*deviceId*/, 0/*edgeFlags*/, getSources(), 0/*flags*/);
|
||||
mEvent->setActionButton(mActionButton);
|
||||
}else {
|
||||
#if 1
|
||||
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::obtainNoHistory(*mEvent);
|
||||
mEvent->recycle();
|
||||
mEvent = ne;
|
||||
mEvent->addSample(mMoveTime,coords);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
lastEvent = mEvents.size()>1?(MotionEvent*)mEvents.back():nullptr;
|
||||
pointerCount =(mDeviceClasses&INPUT_DEVICE_CLASS_TOUCH_MT)?std::max(mLastBits.count(),mCurrBits.count()):1;
|
||||
if(0&&lastEvent&&(lastEvent->getActionMasked()==MotionEvent::ACTION_MOVE)){
|
||||
lastEvent->addSample(mMoveTime,mPointerCoords.data());
|
||||
LOGI("%s",printEvent(mEvent).c_str());
|
||||
//goto CLEAR_END;
|
||||
}else {
|
||||
const bool useBackupProps = ((action==MotionEvent::ACTION_UP)||(action==MotionEvent::ACTION_POINTER_UP))&&(mDeviceClasses&INPUT_DEVICE_CLASS_TOUCH_MT);
|
||||
const PointerCoords *coords = useBackupProps ? mPointerCoordsBak.data(): mPointerCoords.data();
|
||||
const PointerProperties*props= useBackupProps ? mPointerPropsBak.data() : mPointerProps.data();
|
||||
mEvent = MotionEvent::obtain(mMoveTime , mMoveTime , action , pointerCount,props,coords, 0/*metaState*/,mButtonState,
|
||||
0,0/*x/yPrecision*/,getId()/*deviceId*/, 0/*edgeFlags*/, getSources(), 0/*flags*/);
|
||||
LOGI_IF(action!=MotionEvent::ACTION_MOVE,"mask=%08x,%08x prop.id=%d/%d]\n%s",mLastBits.value,mCurrBits.value,mProp.id,
|
||||
mTrackID,printEvent(mEvent).c_str());
|
||||
}
|
||||
mEvent->setActionButton(mActionButton);
|
||||
mEvent->setAction(action|(pointIndex<<MotionEvent::ACTION_POINTER_INDEX_SHIFT));
|
||||
}
|
||||
|
||||
LOGD_IF(action!=MotionEvent::ACTION_MOVE,"mask=%08x,%08x action=%d Poiter[%d]=(%.f,%.f)",mLastBits.value,
|
||||
mCurrBits.value,action,pointIndex,mEvent->getX(pointIndex),mEvent->getY(pointIndex));
|
||||
if( mLastBits.count() > mCurrBits.count() ){
|
||||
const uint32_t pointerIndex = BitSet32::firstMarkedBit(mLastBits.value^mCurrBits.value);
|
||||
LOGD("clearbits %d %08x,%08x",pointerIndex,mLastBits.value,mCurrBits.value);
|
||||
mCurrBits.clearBit(pointIndex);
|
||||
if(mDeviceClasses&INPUT_DEVICE_CLASS_TOUCH_MT) mCurrBits.clearBit(pointIndex);
|
||||
auto it = mTrack2Slot.find(pointerIndex);
|
||||
if( it != mTrack2Slot.end() )mTrack2Slot.erase(it);
|
||||
auto it2 = mPointMAP.find(pointIndex);
|
||||
if( it2 != mPointMAP.end() )mPointMAP.erase(it2);
|
||||
}
|
||||
mPointerProps.erase (mPointerProps.begin() + pointIndex);
|
||||
mPointerCoords.erase(mPointerCoords.begin()+ pointIndex);
|
||||
mPointerProps.resize(mPointerProps.size()+1);
|
||||
mPointerCoords.resize(mPointerCoords.size()+1);
|
||||
}else{
|
||||
mPointerCoordsBak.clear();
|
||||
mPointerCoordsBak.assign(mPointerCoords.begin(),mPointerCoords.begin()+pointerCount);
|
||||
mPointerPropsBak.clear();
|
||||
mPointerPropsBak.assign(mPointerProps.begin(),mPointerProps.begin()+pointerCount);
|
||||
}
|
||||
|
||||
if( int(mEvent->getHistorySize())>=0 ){
|
||||
mLastDownX = mEvent->getX();
|
||||
@ -551,12 +572,14 @@ int TouchDevice::putRawEvent(const struct timeval&tv,int type,int code,int value
|
||||
mEvents.push_back(e);
|
||||
}
|
||||
CLEAR_END:
|
||||
mCoord.clear();mProp.clear();
|
||||
mLastBits.value = mCurrBits.value;
|
||||
if( (mDeviceClasses&INPUT_DEVICE_CLASS_TOUCH_MT) && (mTypeB==false) ){
|
||||
mCurrBits.clear();//only typeA
|
||||
mTrack2Slot.clear();
|
||||
}
|
||||
}break;
|
||||
for(int i=0;i<pointerCount;i++){mPointerCoords[i].clear();mPointerCoords[i].clear();};
|
||||
}/*endofSYN_REPORT*/
|
||||
}break;/*caseof EV_SYN*/
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef __INPUT_DEVICE_H__
|
||||
#define __INPUT_DEVICE_H__
|
||||
//#include <core/uievents.h>
|
||||
#include <view/keyevent.h>
|
||||
#include <view/motionevent.h>
|
||||
#include <core/bitset.h>
|
||||
@ -231,10 +230,6 @@ protected:
|
||||
int mTrackID;
|
||||
int mTPWidth;
|
||||
int mTPHeight;
|
||||
typedef struct{
|
||||
PointerCoords coord;
|
||||
PointerProperties prop;
|
||||
}TouchPoint;
|
||||
int32_t mLastDownX,mLastDownY;
|
||||
int32_t mMinX,mMaxX;
|
||||
int32_t mMinY,mMaxY;
|
||||
@ -246,7 +241,12 @@ protected:
|
||||
bool mTypeB;
|
||||
BitSet32 mLastBits,mCurrBits;
|
||||
std::map<int,int>mTrack2Slot;
|
||||
std::map<int,TouchPoint>mPointMAP;
|
||||
PointerCoords mCoord;
|
||||
PointerProperties mProp;
|
||||
std::vector<PointerCoords>mPointerCoords;
|
||||
std::vector<PointerCoords>mPointerCoordsBak;
|
||||
std::vector<PointerProperties>mPointerProps;
|
||||
std::vector<PointerProperties>mPointerPropsBak;
|
||||
int getActionByBits(int&pointIndex);
|
||||
void setAxisValue(int axis,int value,bool isRelative);
|
||||
int isValidEvent(int type,int code,int value)override;
|
||||
|
@ -668,7 +668,6 @@ void Looper::removeMessages(const MessageHandler* handler, int what) {
|
||||
std::lock_guard<std::recursive_mutex> _l(mLock);
|
||||
|
||||
for( auto it=mMessageEnvelopes.begin();it!=mMessageEnvelopes.end();it++){
|
||||
LOGD("what=%d,%d",it->message.what,what);
|
||||
if((it->handler==handler) && (it->message.what==what)){
|
||||
it=mMessageEnvelopes.erase(it);
|
||||
}
|
||||
|
310
tests/gui/inputdevice_tests.cc
Normal file
310
tests/gui/inputdevice_tests.cc
Normal file
@ -0,0 +1,310 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cdroid.h>
|
||||
#include <ngl_os.h>
|
||||
#include <sys/time.h>
|
||||
#include <porting/cdinput.h>
|
||||
#include <linux/input.h>
|
||||
struct MTEvent{int type,code,value;};
|
||||
class INPUTDEVICE:public testing::Test{
|
||||
public:
|
||||
int EventCount;
|
||||
MotionEvent*OutEvents[128];
|
||||
public:
|
||||
virtual void SetUp(){
|
||||
}
|
||||
virtual void TearDown(){
|
||||
for(int i=0;i<EventCount;i++){
|
||||
OutEvents[i]->recycle();
|
||||
}
|
||||
}
|
||||
int sendEvents(InputDevice&d,MTEvent*mts,int size,MotionEvent**eventOut){
|
||||
int eventCount = 0;
|
||||
for(int i=0;i<size;i++){
|
||||
int32_t tmEVT = i*20*100000;
|
||||
d.putRawEvent({0,tmEVT},mts[i].type,mts[i].code,mts[i].value);
|
||||
}
|
||||
eventCount = d.getEventCount();
|
||||
LOGI("%d Events",eventCount);
|
||||
for(int i=0;d.getEventCount();i++){
|
||||
MotionEvent*e=(MotionEvent*)d.popEvent();
|
||||
const int pointerCount=e->getPointerCount();
|
||||
const int hisCount = e->getHistorySize();
|
||||
if(eventOut)eventOut[i]=e;
|
||||
LOGI("Event[%d].Action=%d/%d pointers=%d history=%d",i,e->getActionMasked(),e->getActionIndex(),pointerCount,hisCount);
|
||||
for(int j=0;j<pointerCount;j++){
|
||||
std::ostringstream oss;
|
||||
for(int k=0;k<hisCount;k++){
|
||||
oss<<"["<<e->getHistoricalRawX(j,k)<<","<<e->getHistoricalRawY(j,k)<<"],";
|
||||
}
|
||||
LOGI(" Point[%d](%d)=(%.f,%.f)[%s]",j,e->getPointerId(j),e->getX(j),e->getY(j),oss.str().c_str());
|
||||
}
|
||||
}
|
||||
return eventCount;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(INPUTDEVICE,ST){
|
||||
TouchDevice d(INJECTDEV_TOUCH);
|
||||
MTEvent mts[]={
|
||||
{EV_KEY,BTN_TOUCH,1},//0
|
||||
{EV_ABS,ABS_X,10},
|
||||
{EV_ABS,ABS_Y,20},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_X,12},//4
|
||||
{EV_ABS,ABS_Y,22},//5
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_X,14},//7
|
||||
{EV_ABS,ABS_Y,24},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_KEY,BTN_TOUCH,0},//10
|
||||
{EV_ABS,ABS_X,16},
|
||||
{EV_ABS,ABS_Y,26},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
};
|
||||
EventCount = sendEvents(d,mts,sizeof(mts)/sizeof(MTEvent),OutEvents);
|
||||
ASSERT_EQ(EventCount,4);
|
||||
ASSERT_EQ(OutEvents[0]->getAction(),MotionEvent::ACTION_DOWN);
|
||||
ASSERT_EQ(OutEvents[0]->getX(0),mts[1].value);
|
||||
ASSERT_EQ(OutEvents[0]->getY(0),mts[2].value);
|
||||
|
||||
ASSERT_EQ(OutEvents[1]->getAction(),MotionEvent::ACTION_MOVE);
|
||||
ASSERT_EQ(OutEvents[1]->getX(0),mts[4].value);
|
||||
ASSERT_EQ(OutEvents[1]->getY(0),mts[5].value);
|
||||
|
||||
ASSERT_EQ(OutEvents[2]->getAction(),MotionEvent::ACTION_MOVE);
|
||||
ASSERT_EQ(OutEvents[2]->getX(0),mts[7].value);
|
||||
ASSERT_EQ(OutEvents[2]->getY(0),mts[8].value);
|
||||
|
||||
ASSERT_EQ(OutEvents[3]->getAction(),MotionEvent::ACTION_UP);
|
||||
ASSERT_EQ(OutEvents[3]->getX(0),mts[11].value);
|
||||
ASSERT_EQ(OutEvents[3]->getY(0),mts[12].value);
|
||||
}
|
||||
|
||||
TEST_F(INPUTDEVICE,MTB){//Type B Events
|
||||
TouchDevice d(INJECTDEV_TOUCH);
|
||||
MTEvent mts[]={
|
||||
{EV_KEY,BTN_TOUCH,1}, //ACTION_DOWN
|
||||
{EV_ABS,ABS_MT_SLOT,0},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,45},
|
||||
{EV_ABS,ABS_MT_POSITION_X ,10},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,20},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_SLOT,0},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_MOVE
|
||||
{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_SLOT,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_SLOT,1},
|
||||
{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_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_SLOT,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_SLOT,1},
|
||||
{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_SLOT,2},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,47},//ACTION_POINTER_DOWN finger 2
|
||||
{EV_ABS,ABS_MT_POSITION_X ,200},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,300},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_SLOT,0},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_UP finger 2
|
||||
{EV_ABS,ABS_MT_POSITION_X ,20},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,30},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_ABS,ABS_MT_SLOT,1},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,46},
|
||||
{EV_ABS,ABS_MT_POSITION_X ,40},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,100},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_ABS,ABS_MT_SLOT,2},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,-1},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_SLOT,0},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_UP 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_SLOT,1},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,-1},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_SLOT,0},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,-1},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
};
|
||||
EventCount = sendEvents(d,mts,sizeof(mts)/sizeof(MTEvent),OutEvents);
|
||||
ASSERT_EQ(EventCount,7);
|
||||
}
|
||||
|
||||
TEST_F(INPUTDEVICE,MTASST){//some wrong MT device ,can working:)
|
||||
TouchDevice d(INJECTDEV_TOUCH);
|
||||
MTEvent mts[]={
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,0x40},//0
|
||||
{EV_ABS,ABS_MT_POSITION_X ,20},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,30},
|
||||
{EV_KEY,BTN_TOUCH,1},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_POSITION_X ,22},//5
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,33},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_POSITION_X ,24},//8
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,34},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,-1},
|
||||
{EV_KEY,BTN_TOUCH,0},
|
||||
{EV_SYN,SYN_REPORT,0}
|
||||
};
|
||||
EventCount = sendEvents(d,mts,sizeof(mts)/sizeof(MTEvent),OutEvents);
|
||||
ASSERT_EQ(EventCount,4);
|
||||
ASSERT_EQ(OutEvents[0]->getAction(),MotionEvent::ACTION_DOWN);
|
||||
ASSERT_EQ(OutEvents[0]->getX(),mts[1].value);
|
||||
ASSERT_EQ(OutEvents[0]->getY(),mts[2].value);
|
||||
|
||||
ASSERT_EQ(OutEvents[1]->getAction(),MotionEvent::ACTION_MOVE);
|
||||
ASSERT_EQ(OutEvents[1]->getX(),mts[5].value);
|
||||
ASSERT_EQ(OutEvents[1]->getY(),mts[6].value);
|
||||
|
||||
ASSERT_EQ(OutEvents[2]->getAction(),MotionEvent::ACTION_MOVE);
|
||||
ASSERT_EQ(OutEvents[2]->getX(),mts[8].value);
|
||||
ASSERT_EQ(OutEvents[2]->getY(),mts[9].value);
|
||||
|
||||
ASSERT_EQ(OutEvents[3]->getAction(),MotionEvent::ACTION_UP);
|
||||
ASSERT_EQ(OutEvents[3]->getX(),mts[8].value);
|
||||
ASSERT_EQ(OutEvents[3]->getY(),mts[9].value);
|
||||
}
|
||||
|
||||
TEST_F(INPUTDEVICE,MTA){//TypeA Events
|
||||
TouchDevice d(INJECTDEV_TOUCH);
|
||||
MTEvent mts[]={
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,1},//0
|
||||
{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,1},//5
|
||||
{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,2},
|
||||
{EV_ABS,ABS_MT_POSITION_X ,120},//10
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,130},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,1},//14
|
||||
{EV_ABS,ABS_MT_POSITION_X ,20},//15
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,30},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,2},
|
||||
{EV_ABS,ABS_MT_POSITION_X ,120},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,130},//20
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,3},
|
||||
{EV_ABS,ABS_MT_POSITION_X ,220},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,230},
|
||||
{EV_SYN,SYN_MT_REPORT,0},//25
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,1},//27
|
||||
{EV_ABS,ABS_MT_POSITION_X ,20},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,30},
|
||||
{EV_SYN,SYN_MT_REPORT,0},//30
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,2},
|
||||
{EV_ABS,ABS_MT_POSITION_X ,120},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,130},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},//35
|
||||
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,2},//36
|
||||
{EV_ABS,ABS_MT_POSITION_X ,120},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,130},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},//40
|
||||
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,2},//41
|
||||
{EV_ABS,ABS_MT_POSITION_X ,123},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,134},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},//45
|
||||
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,-1},//46
|
||||
{EV_KEY,BTN_TOUCH,0},//20
|
||||
{EV_SYN,SYN_REPORT,0}
|
||||
};
|
||||
EventCount = sendEvents(d,mts,sizeof(mts)/sizeof(MTEvent),OutEvents);
|
||||
ASSERT_EQ(EventCount,7);
|
||||
ASSERT_EQ(OutEvents[0]->getAction(),MotionEvent::ACTION_DOWN);
|
||||
ASSERT_EQ(OutEvents[0]->getActionIndex(),0);
|
||||
ASSERT_EQ(OutEvents[0]->getPointerId(0),mts[0].value);
|
||||
ASSERT_EQ(OutEvents[0]->getX(0),mts[1].value);//20
|
||||
ASSERT_EQ(OutEvents[0]->getY(0),mts[2].value);//30
|
||||
|
||||
ASSERT_EQ(OutEvents[1]->getActionMasked(),MotionEvent::ACTION_POINTER_DOWN);
|
||||
ASSERT_EQ(OutEvents[1]->getActionIndex(),1);
|
||||
ASSERT_EQ(OutEvents[1]->getPointerCount(),2);
|
||||
ASSERT_EQ(OutEvents[1]->getPointerId(0),mts[5].value);
|
||||
ASSERT_EQ(OutEvents[1]->getPointerId(1),mts[9].value);
|
||||
ASSERT_EQ(OutEvents[1]->getX(0),mts[6].value);//20
|
||||
ASSERT_EQ(OutEvents[1]->getY(0),mts[7].value);//30
|
||||
ASSERT_EQ(OutEvents[1]->getX(1),mts[10].value);//20
|
||||
ASSERT_EQ(OutEvents[1]->getY(1),mts[11].value);//30
|
||||
|
||||
|
||||
ASSERT_EQ(OutEvents[2]->getActionMasked(),MotionEvent::ACTION_POINTER_DOWN);
|
||||
ASSERT_EQ(OutEvents[2]->getActionIndex(),2);
|
||||
ASSERT_EQ(OutEvents[2]->getPointerCount(),3);
|
||||
ASSERT_EQ(OutEvents[2]->getPointerId(0),mts[14].value);
|
||||
ASSERT_EQ(OutEvents[2]->getPointerId(1),mts[18].value);
|
||||
ASSERT_EQ(OutEvents[2]->getPointerId(2),mts[22].value);
|
||||
ASSERT_EQ(OutEvents[2]->getX(0),mts[15].value);//20
|
||||
ASSERT_EQ(OutEvents[2]->getY(0),mts[16].value);//30
|
||||
ASSERT_EQ(OutEvents[2]->getX(1),mts[19].value);//120
|
||||
ASSERT_EQ(OutEvents[2]->getY(1),mts[20].value);//130
|
||||
ASSERT_EQ(OutEvents[2]->getX(2),mts[23].value);//120
|
||||
ASSERT_EQ(OutEvents[2]->getY(2),mts[24].value);//130
|
||||
|
||||
ASSERT_EQ(OutEvents[3]->getActionMasked(),MotionEvent::ACTION_POINTER_UP);
|
||||
ASSERT_EQ(OutEvents[3]->getActionIndex(),2);
|
||||
ASSERT_EQ(OutEvents[3]->getPointerCount(),3);
|
||||
ASSERT_EQ(OutEvents[3]->getPointerId(0),mts[27].value);
|
||||
ASSERT_EQ(OutEvents[3]->getPointerId(1),mts[31].value);
|
||||
ASSERT_EQ(OutEvents[3]->getX(0),mts[28].value);//20
|
||||
ASSERT_EQ(OutEvents[3]->getY(0),mts[29].value);//30
|
||||
ASSERT_EQ(OutEvents[3]->getX(1),mts[32].value);//120
|
||||
ASSERT_EQ(OutEvents[3]->getY(1),mts[33].value);//130
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <porting/cdinput.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
struct MTEvent{int type,code,value;};
|
||||
class EVENT:public testing::Test{
|
||||
|
||||
public :
|
||||
@ -70,111 +70,6 @@ TEST_F(EVENT,Benchmark){
|
||||
printf("EventPool usedtime=%ld\r\n",1000L*tv2.tv_sec+tv2.tv_usec/1000-1000L*tv1.tv_sec-tv1.tv_usec/1000);
|
||||
}
|
||||
|
||||
TEST_F(EVENT,MT){
|
||||
TouchDevice d(INJECTDEV_TOUCH);
|
||||
struct MTEvent{int type,code,value;};
|
||||
MTEvent mts[]={
|
||||
{EV_KEY,BTN_TOUCH,1}, //ACTION_DOWN
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,45},
|
||||
{EV_ABS,ABS_MT_POSITION_X ,10},
|
||||
{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_MOVE
|
||||
{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 ,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_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},
|
||||
{EV_ABS,ABS_MT_POSITION_Y ,300},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,45},//ACTION_POINTER_UP finger 2
|
||||
{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 ,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 ,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 ,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_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 ,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 ,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},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
{EV_ABS,ABS_MT_TRACKING_ID,-1},
|
||||
{EV_SYN,SYN_MT_REPORT,0},
|
||||
{EV_SYN,SYN_REPORT,0},
|
||||
|
||||
};
|
||||
for(int i=0;i<sizeof(mts)/sizeof(MTEvent);i++){
|
||||
int32_t tmEVT = i*20*100000;
|
||||
d.putRawEvent({0,tmEVT},mts[i].type,mts[i].code,mts[i].value);
|
||||
}
|
||||
for(int i=0;i<d.getEventCount();i++){
|
||||
MotionEvent*e=(MotionEvent*)d.popEvent();
|
||||
const int pointerCount=e->getPointerCount();
|
||||
const int hisCount = e->getHistorySize();
|
||||
LOGI("Event[%d].Action=%d pointers=%d history=%d",i,e->getActionMasked(),pointerCount,hisCount);
|
||||
for(int j=0;j<pointerCount;j++){
|
||||
std::ostringstream oss;
|
||||
for(int k=0;k<hisCount;k++){
|
||||
oss<<"["<<e->getHistoricalRawX(j,k)<<","<<e->getHistoricalRawY(j,k)<<"],";
|
||||
}
|
||||
LOGI(" Point[%d](%d)=(%.f,%.f)[%s]",j,e->getPointerId(j),e->getX(j),e->getY(j),oss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(EVENT,exec){
|
||||
static const char*args[]={"arg1","alpha",NULL};
|
||||
|
Loading…
Reference in New Issue
Block a user