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 DATABUFFER_H__
17 #define DATABUFFER_H__
18 
19 #include <hardware/hwcomposer.h>
20 
21 namespace android {
22 namespace intel {
23 
24 typedef struct crop {
25     // align with android, using 'int' here
26     int x;
27     int y;
28     int w;
29     int h;
30 } crop_t;
31 
32 typedef struct stride {
33     union {
34         struct {
35             uint32_t stride;
36         } rgb;
37         struct {
38             uint32_t yStride;
39             uint32_t uvStride;
40         } yuv;
41     };
42 }stride_t;
43 
44 class DataBuffer {
45 public:
46     enum {
47         FORMAT_INVALID = 0xffffffff,
48     };
49 public:
DataBuffer(buffer_handle_t handle)50     DataBuffer(buffer_handle_t handle)
51     {
52         initBuffer(handle);
53     }
~DataBuffer()54     virtual ~DataBuffer() {}
55 
56 public:
resetBuffer(buffer_handle_t handle)57     virtual void resetBuffer(buffer_handle_t handle) {
58         // nothing to reset, just do initialization
59         initBuffer(handle);
60     }
61 
getHandle()62     buffer_handle_t getHandle() const { return mHandle; }
63 
setStride(stride_t & stride)64     void setStride(stride_t& stride) { mStride = stride; }
getStride()65     stride_t& getStride() { return mStride; }
66 
setWidth(uint32_t width)67     void setWidth(uint32_t width) { mWidth = width; }
getWidth()68     uint32_t getWidth() const { return mWidth; }
69 
setHeight(uint32_t height)70     void setHeight(uint32_t height) { mHeight = height; }
getHeight()71     uint32_t getHeight() const { return mHeight; }
72 
setCrop(int x,int y,int w,int h)73     void setCrop(int x, int y, int w, int h) {
74         mCrop.x = x; mCrop.y = y; mCrop.w = w; mCrop.h = h; }
getCrop()75     crop_t& getCrop() { return mCrop; }
76 
setFormat(uint32_t format)77     void setFormat(uint32_t format) { mFormat = format; }
getFormat()78     uint32_t getFormat() const { return mFormat; }
79 
getKey()80     uint64_t getKey() const { return mKey; }
81 
setIsCompression(bool isCompressed)82     void setIsCompression(bool isCompressed) { mIsCompression = isCompressed; }
isCompression()83     bool isCompression() { return mIsCompression; }
84 
85 private:
initBuffer(buffer_handle_t handle)86     void initBuffer(buffer_handle_t handle) {
87         mHandle = handle;
88         mFormat = 0;
89         mWidth = 0;
90         mHeight = 0;
91         mKey = (uint64_t)handle;
92         memset(&mStride, 0, sizeof(stride_t));
93         memset(&mCrop, 0, sizeof(crop_t));
94     }
95 protected:
96     buffer_handle_t mHandle;
97     stride_t mStride;
98     crop_t mCrop;
99     uint32_t mFormat;
100     uint32_t mWidth;
101     uint32_t mHeight;
102     uint64_t mKey;
103     bool mIsCompression;
104 };
105 
align_to(uint32_t arg,uint32_t align)106 static inline uint32_t align_to(uint32_t arg, uint32_t align)
107 {
108     return ((arg + (align - 1)) & (~(align - 1)));
109 }
110 
111 } // namespace intel
112 } // namespace android
113 
114 #endif /* DATABUFFER_H__ */
115