isv_bufmanager.h revision e5aad73d4992d6c8fbd9e9e3c9cc89abfc83b775
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
30using namespace android;
31
32#define ISV_BUFFER_MANAGER_DEBUG 0
33
34class ISVWorker;
35
36class ISVBuffer
37{
38public:
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;
48private:
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
72public:
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
124private:
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    gralloc_module_t* mpGralloc;
138};
139
140class ISVBufferManager: public RefBase
141{
142public:
143    ISVBufferManager()
144        :mWorker(NULL),
145        mMetaDataMode(false),
146        mNeedClearBuffers(false) {}
147
148    ~ISVBufferManager() {}
149    // set mBuffers size
150    status_t setBufferCount(int32_t size);
151
152    // register/unregister ISVBuffers to mBuffers
153    status_t useBuffer(const sp<ANativeWindowBuffer> nativeBuffer);
154    status_t useBuffer(unsigned long handle);
155    status_t freeBuffer(unsigned long handle);
156
157    // Map to ISVBuffer
158    ISVBuffer* mapBuffer(unsigned long handle);
159    // set isv worker
160    void setWorker(sp<ISVWorker> worker) { mWorker = worker; }
161    void setMetaDataMode(bool metaDataMode) { mMetaDataMode = metaDataMode; }
162    // set buffer flag.
163    status_t setBuffersFlag(uint32_t flag);
164private:
165    typedef enum {
166        GRALLOC_BUFFER_MODE = 0,
167        META_DATA_MODE = 1,
168    } ISV_WORK_MODE;
169
170    sp<ISVWorker> mWorker;
171    bool mMetaDataMode;
172    // VPP buffer queue
173    Vector<ISVBuffer*> mBuffers;
174    Mutex mBufferLock; // to protect access to mBuffers
175    bool mNeedClearBuffers;
176};
177
178
179#endif //#define __ISV_BUFMANAGER_H
180