Home | History | Annotate | Download | only in include
      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:
     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 
     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
    115     int32_t getSurface() { return mSurface; }
    116     // get buffer handle
    117     unsigned long getHandle() { return mBuffer; }
    118     // set/clear/get flag
    119     uint32_t getFlags() { return mFlags; }
    120     void setFlag(uint32_t flag) { mFlags |= flag; return; }
    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 struct ANativeWindowBuffer;
    145 
    146 class ISVBufferManager: public RefBase
    147 {
    148 public:
    149     ISVBufferManager()
    150         :mWorker(NULL),
    151         mMetaDataMode(false),
    152         mNeedClearBuffers(false) {}
    153 
    154     ~ISVBufferManager() {}
    155     // set mBuffers size
    156     status_t setBufferCount(int32_t size);
    157 
    158     // register/unregister ISVBuffers to mBuffers
    159     status_t useBuffer(const sp<ANativeWindowBuffer> nativeBuffer);
    160     status_t useBuffer(unsigned long handle);
    161     status_t freeBuffer(unsigned long handle);
    162 
    163     // Map to ISVBuffer
    164     ISVBuffer* mapBuffer(unsigned long handle);
    165     // set isv worker
    166     void setWorker(sp<ISVWorker> worker) { mWorker = worker; }
    167     void setMetaDataMode(bool metaDataMode) { mMetaDataMode = metaDataMode; }
    168     // set buffer flag.
    169     status_t setBuffersFlag(uint32_t flag);
    170 private:
    171     typedef enum {
    172         GRALLOC_BUFFER_MODE = 0,
    173         META_DATA_MODE = 1,
    174     } ISV_WORK_MODE;
    175 
    176     sp<ISVWorker> mWorker;
    177     bool mMetaDataMode;
    178     // VPP buffer queue
    179     Vector<ISVBuffer*> mBuffers;
    180     Mutex mBufferLock; // to protect access to mBuffers
    181     bool mNeedClearBuffers;
    182 };
    183 
    184 
    185 #endif //#define __ISV_BUFMANAGER_H
    186