void VelocityTracker::clearPointers(BitSet32 idBits) { BitSet32 remainingIdBits(mCurrentPointerIdBits.value & ~idBits.value); mCurrentPointerIdBits = remainingIdBits; if (mActivePointerId >= 0 && idBits.hasBit(mActivePointerId)) { mActivePointerId = !remainingIdBits.isEmpty() ? remainingIdBits.firstMarkedBit() : -1; } mStrategy->clearPointers(idBits); }
void PointerController::setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, BitSet32 spotIdBits) { #if DEBUG_POINTER_UPDATES ALOGD("setSpots: idBits=%08x", spotIdBits.value); for (BitSet32 idBits(spotIdBits); !idBits.isEmpty(); ) { uint32_t id = idBits.firstMarkedBit(); idBits.clearBit(id); const PointerCoords& c = spotCoords[spotIdToIndex[id]]; ALOGD(" spot %d: position=(%0.3f, %0.3f), pressure=%0.3f", id, c.getAxisValue(AMOTION_EVENT_AXIS_X), c.getAxisValue(AMOTION_EVENT_AXIS_Y), c.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); } #endif AutoMutex _l(mLock); mSpriteController->openTransaction(); // Add or move spots for fingers that are down. for (BitSet32 idBits(spotIdBits); !idBits.isEmpty(); ) { uint32_t id = idBits.clearFirstMarkedBit(); const PointerCoords& c = spotCoords[spotIdToIndex[id]]; const SpriteIcon& icon = c.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE) > 0 ? mResources.spotTouch : mResources.spotHover; float x = c.getAxisValue(AMOTION_EVENT_AXIS_X); float y = c.getAxisValue(AMOTION_EVENT_AXIS_Y); Spot* spot = getSpotLocked(id); if (!spot) { spot = createAndAddSpotLocked(id); } spot->updateSprite(&icon, x, y); } // Remove spots for fingers that went up. for (size_t i = 0; i < mLocked.spots.size(); i++) { Spot* spot = mLocked.spots.itemAt(i); if (spot->id != Spot::INVALID_ID && !spotIdBits.hasBit(spot->id)) { fadeOutAndReleaseSpotLocked(spot); } } mSpriteController->closeTransaction(); }
void VelocityTracker::addMovement(nsecs_t eventTime, BitSet32 idBits, const Position* positions) { while (idBits.count() > MAX_POINTERS) { idBits.clearLastMarkedBit(); } if ((mCurrentPointerIdBits.value & idBits.value) && eventTime >= mLastEventTime + ASSUME_POINTER_STOPPED_TIME) { #if DEBUG_VELOCITY ALOGD("VelocityTracker: stopped for %0.3f ms, clearing state.", (eventTime - mLastEventTime) * 0.000001f); #endif // We have not received any movements for too long. Assume that all pointers // have stopped. mStrategy->clear(); } mLastEventTime = eventTime; mCurrentPointerIdBits = idBits; if (mActivePointerId < 0 || !idBits.hasBit(mActivePointerId)) { mActivePointerId = idBits.isEmpty() ? -1 : idBits.firstMarkedBit(); } mStrategy->addMovement(eventTime, idBits, positions); #if DEBUG_VELOCITY ALOGD("VelocityTracker: addMovement eventTime=%" PRId64 ", idBits=0x%08x, activePointerId=%d", eventTime, idBits.value, mActivePointerId); for (BitSet32 iterBits(idBits); !iterBits.isEmpty(); ) { uint32_t id = iterBits.firstMarkedBit(); uint32_t index = idBits.getIndexOfBit(id); iterBits.clearBit(id); Estimator estimator; getEstimator(id, &estimator); ALOGD(" %d: position (%0.3f, %0.3f), " "estimator (degree=%d, xCoeff=%s, yCoeff=%s, confidence=%f)", id, positions[index].x, positions[index].y, int(estimator.degree), vectorToString(estimator.xCoeff, estimator.degree + 1).c_str(), vectorToString(estimator.yCoeff, estimator.degree + 1).c_str(), estimator.confidence); } #endif }
TEST_F(BitSet32Test, BitWiseAnd_NonDisjoint) { b1.markBit(2); b1.markBit(4); b1.markBit(6); b2.markBit(3); b2.markBit(6); b2.markBit(9); BitSet32 tmp = b1 & b2; EXPECT_EQ(tmp.count(), 1u); EXPECT_TRUE(tmp.hasBit(6)); // Check that the operator is symmetric EXPECT_TRUE((b2 & b1) == (b1 & b2)); b1 &= b2; EXPECT_EQ(b1.count(), 1u); EXPECT_EQ(b2.count(), 3u); EXPECT_TRUE(b2.hasBit(3) && b2.hasBit(6) && b2.hasBit(9)); }
void VelocityTrackerState::getVelocity(int32_t id, float* outVx, float* outVy) { if (id == ACTIVE_POINTER_ID) { id = mVelocityTracker.getActivePointerId(); } float vx, vy; if (id >= 0 && id <= MAX_POINTER_ID && mCalculatedIdBits.hasBit(id)) { uint32_t index = mCalculatedIdBits.getIndexOfBit(id); const Velocity& velocity = mCalculatedVelocity[index]; vx = velocity.vx; vy = velocity.vy; } else { vx = 0; vy = 0; } if (outVx) { *outVx = vx; } if (outVy) { *outVy = vy; } }
MVOID MAIN_CLASS_NAME:: applyRelease(UserId_T userId) { NodeId_T const nodeId = userId; sp<IAppCallback> pAppCallback; List<MyListener> listeners; BitSet32 nodeStatusUpdated; NodeStatusUpdater updater(getFrameNo(), mLogLevel); // String8 const logTag = String8::format("frameNo:%u nodeId:%#"PRIxPTR, getFrameNo(), nodeId); MY_LOG1("%s +", logTag.string()); // { RWLock::AutoWLock _lRWLock(mRWLock); Mutex::Autolock _lMapLock(mItemMapLock); // // Update MBOOL isAnyUpdate = updater.run(nodeId, mNodeStatusMap, nodeStatusUpdated); // // Is the entire frame released? if ( isAnyUpdate && 0 == mNodeStatusMap.mInFlightNodeCount ) { nodeStatusUpdated.markBit(IPipelineFrameListener::eMSG_FRAME_RELEASED); // mTimestampFrameDone = ::elapsedRealtimeNano(); // #if 1 // mpPipelineNodeMap = 0; // mpPipelineDAG = 0; mpStreamInfoSet = 0; #endif MY_LOG1( "Done frameNo:%u @ nodeId:%#"PRIxPTR" - timestamp:%"PRIu64"=%"PRIu64"-%"PRIu64, getFrameNo(), nodeId, (mTimestampFrameDone-mTimestampFrameCreated), mTimestampFrameDone, mTimestampFrameCreated ); } // if ( ! nodeStatusUpdated.isEmpty() ) { listeners = mListeners; } // pAppCallback = mpAppCallback.promote(); } // // Release (Hal) Buffers. updater.handleResult(); // // Callback to App. if ( pAppCallback == 0 ) { MY_LOGW("Caonnot promote AppCallback for frameNo:%u, userId:%#"PRIxPTR, getFrameNo(), userId); } else { pAppCallback->updateFrame(getFrameNo(), userId); } // // Callback to listeners if needed. if ( ! nodeStatusUpdated.isEmpty() ) { NSCam::Utils::CamProfile profile(__FUNCTION__, logTag.string()); // List<MyListener>::iterator it = listeners.begin(); for (; it != listeners.end(); ++it) { sp<MyListener::IListener> p = it->mpListener.promote(); if ( p == 0 ) { continue; } // if ( nodeStatusUpdated.hasBit(IPipelineFrameListener::eMSG_ALL_OUT_META_BUFFERS_RELEASED) ) { MY_LOG2("%s O Meta Buffers Released", logTag.string()); p->onPipelineFrame( getFrameNo(), nodeId, IPipelineFrameListener::eMSG_ALL_OUT_META_BUFFERS_RELEASED, it->mpCookie ); } // if ( nodeStatusUpdated.hasBit(IPipelineFrameListener::eMSG_ALL_OUT_IMAGE_BUFFERS_RELEASED) ) { MY_LOG2("%s O Image Buffers Released", logTag.string()); p->onPipelineFrame( getFrameNo(), nodeId, IPipelineFrameListener::eMSG_ALL_OUT_IMAGE_BUFFERS_RELEASED, it->mpCookie ); } // if ( nodeStatusUpdated.hasBit(IPipelineFrameListener::eMSG_FRAME_RELEASED) ) { MY_LOG2("%s Frame Done", logTag.string()); p->onPipelineFrame( getFrameNo(), IPipelineFrameListener::eMSG_FRAME_RELEASED, it->mpCookie ); } } // profile.print_overtime(3, "notify listeners (nodeStatusUpdated:%#x)", nodeStatusUpdated.value); } // MY_LOG1("%s -", logTag.string()); }