Refactor the code

 * Split out classes for pixel buffer and virtual display
 * Move resize handling to appropriate classes
 * Use callbacks for orientation change and client resize
 * Remove unnecessary locking
diff --git a/src/VirtualDisplay.h b/src/VirtualDisplay.h
index f23d32d..002d87d 100644
--- a/src/VirtualDisplay.h
+++ b/src/VirtualDisplay.h
@@ -1,26 +1,70 @@
+//
+// vncflinger - Copyright (C) 2017 Steve Kondik
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef VIRTUAL_DISPLAY_H_
+#define VIRTUAL_DISPLAY_H_
+
+#include <utils/RefBase.h>
+
 #include <gui/CpuConsumer.h>
+#include <gui/IGraphicBufferProducer.h>
+
+#include <ui/DisplayInfo.h>
+#include <ui/Rect.h>
+
+using namespace android;
 
 namespace vncflinger {
 
-class VirtualDisplay {
+class VirtualDisplay : public RefBase {
   public:
-    VirtualDisplay();
+    VirtualDisplay(DisplayInfo* info, uint32_t width, uint32_t height,
+                   sp<CpuConsumer::FrameAvailableListener> listener);
 
-    virtual void onFrameAvailable(const BufferItem& item);
+    virtual ~VirtualDisplay();
+
+    virtual Rect getDisplayRect();
+
+    virtual Rect getSourceRect() {
+        return mSourceRect;
+    }
+
+    CpuConsumer* getConsumer() {
+        return mCpuConsumer.get();
+    }
 
   private:
-    Mutex mEventMutex;
-    Condition mEventCond;
-
-    bool mFrameAvailable;
-
-    // Virtual display
-    sp<IBinder> mDpy;
+    float aspectRatio() {
+        return (float)mSourceRect.getHeight() / (float)mSourceRect.getWidth();
+    }
 
     // Producer side of queue, passed into the virtual display.
     sp<IGraphicBufferProducer> mProducer;
 
     // This receives frames from the virtual display and makes them available
     sp<CpuConsumer> mCpuConsumer;
+
+    // Virtual display
+    sp<IBinder> mDpy;
+
+    sp<CpuConsumer::FrameAvailableListener> mListener;
+
+    uint32_t mWidth, mHeight;
+    Rect mSourceRect;
 };
 };
+#endif