1 /* 2 * Copyright (c) 2018-2020 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 #include "gr_utils.h" 40 41 namespace vendor { 42 namespace qti { 43 namespace hardware { 44 namespace display { 45 namespace mapper { 46 namespace V3_0 { 47 namespace implementation { 48 49 using ::android::sp; 50 using ::android::hardware::hidl_array; 51 using ::android::hardware::hidl_handle; 52 using ::android::hardware::hidl_memory; 53 using ::android::hardware::hidl_string; 54 using ::android::hardware::hidl_vec; 55 using ::android::hardware::Return; 56 using ::android::hardware::Void; 57 using ::android::hardware::graphics::common::V1_2::PixelFormat; 58 using ::android::hardware::graphics::mapper::V3_0::Error; 59 using ::android::hardware::graphics::mapper::V3_0::IMapper; 60 using ::android::hardware::graphics::mapper::V3_0::YCbCrLayout; 61 using ::android::hidl::base::V1_0::DebugInfo; 62 using ::android::hidl::base::V1_0::IBase; 63 using gralloc::BufferManager; 64 using ::vendor::qti::hardware::display::mapperextensions::V1_1::IQtiMapperExtensions; 65 using ::vendor::qti::hardware::display::mapperextensions::V1_1::implementation::QtiMapperExtensions; 66 using ::vendor::qti::hardware::display::mapper::V3_0::IQtiMapper; 67 68 using IMapper_3_0 = android::hardware::graphics::mapper::V3_0::IMapper; 69 using BufferDescriptorInfo_3_0 = 70 android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo; 71 using IMapperBufferDescriptor = android::hardware::graphics::mapper::V3_0::BufferDescriptor; 72 using IMapper_3_0_Error = ::android::hardware::graphics::mapper::V3_0::Error; 73 74 class QtiMapper : public IQtiMapper { 75 public: 76 QtiMapper(); 77 // Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow. 78 Return<void> createDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info, 79 createDescriptor_cb hidl_cb) override; 80 Return<void> importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) override; 81 Return<Error> freeBuffer(void *buffer) override; 82 Return<void> lock(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region, 83 const hidl_handle &acquire_fence, lock_cb hidl_cb) override; 84 Return<void> lockYCbCr(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region, 85 const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) override; 86 Return<void> unlock(void *buffer, unlock_cb hidl_cb) override; 87 88 // Methods from ::android::hardware::graphics::mapper::V2_1::IMapper follow. 89 Return<Error> validateBufferSize(void *buffer, const BufferDescriptorInfo_3_0 &descriptorInfo, 90 uint32_t stride) override; 91 Return<void> getTransportSize(void *buffer, IMapper_3_0::getTransportSize_cb hidl_cb) override; 92 93 Return<void> isSupported(const BufferDescriptorInfo_3_0 &descriptor_info, 94 IMapper_3_0::isSupported_cb hidl_cb) override; 95 96 Return<void> getMapperExtensions(getMapperExtensions_cb hidl_cb); 97 sp<mapperextensions::V1_1::IQtiMapperExtensions> extensions_ = nullptr; Encode(const IMapper_3_0::BufferDescriptorInfo & bd_info)98 hidl_vec<uint32_t> Encode(const IMapper_3_0::BufferDescriptorInfo &bd_info) { 99 hidl_vec<uint32_t> out; 100 out.resize(gralloc::kBufferDescriptorSize); 101 out[0] = gralloc::kMagicVersion; 102 out[1] = bd_info.width; 103 out[2] = bd_info.height; 104 out[3] = bd_info.layerCount; 105 out[4] = static_cast<uint32_t>(bd_info.format); 106 out[5] = static_cast<uint32_t>(bd_info.usage); 107 out[6] = static_cast<uint32_t>(bd_info.usage >> 32); 108 return out; 109 } Decode(const hidl_vec<uint32_t> & in,gralloc::BufferDescriptor * buf_descriptor)110 static gralloc::Error Decode(const hidl_vec<uint32_t> &in, 111 gralloc::BufferDescriptor *buf_descriptor) { 112 if (in.size() != gralloc::kBufferDescriptorSize || in[0] != gralloc::kMagicVersion) { 113 return gralloc::Error::BAD_DESCRIPTOR; 114 } 115 uint32_t width = static_cast<int32_t>(in[1]); 116 uint32_t height = static_cast<int32_t>(in[2]); 117 buf_descriptor->SetDimensions(width, height); 118 uint32_t layer_count = in[3]; 119 buf_descriptor->SetLayerCount(layer_count); 120 uint32_t format = static_cast<int32_t>(in[4]); 121 buf_descriptor->SetColorFormat(format); 122 uint64_t usage = static_cast<uint64_t>(in[6]) << 32 | in[5]; 123 buf_descriptor->SetUsage(usage); 124 return gralloc::Error::NONE; 125 } 126 127 private: 128 BufferManager *buf_mgr_ = nullptr; 129 Error CreateDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info, 130 IMapperBufferDescriptor *descriptor); 131 bool ValidDescriptor(const IMapper::BufferDescriptorInfo &bd); 132 bool GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd); 133 void WaitFenceFd(int fence_fd); 134 Error LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence); 135 }; 136 137 } // namespace implementation 138 } // namespace V3_0 139 } // namespace mapper 140 } // namespace display 141 } // namespace hardware 142 } // namespace qti 143 } // namespace vendor 144 145 #endif // __QTIMAPPER_H__ 146