PointerController.h revision b4ff35df5c04aec71fce7e90a6d6f9ef7180c2ad
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> 21#include <utils/RefBase.h> 22#include <utils/String8.h> 23 24#include <surfaceflinger/Surface.h> 25#include <surfaceflinger/SurfaceComposerClient.h> 26#include <surfaceflinger/ISurfaceComposer.h> 27 28#include <SkBitmap.h> 29 30namespace android { 31 32enum { 33 POINTER_BUTTON_1 = 1 << 0, 34}; 35 36/** 37 * Interface for tracking a single (mouse) pointer. 38 * 39 * The pointer controller is responsible for providing synchronization and for tracking 40 * display orientation changes if needed. 41 */ 42class PointerControllerInterface : public virtual RefBase { 43protected: 44 PointerControllerInterface() { } 45 virtual ~PointerControllerInterface() { } 46 47public: 48 /* Gets the bounds of the region that the pointer can traverse. 49 * Returns true if the bounds are available. */ 50 virtual bool getBounds(float* outMinX, float* outMinY, 51 float* outMaxX, float* outMaxY) const = 0; 52 53 /* Move the pointer. */ 54 virtual void move(float deltaX, float deltaY) = 0; 55 56 /* Sets a mask that indicates which buttons are pressed. */ 57 virtual void setButtonState(uint32_t buttonState) = 0; 58 59 /* Gets a mask that indicates which buttons are pressed. */ 60 virtual uint32_t getButtonState() const = 0; 61 62 /* Sets the absolute location of the pointer. */ 63 virtual void setPosition(float x, float y) = 0; 64 65 /* Gets the absolute location of the pointer. */ 66 virtual void getPosition(float* outX, float* outY) const = 0; 67}; 68 69 70/* 71 * Tracks pointer movements and draws the pointer sprite to a surface. 72 * 73 * Handles pointer acceleration and animation. 74 */ 75class PointerController : public PointerControllerInterface { 76protected: 77 virtual ~PointerController(); 78 79public: 80 PointerController(int32_t pointerLayer); 81 82 virtual bool getBounds(float* outMinX, float* outMinY, 83 float* outMaxX, float* outMaxY) const; 84 virtual void move(float deltaX, float deltaY); 85 virtual void setButtonState(uint32_t buttonState); 86 virtual uint32_t getButtonState() const; 87 virtual void setPosition(float x, float y); 88 virtual void getPosition(float* outX, float* outY) const; 89 90 void setDisplaySize(int32_t width, int32_t height); 91 void setDisplayOrientation(int32_t orientation); 92 void setPointerIcon(const SkBitmap* bitmap, float hotSpotX, float hotSpotY); 93 94private: 95 mutable Mutex mLock; 96 97 int32_t mPointerLayer; 98 sp<SurfaceComposerClient> mSurfaceComposerClient; 99 sp<SurfaceControl> mSurfaceControl; 100 101 struct Locked { 102 int32_t displayWidth; 103 int32_t displayHeight; 104 int32_t displayOrientation; 105 106 float pointerX; 107 float pointerY; 108 uint32_t buttonState; 109 110 SkBitmap* iconBitmap; 111 float iconHotSpotX; 112 float iconHotSpotY; 113 114 bool wantVisible; 115 bool visible; 116 bool drawn; 117 } mLocked; 118 119 bool getBoundsLocked(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const; 120 void setPositionLocked(float x, float y); 121 void updateLocked(); 122 bool createSurfaceIfNeededLocked(); 123 bool drawPointerIfNeededLocked(); 124 bool resizeSurfaceLocked(int32_t width, int32_t height); 125}; 126 127} // namespace android 128 129#endif // _UI_POINTER_CONTROLLER_H 130