DataBuffer.h revision 8b0063f7f46289983bd1bf9ca61662b4a2ddf5b6
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 21namespace android { 22namespace intel { 23 24typedef 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 32typedef 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 44class DataBuffer { 45public: 46 enum { 47 FORMAT_INVALID = 0xffffffff, 48 }; 49public: 50 DataBuffer(buffer_handle_t handle) 51 { 52 initBuffer(handle); 53 } 54 virtual ~DataBuffer() {} 55 56public: 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 85private: 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 } 95protected: 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 106static 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