blob: 1fa74370af51c938379e628b45f9b3eb70d16175 [file] [log] [blame]
Steve Kondik95027ea2017-06-14 17:22:58 -07001//
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 Kondik55db0532017-06-12 11:27:18 -070018#ifndef VNCFLINGER_H
19#define VNCFLINGER_H
20
Steve Kondik77754522017-06-14 17:00:33 -070021#include <gui/CpuConsumer.h>
Steve Kondik55db0532017-06-12 11:27:18 -070022#include <ui/DisplayInfo.h>
23
24#include "rfb/rfb.h"
25
26#define VNC_PORT 5901
27
28namespace android {
29
Steve Kondik7225c7f2017-06-14 00:06:16 -070030class VNCFlinger {
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070031 public:
32 VNCFlinger(int argc, char** argv) : mArgc(argc), mArgv(argv), mOrientation(-1) {
Steve Kondik55db0532017-06-12 11:27:18 -070033 }
34
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070035 virtual ~VNCFlinger() {
36 }
Steve Kondik55db0532017-06-12 11:27:18 -070037
38 virtual status_t start();
39 virtual status_t stop();
40
Steve Kondik7225c7f2017-06-14 00:06:16 -070041 virtual size_t addClient();
42 virtual size_t removeClient();
Steve Kondik55db0532017-06-12 11:27:18 -070043
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070044 private:
Steve Kondik77754522017-06-14 17:00:33 -070045 class FrameListener : public CpuConsumer::FrameAvailableListener {
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070046 public:
47 FrameListener(VNCFlinger* vnc) : mVNC(vnc) {
48 }
Steve Kondik55db0532017-06-12 11:27:18 -070049
Steve Kondik77754522017-06-14 17:00:33 -070050 virtual void onFrameAvailable(const BufferItem& item);
51
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070052 private:
53 FrameListener(FrameListener&) {
54 }
55 VNCFlinger* mVNC;
Steve Kondik77754522017-06-14 17:00:33 -070056 };
57
58 virtual void eventLoop();
59
60 virtual status_t createVirtualDisplay();
Steve Kondik6ec5bc82017-06-15 01:31:51 -070061 virtual status_t destroyVirtualDisplayLocked();
Steve Kondik77754522017-06-14 17:00:33 -070062 virtual status_t createVNCServer();
63
64 virtual void processFrame();
65
Steve Kondik6ec5bc82017-06-15 01:31:51 -070066 virtual bool isDeviceRotated(int orientation);
67 virtual bool updateDisplayProjection();
68 virtual status_t updateFBSize(int width, int height, int stride);
69
Steve Kondik77754522017-06-14 17:00:33 -070070 // vncserver callbacks
Steve Kondik55db0532017-06-12 11:27:18 -070071 static ClientGoneHookPtr onClientGone(rfbClientPtr cl);
72 static enum rfbNewClientAction onNewClient(rfbClientPtr cl);
Steve Kondikef4e8652017-06-14 15:07:54 -070073 static void onFrameStart(rfbClientPtr cl);
74 static void onFrameDone(rfbClientPtr cl, int result);
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070075 static void rfbLogger(const char* format, ...);
76
77 int mArgc;
78 char** mArgv;
Steve Kondik7225c7f2017-06-14 00:06:16 -070079
Steve Kondik77754522017-06-14 17:00:33 -070080 bool mRunning;
81 bool mFrameAvailable;
Steve Kondik6ec5bc82017-06-15 01:31:51 -070082 bool mRotate;
83 bool mVDSActive;
Steve Kondik77754522017-06-14 17:00:33 -070084
85 Mutex mEventMutex;
86 Mutex mUpdateMutex;
87
88 Condition mEventCond;
Steve Kondik7225c7f2017-06-14 00:06:16 -070089
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070090 int mWidth, mHeight, mOrientation;
Steve Kondik55db0532017-06-12 11:27:18 -070091
92 size_t mClientCount;
Steve Kondik77754522017-06-14 17:00:33 -070093
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070094 // Framebuffer
95 uint8_t* mVNCBuf;
Steve Kondik6ec5bc82017-06-15 01:31:51 -070096
Steve Kondik2c9d0cf2017-06-15 23:39:29 -070097 // Server instance
98 rfbScreenInfoPtr mVNCScreen;
99
100 // Primary display
101 sp<IBinder> mMainDpy;
102
103 // Virtual display
104 sp<IBinder> mDpy;
Steve Kondik77754522017-06-14 17:00:33 -0700105
106 // Producer side of queue, passed into the virtual display.
107 sp<IGraphicBufferProducer> mProducer;
108
109 // This receives frames from the virtual display and makes them available
110 sp<CpuConsumer> mCpuConsumer;
111
Steve Kondik2c9d0cf2017-06-15 23:39:29 -0700112 // Consumer callback
113 sp<FrameListener> mListener;
Steve Kondik55db0532017-06-12 11:27:18 -0700114};
Steve Kondik55db0532017-06-12 11:27:18 -0700115};
116#endif