diff --git a/src/InputDevice.cpp b/src/InputDevice.cpp index 3d4776e23641e3b5419554ec6a198e06317a49f8..a4b6d7c464c88cea56dcce49af780464a1c774db 100644 --- a/src/InputDevice.cpp +++ b/src/InputDevice.cpp @@ -247,7 +247,7 @@ void InputDevice::pointerEvent(int buttonMask, int x, int y, rfbClientPtr /* cl inject(EV_ABS, ABS_Y, y); inject(EV_SYN, SYN_REPORT, 0); - } else if (buttonMask & 1) { // left btn clicked + } else if (buttonMask & 1) { // left btn clicked mLeftClicked = true; inject(EV_ABS, ABS_X, x); diff --git a/src/InputDevice.h b/src/InputDevice.h index e09bd3bc778ab6274a2a578e3a1a15807886fb4a..17444785b28f37e8a7d772a5d003e03af47b4f29 100644 --- a/src/InputDevice.h +++ b/src/InputDevice.h @@ -22,18 +22,17 @@ #include <utils/Mutex.h> #include <utils/Singleton.h> -#include <rfb/rfb.h> #include <linux/uinput.h> +#include <rfb/rfb.h> #define UINPUT_DEVICE "/dev/uinput" namespace android { class InputDevice : public Singleton<InputDevice> { + friend class Singleton; -friend class Singleton; - -public: + public: virtual status_t start(uint32_t width, uint32_t height); virtual status_t stop(); virtual status_t reconfigure(uint32_t width, uint32_t height); @@ -41,11 +40,12 @@ public: static void onKeyEvent(rfbBool down, rfbKeySym key, rfbClientPtr cl); static void onPointerEvent(int buttonMask, int x, int y, rfbClientPtr cl); - InputDevice() : mFD(-1) {} - virtual ~InputDevice() {} - -private: + InputDevice() : mFD(-1) { + } + virtual ~InputDevice() { + } + private: status_t inject(uint16_t type, uint16_t code, int32_t value); status_t injectSyn(uint16_t type, uint16_t code, int32_t value); status_t movePointer(int32_t x, int32_t y); @@ -68,8 +68,6 @@ private: bool mLeftClicked; bool mRightClicked; bool mMiddleClicked; - }; - }; #endif diff --git a/src/VNCFlinger.cpp b/src/VNCFlinger.cpp index fa28bbd547cc3481e032f202a47223e186263927..37a861419778e190382e6f6970701e9a8b18ace6 100644 --- a/src/VNCFlinger.cpp +++ b/src/VNCFlinger.cpp @@ -19,25 +19,23 @@ #include <utils/Log.h> #include <binder/IPCThreadState.h> -#include <binder/ProcessState.h> #include <binder/IServiceManager.h> +#include <binder/ProcessState.h> +#include <gui/IGraphicBufferProducer.h> #include <gui/ISurfaceComposer.h> #include <gui/SurfaceComposerClient.h> -#include <gui/IGraphicBufferProducer.h> #include "InputDevice.h" #include "VNCFlinger.h" - using namespace android; status_t VNCFlinger::start() { sp<ProcessState> self = ProcessState::self(); self->startThreadPool(); - mMainDpy = SurfaceComposerClient::getBuiltInDisplay( - ISurfaceComposer::eDisplayIdMain); + mMainDpy = SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain); updateDisplayProjection(); @@ -101,13 +99,12 @@ status_t VNCFlinger::createVirtualDisplay() { mListener = new FrameListener(this); mCpuConsumer->setFrameAvailableListener(mListener); - mDpy = SurfaceComposerClient::createDisplay( - String8("VNC-VirtualDisplay"), false /*secure*/); + mDpy = SurfaceComposerClient::createDisplay(String8("VNC-VirtualDisplay"), false /*secure*/); SurfaceComposerClient::openGlobalTransaction(); SurfaceComposerClient::setDisplaySurface(mDpy, mProducer); - //setDisplayProjection(mDpy, mainDpyInfo); - SurfaceComposerClient::setDisplayLayerStack(mDpy, 0); // default stack + // setDisplayProjection(mDpy, mainDpyInfo); + SurfaceComposerClient::setDisplayLayerStack(mDpy, 0); // default stack SurfaceComposerClient::closeGlobalTransaction(); mVDSActive = true; @@ -118,7 +115,6 @@ status_t VNCFlinger::createVirtualDisplay() { } status_t VNCFlinger::destroyVirtualDisplayLocked() { - mCpuConsumer.clear(); mProducer.clear(); SurfaceComposerClient::destroyDisplay(mDpy); @@ -131,7 +127,6 @@ status_t VNCFlinger::destroyVirtualDisplayLocked() { } status_t VNCFlinger::createVNCServer() { - status_t err = NO_ERROR; rfbLog = VNCFlinger::rfbLogger; @@ -145,16 +140,16 @@ status_t VNCFlinger::createVNCServer() { } mVNCBuf = new uint8_t[mWidth * mHeight * 4]; - mVNCScreen->frameBuffer = (char *) mVNCBuf; + mVNCScreen->frameBuffer = (char*)mVNCBuf; mVNCScreen->desktopName = "VNCFlinger"; mVNCScreen->alwaysShared = TRUE; mVNCScreen->httpDir = NULL; mVNCScreen->port = VNC_PORT; - mVNCScreen->newClientHook = (rfbNewClientHookPtr) VNCFlinger::onNewClient; + mVNCScreen->newClientHook = (rfbNewClientHookPtr)VNCFlinger::onNewClient; mVNCScreen->kbdAddEvent = InputDevice::onKeyEvent; mVNCScreen->ptrAddEvent = InputDevice::onPointerEvent; - mVNCScreen->displayHook = (rfbDisplayHookPtr) VNCFlinger::onFrameStart; - mVNCScreen->displayFinishedHook = (rfbDisplayFinishedHookPtr) VNCFlinger::onFrameDone; + mVNCScreen->displayHook = (rfbDisplayHookPtr)VNCFlinger::onFrameStart; + mVNCScreen->displayFinishedHook = (rfbDisplayFinishedHookPtr)VNCFlinger::onFrameDone; mVNCScreen->serverFormat.trueColour = true; mVNCScreen->serverFormat.bitsPerPixel = 32; mVNCScreen->handleEventsEagerly = true; @@ -210,37 +205,32 @@ size_t VNCFlinger::removeClient() { ClientGoneHookPtr VNCFlinger::onClientGone(rfbClientPtr cl) { ALOGV("onClientGone"); - VNCFlinger *vf = (VNCFlinger *)cl->screen->screenData; + VNCFlinger* vf = (VNCFlinger*)cl->screen->screenData; vf->removeClient(); return 0; } enum rfbNewClientAction VNCFlinger::onNewClient(rfbClientPtr cl) { ALOGV("onNewClient"); - cl->clientGoneHook = (ClientGoneHookPtr) VNCFlinger::onClientGone; - VNCFlinger *vf = (VNCFlinger *)cl->screen->screenData; + cl->clientGoneHook = (ClientGoneHookPtr)VNCFlinger::onClientGone; + VNCFlinger* vf = (VNCFlinger*)cl->screen->screenData; vf->addClient(); return RFB_CLIENT_ACCEPT; } void VNCFlinger::onFrameStart(rfbClientPtr cl) { - VNCFlinger *vf = (VNCFlinger *)cl->screen->screenData; + VNCFlinger* vf = (VNCFlinger*)cl->screen->screenData; vf->mUpdateMutex.lock(); ALOGV("frame start"); } void VNCFlinger::onFrameDone(rfbClientPtr cl, int status) { - VNCFlinger *vf = (VNCFlinger *)cl->screen->screenData; - - if (vf->mInputReconfigPending) { - //InputDevice::getInstance().reconfigure(vf->mWidth, vf->mHeight); - vf->mInputReconfigPending = false; - } + VNCFlinger* vf = (VNCFlinger*)cl->screen->screenData; vf->mUpdateMutex.unlock(); ALOGV("frame done! %d", status); } -void VNCFlinger::rfbLogger(const char *format, ...) { +void VNCFlinger::rfbLogger(const char* format, ...) { va_list args; char buf[256]; @@ -254,8 +244,7 @@ void VNCFlinger::FrameListener::onFrameAvailable(const BufferItem& item) { Mutex::Autolock _l(mVNC->mEventMutex); mVNC->mFrameAvailable = true; mVNC->mEventCond.signal(); - ALOGV("onFrameAvailable: mTimestamp=%ld mFrameNumber=%ld", - item.mTimestamp, item.mFrameNumber); + ALOGV("onFrameAvailable: mTimestamp=%ld mFrameNumber=%ld", item.mTimestamp, item.mFrameNumber); } void VNCFlinger::processFrame() { @@ -274,9 +263,8 @@ void VNCFlinger::processFrame() { return; } - ALOGV("processFrame: ptr: %p format: %x (%dx%d, stride=%d)", - imgBuffer.data, imgBuffer.format, imgBuffer.width, - imgBuffer.height, imgBuffer.stride); + ALOGV("processFrame: ptr: %p format: %x (%dx%d, stride=%d)", imgBuffer.data, imgBuffer.format, + imgBuffer.width, imgBuffer.height, imgBuffer.stride); updateFBSize(imgBuffer.width, imgBuffer.height, imgBuffer.stride); @@ -291,8 +279,7 @@ void VNCFlinger::processFrame() { * Returns "true" if the device is rotated 90 degrees. */ bool VNCFlinger::isDeviceRotated(int orientation) { - return orientation != DISPLAY_ORIENTATION_0 && - orientation != DISPLAY_ORIENTATION_180; + return orientation != DISPLAY_ORIENTATION_0 && orientation != DISPLAY_ORIENTATION_180; } /* @@ -300,7 +287,6 @@ bool VNCFlinger::isDeviceRotated(int orientation) { * and device orientation. */ bool VNCFlinger::updateDisplayProjection() { - DisplayInfo info; status_t err = SurfaceComposerClient::getDisplayInfo(mMainDpy, &info); if (err != NO_ERROR) { @@ -341,13 +327,10 @@ bool VNCFlinger::updateDisplayProjection() { } status_t VNCFlinger::updateFBSize(int width, int height, int stride) { - if ((mVNCScreen->paddedWidthInBytes / 4) != stride || - mVNCScreen->height != height || - mVNCScreen->width != width) { - - ALOGD("updateFBSize: old=[%dx%d %d] new=[%dx%d %d]", - mVNCScreen->width, mVNCScreen->height, mVNCScreen->paddedWidthInBytes / 4, - width, height, stride); + if ((mVNCScreen->paddedWidthInBytes / 4) != stride || mVNCScreen->height != height || + mVNCScreen->width != width) { + ALOGD("updateFBSize: old=[%dx%d %d] new=[%dx%d %d]", mVNCScreen->width, mVNCScreen->height, + mVNCScreen->paddedWidthInBytes / 4, width, height, stride); delete[] mVNCBuf; mVNCBuf = new uint8_t[stride * height * 4]; @@ -355,10 +338,9 @@ status_t VNCFlinger::updateFBSize(int width, int height, int stride) { // little dance here to avoid an ugly immediate resize if (mVNCScreen->height != height || mVNCScreen->width != width) { - mInputReconfigPending = true; - rfbNewFramebuffer(mVNCScreen, (char *)mVNCBuf, width, height, 8, 3, 4); + rfbNewFramebuffer(mVNCScreen, (char*)mVNCBuf, width, height, 8, 3, 4); } else { - mVNCScreen->frameBuffer = (char *)mVNCBuf; + mVNCScreen->frameBuffer = (char*)mVNCBuf; } mVNCScreen->paddedWidthInBytes = stride * 4; } diff --git a/src/VNCFlinger.h b/src/VNCFlinger.h index 0682a2f108056898fedc74c121d3b4e8a27ac9b4..1fa74370af51c938379e628b45f9b3eb70d16175 100644 --- a/src/VNCFlinger.h +++ b/src/VNCFlinger.h @@ -28,15 +28,12 @@ namespace android { class VNCFlinger { -public: - VNCFlinger(int argc, char **argv) : - mArgc(argc), - mArgv(argv), - mClientCount(0), - mOrientation(-1) { + public: + VNCFlinger(int argc, char** argv) : mArgc(argc), mArgv(argv), mOrientation(-1) { } - virtual ~VNCFlinger() {} + virtual ~VNCFlinger() { + } virtual status_t start(); virtual status_t stop(); @@ -44,18 +41,18 @@ public: virtual size_t addClient(); virtual size_t removeClient(); - -private: - + private: class FrameListener : public CpuConsumer::FrameAvailableListener { - public: - FrameListener(VNCFlinger *vnc) : mVNC(vnc) {} + public: + FrameListener(VNCFlinger* vnc) : mVNC(vnc) { + } virtual void onFrameAvailable(const BufferItem& item); - private: - FrameListener(FrameListener&) {} - VNCFlinger *mVNC; + private: + FrameListener(FrameListener&) { + } + VNCFlinger* mVNC; }; virtual void eventLoop(); @@ -75,34 +72,36 @@ private: static enum rfbNewClientAction onNewClient(rfbClientPtr cl); static void onFrameStart(rfbClientPtr cl); static void onFrameDone(rfbClientPtr cl, int result); - static void rfbLogger(const char *format, ...); + static void rfbLogger(const char* format, ...); + + int mArgc; + char** mArgv; bool mRunning; bool mFrameAvailable; bool mRotate; bool mVDSActive; - bool mInputReconfigPending; Mutex mEventMutex; Mutex mUpdateMutex; Condition mEventCond; - rfbScreenInfoPtr mVNCScreen; - uint8_t *mVNCBuf; - - int mWidth, mHeight; + int mWidth, mHeight, mOrientation; - sp<IBinder> mMainDpy; + size_t mClientCount; - int mArgc; - char **mArgv; + // Framebuffer + uint8_t* mVNCBuf; - size_t mClientCount; + // Server instance + rfbScreenInfoPtr mVNCScreen; - int mOrientation; + // Primary display + sp<IBinder> mMainDpy; - sp<FrameListener> mListener; + // Virtual display + sp<IBinder> mDpy; // Producer side of queue, passed into the virtual display. sp<IGraphicBufferProducer> mProducer; @@ -110,10 +109,8 @@ private: // This receives frames from the virtual display and makes them available sp<CpuConsumer> mCpuConsumer; - // The virtual display instance - sp<IBinder> mDpy; - + // Consumer callback + sp<FrameListener> mListener; }; - }; #endif diff --git a/src/main.cpp b/src/main.cpp index e007c7a4f481f8b16b26f346b231e224e0542997..e7dc163fa231fc6ab045ec890593ef0d57182d56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ using namespace android; -int main(int argc, char **argv) { +int main(int argc, char** argv) { VNCFlinger flinger(argc, argv); flinger.start(); }