Home | History | Annotate | Download | only in core
      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   uint32_t size = 0;             //!< Specifies the size of the allocated buffer.
     72   uint32_t fb_id = 0;            // Registered id with the DRM driver
     73   uint32_t gem_handle = 0;       // GEM driver handle for correspoding import of ION buffer
     74 };
     75 
     76 /*! @brief Holds the information about the input/output configuration of an output buffer.
     77 
     78   @sa BufferAllocator::AllocateBuffer
     79   @sa BufferAllocator::FreeBuffer
     80 */
     81 struct BufferInfo {
     82   BufferConfig buffer_config;             //!< Specifies configuration of a buffer to be allocated.
     83   AllocatedBufferInfo alloc_buffer_info;  //!< Specifies buffer information of allocated buffer.
     84 
     85   void *private_data = NULL;              //!< Pointer to private data.
     86 };
     87 
     88 /*! @brief Buffer allocator implemented by the client
     89 
     90   @details This class declares prototype for BufferAllocator methods which must be
     91   implemented by the client. Buffer manager in display manager will use these methods to
     92   allocate/deallocate buffers for display manager.
     93 
     94   @sa CoreInterface::CreateCore
     95 */
     96 class BufferAllocator {
     97  public:
     98   /*! @brief Method to allocate ouput buffer for the given input configuration.
     99 
    100     @details This method allocates memory based on input configuration.
    101 
    102     @param[in] buffer_info \link BufferInfo \endlink
    103 
    104     @return \link DisplayError \endlink
    105   */
    106   virtual DisplayError AllocateBuffer(BufferInfo *buffer_info) = 0;
    107 
    108 
    109   /*! @brief Method to deallocate the ouput buffer.
    110 
    111     @details This method deallocates the memory allocated using AllocateBuffer method.
    112 
    113     @param[in] buffer_info \link BufferInfo \endlink
    114 
    115     @return \link DisplayError \endlink
    116   */
    117   virtual DisplayError FreeBuffer(BufferInfo *buffer_info) = 0;
    118 
    119 
    120   /*! @brief Method to get the buffer size.
    121 
    122     @details This method returns buffer size for a specific configuration mentioned in buffer info.
    123 
    124     @param[in] buffer_info \link BufferInfo \endlink
    125 
    126     @return \link unsigned int \endlink
    127   */
    128   virtual uint32_t GetBufferSize(BufferInfo *buffer_info) = 0;
    129 
    130   /*! @brief Method to Get the AllocatedBufferInfo only.
    131 
    132     @details This method populates the AllocatedBufferInfo as per the configuration in BufferInfo,
    133     but fd will be invalid.
    134 
    135     @param[in] buffer_info \link BufferInfo \endlink
    136 
    137     @param[out] allocated_buffer_info \link AllocatedBufferInfo \endlink
    138 
    139     @return \link DisplayError \endlink
    140   */
    141   virtual DisplayError GetAllocatedBufferInfo(const BufferConfig &buffer_config,
    142                                               AllocatedBufferInfo *allocated_buffer_info) = 0;
    143 
    144  protected:
    145   virtual ~BufferAllocator() { }
    146 };
    147 
    148 }  // namespace sdm
    149 
    150 #endif  // __BUFFER_ALLOCATOR_H__
    151 
    152