blob: 0682a2f108056898fedc74c121d3b4e8a27ac9b4 [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 Kondik55db0532017-06-12 11:27:18 -070031public:
32 VNCFlinger(int argc, char **argv) :
33 mArgc(argc),
34 mArgv(argv),
Steve Kondik6ec5bc82017-06-15 01:31:51 -070035 mClientCount(0),
36 mOrientation(-1) {
Steve Kondik55db0532017-06-12 11:27:18 -070037 }
38
Steve Kondik7225c7f2017-06-14 00:06:16 -070039 virtual ~VNCFlinger() {}
Steve Kondik55db0532017-06-12 11:27:18 -070040
41 virtual status_t start();
42 virtual status_t stop();
43
Steve Kondik7225c7f2017-06-14 00:06:16 -070044 virtual size_t addClient();
45 virtual size_t removeClient();
Steve Kondik55db0532017-06-12 11:27:18 -070046
Steve Kondikef4e8652017-06-14 15:07:54 -070047
Steve Kondik55db0532017-06-12 11:27:18 -070048private:
Steve Kondik7225c7f2017-06-14 00:06:16 -070049
Steve Kondik77754522017-06-14 17:00:33 -070050 class FrameListener : public CpuConsumer::FrameAvailableListener {
51 public:
52 FrameListener(VNCFlinger *vnc) : mVNC(vnc) {}
Steve Kondik55db0532017-06-12 11:27:18 -070053
Steve Kondik77754522017-06-14 17:00:33 -070054 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 Kondik6ec5bc82017-06-15 01:31:51 -070064 virtual status_t destroyVirtualDisplayLocked();
Steve Kondik77754522017-06-14 17:00:33 -070065 virtual status_t createVNCServer();
66
67 virtual void processFrame();
68
Steve Kondik6ec5bc82017-06-15 01:31:51 -070069 virtual bool isDeviceRotated(int orientation);
70 virtual bool updateDisplayProjection();
71 virtual status_t updateFBSize(int width, int height, int stride);
72
Steve Kondik77754522017-06-14 17:00:33 -070073 // vncserver callbacks
Steve Kondik55db0532017-06-12 11:27:18 -070074 static ClientGoneHookPtr onClientGone(rfbClientPtr cl);
75 static enum rfbNewClientAction onNewClient(rfbClientPtr cl);
Steve Kondikef4e8652017-06-14 15:07:54 -070076 static void onFrameStart(rfbClientPtr cl);
77 static void onFrameDone(rfbClientPtr cl, int result);
Steve Kondik55db0532017-06-12 11:27:18 -070078 static void rfbLogger(const char *format, ...);
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;
84 bool mInputReconfigPending;
Steve Kondik77754522017-06-14 17:00:33 -070085
86 Mutex mEventMutex;
87 Mutex mUpdateMutex;
88
89 Condition mEventCond;
Steve Kondik7225c7f2017-06-14 00:06:16 -070090
Steve Kondik55db0532017-06-12 11:27:18 -070091 rfbScreenInfoPtr mVNCScreen;
92 uint8_t *mVNCBuf;
93
Steve Kondik6ec5bc82017-06-15 01:31:51 -070094 int mWidth, mHeight;
Steve Kondik55db0532017-06-12 11:27:18 -070095
96 sp<IBinder> mMainDpy;
Steve Kondik55db0532017-06-12 11:27:18 -070097
98 int mArgc;
99 char **mArgv;
100
101 size_t mClientCount;
Steve Kondik77754522017-06-14 17:00:33 -0700102
Steve Kondik6ec5bc82017-06-15 01:31:51 -0700103 int mOrientation;
104
Steve Kondik77754522017-06-14 17:00:33 -0700105 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 Kondik55db0532017-06-12 11:27:18 -0700116};
117
118};
119#endif