Fix virtual displays for HWC<=1.1

If we're using a HWC that doesn't support virtual displays, or we have
more virtual displays than HWC supports concurrently, the
VirtualDisplaySurface should simply be a passthrough from source
(GLES) to sink.

This change also tries to distinguish between display types and HWC
display IDs a little better, though there's more to do here. Probably
needs a higher-level rethink; it's too error-prone now.

Bug: 8446838
Change-Id: I708d2cf262ec30177042304f174ca5b8da701df1
diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h
index 61bafed..0706e75 100644
--- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h
+++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.h
@@ -45,12 +45,18 @@
  * eglSwapBuffers doesn't immediately dequeue a buffer for the next frame,
  * since we can't rely on being able to dequeue more than one buffer at a time.
  *
+ * This class also has a passthrough mode, where it doesn't use a
+ * BufferQueueInterposer and never sends buffers to HWC. Instead, OpenGL ES
+ * output buffers are queued directly to the virtual display sink; this class
+ * is inactive after construction. This mode is used when the HWC doesn't
+ * support compositing for virtual displays.
+ *
  * TODO(jessehall): Add a libgui test that ensures that EGL/GLES do lazy
  * dequeBuffers; we've wanted to require that for other reasons anyway.
  */
 class VirtualDisplaySurface : public DisplaySurface {
 public:
-    VirtualDisplaySurface(HWComposer& hwc, int disp,
+    VirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
             const sp<IGraphicBufferProducer>& sink,
             const String8& name);
 
@@ -66,10 +72,14 @@
 
     // immutable after construction
     HWComposer& mHwc;
-    int mDisplayId;
-    sp<BufferQueueInterposer> mSource;
+    int32_t mDisplayId;
     String8 mName;
 
+    // with HWC support, both of these point to the same object.
+    // otherwise, mInterposer is NULL and mSourceProducer is the sink.
+    sp<BufferQueueInterposer> mInterposer;
+    sp<IGraphicBufferProducer> mSourceProducer;
+
     // mutable, must be synchronized with mMutex
     Mutex mMutex;
     sp<GraphicBuffer> mAcquiredBuffer;