Steve Kondik | 961b4cc | 2017-06-22 18:10:50 -0700 | [diff] [blame^] | 1 | #ifndef ANDROID_DESKTOP_H_ |
| 2 | #define ANDROID_DESKTOP_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | |
| 6 | #include <utils/Condition.h> |
| 7 | #include <utils/Mutex.h> |
| 8 | #include <utils/RefBase.h> |
| 9 | #include <utils/Thread.h> |
| 10 | |
| 11 | #include <gui/CpuConsumer.h> |
| 12 | |
| 13 | #include <rfb/PixelBuffer.h> |
| 14 | #include <rfb/SDesktop.h> |
| 15 | #include <rfb/VNCServerST.h> |
| 16 | |
| 17 | #include "InputDevice.h" |
| 18 | |
| 19 | |
| 20 | using namespace android; |
| 21 | |
| 22 | namespace vncflinger { |
| 23 | |
| 24 | static const rfb::PixelFormat pfRGBX(32, 24, false, true, 255, 255, 255, 0, 8, 16); |
| 25 | |
| 26 | class AndroidDesktop : public rfb::SDesktop, public RefBase { |
| 27 | public: |
| 28 | AndroidDesktop(); |
| 29 | |
| 30 | virtual ~AndroidDesktop(); |
| 31 | |
| 32 | virtual void start(rfb::VNCServer* vs); |
| 33 | virtual void stop(); |
| 34 | |
| 35 | virtual rfb::Point getFbSize(); |
| 36 | virtual unsigned int setScreenLayout(int fb_width, int fb_height, const rfb::ScreenSet& layout); |
| 37 | |
| 38 | virtual void keyEvent(rdr::U32 key, bool down); |
| 39 | virtual void pointerEvent(const rfb::Point& pos, int buttonMask); |
| 40 | |
| 41 | virtual void processFrames(); |
| 42 | |
| 43 | virtual int getEventFd() { |
| 44 | return mEventFd; |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | class FrameListener : public CpuConsumer::FrameAvailableListener { |
| 49 | public: |
| 50 | FrameListener(AndroidDesktop* desktop) : mDesktop(desktop) { |
| 51 | } |
| 52 | |
| 53 | virtual void onFrameAvailable(const BufferItem& item); |
| 54 | |
| 55 | private: |
| 56 | FrameListener(FrameListener&) { |
| 57 | } |
| 58 | AndroidDesktop* mDesktop; |
| 59 | }; |
| 60 | |
| 61 | class AndroidPixelBuffer : public RefBase, public rfb::ManagedPixelBuffer { |
| 62 | public: |
| 63 | AndroidPixelBuffer(uint64_t width, uint64_t height) |
| 64 | : rfb::ManagedPixelBuffer(sRGBX, width, height) { |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | virtual status_t createVirtualDisplay(); |
| 69 | virtual status_t destroyVirtualDisplay(); |
| 70 | |
| 71 | virtual void notify(); |
| 72 | |
| 73 | virtual status_t updateDisplayProjection(); |
| 74 | virtual bool updateFBSize(uint64_t width, uint64_t height); |
| 75 | virtual void processDesktopResize(); |
| 76 | |
| 77 | uint64_t mSourceWidth, mSourceHeight; |
| 78 | uint64_t mWidth, mHeight; |
| 79 | Rect mDisplayRect; |
| 80 | |
| 81 | bool mRotated; |
| 82 | |
| 83 | Mutex mMutex; |
| 84 | |
| 85 | bool mFrameAvailable; |
| 86 | bool mProjectionChanged; |
| 87 | bool mRotate; |
| 88 | bool mVDSActive; |
| 89 | |
| 90 | uint64_t mFrameNumber; |
| 91 | nsecs_t mFrameStartWhen; |
| 92 | |
| 93 | int mEventFd; |
| 94 | |
| 95 | // Android virtual display is always 32-bit |
| 96 | static const rfb::PixelFormat sRGBX; |
| 97 | |
| 98 | // Server instance |
| 99 | rfb::VNCServerST* mServer; |
| 100 | |
| 101 | // Pixel buffer |
| 102 | sp<AndroidPixelBuffer> mPixels; |
| 103 | |
| 104 | // Primary display |
| 105 | sp<IBinder> mMainDpy; |
| 106 | |
| 107 | // Virtual display |
| 108 | sp<IBinder> mDpy; |
| 109 | |
| 110 | // Producer side of queue, passed into the virtual display. |
| 111 | sp<IGraphicBufferProducer> mProducer; |
| 112 | |
| 113 | // This receives frames from the virtual display and makes them available |
| 114 | sp<CpuConsumer> mCpuConsumer; |
| 115 | |
| 116 | // Listener for virtual display buffers |
| 117 | sp<FrameListener> mListener; |
| 118 | |
| 119 | // Virtual input device |
| 120 | sp<InputDevice> mInputDevice; |
| 121 | }; |
| 122 | }; |
| 123 | |
| 124 | #endif |