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