Pack PointerCoords with BitSet. DO NOT MERGE
The converstion from Java PointerCoords to native and then back again was inconsistent. Using a BitSet for all of these operations keeps it in sync. Bug: 15000382 Change-Id: Id3a4558dae3ba3df7c4a9b3cb9d5580b957db8d5
This commit is contained in:
@@ -211,8 +211,9 @@ static void pointerCoordsToNative(JNIEnv* env, jobject pointerCoordsObj,
|
||||
outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION,
|
||||
env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.orientation));
|
||||
|
||||
uint64_t bits = env->GetLongField(pointerCoordsObj, gPointerCoordsClassInfo.mPackedAxisBits);
|
||||
if (bits) {
|
||||
BitSet64 bits =
|
||||
BitSet64(env->GetLongField(pointerCoordsObj, gPointerCoordsClassInfo.mPackedAxisBits));
|
||||
if (!bits.isEmpty()) {
|
||||
jfloatArray valuesArray = jfloatArray(env->GetObjectField(pointerCoordsObj,
|
||||
gPointerCoordsClassInfo.mPackedAxisValues));
|
||||
if (valuesArray) {
|
||||
@@ -221,11 +222,9 @@ static void pointerCoordsToNative(JNIEnv* env, jobject pointerCoordsObj,
|
||||
|
||||
uint32_t index = 0;
|
||||
do {
|
||||
uint32_t axis = __builtin_ctzll(bits);
|
||||
uint64_t axisBit = 1LL << axis;
|
||||
bits &= ~axisBit;
|
||||
uint32_t axis = bits.clearFirstMarkedBit();
|
||||
outRawPointerCoords->setAxisValue(axis, values[index++]);
|
||||
} while (bits);
|
||||
} while (!bits.isEmpty());
|
||||
|
||||
env->ReleasePrimitiveArrayCritical(valuesArray, values, JNI_ABORT);
|
||||
env->DeleteLocalRef(valuesArray);
|
||||
@@ -275,21 +274,19 @@ static void pointerCoordsFromNative(JNIEnv* env, const PointerCoords* rawPointer
|
||||
env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.orientation,
|
||||
rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
|
||||
|
||||
const uint64_t unpackedAxisBits = 0
|
||||
| (1LL << AMOTION_EVENT_AXIS_X)
|
||||
| (1LL << AMOTION_EVENT_AXIS_Y)
|
||||
| (1LL << AMOTION_EVENT_AXIS_PRESSURE)
|
||||
| (1LL << AMOTION_EVENT_AXIS_SIZE)
|
||||
| (1LL << AMOTION_EVENT_AXIS_TOUCH_MAJOR)
|
||||
| (1LL << AMOTION_EVENT_AXIS_TOUCH_MINOR)
|
||||
| (1LL << AMOTION_EVENT_AXIS_TOOL_MAJOR)
|
||||
| (1LL << AMOTION_EVENT_AXIS_TOOL_MINOR)
|
||||
| (1LL << AMOTION_EVENT_AXIS_ORIENTATION);
|
||||
|
||||
uint64_t outBits = 0;
|
||||
uint64_t remainingBits = rawPointerCoords->bits & ~unpackedAxisBits;
|
||||
if (remainingBits) {
|
||||
uint32_t packedAxesCount = __builtin_popcountll(remainingBits);
|
||||
BitSet64 bits = BitSet64(rawPointerCoords->bits);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_X);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_Y);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_PRESSURE);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_SIZE);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_TOUCH_MAJOR);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_TOUCH_MINOR);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_TOOL_MAJOR);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_TOOL_MINOR);
|
||||
bits.clearBit(AMOTION_EVENT_AXIS_ORIENTATION);
|
||||
if (!bits.isEmpty()) {
|
||||
uint32_t packedAxesCount = bits.count();
|
||||
jfloatArray outValuesArray = obtainPackedAxisValuesArray(env, packedAxesCount,
|
||||
outPointerCoordsObj);
|
||||
if (!outValuesArray) {
|
||||
@@ -302,12 +299,10 @@ static void pointerCoordsFromNative(JNIEnv* env, const PointerCoords* rawPointer
|
||||
const float* values = rawPointerCoords->values;
|
||||
uint32_t index = 0;
|
||||
do {
|
||||
uint32_t axis = __builtin_ctzll(remainingBits);
|
||||
uint64_t axisBit = 1LL << axis;
|
||||
remainingBits &= ~axisBit;
|
||||
outBits |= axisBit;
|
||||
uint32_t axis = bits.clearFirstMarkedBit();
|
||||
outBits |= BitSet64::valueForBit(axis);
|
||||
outValues[index++] = rawPointerCoords->getAxisValue(axis);
|
||||
} while (remainingBits);
|
||||
} while (!bits.isEmpty());
|
||||
|
||||
env->ReleasePrimitiveArrayCritical(outValuesArray, outValues, 0);
|
||||
env->DeleteLocalRef(outValuesArray);
|
||||
|
||||
Reference in New Issue
Block a user