1 /* 2 * Copyright (c) 2015 - 2017, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 /*! @file buffer_allocator.h 31 @brief Interface file for platform specific buffer allocator. 32 33 @details This interface is used by SDM to allocate internal buffers. 34 */ 35 36 #ifndef __BUFFER_ALLOCATOR_H__ 37 #define __BUFFER_ALLOCATOR_H__ 38 39 #include "layer_buffer.h" 40 41 namespace sdm { 42 /*! @brief Input configuration set by the client for buffer allocation. 43 44 @sa BufferInfo::BufferConfig 45 */ 46 47 struct BufferConfig { 48 uint32_t width = 0; //!< Specifies buffer width for buffer allocation. 49 uint32_t height = 0; //!< Specifies buffer height for buffer allocation. 50 LayerBufferFormat format = kFormatInvalid; //!< Specifies buffer format for buffer allocation. 51 uint32_t buffer_count = 0; //!< Specifies number of buffers to be allocated. 52 bool secure = false; //!< Specifies buffer to be allocated from 53 //!< secure region. 54 bool cache = false; //!< Specifies whether the buffer needs to be cache. 55 bool secure_camera = false; //!< Specifies buffer to be allocated from specific 56 //!< secure heap and with a specific alignment. 57 bool gfx_client = false; //!< Specifies whether buffer is used by gfx. 58 }; 59 60 /*! @brief Holds the information about the allocated buffer. 61 62 @sa BufferAllocator::AllocateBuffer 63 @sa BufferAllocator::FreeBuffer 64 @sa BufferAllocator::GetAllocatedBufferInfo 65 */ 66 struct AllocatedBufferInfo { 67 int fd = -1; //!< Specifies the fd of the allocated buffer. 68 uint32_t stride = 0; //!< Specifies allocated buffer stride in bytes. 69 uint32_t aligned_width = 0; //!< Specifies aligned allocated buffer width in pixels. 70 uint32_t aligned_height = 0; //!< Specifies aligned allocated buffer height in pixels. 71 LayerBufferFormat format = kFormatInvalid; // Specifies buffer format for allocated buffer. 72 uint32_t size = 0; //!< Specifies the size of the allocated buffer. 73 }; 74 75 /*! @brief Holds the information about the input/output configuration of an output buffer. 76 77 @sa BufferAllocator::AllocateBuffer 78 @sa BufferAllocator::FreeBuffer 79 */ 80 struct BufferInfo { 81 BufferConfig buffer_config; //!< Specifies configuration of a buffer to be allocated. 82 AllocatedBufferInfo alloc_buffer_info; //!< Specifies buffer information of allocated buffer. 83 84 void *private_data = NULL; //!< Pointer to private data. 85 }; 86 87 /*! @brief Buffer allocator implemented by the client 88 89 @details This class declares prototype for BufferAllocator methods which must be 90 implemented by the client. Buffer manager in display manager will use these methods to 91 allocate/deallocate buffers for display manager. 92 93 @sa CoreInterface::CreateCore 94 */ 95 class BufferAllocator { 96 public: 97 /*! @brief Method to allocate ouput buffer for the given input configuration. 98 99 @details This method allocates memory based on input configuration. 100 101 @param[in] buffer_info \link BufferInfo \endlink 102 103 @return \link DisplayError \endlink 104 */ 105 virtual DisplayError AllocateBuffer(BufferInfo *buffer_info) = 0; 106 107 108 /*! @brief Method to deallocate the ouput buffer. 109 110 @details This method deallocates the memory allocated using AllocateBuffer method. 111 112 @param[in] buffer_info \link BufferInfo \endlink 113 114 @return \link DisplayError \endlink 115 */ 116 virtual DisplayError FreeBuffer(BufferInfo *buffer_info) = 0; 117 118 119 /*! @brief Method to get the buffer size. 120 121 @details This method returns buffer size for a specific configuration mentioned in buffer info. 122 123 @param[in] buffer_info \link BufferInfo \endlink 124 125 @return \link unsigned int \endlink 126 */ 127 virtual uint32_t GetBufferSize(BufferInfo *buffer_info) = 0; 128 129 /*! @brief Method to Get the AllocatedBufferInfo only. 130 131 @details This method populates the AllocatedBufferInfo as per the configuration in BufferInfo, 132 but fd will be invalid. 133 134 @param[in] buffer_info \link BufferInfo \endlink 135 136 @param[out] allocated_buffer_info \link AllocatedBufferInfo \endlink 137 138 @return \link DisplayError \endlink 139 */ 140 virtual DisplayError GetAllocatedBufferInfo(const BufferConfig &buffer_config, 141 AllocatedBufferInfo *allocated_buffer_info) = 0; 142 143 /* 144 * Retuns a buffer's layout in terms of number of planes, stride and offset of each plane 145 * Input: AllocatedBufferInfo with a valid aligned width, aligned height, SDM format 146 * Output: stride for each plane, offset of each plane from base, number of planes 147 */ 148 virtual DisplayError GetBufferLayout(const AllocatedBufferInfo &buf_info, 149 uint32_t stride[4], uint32_t offset[4], 150 uint32_t *num_planes) { return kErrorNotSupported; } 151 152 protected: 153 virtual ~BufferAllocator() { } 154 }; 155 156 } // namespace sdm 157 158 #endif // __BUFFER_ALLOCATOR_H__ 159 160