vnc: Code cleanup
diff --git a/src/InputDevice.cpp b/src/InputDevice.cpp
index 3d4776e..a4b6d7c 100644
--- a/src/InputDevice.cpp
+++ b/src/InputDevice.cpp
@@ -247,7 +247,7 @@
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 e09bd3b..1744478 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 @@
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() {}
+ InputDevice() : mFD(-1) {
+ }
+ virtual ~InputDevice() {
+ }
-private:
-
+ 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 @@
bool mLeftClicked;
bool mRightClicked;
bool mMiddleClicked;
-
};
-
};
#endif
diff --git a/src/VNCFlinger.cpp b/src/VNCFlinger.cpp
index fa28bbd..37a8614 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 @@
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::destroyVirtualDisplayLocked() {
-
mCpuConsumer.clear();
mProducer.clear();
SurfaceComposerClient::destroyDisplay(mDpy);
@@ -131,7 +127,6 @@
}
status_t VNCFlinger::createVNCServer() {
-
status_t err = NO_ERROR;
rfbLog = VNCFlinger::rfbLogger;
@@ -145,16 +140,16 @@
}
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 @@
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 @@
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 @@
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 @@
* 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 @@
* and device orientation.
*/
bool VNCFlinger::updateDisplayProjection() {
-
DisplayInfo info;
status_t err = SurfaceComposerClient::getDisplayInfo(mMainDpy, &info);
if (err != NO_ERROR) {
@@ -341,13 +327,10 @@
}
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 @@
// 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 0682a2f..1fa7437 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 @@
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 @@
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;
-
- sp<IBinder> mMainDpy;
-
- int mArgc;
- char **mArgv;
+ int mWidth, mHeight, mOrientation;
size_t mClientCount;
- int mOrientation;
+ // Framebuffer
+ uint8_t* mVNCBuf;
- sp<FrameListener> mListener;
+ // Server instance
+ rfbScreenInfoPtr mVNCScreen;
+
+ // Primary display
+ sp<IBinder> mMainDpy;
+
+ // Virtual display
+ sp<IBinder> mDpy;
// Producer side of queue, passed into the virtual display.
sp<IGraphicBufferProducer> mProducer;
@@ -110,10 +109,8 @@
// 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 e007c7a..e7dc163 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();
}