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 | |
| 34 | enum { |
| 35 | POINTER_BUTTON_1 = 1 << 0, |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * Interface for tracking a single (mouse) pointer. |
| 40 | * |
| 41 | * The pointer controller is responsible for providing synchronization and for tracking |
| 42 | * display orientation changes if needed. |
| 43 | */ |
| 44 | class PointerControllerInterface : public virtual RefBase { |
| 45 | protected: |
| 46 | PointerControllerInterface() { } |
| 47 | virtual ~PointerControllerInterface() { } |
| 48 | |
| 49 | public: |
| 50 | /* Gets the bounds of the region that the pointer can traverse. |
| 51 | * Returns true if the bounds are available. */ |
| 52 | virtual bool getBounds(float* outMinX, float* outMinY, |
| 53 | float* outMaxX, float* outMaxY) const = 0; |
| 54 | |
| 55 | /* Move the pointer. */ |
| 56 | virtual void move(float deltaX, float deltaY) = 0; |
| 57 | |
| 58 | /* Sets a mask that indicates which buttons are pressed. */ |
| 59 | virtual void setButtonState(uint32_t buttonState) = 0; |
| 60 | |
| 61 | /* Gets a mask that indicates which buttons are pressed. */ |
| 62 | virtual uint32_t getButtonState() const = 0; |
| 63 | |
| 64 | /* Sets the absolute location of the pointer. */ |
| 65 | virtual void setPosition(float x, float y) = 0; |
| 66 | |
| 67 | /* Gets the absolute location of the pointer. */ |
| 68 | virtual void getPosition(float* outX, float* outY) const = 0; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 69 | |
| 70 | /* Fades the pointer out now. */ |
| 71 | virtual void fade() = 0; |
| 72 | |
| 73 | /* Makes the pointer visible if it has faded out. */ |
| 74 | virtual void unfade() = 0; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | |
| 78 | /* |
| 79 | * Tracks pointer movements and draws the pointer sprite to a surface. |
| 80 | * |
| 81 | * Handles pointer acceleration and animation. |
| 82 | */ |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 83 | class PointerController : public PointerControllerInterface, public MessageHandler { |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 84 | protected: |
| 85 | virtual ~PointerController(); |
| 86 | |
| 87 | public: |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 88 | enum InactivityFadeDelay { |
| 89 | INACTIVITY_FADE_DELAY_NORMAL = 0, |
| 90 | INACTIVITY_FADE_DELAY_SHORT = 1, |
| 91 | }; |
| 92 | |
| 93 | PointerController(const sp<Looper>& looper, int32_t pointerLayer); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 94 | |
| 95 | virtual bool getBounds(float* outMinX, float* outMinY, |
| 96 | float* outMaxX, float* outMaxY) const; |
| 97 | virtual void move(float deltaX, float deltaY); |
| 98 | virtual void setButtonState(uint32_t buttonState); |
| 99 | virtual uint32_t getButtonState() const; |
| 100 | virtual void setPosition(float x, float y); |
| 101 | virtual void getPosition(float* outX, float* outY) const; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 102 | virtual void fade(); |
| 103 | virtual void unfade(); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 104 | |
| 105 | void setDisplaySize(int32_t width, int32_t height); |
| 106 | void setDisplayOrientation(int32_t orientation); |
| 107 | void setPointerIcon(const SkBitmap* bitmap, float hotSpotX, float hotSpotY); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 108 | void setInactivityFadeDelay(InactivityFadeDelay inactivityFadeDelay); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 109 | |
| 110 | private: |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 111 | enum { |
| 112 | MSG_FADE_STEP = 0, |
| 113 | }; |
| 114 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 115 | mutable Mutex mLock; |
| 116 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 117 | sp<Looper> mLooper; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 118 | int32_t mPointerLayer; |
| 119 | sp<SurfaceComposerClient> mSurfaceComposerClient; |
| 120 | sp<SurfaceControl> mSurfaceControl; |
| 121 | |
| 122 | struct Locked { |
| 123 | int32_t displayWidth; |
| 124 | int32_t displayHeight; |
| 125 | int32_t displayOrientation; |
| 126 | |
| 127 | float pointerX; |
| 128 | float pointerY; |
| 129 | uint32_t buttonState; |
| 130 | |
| 131 | SkBitmap* iconBitmap; |
| 132 | float iconHotSpotX; |
| 133 | float iconHotSpotY; |
| 134 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 135 | float fadeAlpha; |
| 136 | InactivityFadeDelay inactivityFadeDelay; |
| 137 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 138 | bool wantVisible; |
| 139 | bool visible; |
| 140 | bool drawn; |
| 141 | } mLocked; |
| 142 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 143 | sp<WeakMessageHandler> mHandler; |
| 144 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 145 | bool getBoundsLocked(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const; |
| 146 | void setPositionLocked(float x, float y); |
| 147 | void updateLocked(); |
| 148 | bool createSurfaceIfNeededLocked(); |
| 149 | bool drawPointerIfNeededLocked(); |
| 150 | bool resizeSurfaceLocked(int32_t width, int32_t height); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame^] | 151 | |
| 152 | void handleMessage(const Message& message); |
| 153 | bool unfadeBeforeUpdateLocked(); |
| 154 | void startFadeLocked(); |
| 155 | void startInactivityFadeDelayLocked(); |
| 156 | void fadeStepLocked(); |
| 157 | bool isFadingLocked(); |
| 158 | nsecs_t getInactivityFadeDelayTimeLocked(); |
| 159 | void sendFadeStepMessageDelayedLocked(nsecs_t delayTime); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | } // namespace android |
| 163 | |
| 164 | #endif // _UI_POINTER_CONTROLLER_H |