Skip to content

Commit

Permalink
[embedlite] Fix touch event serialization.
Browse files Browse the repository at this point in the history
There are currently 3 problems:
1. The unit32_t is not a correct type for the value returnes by
   nsTArray<SingleTouchData>::Length. The actual return type is
   nsTArray<T>::size_type which is currently typedefed to size_t.
   On x86_64 systems this is a 64bit value.
2. InputData's modifiers and mTimeStamp member variables were not
   serialized/deserialized.
3. MultiTouchInput's mLocalScreenPoint was not serialized/deserialized.

This patch also uses gecko own WriteParam/ReadParam functions for types
like ScreenSize, ScreenIntPoint, ParentLayerPoint. Previous code
manually serialized those types which is rather error prone. The code
needed to be inspected after each engine update to check if the types
did not gain some additional member variables which need to be
serialized.

Signed-off-by: Piotr Tworek <piotr.tworek@jollamobile.com>
  • Loading branch information
tworaz committed Jul 14, 2015
1 parent 2af90b7 commit e7538b6
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions embedding/embedlite/embedhelpers/InputDataIPC.h
Expand Up @@ -20,13 +20,17 @@ struct ParamTraits<mozilla::InputData>
{
WriteParam(aMsg, (uint8_t)aParam.mInputType);
WriteParam(aMsg, aParam.mTime);
WriteParam(aMsg, aParam.mTimeStamp);
WriteParam(aMsg, aParam.modifiers);
}

static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
uint8_t inputType = 0;
bool ret = ReadParam(aMsg, aIter, &inputType) &&
ReadParam(aMsg, aIter, &aResult->mTime);
ReadParam(aMsg, aIter, &aResult->mTime) &&
ReadParam(aMsg, aIter, &aResult->mTimeStamp) &&
ReadParam(aMsg, aIter, &aResult->modifiers);
aResult->mInputType = static_cast<mozilla::InputType>(inputType);
return ret;
}
Expand All @@ -46,10 +50,9 @@ struct ParamTraits<mozilla::MultiTouchInput>
for (uint32_t i = 0; i < aParam.mTouches.Length(); ++i) {
const mozilla::SingleTouchData& data = aParam.mTouches[i];
WriteParam(aMsg, data.mIdentifier);
WriteParam(aMsg, data.mScreenPoint.x);
WriteParam(aMsg, data.mScreenPoint.y);
WriteParam(aMsg, data.mRadius.width);
WriteParam(aMsg, data.mRadius.height);
WriteParam(aMsg, data.mScreenPoint);
WriteParam(aMsg, data.mLocalScreenPoint);
WriteParam(aMsg, data.mRadius);
WriteParam(aMsg, data.mRotationAngle);
WriteParam(aMsg, data.mForce);
}
Expand All @@ -58,34 +61,24 @@ struct ParamTraits<mozilla::MultiTouchInput>
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
uint8_t inputType = 0;
uint32_t numTouches = 0;
nsTArray<mozilla::SingleTouchData>::size_type numTouches = 0;
if (!ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) ||
!ReadParam(aMsg, aIter, &inputType) ||
!ReadParam(aMsg, aIter, &numTouches)) {
return false;
}
aResult->mType = static_cast<mozilla::MultiTouchInput::MultiTouchType>(inputType);
for (uint32_t i = 0; i < numTouches; ++i) {
int32_t identifier;
mozilla::ScreenIntPoint refPoint;
mozilla::ScreenSize radius;
float rotationAngle;
float force;
if (!ReadParam(aMsg, aIter, &identifier) ||
!ReadParam(aMsg, aIter, &refPoint.x) ||
!ReadParam(aMsg, aIter, &refPoint.y) ||
!ReadParam(aMsg, aIter, &radius.width) ||
!ReadParam(aMsg, aIter, &radius.height) ||
!ReadParam(aMsg, aIter, &rotationAngle) ||
!ReadParam(aMsg, aIter, &force)) {
mozilla::SingleTouchData touchData;
if (!ReadParam(aMsg, aIter, &touchData.mIdentifier) ||
!ReadParam(aMsg, aIter, &touchData.mScreenPoint) ||
!ReadParam(aMsg, aIter, &touchData.mLocalScreenPoint) ||
!ReadParam(aMsg, aIter, &touchData.mRadius) ||
!ReadParam(aMsg, aIter, &touchData.mRotationAngle) ||
!ReadParam(aMsg, aIter, &touchData.mForce)) {
return false;
}
aResult->mTouches.AppendElement(
mozilla::SingleTouchData(identifier,
refPoint,
radius,
rotationAngle,
force));
aResult->mTouches.AppendElement(touchData);
}

return true;
Expand Down

0 comments on commit e7538b6

Please sign in to comment.