Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _UI_POINTER_CONTROLLER_H |
| 18 | #define _UI_POINTER_CONTROLLER_H |
| 19 | |
| 20 | #include <ui/DisplayInfo.h> |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 21 | #include <ui/Input.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 22 | #include <utils/RefBase.h> |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 23 | #include <utils/Looper.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 24 | #include <utils/String8.h> |
| 25 | |
| 26 | #include <surfaceflinger/Surface.h> |
| 27 | #include <surfaceflinger/SurfaceComposerClient.h> |
| 28 | #include <surfaceflinger/ISurfaceComposer.h> |
| 29 | |
| 30 | #include <SkBitmap.h> |
| 31 | |
| 32 | namespace android { |
| 33 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Interface for tracking a single (mouse) pointer. |
| 36 | * |
| 37 | * The pointer controller is responsible for providing synchronization and for tracking |
| 38 | * display orientation changes if needed. |
| 39 | */ |
| 40 | class PointerControllerInterface : public virtual RefBase { |
| 41 | protected: |
| 42 | PointerControllerInterface() { } |
| 43 | virtual ~PointerControllerInterface() { } |
| 44 | |
| 45 | public: |
| 46 | /* Gets the bounds of the region that the pointer can traverse. |
| 47 | * Returns true if the bounds are available. */ |
| 48 | virtual bool getBounds(float* outMinX, float* outMinY, |
| 49 | float* outMaxX, float* outMaxY) const = 0; |
| 50 | |
| 51 | /* Move the pointer. */ |
| 52 | virtual void move(float deltaX, float deltaY) = 0; |
| 53 | |
| 54 | /* Sets a mask that indicates which buttons are pressed. */ |
| 55 | virtual void setButtonState(uint32_t buttonState) = 0; |
| 56 | |
| 57 | /* Gets a mask that indicates which buttons are pressed. */ |
| 58 | virtual uint32_t getButtonState() const = 0; |
| 59 | |
| 60 | /* Sets the absolute location of the pointer. */ |
| 61 | virtual void setPosition(float x, float y) = 0; |
| 62 | |
| 63 | /* Gets the absolute location of the pointer. */ |
| 64 | virtual void getPosition(float* outX, float* outY) const = 0; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 65 | |
| 66 | /* Fades the pointer out now. */ |
| 67 | virtual void fade() = 0; |
| 68 | |
| 69 | /* Makes the pointer visible if it has faded out. */ |
| 70 | virtual void unfade() = 0; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | |
| 74 | /* |
| 75 | * Tracks pointer movements and draws the pointer sprite to a surface. |
| 76 | * |
| 77 | * Handles pointer acceleration and animation. |
| 78 | */ |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 79 | class PointerController : public PointerControllerInterface, public MessageHandler { |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 80 | protected: |
| 81 | virtual ~PointerController(); |
| 82 | |
| 83 | public: |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 84 | enum InactivityFadeDelay { |
| 85 | INACTIVITY_FADE_DELAY_NORMAL = 0, |
| 86 | INACTIVITY_FADE_DELAY_SHORT = 1, |
| 87 | }; |
| 88 | |
| 89 | PointerController(const sp<Looper>& looper, int32_t pointerLayer); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 90 | |
| 91 | virtual bool getBounds(float* outMinX, float* outMinY, |
| 92 | float* outMaxX, float* outMaxY) const; |
| 93 | virtual void move(float deltaX, float deltaY); |
| 94 | virtual void setButtonState(uint32_t buttonState); |
| 95 | virtual uint32_t getButtonState() const; |
| 96 | virtual void setPosition(float x, float y); |
| 97 | virtual void getPosition(float* outX, float* outY) const; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 98 | virtual void fade(); |
| 99 | virtual void unfade(); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 100 | |
| 101 | void setDisplaySize(int32_t width, int32_t height); |
| 102 | void setDisplayOrientation(int32_t orientation); |
| 103 | void setPointerIcon(const SkBitmap* bitmap, float hotSpotX, float hotSpotY); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 104 | void setInactivityFadeDelay(InactivityFadeDelay inactivityFadeDelay); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 105 | |
| 106 | private: |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 107 | enum { |
| 108 | MSG_FADE_STEP = 0, |
| 109 | }; |
| 110 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 111 | mutable Mutex mLock; |
| 112 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 113 | sp<Looper> mLooper; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 114 | int32_t mPointerLayer; |
| 115 | sp<SurfaceComposerClient> mSurfaceComposerClient; |
| 116 | sp<SurfaceControl> mSurfaceControl; |
| 117 | |
| 118 | struct Locked { |
| 119 | int32_t displayWidth; |
| 120 | int32_t displayHeight; |
| 121 | int32_t displayOrientation; |
| 122 | |
| 123 | float pointerX; |
| 124 | float pointerY; |
| 125 | uint32_t buttonState; |
| 126 | |
| 127 | SkBitmap* iconBitmap; |
| 128 | float iconHotSpotX; |
| 129 | float iconHotSpotY; |
| 130 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 131 | float fadeAlpha; |
| 132 | InactivityFadeDelay inactivityFadeDelay; |
| 133 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 134 | bool wantVisible; |
| 135 | bool visible; |
| 136 | bool drawn; |
| 137 | } mLocked; |
| 138 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 139 | sp<WeakMessageHandler> mHandler; |
| 140 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 141 | bool getBoundsLocked(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const; |
| 142 | void setPositionLocked(float x, float y); |
| 143 | void updateLocked(); |
| 144 | bool createSurfaceIfNeededLocked(); |
| 145 | bool drawPointerIfNeededLocked(); |
| 146 | bool resizeSurfaceLocked(int32_t width, int32_t height); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 147 | |
| 148 | void handleMessage(const Message& message); |
| 149 | bool unfadeBeforeUpdateLocked(); |
| 150 | void startFadeLocked(); |
| 151 | void startInactivityFadeDelayLocked(); |
| 152 | void fadeStepLocked(); |
| 153 | bool isFadingLocked(); |
| 154 | nsecs_t getInactivityFadeDelayTimeLocked(); |
| 155 | void sendFadeStepMessageDelayedLocked(nsecs_t delayTime); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | } // namespace android |
| 159 | |
| 160 | #endif // _UI_POINTER_CONTROLLER_H |