1 /* 2 * Copyright (c) 2015, 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 }; 56 57 /*! @brief Holds the information about the allocated buffer. 58 59 @sa BufferAllocator::AllocateBuffer 60 @sa BufferAllocator::FreeBuffer 61 */ 62 struct AllocatedBufferInfo { 63 int fd = -1; //!< Specifies the fd of the allocated buffer. 64 uint32_t stride = 0; //!< Specifies allocated buffer stride in bytes. 65 uint32_t aligned_width = 0; //!< Specifies aligned allocated buffer width in pixels. 66 uint32_t aligned_height = 0; //!< Specifies aligned allocated buffer height in pixels. 67 uint32_t size = 0; //!< Specifies the size of the allocated buffer. 68 }; 69 70 /*! @brief Holds the information about the input/output configuration of an output buffer. 71 72 @sa BufferAllocator::AllocateBuffer 73 @sa BufferAllocator::FreeBuffer 74 */ 75 struct BufferInfo { 76 BufferConfig buffer_config; //!< Specifies configuration of a buffer to be allocated. 77 AllocatedBufferInfo alloc_buffer_info; //!< Specifies buffer information of allocated buffer. 78 79 void *private_data = NULL; //!< Pointer to private data. 80 }; 81 82 /*! @brief Buffer allocator implemented by the client 83 84 @details This class declares prototype for BufferAllocator methods which must be 85 implemented by the client. Buffer manager in display manager will use these methods to 86 allocate/deallocate buffers for display manager. 87 88 @sa CoreInterface::CreateCore 89 */ 90 class BufferAllocator { 91 public: 92 /*! @brief Method to allocate ouput buffer for the given input configuration. 93 94 @details This method allocates memory based on input configuration. 95 96 @param[in] buffer_info \link BufferInfo \endlink 97 98 @return \link DisplayError \endlink 99 */ 100 virtual DisplayError AllocateBuffer(BufferInfo *buffer_info) = 0; 101 102 103 /*! @brief Method to deallocate the ouput buffer. 104 105 @details This method deallocates the memory allocated using AllocateBuffer method. 106 107 @param[in] buffer_info \link BufferInfo \endlink 108 109 @return \link DisplayError \endlink 110 */ 111 virtual DisplayError FreeBuffer(BufferInfo *buffer_info) = 0; 112 113 114 /*! @brief Method to get the buffer size. 115 116 @details This method returns buffer size for a specific configuration mentioned in buffer info. 117 118 @param[in] buffer_info \link BufferInfo \endlink 119 120 @return \link unsigned int \endlink 121 */ 122 virtual uint32_t GetBufferSize(BufferInfo *buffer_info) = 0; 123 124 protected: 125 virtual ~BufferAllocator() { } 126 }; 127 128 } // namespace sdm 129 130 #endif // __BUFFER_ALLOCATOR_H__ 131 132