Home | History | Annotate | Download | only in include
      1 /*
      2 // Copyright(c)2014 IntelCorporation
      3 //
      4 // LicensedundertheApacheLicense,Version2.0(the"License");
      5 // youmaynotusethisfileexceptincompliancewiththeLicense.
      6 // YoumayobtainacopyoftheLicenseat
      7 //
      8 // http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software
     11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS,
     12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
     13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand
     14 // limitationsundertheLicense.
     15 */
     16 #ifndef BUFFERMANAGER_H_
     17 #define BUFFERMANAGER_H_
     18 
     19 #include <common/utils/Dump.h>
     20 #include <DataBuffer.h>
     21 #include <BufferMapper.h>
     22 #include <common/buffers/BufferCache.h>
     23 #include <utils/Mutex.h>
     24 
     25 namespace android {
     26 namespace intel {
     27 
     28 // Gralloc Buffer Manager
     29 class BufferManager {
     30 public:
     31     BufferManager();
     32     virtual ~BufferManager();
     33 
     34     bool initCheck() const;
     35     virtual bool initialize();
     36     virtual void deinitialize();
     37 
     38     // dump interface
     39     void dump(Dump& d);
     40 
     41     // lockDataBuffer and unlockDataBuffer must be used in serial
     42     // nested calling of them will cause a deadlock
     43     DataBuffer* lockDataBuffer(uint32_t handle);
     44     void unlockDataBuffer(DataBuffer *buffer);
     45 
     46     // get and put interfaces are deprecated
     47     // use lockDataBuffer and unlockDataBuffer instead
     48     DataBuffer* get(uint32_t handle);
     49     void put(DataBuffer *buffer);
     50 
     51     // map/unmap a data buffer into/from display memory
     52     BufferMapper* map(DataBuffer& buffer);
     53     void unmap(BufferMapper *mapper);
     54 
     55     // frame buffer management
     56     //return 0 if allocation fails
     57     virtual uint32_t allocFrameBuffer(int width, int height, int *stride);
     58     virtual void freeFrameBuffer(uint32_t kHandle);
     59 
     60     uint32_t allocGrallocBuffer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
     61     void freeGrallocBuffer(uint32_t handle);
     62     virtual bool blitGrallocBuffer(uint32_t srcHandle, uint32_t dstHandle,
     63                                   crop_t& srcCrop, uint32_t async) = 0;
     64 protected:
     65     virtual DataBuffer* createDataBuffer(uint32_t handle) = 0;
     66     virtual BufferMapper* createBufferMapper(DataBuffer& buffer) = 0;
     67 
     68     const hw_device_t *mGralloc;
     69 private:
     70     enum {
     71         // make the buffer pool large enough
     72         DEFAULT_BUFFER_POOL_SIZE = 128,
     73     };
     74 
     75     alloc_device_t *mAllocDev;
     76     KeyedVector<uint32_t, BufferMapper*> mFrameBuffers;
     77     BufferCache *mBufferPool;
     78     DataBuffer *mDataBuffer;
     79     Mutex mDataBufferLock;
     80     Mutex mLock;
     81     bool mInitialized;
     82 };
     83 
     84 } // namespace intel
     85 } // namespace android
     86 
     87 #endif /* BUFFERMANAGER_H_ */
     88