1 /* 2 // Copyright (c) 2014 Intel Corporation 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 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(gralloc_module_t *module, 66 uint32_t handle) = 0; 67 virtual BufferMapper* createBufferMapper(gralloc_module_t *module, 68 DataBuffer& buffer) = 0; 69 70 gralloc_module_t *mGrallocModule; 71 private: 72 enum { 73 // make the buffer pool large enough 74 DEFAULT_BUFFER_POOL_SIZE = 128, 75 }; 76 77 alloc_device_t *mAllocDev; 78 KeyedVector<uint32_t, BufferMapper*> mFrameBuffers; 79 BufferCache *mBufferPool; 80 DataBuffer *mDataBuffer; 81 Mutex mDataBufferLock; 82 Mutex mLock; 83 bool mInitialized; 84 }; 85 86 } // namespace intel 87 } // namespace android 88 89 #endif /* BUFFERMANAGER_H_ */ 90