1 /* 2 * Copyright (c) 2018-2019 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 #ifndef __QTIMAPPER_H__ 31 #define __QTIMAPPER_H__ 32 33 #include <hidl/MQDescriptor.h> 34 #include <hidl/Status.h> 35 #include <vendor/qti/hardware/display/mapper/3.0/IQtiMapper.h> 36 37 #include "QtiMapperExtensions.h" 38 #include "gr_buf_mgr.h" 39 namespace vendor { 40 namespace qti { 41 namespace hardware { 42 namespace display { 43 namespace mapper { 44 namespace implementation { 45 46 using ::android::sp; 47 using ::android::hardware::hidl_array; 48 using ::android::hardware::hidl_handle; 49 using ::android::hardware::hidl_memory; 50 using ::android::hardware::hidl_string; 51 using ::android::hardware::hidl_vec; 52 using ::android::hardware::Return; 53 using ::android::hardware::Void; 54 using ::android::hardware::graphics::common::V1_2::PixelFormat; 55 using ::android::hardware::graphics::mapper::V3_0::Error; 56 using ::android::hardware::graphics::mapper::V3_0::IMapper; 57 using ::android::hardware::graphics::mapper::V3_0::YCbCrLayout; 58 using ::android::hidl::base::V1_0::DebugInfo; 59 using ::android::hidl::base::V1_0::IBase; 60 using gralloc::BufferManager; 61 using ::vendor::qti::hardware::display::mapper::V3_0::IQtiMapper; 62 using ::vendor::qti::hardware::display::mapperextensions::V1_1::IQtiMapperExtensions; 63 using ::vendor::qti::hardware::display::mapperextensions::V1_1::implementation::QtiMapperExtensions; 64 65 using IMapper_3_0 = android::hardware::graphics::mapper::V3_0::IMapper; 66 using BufferDescriptorInfo_3_0 = 67 android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo; 68 using IMapperBufferDescriptor = android::hardware::graphics::mapper::V3_0::BufferDescriptor; 69 70 class QtiMapper : public IQtiMapper { 71 public: 72 QtiMapper(); 73 // Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow. 74 Return<void> createDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info, 75 createDescriptor_cb hidl_cb) override; 76 Return<void> importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) override; 77 Return<Error> freeBuffer(void *buffer) override; 78 Return<void> lock(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region, 79 const hidl_handle &acquire_fence, lock_cb hidl_cb) override; 80 Return<void> lockYCbCr(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region, 81 const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) override; 82 Return<void> unlock(void *buffer, unlock_cb hidl_cb) override; 83 84 // Methods from ::android::hardware::graphics::mapper::V2_1::IMapper follow. 85 Return<Error> validateBufferSize(void *buffer, const BufferDescriptorInfo_3_0 &descriptorInfo, 86 uint32_t stride) override; 87 Return<void> getTransportSize(void *buffer, IMapper_3_0::getTransportSize_cb hidl_cb) override; 88 89 Return<void> isSupported(const BufferDescriptorInfo_3_0 &descriptor_info, 90 IMapper_3_0::isSupported_cb hidl_cb) override; 91 92 Return<void> getMapperExtensions(getMapperExtensions_cb hidl_cb); 93 sp<mapperextensions::V1_1::IQtiMapperExtensions> extensions_ = nullptr; 94 95 private: 96 BufferManager *buf_mgr_ = nullptr; 97 Error CreateDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info, 98 IMapperBufferDescriptor *descriptor); 99 bool ValidDescriptor(const IMapper::BufferDescriptorInfo &bd); 100 bool GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd); 101 void WaitFenceFd(int fence_fd); 102 Error LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence); 103 }; 104 105 extern "C" IMapper_3_0 *HIDL_FETCH_IMapper(const char *name); 106 extern "C" IQtiMapper *HIDL_FETCH_IQtiMapper(const char *name); 107 108 } // namespace implementation 109 } // namespace mapper 110 } // namespace display 111 } // namespace hardware 112 } // namespace qti 113 } // namespace vendor 114 115 #endif // __QTIMAPPER_H__ 116