Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 1 | /* |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 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> |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 35 | #include <vendor/qti/hardware/display/mapper/3.0/IQtiMapper.h> |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 36 | |
Tharaga Balachandran | f7e62a3 | 2019-06-06 11:33:29 -0400 | [diff] [blame] | 37 | #include "QtiMapperExtensions.h" |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 38 | #include "gr_buf_mgr.h" |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame] | 39 | #include "gr_utils.h" |
| 40 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 41 | namespace vendor { |
| 42 | namespace qti { |
| 43 | namespace hardware { |
| 44 | namespace display { |
| 45 | namespace mapper { |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame] | 46 | namespace V3_0 { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 47 | namespace implementation { |
| 48 | |
Tharaga Balachandran | f7e62a3 | 2019-06-06 11:33:29 -0400 | [diff] [blame] | 49 | using ::android::sp; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 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; |
Tharaga Balachandran | f7e62a3 | 2019-06-06 11:33:29 -0400 | [diff] [blame] | 55 | using ::android::hardware::Return; |
| 56 | using ::android::hardware::Void; |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 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; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 61 | using ::android::hidl::base::V1_0::DebugInfo; |
| 62 | using ::android::hidl::base::V1_0::IBase; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 63 | using gralloc::BufferManager; |
Ashish Kumar | 2543577 | 2019-08-06 16:15:56 +0530 | [diff] [blame] | 64 | using ::vendor::qti::hardware::display::mapperextensions::V1_1::IQtiMapperExtensions; |
| 65 | using ::vendor::qti::hardware::display::mapperextensions::V1_1::implementation::QtiMapperExtensions; |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 66 | using ::vendor::qti::hardware::display::mapper::V3_0::IQtiMapper; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 67 | |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 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; |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame] | 72 | using IMapper_3_0_Error = ::android::hardware::graphics::mapper::V3_0::Error; |
Naseer Ahmed | 920d71b | 2018-03-08 16:54:28 -0500 | [diff] [blame] | 73 | |
Ashish Kumar | f04c3de | 2018-08-01 14:45:14 +0530 | [diff] [blame] | 74 | class QtiMapper : public IQtiMapper { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 75 | public: |
| 76 | QtiMapper(); |
| 77 | // Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow. |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 78 | Return<void> createDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info, |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 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; |
Naseer Ahmed | 036d57d | 2018-03-02 15:42:45 -0500 | [diff] [blame] | 87 | |
Naseer Ahmed | 920d71b | 2018-03-08 16:54:28 -0500 | [diff] [blame] | 88 | // Methods from ::android::hardware::graphics::mapper::V2_1::IMapper follow. |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 89 | Return<Error> validateBufferSize(void *buffer, const BufferDescriptorInfo_3_0 &descriptorInfo, |
Naseer Ahmed | 920d71b | 2018-03-08 16:54:28 -0500 | [diff] [blame] | 90 | uint32_t stride) override; |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 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; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 95 | |
Tharaga Balachandran | f7e62a3 | 2019-06-06 11:33:29 -0400 | [diff] [blame] | 96 | Return<void> getMapperExtensions(getMapperExtensions_cb hidl_cb); |
Ashish Kumar | 2543577 | 2019-08-06 16:15:56 +0530 | [diff] [blame] | 97 | sp<mapperextensions::V1_1::IQtiMapperExtensions> extensions_ = nullptr; |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame] | 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 | } |
| 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 | int32_t width = static_cast<int32_t>(in[1]); |
| 116 | int32_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 | int32_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 | } |
Ashish Kumar | 28fa16f | 2019-02-22 05:24:02 +0530 | [diff] [blame] | 126 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 127 | private: |
| 128 | BufferManager *buf_mgr_ = nullptr; |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 129 | Error CreateDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info, |
| 130 | IMapperBufferDescriptor *descriptor); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 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 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 137 | } // namespace implementation |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame] | 138 | } // namespace V3_0 |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 139 | } // namespace mapper |
| 140 | } // namespace display |
| 141 | } // namespace hardware |
| 142 | } // namespace qti |
| 143 | } // namespace vendor |
| 144 | |
| 145 | #endif // __QTIMAPPER_H__ |