1 /* 2 * Copyright@ Samsung Electronics Co. LTD 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 17 /*! 18 * \file ExynosBuffer.h 19 * \brief header file for ExynosBuffer 20 * \author Sangwoo, Park(sw5771.park@samsung.com) 21 * \date 2011/06/02 22 * 23 * <b>Revision History: </b> 24 * - 2010/06/03 : Sangwoo, Park(sw5771.park@samsung.com) \n 25 * Initial version 26 * 27 * - 2012/03/14 : sangwoo.park(sw5771.park@samsung.com) \n 28 * Change file, struct name to ExynosXXX. 29 * 30 * - 2012/10/08 : sangwoo.park(sw5771.park@samsung.com) \n 31 * Add BUFFER_PLANE_NUM_DEFAULT, and, Increase Buffer as 4. 32 * 33 */ 34 35 #ifndef EXYNOS_BUFFER_H_ 36 #define EXYNOS_BUFFER_H_ 37 38 #include <sys/types.h> 39 40 //! Buffer information 41 /*! 42 * \ingroup Exynos 43 */ 44 struct ExynosBuffer 45 { 46 public: 47 //! Buffer type 48 enum BUFFER_TYPE 49 { 50 BUFFER_TYPE_BASE = 0, 51 BUFFER_TYPE_VIRT = 1 << 0, //!< virtual address 52 BUFFER_TYPE_PHYS = 1 << 1, //!< physical address 53 BUFFER_TYPE_FD = 1 << 2, //!< fd address 54 BUFFER_TYPE_RESERVED = 1 << 3, //!< reserved type 55 BUFFER_TYPE_MAX, 56 }; 57 58 //! Buffer plane number 59 enum BUFFER_PLANE_NUM 60 { 61 BUFFER_PLANE_NUM_DEFAULT = 4, 62 }; 63 64 //! Buffer virtual address 65 union { 66 char *p; //! single address. 67 char *extP[BUFFER_PLANE_NUM_DEFAULT]; //! Y Cb Cr. 68 } virt; 69 70 //! Buffer physical address 71 union { 72 unsigned int p; //! single address. 73 unsigned int extP[BUFFER_PLANE_NUM_DEFAULT]; //! Y Cb Cr. 74 } phys; 75 76 //! Buffer file descriptors 77 union { 78 int fd; //! single address. 79 int extFd[BUFFER_PLANE_NUM_DEFAULT]; //! Y Cb Cr. 80 } fd; 81 82 //! Buffer reserved id 83 union { 84 int p; //! \n 85 int extP[BUFFER_PLANE_NUM_DEFAULT]; //! \n 86 } reserved; 87 88 //! Buffer size 89 union { 90 unsigned int s; 91 unsigned int extS[BUFFER_PLANE_NUM_DEFAULT]; 92 } size; 93 94 #ifdef __cplusplus 95 //! Constructor ExynosBufferExynosBuffer96 ExynosBuffer() 97 { 98 for (int i = 0; i < BUFFER_PLANE_NUM_DEFAULT; i++) { 99 virt. extP [i] = NULL; 100 phys. extP [i] = 0; 101 fd. extFd[i] = -1; 102 reserved.extP [i] = 0; 103 size. extS [i] = 0; 104 } 105 } 106 107 //! Constructor ExynosBufferExynosBuffer108 ExynosBuffer(const ExynosBuffer *other) 109 { 110 for (int i = 0; i < BUFFER_PLANE_NUM_DEFAULT; i++) { 111 virt. extP [i] = other->virt.extP[i]; 112 phys. extP [i] = other->phys.extP[i]; 113 fd. extFd[i] = other->fd.extFd[i]; 114 reserved.extP [i] = other->reserved.extP[i]; 115 size. extS [i] = other->size.extS[i]; 116 } 117 } 118 119 //! Operator(=) override 120 ExynosBuffer& operator =(const ExynosBuffer &other) 121 { 122 for (int i = 0; i < BUFFER_PLANE_NUM_DEFAULT; i++) { 123 virt. extP [i] = other.virt.extP[i]; 124 phys. extP [i] = other.phys.extP[i]; 125 fd. extFd[i] = other.fd.extFd[i]; 126 reserved.extP [i] = other.reserved.extP[i]; 127 size. extS [i] = other.size.extS[i]; 128 } 129 return *this; 130 } 131 132 //! Operator(==) override 133 bool operator ==(const ExynosBuffer &other) const 134 { 135 bool ret = true; 136 137 for (int i = 0; i < BUFFER_PLANE_NUM_DEFAULT; i++) { 138 if ( virt. extP [i] != other.virt. extP[i] 139 || phys. extP [i] != other.phys. extP[i] 140 || fd. extFd[i] != other.fd. extFd[i] 141 || reserved.extP [i] != other.reserved.extP[i] 142 || size. extS [i] != other.size. extS[i]) { 143 ret = false; 144 break; 145 } 146 } 147 148 return ret; 149 } 150 151 //! Operator(!=) override 152 bool operator !=(const ExynosBuffer &other) const 153 { 154 // use operator(==) 155 return !(*this == other); 156 } 157 158 //! Get Buffer type BUFFER_TYPEExynosBuffer159 static int BUFFER_TYPE(ExynosBuffer *buf) 160 { 161 int type = BUFFER_TYPE_BASE; 162 if (buf->virt.p) 163 type |= BUFFER_TYPE_VIRT; 164 if (buf->phys.p) 165 type |= BUFFER_TYPE_PHYS; 166 if (buf->fd.fd >= 0) 167 type |= BUFFER_TYPE_FD; 168 if (buf->reserved.p) 169 type |= BUFFER_TYPE_RESERVED; 170 171 return type; 172 } 173 #endif 174 }; 175 176 #endif //EXYNOS_BUFFER_H_ 177