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