Home | History | Annotate | Download | only in include
      1 /*
      2 // Copyright(c)2014 IntelCorporation
      3 //
      4 // LicensedundertheApacheLicense,Version2.0(the"License");
      5 // youmaynotusethisfileexceptincompliancewiththeLicense.
      6 // YoumayobtainacopyoftheLicenseat
      7 //
      8 // http://www.apache.org/licenses/LICENSE-2.0
      9 //
     10 // Unlessrequiredbyapplicablelaworagreedtoinwriting,software
     11 // distributedundertheLicenseisdistributedonan"ASIS"BASIS,
     12 // WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
     13 // SeetheLicenseforthespecificlanguagegoverningpermissionsand
     14 // limitationsundertheLicense.
     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:
     50     DataBuffer(buffer_handle_t handle)
     51     {
     52         initBuffer(handle);
     53     }
     54     virtual ~DataBuffer() {}
     55 
     56 public:
     57     virtual void resetBuffer(buffer_handle_t handle) {
     58         // nothing to reset, just do initialization
     59         initBuffer(handle);
     60     }
     61 
     62     buffer_handle_t getHandle() const { return mHandle; }
     63 
     64     void setStride(stride_t& stride) { mStride = stride; }
     65     stride_t& getStride() { return mStride; }
     66 
     67     void setWidth(uint32_t width) { mWidth = width; }
     68     uint32_t getWidth() const { return mWidth; }
     69 
     70     void setHeight(uint32_t height) { mHeight = height; }
     71     uint32_t getHeight() const { return mHeight; }
     72 
     73     void setCrop(int x, int y, int w, int h) {
     74         mCrop.x = x; mCrop.y = y; mCrop.w = w; mCrop.h = h; }
     75     crop_t& getCrop() { return mCrop; }
     76 
     77     void setFormat(uint32_t format) { mFormat = format; }
     78     uint32_t getFormat() const { return mFormat; }
     79 
     80     uint64_t getKey() const { return mKey; }
     81 
     82     void setIsCompression(bool isCompressed) { mIsCompression = isCompressed; }
     83     bool isCompression() { return mIsCompression; }
     84 
     85 private:
     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 
    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