blob: 41a8543b25ec26c0e5159255879bd66a2c417f5c [file] [log] [blame]
Steve Kondik961b4cc2017-06-22 18:10:50 -07001#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
maxwen80ee9662021-10-05 21:08:06 +020013#include <ui/DisplayMode.h>
maxwenad0a9222020-09-20 14:40:41 +020014#include <ui/DisplayState.h>
Steve Kondik6f9ab852017-07-09 21:30:20 -070015
Steve Kondik961b4cc2017-06-22 18:10:50 -070016#include <rfb/PixelBuffer.h>
17#include <rfb/SDesktop.h>
Steve Kondik71850752019-09-12 12:45:23 -070018#include <rfb/ScreenSet.h>
Steve Kondik961b4cc2017-06-22 18:10:50 -070019
Steve Kondik6f9ab852017-07-09 21:30:20 -070020#include "AndroidPixelBuffer.h"
Steve Kondik961b4cc2017-06-22 18:10:50 -070021#include "InputDevice.h"
Steve Kondik6f9ab852017-07-09 21:30:20 -070022#include "VirtualDisplay.h"
Steve Kondik961b4cc2017-06-22 18:10:50 -070023
24using namespace android;
25
26namespace vncflinger {
27
Steve Kondik6f9ab852017-07-09 21:30:20 -070028class AndroidDesktop : public rfb::SDesktop,
29 public CpuConsumer::FrameAvailableListener,
30 public AndroidPixelBuffer::BufferDimensionsListener {
Steve Kondik961b4cc2017-06-22 18:10:50 -070031 public:
32 AndroidDesktop();
33
34 virtual ~AndroidDesktop();
35
36 virtual void start(rfb::VNCServer* vs);
37 virtual void stop();
Steve Kondikf19d1422019-09-06 13:52:12 -070038 virtual void terminate();
Steve Kondik961b4cc2017-06-22 18:10:50 -070039
Steve Kondik961b4cc2017-06-22 18:10:50 -070040 virtual unsigned int setScreenLayout(int fb_width, int fb_height, const rfb::ScreenSet& layout);
41
Steve Kondikf19d1422019-09-06 13:52:12 -070042 virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
Steve Kondik961b4cc2017-06-22 18:10:50 -070043 virtual void pointerEvent(const rfb::Point& pos, int buttonMask);
44
45 virtual void processFrames();
46
47 virtual int getEventFd() {
48 return mEventFd;
49 }
50
Steve Kondik6f9ab852017-07-09 21:30:20 -070051 virtual void onBufferDimensionsChanged(uint32_t width, uint32_t height);
52
53 virtual void onFrameAvailable(const BufferItem& item);
54
Steve Kondikf19d1422019-09-06 13:52:12 -070055 virtual void queryConnection(network::Socket* sock, const char* userName);
56
Steve Kondik961b4cc2017-06-22 18:10:50 -070057 private:
Steve Kondik961b4cc2017-06-22 18:10:50 -070058 virtual void notify();
59
Steve Kondik6f9ab852017-07-09 21:30:20 -070060 virtual status_t updateDisplayInfo();
Steve Kondik961b4cc2017-06-22 18:10:50 -070061
Steve Kondik71850752019-09-12 12:45:23 -070062 virtual rfb::ScreenSet computeScreenLayout();
63
Steve Kondik961b4cc2017-06-22 18:10:50 -070064 Rect mDisplayRect;
65
Steve Kondik6f9ab852017-07-09 21:30:20 -070066 Mutex mLock;
Steve Kondik961b4cc2017-06-22 18:10:50 -070067
68 uint64_t mFrameNumber;
Steve Kondik961b4cc2017-06-22 18:10:50 -070069
70 int mEventFd;
71
Steve Kondik961b4cc2017-06-22 18:10:50 -070072 // Server instance
Steve Kondik71850752019-09-12 12:45:23 -070073 rfb::VNCServer* mServer;
Steve Kondik961b4cc2017-06-22 18:10:50 -070074
75 // Pixel buffer
76 sp<AndroidPixelBuffer> mPixels;
77
Steve Kondik6f9ab852017-07-09 21:30:20 -070078 // Virtual display controller
79 sp<VirtualDisplay> mVirtualDisplay;
80
Steve Kondik961b4cc2017-06-22 18:10:50 -070081 // Primary display
maxwen80ee9662021-10-05 21:08:06 +020082 ui::DisplayMode mDisplayMode = {};
maxwenad0a9222020-09-20 14:40:41 +020083 ui::DisplayState mDisplayState = {};
Steve Kondik961b4cc2017-06-22 18:10:50 -070084
85 // Virtual input device
86 sp<InputDevice> mInputDevice;
87};
88};
89
90#endif