Add multi-frame support to RenderScript:

Bug: 23535524

 - Allow multi-consumer for a single BufferQueue with specifying the
   the number of buffers need.
 - Allow USAGE_IO_INPUT allocations share the same BufferQueue with
   an existing Allocation.
 - Individual allocations can still call ioReceive independently
 - Add getTimeStamp() for multi-frame processing.

Change-Id: Ia8f48f5fc50d578c68306bb32f0eac9636f5f32a
diff --git a/rsAllocation.h b/rsAllocation.h
index a1b6c8f..4d09679 100644
--- a/rsAllocation.h
+++ b/rsAllocation.h
@@ -50,6 +50,8 @@
     const static int MAX_LOD = 16;
     // The mininum alignment requirement for RenderScript. Must be power of 2 and larger than 0.
     const static size_t kMinimumRSAlignment = 16;
+    // The maximun number of Allocations that can share a single BufferQueue;
+    const static uint32_t MAX_NUM_ALLOC = 16;
 
     struct Hal {
         void * drv;
@@ -180,10 +182,13 @@
         return mHal.state.mipmapControl != RS_ALLOCATION_MIPMAP_NONE;
     }
 
+    void setupGrallocConsumer(const Context *rsc, uint32_t numAlloc);
+    void shareBufferQueue(const Context *rsc, const Allocation *alloc);
     void * getSurface(const Context *rsc);
     void setSurface(const Context *rsc, RsNativeWindow sur);
     void ioSend(const Context *rsc);
     void ioReceive(const Context *rsc);
+    int64_t getTimeStamp() {return mHal.state.timestamp;}
 
     void adapterOffset(Context *rsc, const uint32_t *offsets, size_t len);
 
@@ -218,14 +223,21 @@
 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
     class NewBufferListener : public android::ConsumerBase::FrameAvailableListener {
     public:
+        NewBufferListener(uint32_t numAlloc);
+        virtual ~NewBufferListener();
         const android::renderscript::Context *rsc;
-        const android::renderscript::Allocation *alloc;
+        const android::renderscript::Allocation **alloc;
 
         virtual void onFrameAvailable(const BufferItem& item);
+    private:
+        uint32_t mNumAlloc;
     };
 
     sp<NewBufferListener> mBufferListener;
     sp< GrallocConsumer > mGrallocConsumer;
+    sp<IGraphicBufferProducer> mGraphicBufferProducer;
+    bool mBufferQueueInited = false;
+    uint32_t mCurrentIdx;
 #endif