summaryrefslogtreecommitdiff
path: root/ISV/include/isv_bufmanager.h
blob: 18c3209079744ea7908dfcfc01d94bab01ee6755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * Copyright (C) 2012 Intel Corporation.  All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef __ISV_BUFMANAGER_H
#define __ISV_BUFMANAGER_H

#include <utils/RefBase.h>
#include <utils/Mutex.h>
#include <utils/Errors.h>
#include <utils/Vector.h>
#include "isv_worker.h"
#ifndef TARGET_VPP_USE_GEN
#include "hal_public.h"
#endif

using namespace android;

#define ISV_BUFFER_MANAGER_DEBUG 0

class ISVWorker;

class ISVBuffer
{
public:
    typedef enum {
        ISV_BUFFER_GRALLOC,
        ISV_BUFFER_METADATA,
    } ISV_BUFFERTYPE;

    typedef enum {
        ISV_BUFFER_NEED_CLEAR       = 0x00000001,
        ISV_BUFFER_CROP_CHANGED     = 0x00000002,
    } ISV_BUFFERFLAG;
private:
    //FIX ME: copy from ufo gralloc.h
    typedef struct _ufo_buffer_details_t
    {
        int width;       // \see alloc_device_t::alloc
        int height;      // \see alloc_device_t::alloc
        int format;      // \see alloc_device_t::alloc
        int usage;       // \see alloc_device_t::alloc
        int name;        // flink
        uint32_t fb;     // framebuffer id
        int drmformat;   // drm format
        int pitch;       // buffer pitch (in bytes)
        int size;        // buffer size (in bytes)
        int allocWidth;  // allocated buffer width in pixels.
        int allocHeight; // allocated buffer height in lines.
        int allocOffsetX;// horizontal pixel offset to content origin within allocated buffer.
        int allocOffsetY;// vertical line offset to content origin within allocated buffer.
    } ufo_buffer_details_t;

    enum
    {
        INTEL_UFO_GRALLOC_MODULE_PERFORM_GET_BO_INFO = 6 // (buffer_handle_t, buffer_info_t*)
    };

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)
        :mWorker(worker),
        mBuffer(buffer),
        mGrallocHandle(grallocHandle),
        mWidth(width),
        mHeight(height),
        mSurfaceHeight(0),
        mStride(stride),
        mColorFormat(colorFormat),
        mType(type),
        mSurface(-1),
        mFlags(flag),
        mpGralloc(NULL) {}

    ISVBuffer(sp<ISVWorker> worker,
            unsigned long buffer,
            ISV_BUFFERTYPE type,
            uint32_t flag)
        :mWorker(worker),
        mBuffer(buffer),
        mGrallocHandle(0),
        mWidth(0),
        mHeight(0),
        mSurfaceHeight(0),
        mStride(0),
        mColorFormat(0),
        mType(type),
        mSurface(-1),
        mFlags(flag),
        mpGralloc(NULL) {}

    ~ISVBuffer();

    // init buffer info
    // FIXME: hackFormat is for VP9, should be removed in future
    status_t initBufferInfo(uint32_t hackFormat);

    // get va surface
    int32_t getSurface() { return mSurface; }
    // get buffer handle
    unsigned long getHandle() { return mBuffer; }
    // set/clear/get flag
    uint32_t getFlags() { return mFlags; }
    void setFlag(uint32_t flag) { mFlags |= flag; return; }
    void unsetFlag(uint32_t flag) { mFlags &= ~flag; return; }
    status_t clearIfNeed();

private:

    sp<ISVWorker> mWorker;
    unsigned long mBuffer;
    unsigned long mGrallocHandle;
    uint32_t mWidth;
    uint32_t mHeight;
    uint32_t mSurfaceHeight;
    uint32_t mStride;
    uint32_t mColorFormat;
    ISV_BUFFERTYPE mType;
    int32_t mSurface;
    uint32_t mFlags;
    gralloc_module_t* mpGralloc;
};

class ISVBufferManager: public RefBase
{
public:
    ISVBufferManager()
        :mWorker(NULL),
        mMetaDataMode(false),
        mNeedClearBuffers(false) {}

    ~ISVBufferManager() {}
    // set mBuffers size
    status_t setBufferCount(int32_t size);

    // register/unregister ISVBuffers to mBuffers
    status_t useBuffer(const sp<ANativeWindowBuffer> nativeBuffer);
    status_t useBuffer(unsigned long handle);
    status_t freeBuffer(unsigned long handle);

    // Map to ISVBuffer
    ISVBuffer* mapBuffer(unsigned long handle);
    // set isv worker
    void setWorker(sp<ISVWorker> worker) { mWorker = worker; }
    void setMetaDataMode(bool metaDataMode) { mMetaDataMode = metaDataMode; }
    // set buffer flag.
    status_t setBuffersFlag(uint32_t flag);
private:
    typedef enum {
        GRALLOC_BUFFER_MODE = 0,
        META_DATA_MODE = 1,
    } ISV_WORK_MODE;

    sp<ISVWorker> mWorker;
    bool mMetaDataMode;
    // VPP buffer queue
    Vector<ISVBuffer*> mBuffers;
    Mutex mBufferLock; // to protect access to mBuffers
    bool mNeedClearBuffers;
};


#endif //#define __ISV_BUFMANAGER_H