| /* | |
| * Copyright (C) 2010 The Android Open Source Project | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| #ifndef _UI_POINTER_CONTROLLER_H | |
| #define _UI_POINTER_CONTROLLER_H | |
| #include <PointerControllerInterface.h> | |
| #include <gui/DisplayInfo.h> | |
| #include <input/DisplayViewport.h> | |
| #include <input/Input.h> | |
| #include <math/vec2.h> | |
| #include <ui/LogicalDisplayId.h> | |
| #include <ui/Transform.h> | |
| #include <utils/BitSet.h> | |
| #include <utils/Looper.h> | |
| #include <utils/StrongPointer.h> | |
| #include <flat_set> | |
| #include <memory> | |
| #include <mutex> | |
| #include <string> | |
| #include <unordered_map> | |
| #include <unordered_set> | |
| #include <vector> | |
| #include "MouseCursorController.h" | |
| #include "PointerControllerContext.h" | |
| #include "SpriteController.h" | |
| #include "SpriteIcon.h" | |
| #include "TouchSpotController.h" | |
| namespace android { | |
| /* | |
| * Tracks pointer movements and draws the pointer sprite to a surface. | |
| * | |
| * Handles pointer acceleration and animation. | |
| */ | |
| class PointerController : public PointerControllerInterface { | |
| public: | |
| static std::shared_ptr<PointerController> create( | |
| const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper, | |
| SpriteController& spriteController, ControllerType type, | |
| const std::vector<gui::DisplayInfo>& initialDisplayInfos); | |
| ~PointerController() override; | |
| vec2 move(float deltaX, float deltaY) override; | |
| void setPosition(float x, float y) override; | |
| vec2 getPosition() const override; | |
| vec2 getPositionInLogicalDisplay() const override; | |
| ui::LogicalDisplayId getDisplayId() const override; | |
| void fade(Transition transition) override; | |
| void unfade(Transition transition) override; | |
| void setDisplayViewport(const DisplayViewport& viewport) override; | |
| void setPresentation(Presentation presentation) override; | |
| void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, | |
| BitSet32 spotIdBits, ui::LogicalDisplayId displayId) override; | |
| void clearSpots() override; | |
| void updatePointerIcon(PointerIconStyle iconId) override; | |
| void setCustomPointerIcon(const SpriteIcon& icon) override; | |
| void setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId displayId) override; | |
| void clearSkipScreenshotFlags() override; | |
| void setSkipOnUnsecureMirroredDisplayFlagForDisplay(ui::LogicalDisplayId displayId) override; | |
| void clearSkipOnUnsecureMirroredDisplayFlags() override; | |
| ui::Transform getDisplayTransform() const override; | |
| virtual void setInactivityTimeout(InactivityTimeout inactivityTimeout); | |
| void doInactivityTimeout(); | |
| void reloadPointerResources(); | |
| void onDisplayViewportsUpdated(const std::vector<DisplayViewport>& viewports); | |
| void onDisplayInfosChanged(const std::vector<gui::DisplayInfo>& displayInfos) override; | |
| virtual ControllerType getControllerType() const { | |
| return ControllerType::MOUSE; | |
| } | |
| std::string dump() override; | |
| protected: | |
| PointerController(const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper, | |
| SpriteController& spriteController, | |
| const std::vector<gui::DisplayInfo>& initialDisplayInfos); | |
| private: | |
| friend PointerControllerContext::LooperCallback; | |
| friend PointerControllerContext::MessageHandler; | |
| PointerControllerContext mContext; | |
| MouseCursorController mCursorController; | |
| mutable std::mutex mLock; | |
| struct Locked { | |
| Presentation presentation; | |
| ui::LogicalDisplayId pointerDisplayId = ui::LogicalDisplayId::INVALID; | |
| std::vector<gui::DisplayInfo> mDisplayInfos; | |
| std::unordered_map<ui::LogicalDisplayId, TouchSpotController> spotControllers; | |
| std::unordered_set<ui::LogicalDisplayId> displaysToSkipScreenshot; | |
| // The set of logical display IDs where pointer indicators (e.g., mouse cursor, | |
| // touch spots) should be hidden when the display is mirrored to an unsecure | |
| // display. | |
| std::flat_set<ui::LogicalDisplayId> displaysToSkipOnUnsecureMirrored; | |
| } mLocked GUARDED_BY(mLock); | |
| const ui::Transform& getTransformForDisplayLocked(ui::LogicalDisplayId displayId) const | |
| REQUIRES(mLock); | |
| void clearSpotsLocked() REQUIRES(mLock); | |
| }; | |
| class MousePointerController : public PointerController { | |
| public: | |
| /** A version of PointerController that controls one mouse pointer. */ | |
| MousePointerController(const sp<PointerControllerPolicyInterface>& policy, | |
| const sp<Looper>& looper, SpriteController& spriteController, | |
| const std::vector<gui::DisplayInfo>& initialDisplayInfos); | |
| ~MousePointerController() override; | |
| void setPresentation(Presentation) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void setSpots(const PointerCoords*, const uint32_t*, BitSet32, ui::LogicalDisplayId) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void clearSpots() override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| }; | |
| class TouchPointerController : public PointerController { | |
| public: | |
| /** A version of PointerController that controls touch spots. */ | |
| TouchPointerController(const sp<PointerControllerPolicyInterface>& policy, | |
| const sp<Looper>& looper, SpriteController& spriteController, | |
| const std::vector<gui::DisplayInfo>& initialDisplayInfos); | |
| ~TouchPointerController() override; | |
| vec2 move(float, float) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void setPosition(float, float) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| vec2 getPosition() const override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| vec2 getPositionInLogicalDisplay() const override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| ui::LogicalDisplayId getDisplayId() const override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void fade(Transition) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void unfade(Transition) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void setDisplayViewport(const DisplayViewport&) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void setPresentation(Presentation) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void updatePointerIcon(PointerIconStyle) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void setCustomPointerIcon(const SpriteIcon&) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| // fade() should not be called by inactivity timeout. Do nothing. | |
| void setInactivityTimeout(InactivityTimeout) override {} | |
| ControllerType getControllerType() const override { | |
| return ControllerType::TOUCH; | |
| } | |
| }; | |
| class StylusPointerController : public PointerController { | |
| public: | |
| /** A version of PointerController that controls one stylus pointer. */ | |
| StylusPointerController(const sp<PointerControllerPolicyInterface>& policy, | |
| const sp<Looper>& looper, SpriteController& spriteController, | |
| const std::vector<gui::DisplayInfo>& initialDisplayInfos); | |
| ~StylusPointerController() override; | |
| void setPresentation(Presentation) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void setSpots(const PointerCoords*, const uint32_t*, BitSet32, ui::LogicalDisplayId) override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| void clearSpots() override { | |
| LOG_ALWAYS_FATAL("Should not be called"); | |
| } | |
| ControllerType getControllerType() const override { | |
| return ControllerType::STYLUS; | |
| } | |
| }; | |
| } // namespace android | |
| #endif // _UI_POINTER_CONTROLLER_H |