isv_bufmanager.h revision 25b2a4f2f53ada7434b5c77d26a7e4f29aa85edd
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
27using namespace android;
28
29#define ISV_BUFFER_MANAGER_DEBUG 0
30
31class ISVWorker;
32
33class ISVBuffer
34{
35public:
36    typedef enum {
37        ISV_BUFFER_GRALLOC,
38        ISV_BUFFER_METADATA,
39    } ISV_BUFFERTYPE;
40private:
41    //FIX ME: copy from ufo gralloc.h
42    typedef struct _ufo_buffer_details_t
43    {
44        int width;       // \see alloc_device_t::alloc
45        int height;      // \see alloc_device_t::alloc
46        int format;      // \see alloc_device_t::alloc
47        int usage;       // \see alloc_device_t::alloc
48        int name;        // flink
49        uint32_t fb;     // framebuffer id
50        int drmformat;   // drm format
51        int pitch;       // buffer pitch (in bytes)
52        int size;        // buffer size (in bytes)
53        int allocWidth;  // allocated buffer width in pixels.
54        int allocHeight; // allocated buffer height in lines.
55        int allocOffsetX;// horizontal pixel offset to content origin within allocated buffer.
56        int allocOffsetY;// vertical line offset to content origin within allocated buffer.
57    } ufo_buffer_details_t;
58
59    enum
60    {
61        INTEL_UFO_GRALLOC_MODULE_PERFORM_GET_BO_INFO = 6 // (buffer_handle_t, buffer_info_t*)
62    };
63
64public:
65    ISVBuffer(sp<ISVWorker> worker,
66            uint32_t buffer, uint32_t grallocHandle,
67            uint32_t width, uint32_t height,
68            uint32_t stride, uint32_t colorFormat,
69            ISV_BUFFERTYPE type)
70        :mWorker(worker),
71        mBuffer(buffer),
72        mGrallocHandle(grallocHandle),
73        mWidth(width),
74        mHeight(height),
75        mStride(stride),
76        mColorFormat(colorFormat),
77        mType(type),
78        mSurface(-1) {}
79
80    ISVBuffer(sp<ISVWorker> worker,
81            uint32_t buffer,
82            ISV_BUFFERTYPE type)
83        :mWorker(worker),
84        mBuffer(buffer),
85        mGrallocHandle(0),
86        mWidth(0),
87        mHeight(0),
88        mStride(0),
89        mColorFormat(0),
90        mType(type),
91        mSurface(-1) {}
92
93    ~ISVBuffer();
94
95    // init buffer info
96    status_t initBufferInfo();
97
98    // get va surface
99    uint32_t getSurface() { return mSurface; }
100    // get buffer handle
101    uint32_t getHandle() { return mBuffer; }
102
103private:
104    sp<ISVWorker> mWorker;
105    uint32_t mBuffer;
106    uint32_t mGrallocHandle;
107    uint32_t mWidth;
108    uint32_t mHeight;
109    uint32_t mStride;
110    uint32_t mColorFormat;
111    ISV_BUFFERTYPE mType;
112    int32_t mSurface;
113};
114
115class ISVBufferManager: public RefBase
116{
117public:
118    ISVBufferManager()
119        :mWorker(NULL),
120        mMetaDataMode(false) {}
121
122    ~ISVBufferManager() {}
123    // set mBuffers size
124    status_t setBufferCount(int32_t size);
125
126    // register/unregister ISVBuffers to mBuffers
127    status_t useBuffer(const sp<ANativeWindowBuffer> nativeBuffer);
128    status_t useBuffer(uint32_t handle);
129    status_t freeBuffer(uint32_t handle);
130
131    // Map to ISVBuffer
132    ISVBuffer* mapBuffer(uint32_t handle);
133    // set isv worker
134    void setWorker(sp<ISVWorker> worker) { mWorker = worker; }
135    void setMetaDataMode(bool metaDataMode) { mMetaDataMode = metaDataMode; }
136private:
137    typedef enum {
138        GRALLOC_BUFFER_MODE = 0,
139        META_DATA_MODE = 1,
140    } ISV_WORK_MODE;
141
142    sp<ISVWorker> mWorker;
143    bool mMetaDataMode;
144    // VPP buffer queue
145    Vector<ISVBuffer*> mBuffers;
146    Mutex mBufferLock; // to protect access to mBuffers
147};
148
149
150#endif //#define __ISV_BUFMANAGER_H
151