Generate ACTION_CANCEL on joystick disconnect. DO NOT MERGE
Bug: 11480300 Change-Id: I5a4096970c9e588d134f05dd0eb3a9c91c836b2f
This commit is contained in:
parent
40c68757ef
commit
d0bd391146
@ -22,11 +22,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <android/input.h>
|
#include <android/input.h>
|
||||||
#include <utils/Vector.h>
|
#include <utils/BitSet.h>
|
||||||
#include <utils/KeyedVector.h>
|
#include <utils/KeyedVector.h>
|
||||||
#include <utils/Timers.h>
|
|
||||||
#include <utils/RefBase.h>
|
#include <utils/RefBase.h>
|
||||||
#include <utils/String8.h>
|
#include <utils/String8.h>
|
||||||
|
#include <utils/Timers.h>
|
||||||
|
#include <utils/Vector.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Additional private constants not defined in ndk/ui/input.h.
|
* Additional private constants not defined in ndk/ui/input.h.
|
||||||
@ -205,7 +206,11 @@ struct PointerCoords {
|
|||||||
float values[MAX_AXES];
|
float values[MAX_AXES];
|
||||||
|
|
||||||
inline void clear() {
|
inline void clear() {
|
||||||
bits = 0;
|
BitSet64::clear(bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isEmpty() const {
|
||||||
|
return BitSet64::isEmpty(bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
float getAxisValue(int32_t axis) const;
|
float getAxisValue(int32_t axis) const;
|
||||||
|
@ -158,16 +158,10 @@ void KeyEvent::initialize(const KeyEvent& from) {
|
|||||||
// --- PointerCoords ---
|
// --- PointerCoords ---
|
||||||
|
|
||||||
float PointerCoords::getAxisValue(int32_t axis) const {
|
float PointerCoords::getAxisValue(int32_t axis) const {
|
||||||
if (axis < 0 || axis > 63) {
|
if (axis < 0 || axis > 63 || !BitSet64::hasBit(bits, axis)){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return values[BitSet64::getIndexOfBit(bits, axis)];
|
||||||
uint64_t axisBit = 1LL << axis;
|
|
||||||
if (!(bits & axisBit)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL));
|
|
||||||
return values[index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t PointerCoords::setAxisValue(int32_t axis, float value) {
|
status_t PointerCoords::setAxisValue(int32_t axis, float value) {
|
||||||
@ -175,22 +169,23 @@ status_t PointerCoords::setAxisValue(int32_t axis, float value) {
|
|||||||
return NAME_NOT_FOUND;
|
return NAME_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t axisBit = 1LL << axis;
|
uint32_t index = BitSet64::getIndexOfBit(bits, axis);
|
||||||
uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL));
|
if (!BitSet64::hasBit(bits, axis)) {
|
||||||
if (!(bits & axisBit)) {
|
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
return OK; // axes with value 0 do not need to be stored
|
return OK; // axes with value 0 do not need to be stored
|
||||||
}
|
}
|
||||||
uint32_t count = __builtin_popcountll(bits);
|
|
||||||
|
uint32_t count = BitSet64::count(bits);
|
||||||
if (count >= MAX_AXES) {
|
if (count >= MAX_AXES) {
|
||||||
tooManyAxes(axis);
|
tooManyAxes(axis);
|
||||||
return NO_MEMORY;
|
return NO_MEMORY;
|
||||||
}
|
}
|
||||||
bits |= axisBit;
|
BitSet64::markBit(bits, axis);
|
||||||
for (uint32_t i = count; i > index; i--) {
|
for (uint32_t i = count; i > index; i--) {
|
||||||
values[i] = values[i - 1];
|
values[i] = values[i - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
values[index] = value;
|
values[index] = value;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -222,7 +217,7 @@ void PointerCoords::applyOffset(float xOffset, float yOffset) {
|
|||||||
status_t PointerCoords::readFromParcel(Parcel* parcel) {
|
status_t PointerCoords::readFromParcel(Parcel* parcel) {
|
||||||
bits = parcel->readInt64();
|
bits = parcel->readInt64();
|
||||||
|
|
||||||
uint32_t count = __builtin_popcountll(bits);
|
uint32_t count = BitSet64::count(bits);
|
||||||
if (count > MAX_AXES) {
|
if (count > MAX_AXES) {
|
||||||
return BAD_VALUE;
|
return BAD_VALUE;
|
||||||
}
|
}
|
||||||
@ -236,7 +231,7 @@ status_t PointerCoords::readFromParcel(Parcel* parcel) {
|
|||||||
status_t PointerCoords::writeToParcel(Parcel* parcel) const {
|
status_t PointerCoords::writeToParcel(Parcel* parcel) const {
|
||||||
parcel->writeInt64(bits);
|
parcel->writeInt64(bits);
|
||||||
|
|
||||||
uint32_t count = __builtin_popcountll(bits);
|
uint32_t count = BitSet64::count(bits);
|
||||||
for (uint32_t i = 0; i < count; i++) {
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
parcel->writeFloat(values[i]);
|
parcel->writeFloat(values[i]);
|
||||||
}
|
}
|
||||||
@ -253,7 +248,7 @@ bool PointerCoords::operator==(const PointerCoords& other) const {
|
|||||||
if (bits != other.bits) {
|
if (bits != other.bits) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint32_t count = __builtin_popcountll(bits);
|
uint32_t count = BitSet64::count(bits);
|
||||||
for (uint32_t i = 0; i < count; i++) {
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
if (values[i] != other.values[i]) {
|
if (values[i] != other.values[i]) {
|
||||||
return false;
|
return false;
|
||||||
@ -264,7 +259,7 @@ bool PointerCoords::operator==(const PointerCoords& other) const {
|
|||||||
|
|
||||||
void PointerCoords::copyFrom(const PointerCoords& other) {
|
void PointerCoords::copyFrom(const PointerCoords& other) {
|
||||||
bits = other.bits;
|
bits = other.bits;
|
||||||
uint32_t count = __builtin_popcountll(bits);
|
uint32_t count = BitSet64::count(bits);
|
||||||
for (uint32_t i = 0; i < count; i++) {
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
values[i] = other.values[i];
|
values[i] = other.values[i];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user