Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6fffd2b8 authored by Michael Wright's avatar Michael Wright Committed by Android (Google) Code Review
Browse files

Merge "Pack PointerCoords with BitSet. DO NOT MERGE" into lmp-preview-dev

parents 508a8a0a cb183fcd
Loading
Loading
Loading
Loading
+20 −25
Original line number Diff line number Diff line
@@ -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);