1/*
2// Copyright (c) 2014 Intel Corporation 
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#ifndef BUFFERMAPPER_H__
17#define BUFFERMAPPER_H__
18
19#include <DataBuffer.h>
20
21namespace android {
22namespace intel {
23
24class BufferMapper : public DataBuffer {
25public:
26    BufferMapper(DataBuffer& buffer)
27        : DataBuffer(buffer),
28          mRefCount(0)
29    {
30    }
31    virtual ~BufferMapper() {}
32public:
33    int incRef()
34    {
35        mRefCount++;
36        return mRefCount;
37    }
38    int decRef()
39    {
40        mRefCount--;
41        return mRefCount;
42    }
43
44    int getRef() const
45    {
46        return mRefCount;
47    }
48
49    // map the given buffer into both DC & CPU MMU
50    virtual bool map() = 0;
51    // unmap the give buffer from both DC & CPU MMU
52    virtual bool unmap() = 0;
53
54    // return gtt page offset
55    virtual uint32_t getGttOffsetInPage(int subIndex) const = 0;
56    virtual void* getCpuAddress(int subIndex) const = 0;
57    virtual uint32_t getSize(int subIndex) const = 0;
58    virtual uint32_t getKHandle(int subIndex) = 0;
59    virtual uint32_t getFbHandle(int subIndex) = 0;
60    virtual void putFbHandle() = 0;
61private:
62    int mRefCount;
63};
64
65} // namespace intel
66} // namespace android
67
68#endif /* BUFFERMAPPER_H__ */
69