14a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh/* 24a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. 34a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* 44a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* Redistribution and use in source and binary forms, with or without 54a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* modification, are permitted provided that the following conditions are 64a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* met: 74a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* * Redistributions of source code must retain the above copyright 84a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* notice, this list of conditions and the following disclaimer. 94a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* * Redistributions in binary form must reproduce the above 104a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* copyright notice, this list of conditions and the following 114a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* disclaimer in the documentation and/or other materials provided 124a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* with the distribution. 134a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* * Neither the name of The Linux Foundation nor the names of its 144a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* contributors may be used to endorse or promote products derived 154a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* from this software without specific prior written permission. 164a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* 174a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 184a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 194a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 204a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 214a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 224a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 234a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 244a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 254a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 264a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 274a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh*/ 294a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#ifdef USE_GRALLOC1 304a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#ifndef __HWC_BUFFER_ALLOCATOR_H__ 314a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#define __HWC_BUFFER_ALLOCATOR_H__ 324a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 334a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#include <fcntl.h> 344a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#include <sys/mman.h> 354a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 364a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#include <hardware/gralloc1.h> 374a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#include "gralloc_priv.h" 384a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 394a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanhnamespace sdm { 404a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 414a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanhtemplate <class Type> 424a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanhinline Type ALIGN(Type x, Type align) { 434a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh return (x + align - 1) & ~(align - 1); 444a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh} 454a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 464a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanhclass HWCBufferAllocator : public BufferAllocator { 474a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh public: 484a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh HWCBufferAllocator(); 494a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh ~HWCBufferAllocator(); 504a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 514a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh DisplayError AllocateBuffer(BufferInfo *buffer_info); 524a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh DisplayError FreeBuffer(BufferInfo *buffer_info); 534a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh uint32_t GetBufferSize(BufferInfo *buffer_info); 544a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 554a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh void GetCustomWidthAndHeight(const private_handle_t *handle, int *width, int *height); 564a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh void GetAlignedWidthAndHeight(int width, int height, int format, uint32_t alloc_type, 574a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh int *aligned_width, int *aligned_height); 584a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh DisplayError GetAllocatedBufferInfo(const BufferConfig &buffer_config, 594a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh AllocatedBufferInfo *allocated_buffer_info); 604a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh DisplayError GetBufferLayout(const AllocatedBufferInfo &buf_info, 614a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh uint32_t stride[4], uint32_t offset[4], 624a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh uint32_t *num_planes); 634a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh int SetBufferInfo(LayerBufferFormat format, int *target, uint64_t *flags); 644a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh DisplayError MapBuffer(const private_handle_t *handle, int acquire_fence); 654a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 664a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh private: 674a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh gralloc1_device_t *gralloc_device_ = nullptr; 684a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh const hw_module_t *module_; 694a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh GRALLOC1_PFN_RELEASE ReleaseBuffer_ = nullptr; 704a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh GRALLOC1_PFN_PERFORM Perform_ = nullptr; 714a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh GRALLOC1_PFN_LOCK Lock_ = nullptr; 724a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh}; 734a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 744a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh} // namespace sdm 754a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#endif // __HWC_BUFFER_ALLOCATOR_H__ 764a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#else 774a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#include "../hwc/hwc_buffer_allocator.h" 784a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh#endif // __HWC_BUFFER_ALLOCATOR_H__ 794a1efd0680d2e9b61739e1eaeffd89174d6d2605Alain Vongsouvanh 80