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 | #define LOG_TAG "PointerController" |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | // Log debug messages about pointer updates |
| 22 | #define DEBUG_POINTER_UPDATES 0 |
| 23 | |
| 24 | #include "PointerController.h" |
| 25 | |
| 26 | #include <cutils/log.h> |
| 27 | |
Andreas Gampe | 6b83b76 | 2014-11-10 15:55:11 -0800 | [diff] [blame] | 28 | #pragma GCC diagnostic push |
| 29 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 30 | #include <SkBitmap.h> |
| 31 | #include <SkCanvas.h> |
| 32 | #include <SkColor.h> |
| 33 | #include <SkPaint.h> |
| 34 | #include <SkXfermode.h> |
Andreas Gampe | 6b83b76 | 2014-11-10 15:55:11 -0800 | [diff] [blame] | 35 | #pragma GCC diagnostic pop |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 36 | |
| 37 | namespace android { |
| 38 | |
| 39 | // --- PointerController --- |
| 40 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 41 | // Time to wait before starting the fade when the pointer is inactive. |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 42 | static const nsecs_t INACTIVITY_TIMEOUT_DELAY_TIME_NORMAL = 15 * 1000 * 1000000LL; // 15 seconds |
| 43 | static const nsecs_t INACTIVITY_TIMEOUT_DELAY_TIME_SHORT = 3 * 1000 * 1000000LL; // 3 seconds |
| 44 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 45 | // Time to spend fading out the spot completely. |
| 46 | static const nsecs_t SPOT_FADE_DURATION = 200 * 1000000LL; // 200 ms |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 47 | |
| 48 | // Time to spend fading out the pointer completely. |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 49 | static const nsecs_t POINTER_FADE_DURATION = 500 * 1000000LL; // 500 ms |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 50 | |
Jun Mukai | c0c0ac3 | 2015-10-27 10:09:21 -0700 | [diff] [blame] | 51 | // The number of events to be read at once for DisplayEventReceiver. |
| 52 | static const int EVENT_BUFFER_SIZE = 100; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 53 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 54 | // --- PointerController --- |
| 55 | |
| 56 | PointerController::PointerController(const sp<PointerControllerPolicyInterface>& policy, |
| 57 | const sp<Looper>& looper, const sp<SpriteController>& spriteController) : |
| 58 | mPolicy(policy), mLooper(looper), mSpriteController(spriteController) { |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 59 | mHandler = new WeakMessageHandler(this); |
| 60 | |
Jun Mukai | c0c0ac3 | 2015-10-27 10:09:21 -0700 | [diff] [blame] | 61 | if (mDisplayEventReceiver.initCheck() == NO_ERROR) { |
| 62 | mLooper->addFd(mDisplayEventReceiver.getFd(), Looper::POLL_CALLBACK, |
| 63 | Looper::EVENT_INPUT, this, nullptr); |
| 64 | } else { |
| 65 | ALOGE("Failed to initialize DisplayEventReceiver."); |
| 66 | } |
| 67 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 68 | AutoMutex _l(mLock); |
| 69 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 70 | mLocked.animationPending = false; |
| 71 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 72 | mLocked.displayWidth = -1; |
| 73 | mLocked.displayHeight = -1; |
| 74 | mLocked.displayOrientation = DISPLAY_ORIENTATION_0; |
| 75 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 76 | mLocked.presentation = PRESENTATION_POINTER; |
| 77 | mLocked.presentationChanged = false; |
| 78 | |
| 79 | mLocked.inactivityTimeout = INACTIVITY_TIMEOUT_NORMAL; |
| 80 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 81 | mLocked.pointerFadeDirection = 0; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 82 | mLocked.pointerX = 0; |
| 83 | mLocked.pointerY = 0; |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 84 | mLocked.pointerAlpha = 0.0f; // pointer is initially faded |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 85 | mLocked.pointerSprite = mSpriteController->createSprite(); |
| 86 | mLocked.pointerIconChanged = false; |
Jun Mukai | 5ec7420 | 2015-10-07 16:58:09 +0900 | [diff] [blame] | 87 | mLocked.requestedPointerShape = mPolicy->getDefaultPointerIconId(); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 88 | |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 89 | mLocked.animationFrameIndex = 0; |
| 90 | mLocked.lastFrameUpdatedTime = 0; |
| 91 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 92 | mLocked.buttonState = 0; |
| 93 | |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 94 | mPolicy->loadPointerIcon(&mLocked.pointerIcon); |
| 95 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 96 | loadResources(); |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 97 | |
| 98 | if (mLocked.pointerIcon.isValid()) { |
| 99 | mLocked.pointerIconChanged = true; |
| 100 | updatePointerLocked(); |
| 101 | } |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | PointerController::~PointerController() { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 105 | mLooper->removeMessages(mHandler); |
| 106 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 107 | AutoMutex _l(mLock); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 108 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 109 | mLocked.pointerSprite.clear(); |
| 110 | |
| 111 | for (size_t i = 0; i < mLocked.spots.size(); i++) { |
| 112 | delete mLocked.spots.itemAt(i); |
| 113 | } |
| 114 | mLocked.spots.clear(); |
| 115 | mLocked.recycledSprites.clear(); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | bool PointerController::getBounds(float* outMinX, float* outMinY, |
| 119 | float* outMaxX, float* outMaxY) const { |
| 120 | AutoMutex _l(mLock); |
| 121 | |
| 122 | return getBoundsLocked(outMinX, outMinY, outMaxX, outMaxY); |
| 123 | } |
| 124 | |
| 125 | bool PointerController::getBoundsLocked(float* outMinX, float* outMinY, |
| 126 | float* outMaxX, float* outMaxY) const { |
| 127 | if (mLocked.displayWidth <= 0 || mLocked.displayHeight <= 0) { |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | *outMinX = 0; |
| 132 | *outMinY = 0; |
| 133 | switch (mLocked.displayOrientation) { |
| 134 | case DISPLAY_ORIENTATION_90: |
| 135 | case DISPLAY_ORIENTATION_270: |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 136 | *outMaxX = mLocked.displayHeight - 1; |
| 137 | *outMaxY = mLocked.displayWidth - 1; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 138 | break; |
| 139 | default: |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 140 | *outMaxX = mLocked.displayWidth - 1; |
| 141 | *outMaxY = mLocked.displayHeight - 1; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | void PointerController::move(float deltaX, float deltaY) { |
| 148 | #if DEBUG_POINTER_UPDATES |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 149 | ALOGD("Move pointer by deltaX=%0.3f, deltaY=%0.3f", deltaX, deltaY); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 150 | #endif |
| 151 | if (deltaX == 0.0f && deltaY == 0.0f) { |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | AutoMutex _l(mLock); |
| 156 | |
| 157 | setPositionLocked(mLocked.pointerX + deltaX, mLocked.pointerY + deltaY); |
| 158 | } |
| 159 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 160 | void PointerController::setButtonState(int32_t buttonState) { |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 161 | #if DEBUG_POINTER_UPDATES |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 162 | ALOGD("Set button state 0x%08x", buttonState); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 163 | #endif |
| 164 | AutoMutex _l(mLock); |
| 165 | |
| 166 | if (mLocked.buttonState != buttonState) { |
| 167 | mLocked.buttonState = buttonState; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 171 | int32_t PointerController::getButtonState() const { |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 172 | AutoMutex _l(mLock); |
| 173 | |
| 174 | return mLocked.buttonState; |
| 175 | } |
| 176 | |
| 177 | void PointerController::setPosition(float x, float y) { |
| 178 | #if DEBUG_POINTER_UPDATES |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 179 | ALOGD("Set pointer position to x=%0.3f, y=%0.3f", x, y); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 180 | #endif |
| 181 | AutoMutex _l(mLock); |
| 182 | |
| 183 | setPositionLocked(x, y); |
| 184 | } |
| 185 | |
| 186 | void PointerController::setPositionLocked(float x, float y) { |
| 187 | float minX, minY, maxX, maxY; |
| 188 | if (getBoundsLocked(&minX, &minY, &maxX, &maxY)) { |
| 189 | if (x <= minX) { |
| 190 | mLocked.pointerX = minX; |
| 191 | } else if (x >= maxX) { |
| 192 | mLocked.pointerX = maxX; |
| 193 | } else { |
| 194 | mLocked.pointerX = x; |
| 195 | } |
| 196 | if (y <= minY) { |
| 197 | mLocked.pointerY = minY; |
| 198 | } else if (y >= maxY) { |
| 199 | mLocked.pointerY = maxY; |
| 200 | } else { |
| 201 | mLocked.pointerY = y; |
| 202 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 203 | updatePointerLocked(); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | void PointerController::getPosition(float* outX, float* outY) const { |
| 208 | AutoMutex _l(mLock); |
| 209 | |
| 210 | *outX = mLocked.pointerX; |
| 211 | *outY = mLocked.pointerY; |
| 212 | } |
| 213 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 214 | void PointerController::fade(Transition transition) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 215 | AutoMutex _l(mLock); |
| 216 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 217 | // Remove the inactivity timeout, since we are fading now. |
| 218 | removeInactivityTimeoutLocked(); |
| 219 | |
| 220 | // Start fading. |
| 221 | if (transition == TRANSITION_IMMEDIATE) { |
| 222 | mLocked.pointerFadeDirection = 0; |
| 223 | mLocked.pointerAlpha = 0.0f; |
| 224 | updatePointerLocked(); |
| 225 | } else { |
| 226 | mLocked.pointerFadeDirection = -1; |
| 227 | startAnimationLocked(); |
| 228 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 231 | void PointerController::unfade(Transition transition) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 232 | AutoMutex _l(mLock); |
| 233 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 234 | // Always reset the inactivity timer. |
| 235 | resetInactivityTimeoutLocked(); |
| 236 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 237 | // Start unfading. |
| 238 | if (transition == TRANSITION_IMMEDIATE) { |
| 239 | mLocked.pointerFadeDirection = 0; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 240 | mLocked.pointerAlpha = 1.0f; |
| 241 | updatePointerLocked(); |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 242 | } else { |
| 243 | mLocked.pointerFadeDirection = 1; |
| 244 | startAnimationLocked(); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 248 | void PointerController::setPresentation(Presentation presentation) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 249 | AutoMutex _l(mLock); |
| 250 | |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 251 | if (presentation == PRESENTATION_POINTER && mLocked.additionalMouseResources.empty()) { |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 252 | mPolicy->loadAdditionalMouseResources(&mLocked.additionalMouseResources, |
| 253 | &mLocked.animationResources); |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 256 | if (mLocked.presentation != presentation) { |
| 257 | mLocked.presentation = presentation; |
| 258 | mLocked.presentationChanged = true; |
| 259 | |
| 260 | if (presentation != PRESENTATION_SPOT) { |
| 261 | fadeOutAndReleaseAllSpotsLocked(); |
| 262 | } |
| 263 | |
| 264 | updatePointerLocked(); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
Jeff Brown | cb5ffcf | 2011-06-06 20:03:18 -0700 | [diff] [blame] | 268 | void PointerController::setSpots(const PointerCoords* spotCoords, |
| 269 | const uint32_t* spotIdToIndex, BitSet32 spotIdBits) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 270 | #if DEBUG_POINTER_UPDATES |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 271 | ALOGD("setSpots: idBits=%08x", spotIdBits.value); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 272 | for (BitSet32 idBits(spotIdBits); !idBits.isEmpty(); ) { |
| 273 | uint32_t id = idBits.firstMarkedBit(); |
| 274 | idBits.clearBit(id); |
| 275 | const PointerCoords& c = spotCoords[spotIdToIndex[id]]; |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 276 | ALOGD(" spot %d: position=(%0.3f, %0.3f), pressure=%0.3f", id, |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 277 | c.getAxisValue(AMOTION_EVENT_AXIS_X), |
| 278 | c.getAxisValue(AMOTION_EVENT_AXIS_Y), |
| 279 | c.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); |
| 280 | } |
| 281 | #endif |
| 282 | |
| 283 | AutoMutex _l(mLock); |
| 284 | |
| 285 | mSpriteController->openTransaction(); |
| 286 | |
| 287 | // Add or move spots for fingers that are down. |
| 288 | for (BitSet32 idBits(spotIdBits); !idBits.isEmpty(); ) { |
Jeff Brown | be1aa82 | 2011-07-27 16:04:54 -0700 | [diff] [blame] | 289 | uint32_t id = idBits.clearFirstMarkedBit(); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 290 | const PointerCoords& c = spotCoords[spotIdToIndex[id]]; |
| 291 | const SpriteIcon& icon = c.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE) > 0 |
| 292 | ? mResources.spotTouch : mResources.spotHover; |
| 293 | float x = c.getAxisValue(AMOTION_EVENT_AXIS_X); |
| 294 | float y = c.getAxisValue(AMOTION_EVENT_AXIS_Y); |
| 295 | |
| 296 | Spot* spot = getSpotLocked(id); |
| 297 | if (!spot) { |
| 298 | spot = createAndAddSpotLocked(id); |
| 299 | } |
| 300 | |
| 301 | spot->updateSprite(&icon, x, y); |
| 302 | } |
| 303 | |
| 304 | // Remove spots for fingers that went up. |
| 305 | for (size_t i = 0; i < mLocked.spots.size(); i++) { |
| 306 | Spot* spot = mLocked.spots.itemAt(i); |
| 307 | if (spot->id != Spot::INVALID_ID |
| 308 | && !spotIdBits.hasBit(spot->id)) { |
| 309 | fadeOutAndReleaseSpotLocked(spot); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | mSpriteController->closeTransaction(); |
| 314 | } |
| 315 | |
| 316 | void PointerController::clearSpots() { |
| 317 | #if DEBUG_POINTER_UPDATES |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 318 | ALOGD("clearSpots"); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 319 | #endif |
| 320 | |
| 321 | AutoMutex _l(mLock); |
| 322 | |
| 323 | fadeOutAndReleaseAllSpotsLocked(); |
| 324 | } |
| 325 | |
| 326 | void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout) { |
| 327 | AutoMutex _l(mLock); |
| 328 | |
| 329 | if (mLocked.inactivityTimeout != inactivityTimeout) { |
| 330 | mLocked.inactivityTimeout = inactivityTimeout; |
| 331 | resetInactivityTimeoutLocked(); |
| 332 | } |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 335 | void PointerController::reloadPointerResources() { |
| 336 | AutoMutex _l(mLock); |
| 337 | |
| 338 | loadResources(); |
| 339 | |
| 340 | if (mLocked.presentation == PRESENTATION_POINTER) { |
| 341 | mLocked.additionalMouseResources.clear(); |
| 342 | mLocked.animationResources.clear(); |
| 343 | mPolicy->loadPointerIcon(&mLocked.pointerIcon); |
| 344 | mPolicy->loadAdditionalMouseResources(&mLocked.additionalMouseResources, |
| 345 | &mLocked.animationResources); |
| 346 | } |
| 347 | |
| 348 | mLocked.presentationChanged = true; |
| 349 | updatePointerLocked(); |
| 350 | } |
| 351 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 352 | void PointerController::setDisplayViewport(int32_t width, int32_t height, int32_t orientation) { |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 353 | AutoMutex _l(mLock); |
| 354 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 355 | // Adjust to use the display's unrotated coordinate frame. |
| 356 | if (orientation == DISPLAY_ORIENTATION_90 |
| 357 | || orientation == DISPLAY_ORIENTATION_270) { |
| 358 | int32_t temp = height; |
| 359 | height = width; |
| 360 | width = temp; |
| 361 | } |
| 362 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 363 | if (mLocked.displayWidth != width || mLocked.displayHeight != height) { |
| 364 | mLocked.displayWidth = width; |
| 365 | mLocked.displayHeight = height; |
| 366 | |
| 367 | float minX, minY, maxX, maxY; |
| 368 | if (getBoundsLocked(&minX, &minY, &maxX, &maxY)) { |
| 369 | mLocked.pointerX = (minX + maxX) * 0.5f; |
| 370 | mLocked.pointerY = (minY + maxY) * 0.5f; |
| 371 | } else { |
| 372 | mLocked.pointerX = 0; |
| 373 | mLocked.pointerY = 0; |
| 374 | } |
| 375 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 376 | fadeOutAndReleaseAllSpotsLocked(); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 377 | } |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 378 | |
| 379 | if (mLocked.displayOrientation != orientation) { |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 380 | // Apply offsets to convert from the pixel top-left corner position to the pixel center. |
| 381 | // This creates an invariant frame of reference that we can easily rotate when |
| 382 | // taking into account that the pointer may be located at fractional pixel offsets. |
| 383 | float x = mLocked.pointerX + 0.5f; |
| 384 | float y = mLocked.pointerY + 0.5f; |
| 385 | float temp; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 386 | |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 387 | // Undo the previous rotation. |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 388 | switch (mLocked.displayOrientation) { |
| 389 | case DISPLAY_ORIENTATION_90: |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 390 | temp = x; |
| 391 | x = mLocked.displayWidth - y; |
| 392 | y = temp; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 393 | break; |
| 394 | case DISPLAY_ORIENTATION_180: |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 395 | x = mLocked.displayWidth - x; |
| 396 | y = mLocked.displayHeight - y; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 397 | break; |
| 398 | case DISPLAY_ORIENTATION_270: |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 399 | temp = x; |
| 400 | x = y; |
| 401 | y = mLocked.displayHeight - temp; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 402 | break; |
| 403 | } |
| 404 | |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 405 | // Perform the new rotation. |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 406 | switch (orientation) { |
| 407 | case DISPLAY_ORIENTATION_90: |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 408 | temp = x; |
| 409 | x = y; |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 410 | y = mLocked.displayWidth - temp; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 411 | break; |
| 412 | case DISPLAY_ORIENTATION_180: |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 413 | x = mLocked.displayWidth - x; |
| 414 | y = mLocked.displayHeight - y; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 415 | break; |
| 416 | case DISPLAY_ORIENTATION_270: |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 417 | temp = x; |
| 418 | x = mLocked.displayHeight - y; |
| 419 | y = temp; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 420 | break; |
| 421 | } |
| 422 | |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 423 | // Apply offsets to convert from the pixel center to the pixel top-left corner position |
| 424 | // and save the results. |
| 425 | mLocked.pointerX = x - 0.5f; |
| 426 | mLocked.pointerY = y - 0.5f; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 427 | mLocked.displayOrientation = orientation; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 428 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 429 | |
| 430 | updatePointerLocked(); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 433 | void PointerController::updatePointerShape(int32_t iconId) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 434 | AutoMutex _l(mLock); |
| 435 | if (mLocked.requestedPointerShape != iconId) { |
| 436 | mLocked.requestedPointerShape = iconId; |
| 437 | mLocked.presentationChanged = true; |
| 438 | updatePointerLocked(); |
| 439 | } |
| 440 | } |
| 441 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 442 | void PointerController::handleMessage(const Message& message) { |
| 443 | switch (message.what) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 444 | case MSG_INACTIVITY_TIMEOUT: |
| 445 | doInactivityTimeout(); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 446 | break; |
| 447 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Jun Mukai | c0c0ac3 | 2015-10-27 10:09:21 -0700 | [diff] [blame] | 450 | int PointerController::handleEvent(int /* fd */, int events, void* /* data */) { |
| 451 | if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) { |
| 452 | ALOGE("Display event receiver pipe was closed or an error occurred. " |
| 453 | "events=0x%x", events); |
| 454 | return 0; // remove the callback |
| 455 | } |
| 456 | |
| 457 | if (!(events & Looper::EVENT_INPUT)) { |
| 458 | ALOGW("Received spurious callback for unhandled poll event. " |
| 459 | "events=0x%x", events); |
| 460 | return 1; // keep the callback |
| 461 | } |
| 462 | |
| 463 | bool gotVsync = false; |
| 464 | ssize_t n; |
| 465 | nsecs_t timestamp; |
| 466 | DisplayEventReceiver::Event buf[EVENT_BUFFER_SIZE]; |
| 467 | while ((n = mDisplayEventReceiver.getEvents(buf, EVENT_BUFFER_SIZE)) > 0) { |
| 468 | for (size_t i = 0; i < static_cast<size_t>(n); ++i) { |
| 469 | if (buf[i].header.type == DisplayEventReceiver::DISPLAY_EVENT_VSYNC) { |
| 470 | timestamp = buf[i].header.timestamp; |
| 471 | gotVsync = true; |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | if (gotVsync) { |
| 476 | doAnimate(timestamp); |
| 477 | } |
| 478 | return 1; // keep the callback |
| 479 | } |
| 480 | |
| 481 | void PointerController::doAnimate(nsecs_t timestamp) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 482 | AutoMutex _l(mLock); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 483 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 484 | mLocked.animationPending = false; |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 485 | |
| 486 | bool keepFading = doFadingAnimationLocked(timestamp); |
| 487 | bool keepBitmapFlipping = doBitmapAnimationLocked(timestamp); |
| 488 | if (keepFading || keepBitmapFlipping) { |
| 489 | startAnimationLocked(); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | bool PointerController::doFadingAnimationLocked(nsecs_t timestamp) { |
| 494 | bool keepAnimating = false; |
Jun Mukai | c0c0ac3 | 2015-10-27 10:09:21 -0700 | [diff] [blame] | 495 | nsecs_t frameDelay = timestamp - mLocked.animationTime; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 496 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 497 | // Animate pointer fade. |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 498 | if (mLocked.pointerFadeDirection < 0) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 499 | mLocked.pointerAlpha -= float(frameDelay) / POINTER_FADE_DURATION; |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 500 | if (mLocked.pointerAlpha <= 0.0f) { |
| 501 | mLocked.pointerAlpha = 0.0f; |
| 502 | mLocked.pointerFadeDirection = 0; |
| 503 | } else { |
| 504 | keepAnimating = true; |
| 505 | } |
| 506 | updatePointerLocked(); |
| 507 | } else if (mLocked.pointerFadeDirection > 0) { |
| 508 | mLocked.pointerAlpha += float(frameDelay) / POINTER_FADE_DURATION; |
| 509 | if (mLocked.pointerAlpha >= 1.0f) { |
| 510 | mLocked.pointerAlpha = 1.0f; |
| 511 | mLocked.pointerFadeDirection = 0; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 512 | } else { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 513 | keepAnimating = true; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 514 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 515 | updatePointerLocked(); |
| 516 | } |
| 517 | |
| 518 | // Animate spots that are fading out and being removed. |
| 519 | for (size_t i = 0; i < mLocked.spots.size(); i++) { |
| 520 | Spot* spot = mLocked.spots.itemAt(i); |
| 521 | if (spot->id == Spot::INVALID_ID) { |
| 522 | spot->alpha -= float(frameDelay) / SPOT_FADE_DURATION; |
| 523 | if (spot->alpha <= 0) { |
| 524 | mLocked.spots.removeAt(i--); |
| 525 | releaseSpotLocked(spot); |
| 526 | } else { |
| 527 | spot->sprite->setAlpha(spot->alpha); |
| 528 | keepAnimating = true; |
| 529 | } |
| 530 | } |
| 531 | } |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 532 | return keepAnimating; |
| 533 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 534 | |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 535 | bool PointerController::doBitmapAnimationLocked(nsecs_t timestamp) { |
| 536 | std::map<int32_t, PointerAnimation>::const_iterator iter = mLocked.animationResources.find( |
| 537 | mLocked.requestedPointerShape); |
| 538 | if (iter == mLocked.animationResources.end()) { |
| 539 | return false; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 540 | } |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 541 | |
| 542 | if (timestamp - mLocked.lastFrameUpdatedTime > iter->second.durationPerFrame) { |
| 543 | mSpriteController->openTransaction(); |
| 544 | |
| 545 | int incr = (timestamp - mLocked.lastFrameUpdatedTime) / iter->second.durationPerFrame; |
| 546 | mLocked.animationFrameIndex += incr; |
| 547 | mLocked.lastFrameUpdatedTime += iter->second.durationPerFrame * incr; |
| 548 | while (mLocked.animationFrameIndex >= iter->second.animationFrames.size()) { |
| 549 | mLocked.animationFrameIndex -= iter->second.animationFrames.size(); |
| 550 | } |
| 551 | mLocked.pointerSprite->setIcon(iter->second.animationFrames[mLocked.animationFrameIndex]); |
| 552 | |
| 553 | mSpriteController->closeTransaction(); |
| 554 | } |
| 555 | |
| 556 | // Keep animating. |
| 557 | return true; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 560 | void PointerController::doInactivityTimeout() { |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 561 | fade(TRANSITION_GRADUAL); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 564 | void PointerController::startAnimationLocked() { |
| 565 | if (!mLocked.animationPending) { |
| 566 | mLocked.animationPending = true; |
| 567 | mLocked.animationTime = systemTime(SYSTEM_TIME_MONOTONIC); |
Jun Mukai | c0c0ac3 | 2015-10-27 10:09:21 -0700 | [diff] [blame] | 568 | mDisplayEventReceiver.requestNextVsync(); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 569 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 570 | } |
| 571 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 572 | void PointerController::resetInactivityTimeoutLocked() { |
| 573 | mLooper->removeMessages(mHandler, MSG_INACTIVITY_TIMEOUT); |
| 574 | |
| 575 | nsecs_t timeout = mLocked.inactivityTimeout == INACTIVITY_TIMEOUT_SHORT |
| 576 | ? INACTIVITY_TIMEOUT_DELAY_TIME_SHORT : INACTIVITY_TIMEOUT_DELAY_TIME_NORMAL; |
| 577 | mLooper->sendMessageDelayed(timeout, mHandler, MSG_INACTIVITY_TIMEOUT); |
| 578 | } |
| 579 | |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 580 | void PointerController::removeInactivityTimeoutLocked() { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 581 | mLooper->removeMessages(mHandler, MSG_INACTIVITY_TIMEOUT); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | void PointerController::updatePointerLocked() { |
| 585 | mSpriteController->openTransaction(); |
| 586 | |
| 587 | mLocked.pointerSprite->setLayer(Sprite::BASE_LAYER_POINTER); |
| 588 | mLocked.pointerSprite->setPosition(mLocked.pointerX, mLocked.pointerY); |
| 589 | |
| 590 | if (mLocked.pointerAlpha > 0) { |
| 591 | mLocked.pointerSprite->setAlpha(mLocked.pointerAlpha); |
| 592 | mLocked.pointerSprite->setVisible(true); |
| 593 | } else { |
| 594 | mLocked.pointerSprite->setVisible(false); |
| 595 | } |
| 596 | |
| 597 | if (mLocked.pointerIconChanged || mLocked.presentationChanged) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 598 | if (mLocked.presentation == PRESENTATION_POINTER) { |
Jun Mukai | 5ec7420 | 2015-10-07 16:58:09 +0900 | [diff] [blame] | 599 | if (mLocked.requestedPointerShape == mPolicy->getDefaultPointerIconId()) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 600 | mLocked.pointerSprite->setIcon(mLocked.pointerIcon); |
| 601 | } else { |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 602 | std::map<int32_t, SpriteIcon>::const_iterator iter = |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 603 | mLocked.additionalMouseResources.find(mLocked.requestedPointerShape); |
| 604 | if (iter != mLocked.additionalMouseResources.end()) { |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 605 | std::map<int32_t, PointerAnimation>::const_iterator anim_iter = |
| 606 | mLocked.animationResources.find(mLocked.requestedPointerShape); |
| 607 | if (anim_iter != mLocked.animationResources.end()) { |
| 608 | mLocked.animationFrameIndex = 0; |
| 609 | mLocked.lastFrameUpdatedTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 610 | startAnimationLocked(); |
| 611 | } |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 612 | mLocked.pointerSprite->setIcon(iter->second); |
| 613 | } else { |
| 614 | ALOGW("Can't find the resource for icon id %d", mLocked.requestedPointerShape); |
| 615 | mLocked.pointerSprite->setIcon(mLocked.pointerIcon); |
| 616 | } |
| 617 | } |
| 618 | } else { |
| 619 | mLocked.pointerSprite->setIcon(mResources.spotAnchor); |
| 620 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 621 | mLocked.pointerIconChanged = false; |
| 622 | mLocked.presentationChanged = false; |
| 623 | } |
| 624 | |
| 625 | mSpriteController->closeTransaction(); |
| 626 | } |
| 627 | |
| 628 | PointerController::Spot* PointerController::getSpotLocked(uint32_t id) { |
| 629 | for (size_t i = 0; i < mLocked.spots.size(); i++) { |
| 630 | Spot* spot = mLocked.spots.itemAt(i); |
| 631 | if (spot->id == id) { |
| 632 | return spot; |
| 633 | } |
| 634 | } |
| 635 | return NULL; |
| 636 | } |
| 637 | |
| 638 | PointerController::Spot* PointerController::createAndAddSpotLocked(uint32_t id) { |
| 639 | // Remove spots until we have fewer than MAX_SPOTS remaining. |
| 640 | while (mLocked.spots.size() >= MAX_SPOTS) { |
| 641 | Spot* spot = removeFirstFadingSpotLocked(); |
| 642 | if (!spot) { |
| 643 | spot = mLocked.spots.itemAt(0); |
| 644 | mLocked.spots.removeAt(0); |
| 645 | } |
| 646 | releaseSpotLocked(spot); |
| 647 | } |
| 648 | |
| 649 | // Obtain a sprite from the recycled pool. |
| 650 | sp<Sprite> sprite; |
| 651 | if (! mLocked.recycledSprites.isEmpty()) { |
| 652 | sprite = mLocked.recycledSprites.top(); |
| 653 | mLocked.recycledSprites.pop(); |
| 654 | } else { |
| 655 | sprite = mSpriteController->createSprite(); |
| 656 | } |
| 657 | |
| 658 | // Return the new spot. |
| 659 | Spot* spot = new Spot(id, sprite); |
| 660 | mLocked.spots.push(spot); |
| 661 | return spot; |
| 662 | } |
| 663 | |
| 664 | PointerController::Spot* PointerController::removeFirstFadingSpotLocked() { |
| 665 | for (size_t i = 0; i < mLocked.spots.size(); i++) { |
| 666 | Spot* spot = mLocked.spots.itemAt(i); |
| 667 | if (spot->id == Spot::INVALID_ID) { |
| 668 | mLocked.spots.removeAt(i); |
| 669 | return spot; |
| 670 | } |
| 671 | } |
| 672 | return NULL; |
| 673 | } |
| 674 | |
| 675 | void PointerController::releaseSpotLocked(Spot* spot) { |
| 676 | spot->sprite->clearIcon(); |
| 677 | |
| 678 | if (mLocked.recycledSprites.size() < MAX_RECYCLED_SPRITES) { |
| 679 | mLocked.recycledSprites.push(spot->sprite); |
| 680 | } |
| 681 | |
| 682 | delete spot; |
| 683 | } |
| 684 | |
| 685 | void PointerController::fadeOutAndReleaseSpotLocked(Spot* spot) { |
| 686 | if (spot->id != Spot::INVALID_ID) { |
| 687 | spot->id = Spot::INVALID_ID; |
| 688 | startAnimationLocked(); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | void PointerController::fadeOutAndReleaseAllSpotsLocked() { |
| 693 | for (size_t i = 0; i < mLocked.spots.size(); i++) { |
| 694 | Spot* spot = mLocked.spots.itemAt(i); |
| 695 | fadeOutAndReleaseSpotLocked(spot); |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | void PointerController::loadResources() { |
| 700 | mPolicy->loadPointerResources(&mResources); |
| 701 | } |
| 702 | |
| 703 | |
| 704 | // --- PointerController::Spot --- |
| 705 | |
| 706 | void PointerController::Spot::updateSprite(const SpriteIcon* icon, float x, float y) { |
| 707 | sprite->setLayer(Sprite::BASE_LAYER_SPOT + id); |
| 708 | sprite->setAlpha(alpha); |
| 709 | sprite->setTransformationMatrix(SpriteTransformationMatrix(scale, 0.0f, 0.0f, scale)); |
| 710 | sprite->setPosition(x, y); |
| 711 | |
| 712 | this->x = x; |
| 713 | this->y = y; |
| 714 | |
| 715 | if (icon != lastIcon) { |
| 716 | lastIcon = icon; |
| 717 | if (icon) { |
| 718 | sprite->setIcon(*icon); |
| 719 | sprite->setVisible(true); |
| 720 | } else { |
| 721 | sprite->setVisible(false); |
| 722 | } |
| 723 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 724 | } |
| 725 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 726 | } // namespace android |