input系统的mapper机制

class InputDevice {
      .....
      private:
      .....
      Vector mMappers; //每个inputdevice都有一个自己的私有mMappers类型的数据
     .....
   }

增加自身mapper的函数是
void InputDevice::addMapper(InputMapper* mapper) {
        mMappers.add(mapper);
}

InputDevice* InputReader::createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
        const InputDeviceIdentifier& identifier, uint32_t classes) {
     ......
      if (classes & INPUT_DEVICE_CLASS_SWITCH) {
ALOGE("lisa-addMapper 1");
        device->addMapper(new SwitchInputMapper(device)); //加入相应的mapper
    }


     if (classes & INPUT_DEVICE_CLASS_VIBRATOR) {
ALOGE("lisa-addMapper 2");
        device->addMapper(new VibratorInputMapper(device));
    }
    ......
  }
上面的函数被void InputReader::addDeviceLocked(nsecs_t when, int32_t deviceId) {
    InputDevice* device = createDeviceLocked(deviceId, controllerNumber, identifier, classes);
  }调用


void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {
   ......
   switch (rawEvent->type) {
            case EventHubInterface::DEVICE_ADDED:
                addDeviceLocked(rawEvent->when, rawEvent->deviceId);  //每次有inputdecice加入的时候
                break;
}


  所以在void InputDevice::process(const RawEvent* rawEvents, size_t count) {


   for (size_t i = 0; i < numMappers; i++) { //这里的mapper数量会变化,比如touchscreen是2,按键是1,因为两个是不同的inputdevice

                InputMapper* mapper = mMappers[i];
                mapper->process(rawEvent);
            }


 }


  log如下:E/InputReader( 1247): lisa-deviceIndex=3
E/InputReader( 1247): lisa-InputDevice=a3d3ffc870334637db1e8bbfb999c8c212cbcbc9
E/InputReader( 1247): lisa-InputDevice::process
E/InputReader( 1247): lisa-numMappers=2
E/InputReader( 1247): lisa-KeyboardInputMapper::process
E/InputReader( 1247): lisa-MultiTouchInputMapper::process
E/InputReader( 1247): lisa-TouchInputMapper::process
E/InputReader( 1247): lisa-numMappers=2
E/InputReader( 1247): lisa-KeyboardInputMapper::process
E/InputReader( 1247): lisa-MultiTouchInputMapper::process


上面是touchscreen的log
E/InputReader( 1247): lisa-deviceIndex=1
E/InputReader( 1247): lisa-InputDevice=fb60d4f4370f5dbe8267b63d38dea852987571ab
E/InputReader( 1247): lisa-InputDevice::process
E/InputReader( 1247): lisa-numMappers=1

上面的是keyboard的log


这也解释了如何调用device自身的mapper去process



01-01 00:03:17.299  1204  1292 E InputReader: lisa-addMapper 3
01-01 00:03:17.299  1204  1292 E InputReader: lisa-mMappers.add
01-01 00:03:17.299  1204  1292 I InputReader: Device added: id=-1, name='Virtual', sources=0x00000301
01-01 00:03:17.299  1204  1292 E InputReader: matt-rawEvents; count=6
01-01 00:03:17.299  1204  1292 E InputReader: lisa-addMapper 3
01-01 00:03:17.299  1204  1292 E InputReader: lisa-mMappers.add
01-01 00:03:17.299  1204  1292 I InputReader: Device added: id=5, name='gpio-keys', sources=0x00000101
01-01 00:03:17.299  1204  1292 E InputReader: matt-rawEvents; count=5
01-01 00:03:17.299  1204  1292 E InputReader: lisa-addMapper 5
01-01 00:03:17.299  1204  1292 E InputReader: lisa-mMappers.add
01-01 00:03:17.299  1204  1292 I InputReader:   Touch device 'input_mt_wrapper' could not query the properties of its associated display.
01-01 00:03:17.299  1204  1292 I InputReader: Device added: id=4, name='input_mt_wrapper', sources=0x00002002
01-01 00:03:17.299  1204  1292 E InputReader: matt-rawEvents; count=4
01-01 00:03:17.299  1204  1292 E InputReader: lisa-addMapper 3    //device->addMapper(new KeyboardInputMapper(device, keyboardSource, keyboardType));加了一个
01-01 00:03:17.299  1204  1292 E InputReader: lisa-mMappers.add
01-01 00:03:17.299  1204  1292 E InputReader: lisa-addMapper 5    // device->addMapper(new MultiTouchInputMapper(device));再加一个
01-01 00:03:17.299  1204  1292 E InputReader: lisa-mMappers.add
01-01 00:03:17.299  1204  1292 I InputReader:   Touch device 'ft5x06_ts' could not query the properties of its associated display. // 所以touch有两个mapper
01-01 00:03:17.299  1204  1292 I InputReader: Device added: id=3, name='ft5x06_ts', sources=0x00001103
01-01 00:03:17.299  1204  1292 E InputReader: matt-rawEvents; count=3
01-01 00:03:17.299  1204  1292 E InputReader: lisa-addMapper 4
01-01 00:03:17.299  1204  1292 E InputReader: lisa-mMappers.add
01-01 00:03:17.309  1204  1292 I InputReader: Device added: id=2, name='hbtp_vm', sources=0x00002002
01-01 00:03:17.309  1204  1292 E InputReader: matt-rawEvents; count=2
01-01 00:03:17.309  1204  1292 E InputReader: lisa-addMapper 3
01-01 00:03:17.309  1204  1292 E InputReader: lisa-mMappers.add
01-01 00:03:17.309  1204  1292 I InputReader: Device added: id=1, name='qpnp_pon', sources=0x00000101

你可能感兴趣的:(input系统的mapper机制)