All consumers now take an IGraphicBufferConsumer instead of a BufferQueue

this means they only have access to the consumer end of
the interface. we had a lot of code that assumed consumers
where holding a BufferQueue (i.e.: both ends), so most of
this change is untangling in fix that

Bug: 9265647
Change-Id: Ic2e2596ee14c7535f51bf26d9a897a0fc036d22c
diff --git a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp
index 57cb361..30b0084 100644
--- a/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp
+++ b/services/surfaceflinger/DisplayHardware/VirtualDisplaySurface.cpp
@@ -40,8 +40,10 @@
 }
 
 VirtualDisplaySurface::VirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
-        const sp<IGraphicBufferProducer>& sink, const String8& name)
-:   ConsumerBase(new BufferQueue()),
+        const sp<IGraphicBufferProducer>& sink,
+        const sp<BufferQueue>& bq,
+        const String8& name)
+:   ConsumerBase(bq),
     mHwc(hwc),
     mDisplayId(dispId),
     mDisplayName(name),
@@ -51,7 +53,7 @@
     mDbgLastCompositionType(COMPOSITION_UNKNOWN)
 {
     mSource[SOURCE_SINK] = sink;
-    mSource[SOURCE_SCRATCH] = mBufferQueue;
+    mSource[SOURCE_SCRATCH] = bq;
 
     resetPerFrameState();
 
@@ -60,26 +62,15 @@
     mSource[SOURCE_SINK]->query(NATIVE_WINDOW_HEIGHT, &sinkHeight);
 
     ConsumerBase::mName = String8::format("VDS: %s", mDisplayName.string());
-    mBufferQueue->setConsumerName(ConsumerBase::mName);
-    mBufferQueue->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER);
-    mBufferQueue->setDefaultBufferSize(sinkWidth, sinkHeight);
-    mBufferQueue->setDefaultMaxBufferCount(2);
+    mConsumer->setConsumerName(ConsumerBase::mName);
+    mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_COMPOSER);
+    mConsumer->setDefaultBufferSize(sinkWidth, sinkHeight);
+    mConsumer->setDefaultMaxBufferCount(2);
 }
 
 VirtualDisplaySurface::~VirtualDisplaySurface() {
 }
 
-sp<IGraphicBufferProducer> VirtualDisplaySurface::getIGraphicBufferProducer() const {
-    if (mDisplayId >= 0) {
-        return static_cast<IGraphicBufferProducer*>(
-                const_cast<VirtualDisplaySurface*>(this));
-    } else {
-        // There won't be any interaction with HWC for this virtual display,
-        // so the GLES driver can pass buffers directly to the sink.
-        return mSource[SOURCE_SINK];
-    }
-}
-
 status_t VirtualDisplaySurface::prepareFrame(CompositionType compositionType) {
     if (mDisplayId < 0)
         return NO_ERROR;
@@ -294,7 +285,7 @@
         // Queue the buffer back into the scratch pool
         QueueBufferOutput scratchQBO;
         int sslot = mapProducer2SourceSlot(SOURCE_SCRATCH, pslot);
-        result = mBufferQueue->queueBuffer(sslot, input, &scratchQBO);
+        result = mSource[SOURCE_SCRATCH]->queueBuffer(sslot, input, &scratchQBO);
         if (result != NO_ERROR)
             return result;