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 */ 31 32 #ifndef EXYNOS_BUFFER_H_ 33 #define EXYNOS_BUFFER_H_ 34 35 #include <sys/types.h> 36 37 //! Buffer information 38 /*! 39 * \ingroup Exynos 40 */ 41 struct ExynosBuffer 42 { 43 public: 44 //! Buffer type 45 enum BUFFER_TYPE 46 { 47 BUFFER_TYPE_BASE = 0, 48 BUFFER_TYPE_VIRT = 1, //!< virtual address 49 BUFFER_TYPE_PHYS = 1 << 1, //!< physical address 50 BUFFER_TYPE_RESERVED = 1 << 2, //!< reserved type 51 BUFFER_TYPE_FD = 1 << 3, //!< physical address 52 BUFFER_TYPE_MAX, 53 }; 54 55 //! Buffer virtual address 56 union { 57 char *p; //! single address. 58 char *extP[3]; //! Y Cb Cr. 59 } virt; 60 61 //! Buffer physical address 62 union { 63 unsigned int p; //! single address. 64 unsigned int extP[3]; //! Y Cb Cr. 65 } phys; 66 67 //! Buffer file descriptors 68 union { 69 int fd; 70 int extFd[3]; 71 } fd; 72 73 //! Buffer reserved id 74 union { 75 unsigned int p; //! \n 76 unsigned int extP[3]; //! \n 77 } reserved; 78 79 //! Buffer size 80 union { 81 unsigned int s; 82 unsigned int extS[3]; 83 } size; 84 85 #ifdef __cplusplus 86 //! Constructor ExynosBufferExynosBuffer87 ExynosBuffer() 88 { 89 for (int i = 0; i < 3; i++) { 90 virt. extP[i] = NULL; 91 phys. extP[i] = 0; 92 fd. extFd[i] = -1; 93 reserved.extP[i] = 0; 94 size. extS[i] = 0; 95 } 96 } 97 98 //! Constructor ExynosBufferExynosBuffer99 ExynosBuffer(const ExynosBuffer *other) 100 { 101 for (int i = 0; i < 3; i++) { 102 virt. extP[i] = other->virt.extP[i]; 103 phys. extP[i] = other->phys.extP[i]; 104 fd. extFd[i] = other->fd.extFd[i]; 105 reserved.extP[i] = other->reserved.extP[i]; 106 size. extS[i] = other->size.extS[i]; 107 } 108 } 109 110 //! Operator(=) override 111 ExynosBuffer& operator =(const ExynosBuffer &other) 112 { 113 for (int i = 0; i < 3; i++) { 114 virt. extP[i] = other.virt.extP[i]; 115 phys. extP[i] = other.phys.extP[i]; 116 fd. extFd[i] = other.fd.extFd[i]; 117 reserved.extP[i] = other.reserved.extP[i]; 118 size. extS[i] = other.size.extS[i]; 119 } 120 return *this; 121 } 122 123 //! Operator(==) override 124 bool operator ==(const ExynosBuffer &other) const 125 { 126 return ( virt. extP[0] == other.virt.extP[0] 127 && virt. extP[1] == other.virt.extP[1] 128 && virt. extP[2] == other.virt.extP[2] 129 && phys. extP[0] == other.phys.extP[0] 130 && phys. extP[1] == other.phys.extP[1] 131 && phys. extP[2] == other.phys.extP[2] 132 && fd. extFd[0] == other.fd.extFd[0] 133 && fd. extFd[1] == other.fd.extFd[1] 134 && fd. extFd[2] == other.fd.extFd[2] 135 && reserved.extP[0] == other.reserved.extP[0] 136 && reserved.extP[1] == other.reserved.extP[1] 137 && reserved.extP[2] == other.reserved.extP[2] 138 && size. extS[0] == other.size.extS[0] 139 && size. extS[1] == other.size.extS[1] 140 && size. extS[2] == other.size.extS[2]); 141 } 142 143 //! Operator(!=) override 144 bool operator !=(const ExynosBuffer &other) const 145 { 146 // use operator(==) 147 return !(*this == other); 148 } 149 150 //! Get Buffer type BUFFER_TYPEExynosBuffer151 static int BUFFER_TYPE(ExynosBuffer *buf) 152 { 153 int type = BUFFER_TYPE_BASE; 154 if (buf->virt.p) 155 type |= BUFFER_TYPE_VIRT; 156 if (buf->phys.p) 157 type |= BUFFER_TYPE_PHYS; 158 if (buf->fd.fd >= 0) 159 type |= BUFFER_TYPE_FD; 160 if (buf->reserved.p) 161 type |= BUFFER_TYPE_RESERVED; 162 163 return type; 164 } 165 #endif 166 }; 167 168 #endif //EXYNOS_BUFFER_H_ 169