Steve Kondik | 95027ea | 2017-06-14 17:22:58 -0700 | [diff] [blame] | 1 | // |
| 2 | // vncflinger - Copyright (C) 2017 Steve Kondik |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | // |
| 17 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 18 | #ifndef VNCFLINGER_H |
| 19 | #define VNCFLINGER_H |
| 20 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 21 | #include <gui/CpuConsumer.h> |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 22 | #include <ui/DisplayInfo.h> |
| 23 | |
| 24 | #include "rfb/rfb.h" |
| 25 | |
| 26 | #define VNC_PORT 5901 |
| 27 | |
| 28 | namespace android { |
| 29 | |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 30 | class VNCFlinger { |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 31 | public: |
| 32 | VNCFlinger(int argc, char **argv) : |
| 33 | mArgc(argc), |
| 34 | mArgv(argv), |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame^] | 35 | mClientCount(0), |
| 36 | mOrientation(-1) { |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 39 | virtual ~VNCFlinger() {} |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 40 | |
| 41 | virtual status_t start(); |
| 42 | virtual status_t stop(); |
| 43 | |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 44 | virtual size_t addClient(); |
| 45 | virtual size_t removeClient(); |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 46 | |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame] | 47 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 48 | private: |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 49 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 50 | class FrameListener : public CpuConsumer::FrameAvailableListener { |
| 51 | public: |
| 52 | FrameListener(VNCFlinger *vnc) : mVNC(vnc) {} |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 53 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 54 | virtual void onFrameAvailable(const BufferItem& item); |
| 55 | |
| 56 | private: |
| 57 | FrameListener(FrameListener&) {} |
| 58 | VNCFlinger *mVNC; |
| 59 | }; |
| 60 | |
| 61 | virtual void eventLoop(); |
| 62 | |
| 63 | virtual status_t createVirtualDisplay(); |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame^] | 64 | virtual status_t destroyVirtualDisplayLocked(); |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 65 | virtual status_t createVNCServer(); |
| 66 | |
| 67 | virtual void processFrame(); |
| 68 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame^] | 69 | virtual bool isDeviceRotated(int orientation); |
| 70 | virtual bool updateDisplayProjection(); |
| 71 | virtual status_t updateFBSize(int width, int height, int stride); |
| 72 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 73 | // vncserver callbacks |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 74 | static ClientGoneHookPtr onClientGone(rfbClientPtr cl); |
| 75 | static enum rfbNewClientAction onNewClient(rfbClientPtr cl); |
Steve Kondik | ef4e865 | 2017-06-14 15:07:54 -0700 | [diff] [blame] | 76 | static void onFrameStart(rfbClientPtr cl); |
| 77 | static void onFrameDone(rfbClientPtr cl, int result); |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 78 | static void rfbLogger(const char *format, ...); |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 79 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 80 | bool mRunning; |
| 81 | bool mFrameAvailable; |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame^] | 82 | bool mRotate; |
| 83 | bool mVDSActive; |
| 84 | bool mInputReconfigPending; |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 85 | |
| 86 | Mutex mEventMutex; |
| 87 | Mutex mUpdateMutex; |
| 88 | |
| 89 | Condition mEventCond; |
Steve Kondik | 7225c7f | 2017-06-14 00:06:16 -0700 | [diff] [blame] | 90 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 91 | rfbScreenInfoPtr mVNCScreen; |
| 92 | uint8_t *mVNCBuf; |
| 93 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame^] | 94 | int mWidth, mHeight; |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 95 | |
| 96 | sp<IBinder> mMainDpy; |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 97 | |
| 98 | int mArgc; |
| 99 | char **mArgv; |
| 100 | |
| 101 | size_t mClientCount; |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 102 | |
Steve Kondik | 6ec5bc8 | 2017-06-15 01:31:51 -0700 | [diff] [blame^] | 103 | int mOrientation; |
| 104 | |
Steve Kondik | 7775452 | 2017-06-14 17:00:33 -0700 | [diff] [blame] | 105 | sp<FrameListener> mListener; |
| 106 | |
| 107 | // Producer side of queue, passed into the virtual display. |
| 108 | sp<IGraphicBufferProducer> mProducer; |
| 109 | |
| 110 | // This receives frames from the virtual display and makes them available |
| 111 | sp<CpuConsumer> mCpuConsumer; |
| 112 | |
| 113 | // The virtual display instance |
| 114 | sp<IBinder> mDpy; |
| 115 | |
Steve Kondik | 55db053 | 2017-06-12 11:27:18 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | }; |
| 119 | #endif |