1 /* 2 * Copyright (C) 2012 Intel Corporation. All rights reserved. 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 */ 17 18 #ifndef __ISV_BUFMANAGER_H 19 #define __ISV_BUFMANAGER_H 20 21 #include <utils/RefBase.h> 22 #include <utils/Mutex.h> 23 #include <utils/Errors.h> 24 #include <utils/Vector.h> 25 #include "isv_worker.h" 26 #ifndef TARGET_VPP_USE_GEN 27 #include "hal_public.h" 28 #endif 29 30 using namespace android; 31 32 #define ISV_BUFFER_MANAGER_DEBUG 0 33 34 class ISVWorker; 35 36 class ISVBuffer 37 { 38 public: 39 typedef enum { 40 ISV_BUFFER_GRALLOC, 41 ISV_BUFFER_METADATA, 42 } ISV_BUFFERTYPE; 43 44 typedef enum { 45 ISV_BUFFER_NEED_CLEAR = 0x00000001, 46 ISV_BUFFER_CROP_CHANGED = 0x00000002, 47 } ISV_BUFFERFLAG; 48 private: 49 //FIX ME: copy from ufo gralloc.h 50 typedef struct _ufo_buffer_details_t 51 { 52 int width; // \see alloc_device_t::alloc 53 int height; // \see alloc_device_t::alloc 54 int format; // \see alloc_device_t::alloc 55 int usage; // \see alloc_device_t::alloc 56 int name; // flink 57 uint32_t fb; // framebuffer id 58 int drmformat; // drm format 59 int pitch; // buffer pitch (in bytes) 60 int size; // buffer size (in bytes) 61 int allocWidth; // allocated buffer width in pixels. 62 int allocHeight; // allocated buffer height in lines. 63 int allocOffsetX;// horizontal pixel offset to content origin within allocated buffer. 64 int allocOffsetY;// vertical line offset to content origin within allocated buffer. 65 } ufo_buffer_details_t; 66 67 enum 68 { 69 INTEL_UFO_GRALLOC_MODULE_PERFORM_GET_BO_INFO = 6 // (buffer_handle_t, buffer_info_t*) 70 }; 71 72 public: ISVBuffer(sp<ISVWorker> worker,unsigned long buffer,unsigned long grallocHandle,uint32_t width,uint32_t height,uint32_t stride,uint32_t colorFormat,ISV_BUFFERTYPE type,uint32_t flag)73 ISVBuffer(sp<ISVWorker> worker, 74 unsigned long buffer, unsigned long grallocHandle, 75 uint32_t width, uint32_t height, 76 uint32_t stride, uint32_t colorFormat, 77 ISV_BUFFERTYPE type, uint32_t flag) 78 :mWorker(worker), 79 mBuffer(buffer), 80 mGrallocHandle(grallocHandle), 81 mWidth(width), 82 mHeight(height), 83 mSurfaceHeight(0), 84 mStride(stride), 85 mColorFormat(colorFormat), 86 mType(type), 87 mSurface(-1), 88 mFlags(flag), 89 mpGralloc(NULL) {} 90 ISVBuffer(sp<ISVWorker> worker,unsigned long buffer,ISV_BUFFERTYPE type,uint32_t flag)91 ISVBuffer(sp<ISVWorker> worker, 92 unsigned long buffer, 93 ISV_BUFFERTYPE type, 94 uint32_t flag) 95 :mWorker(worker), 96 mBuffer(buffer), 97 mGrallocHandle(0), 98 mWidth(0), 99 mHeight(0), 100 mSurfaceHeight(0), 101 mStride(0), 102 mColorFormat(0), 103 mType(type), 104 mSurface(-1), 105 mFlags(flag), 106 mpGralloc(NULL) {} 107 108 ~ISVBuffer(); 109 110 // init buffer info 111 // FIXME: hackFormat is for VP9, should be removed in future 112 status_t initBufferInfo(uint32_t hackFormat); 113 114 // get va surface getSurface()115 int32_t getSurface() { return mSurface; } 116 // get buffer handle getHandle()117 unsigned long getHandle() { return mBuffer; } 118 // set/clear/get flag getFlags()119 uint32_t getFlags() { return mFlags; } setFlag(uint32_t flag)120 void setFlag(uint32_t flag) { mFlags |= flag; return; } unsetFlag(uint32_t flag)121 void unsetFlag(uint32_t flag) { mFlags &= ~flag; return; } 122 status_t clearIfNeed(); 123 124 private: 125 126 sp<ISVWorker> mWorker; 127 unsigned long mBuffer; 128 unsigned long mGrallocHandle; 129 uint32_t mWidth; 130 uint32_t mHeight; 131 uint32_t mSurfaceHeight; 132 uint32_t mStride; 133 uint32_t mColorFormat; 134 ISV_BUFFERTYPE mType; 135 int32_t mSurface; 136 uint32_t mFlags; 137 #ifdef TARGET_VPP_USE_GEN 138 gralloc_module_t* mpGralloc; 139 #else 140 const hw_device_t* mpGralloc; 141 #endif 142 }; 143 144 class ISVBufferManager: public RefBase 145 { 146 public: ISVBufferManager()147 ISVBufferManager() 148 :mWorker(NULL), 149 mMetaDataMode(false), 150 mNeedClearBuffers(false) {} 151 ~ISVBufferManager()152 ~ISVBufferManager() {} 153 // set mBuffers size 154 status_t setBufferCount(int32_t size); 155 156 // register/unregister ISVBuffers to mBuffers 157 status_t useBuffer(const sp<ANativeWindowBuffer> nativeBuffer); 158 status_t useBuffer(unsigned long handle); 159 status_t freeBuffer(unsigned long handle); 160 161 // Map to ISVBuffer 162 ISVBuffer* mapBuffer(unsigned long handle); 163 // set isv worker setWorker(sp<ISVWorker> worker)164 void setWorker(sp<ISVWorker> worker) { mWorker = worker; } setMetaDataMode(bool metaDataMode)165 void setMetaDataMode(bool metaDataMode) { mMetaDataMode = metaDataMode; } 166 // set buffer flag. 167 status_t setBuffersFlag(uint32_t flag); 168 private: 169 typedef enum { 170 GRALLOC_BUFFER_MODE = 0, 171 META_DATA_MODE = 1, 172 } ISV_WORK_MODE; 173 174 sp<ISVWorker> mWorker; 175 bool mMetaDataMode; 176 // VPP buffer queue 177 Vector<ISVBuffer*> mBuffers; 178 Mutex mBufferLock; // to protect access to mBuffers 179 bool mNeedClearBuffers; 180 }; 181 182 183 #endif //#define __ISV_BUFMANAGER_H 184