|
27 | 27 | #include <utils/Timers.h> |
28 | 28 | #include <utils/RefBase.h> |
29 | 29 | #include <utils/String8.h> |
30 | | -#include <utils/BitSet.h> |
31 | 30 |
|
32 | 31 | #ifdef HAVE_ANDROID_OS |
33 | 32 | class SkMatrix; |
@@ -607,182 +606,6 @@ class PooledInputEventFactory : public InputEventFactoryInterface { |
607 | 606 | Vector<MotionEvent*> mMotionEventPool; |
608 | 607 | }; |
609 | 608 |
|
610 | | -/* |
611 | | - * Calculates the velocity of pointer movements over time. |
612 | | - */ |
613 | | -class VelocityTracker { |
614 | | -public: |
615 | | - // Default polynomial degree. (used by getVelocity) |
616 | | - static const uint32_t DEFAULT_DEGREE = 2; |
617 | | - |
618 | | - // Default sample horizon. (used by getVelocity) |
619 | | - // We don't use too much history by default since we want to react to quick |
620 | | - // changes in direction. |
621 | | - static const nsecs_t DEFAULT_HORIZON = 100 * 1000000; // 100 ms |
622 | | - |
623 | | - struct Position { |
624 | | - float x, y; |
625 | | - }; |
626 | | - |
627 | | - struct Estimator { |
628 | | - static const size_t MAX_DEGREE = 2; |
629 | | - |
630 | | - // Polynomial coefficients describing motion in X and Y. |
631 | | - float xCoeff[MAX_DEGREE + 1], yCoeff[MAX_DEGREE + 1]; |
632 | | - |
633 | | - // Polynomial degree (number of coefficients), or zero if no information is |
634 | | - // available. |
635 | | - uint32_t degree; |
636 | | - |
637 | | - // Confidence (coefficient of determination), between 0 (no fit) and 1 (perfect fit). |
638 | | - float confidence; |
639 | | - |
640 | | - inline void clear() { |
641 | | - degree = 0; |
642 | | - confidence = 0; |
643 | | - for (size_t i = 0; i <= MAX_DEGREE; i++) { |
644 | | - xCoeff[i] = 0; |
645 | | - yCoeff[i] = 0; |
646 | | - } |
647 | | - } |
648 | | - }; |
649 | | - |
650 | | - VelocityTracker(); |
651 | | - |
652 | | - // Resets the velocity tracker state. |
653 | | - void clear(); |
654 | | - |
655 | | - // Resets the velocity tracker state for specific pointers. |
656 | | - // Call this method when some pointers have changed and may be reusing |
657 | | - // an id that was assigned to a different pointer earlier. |
658 | | - void clearPointers(BitSet32 idBits); |
659 | | - |
660 | | - // Adds movement information for a set of pointers. |
661 | | - // The idBits bitfield specifies the pointer ids of the pointers whose positions |
662 | | - // are included in the movement. |
663 | | - // The positions array contains position information for each pointer in order by |
664 | | - // increasing id. Its size should be equal to the number of one bits in idBits. |
665 | | - void addMovement(nsecs_t eventTime, BitSet32 idBits, const Position* positions); |
666 | | - |
667 | | - // Adds movement information for all pointers in a MotionEvent, including historical samples. |
668 | | - void addMovement(const MotionEvent* event); |
669 | | - |
670 | | - // Gets the velocity of the specified pointer id in position units per second. |
671 | | - // Returns false and sets the velocity components to zero if there is |
672 | | - // insufficient movement information for the pointer. |
673 | | - bool getVelocity(uint32_t id, float* outVx, float* outVy) const; |
674 | | - |
675 | | - // Gets a quadratic estimator for the movements of the specified pointer id. |
676 | | - // Returns false and clears the estimator if there is no information available |
677 | | - // about the pointer. |
678 | | - bool getEstimator(uint32_t id, uint32_t degree, nsecs_t horizon, |
679 | | - Estimator* outEstimator) const; |
680 | | - |
681 | | - // Gets the active pointer id, or -1 if none. |
682 | | - inline int32_t getActivePointerId() const { return mActivePointerId; } |
683 | | - |
684 | | - // Gets a bitset containing all pointer ids from the most recent movement. |
685 | | - inline BitSet32 getCurrentPointerIdBits() const { return mMovements[mIndex].idBits; } |
686 | | - |
687 | | -private: |
688 | | - // Number of samples to keep. |
689 | | - static const uint32_t HISTORY_SIZE = 20; |
690 | | - |
691 | | - struct Movement { |
692 | | - nsecs_t eventTime; |
693 | | - BitSet32 idBits; |
694 | | - Position positions[MAX_POINTERS]; |
695 | | - |
696 | | - inline const Position& getPosition(uint32_t id) const { |
697 | | - return positions[idBits.getIndexOfBit(id)]; |
698 | | - } |
699 | | - }; |
700 | | - |
701 | | - uint32_t mIndex; |
702 | | - Movement mMovements[HISTORY_SIZE]; |
703 | | - int32_t mActivePointerId; |
704 | | -}; |
705 | | - |
706 | | - |
707 | | -/* |
708 | | - * Specifies parameters that govern pointer or wheel acceleration. |
709 | | - */ |
710 | | -struct VelocityControlParameters { |
711 | | - // A scale factor that is multiplied with the raw velocity deltas |
712 | | - // prior to applying any other velocity control factors. The scale |
713 | | - // factor should be used to adapt the input device resolution |
714 | | - // (eg. counts per inch) to the output device resolution (eg. pixels per inch). |
715 | | - // |
716 | | - // Must be a positive value. |
717 | | - // Default is 1.0 (no scaling). |
718 | | - float scale; |
719 | | - |
720 | | - // The scaled speed at which acceleration begins to be applied. |
721 | | - // This value establishes the upper bound of a low speed regime for |
722 | | - // small precise motions that are performed without any acceleration. |
723 | | - // |
724 | | - // Must be a non-negative value. |
725 | | - // Default is 0.0 (no low threshold). |
726 | | - float lowThreshold; |
727 | | - |
728 | | - // The scaled speed at which maximum acceleration is applied. |
729 | | - // The difference between highThreshold and lowThreshold controls |
730 | | - // the range of speeds over which the acceleration factor is interpolated. |
731 | | - // The wider the range, the smoother the acceleration. |
732 | | - // |
733 | | - // Must be a non-negative value greater than or equal to lowThreshold. |
734 | | - // Default is 0.0 (no high threshold). |
735 | | - float highThreshold; |
736 | | - |
737 | | - // The acceleration factor. |
738 | | - // When the speed is above the low speed threshold, the velocity will scaled |
739 | | - // by an interpolated value between 1.0 and this amount. |
740 | | - // |
741 | | - // Must be a positive greater than or equal to 1.0. |
742 | | - // Default is 1.0 (no acceleration). |
743 | | - float acceleration; |
744 | | - |
745 | | - VelocityControlParameters() : |
746 | | - scale(1.0f), lowThreshold(0.0f), highThreshold(0.0f), acceleration(1.0f) { |
747 | | - } |
748 | | - |
749 | | - VelocityControlParameters(float scale, float lowThreshold, |
750 | | - float highThreshold, float acceleration) : |
751 | | - scale(scale), lowThreshold(lowThreshold), |
752 | | - highThreshold(highThreshold), acceleration(acceleration) { |
753 | | - } |
754 | | -}; |
755 | | - |
756 | | -/* |
757 | | - * Implements mouse pointer and wheel speed control and acceleration. |
758 | | - */ |
759 | | -class VelocityControl { |
760 | | -public: |
761 | | - VelocityControl(); |
762 | | - |
763 | | - /* Sets the various parameters. */ |
764 | | - void setParameters(const VelocityControlParameters& parameters); |
765 | | - |
766 | | - /* Resets the current movement counters to zero. |
767 | | - * This has the effect of nullifying any acceleration. */ |
768 | | - void reset(); |
769 | | - |
770 | | - /* Translates a raw movement delta into an appropriately |
771 | | - * scaled / accelerated delta based on the current velocity. */ |
772 | | - void move(nsecs_t eventTime, float* deltaX, float* deltaY); |
773 | | - |
774 | | -private: |
775 | | - // If no movements are received within this amount of time, |
776 | | - // we assume the movement has stopped and reset the movement counters. |
777 | | - static const nsecs_t STOP_TIME = 500 * 1000000; // 500 ms |
778 | | - |
779 | | - VelocityControlParameters mParameters; |
780 | | - |
781 | | - nsecs_t mLastMovementTime; |
782 | | - VelocityTracker::Position mRawPosition; |
783 | | - VelocityTracker mVelocityTracker; |
784 | | -}; |
785 | | - |
786 | 609 | } // namespace android |
787 | 610 |
|
788 | 611 | #endif // _ANDROIDFW_INPUT_H |
0 commit comments