Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 1 | /* |
Ashish Kumar | f04c3de | 2018-08-01 14:45:14 +0530 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 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 | #define DEBUG 0 |
| 31 | #include "QtiAllocator.h" |
| 32 | |
| 33 | #include <log/log.h> |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 34 | #include <vendor/qti/hardware/display/mapper/3.0/IQtiMapper.h> |
| 35 | #include <vendor/qti/hardware/display/mapper/4.0/IQtiMapper.h> |
| 36 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 37 | #include <vector> |
| 38 | |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 39 | #include "QtiMapper.h" |
| 40 | #include "QtiMapper4.h" |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 41 | #include "gr_utils.h" |
| 42 | |
| 43 | namespace vendor { |
| 44 | namespace qti { |
| 45 | namespace hardware { |
| 46 | namespace display { |
| 47 | namespace allocator { |
Tharaga Balachandran | ab150ab | 2019-09-26 19:17:58 -0400 | [diff] [blame] | 48 | namespace V3_0 { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 49 | namespace implementation { |
| 50 | |
| 51 | using android::hardware::hidl_handle; |
| 52 | using gralloc::BufferDescriptor; |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 53 | using IMapper_3_0_Error = android::hardware::graphics::mapper::V3_0::Error; |
| 54 | using gralloc::Error; |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 55 | |
| 56 | QtiAllocator::QtiAllocator() { |
| 57 | buf_mgr_ = BufferManager::GetInstance(); |
| 58 | } |
| 59 | |
| 60 | // Methods from ::android::hardware::graphics::allocator::V2_0::IAllocator follow. |
| 61 | Return<void> QtiAllocator::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) { |
| 62 | std::ostringstream os; |
| 63 | buf_mgr_->Dump(&os); |
| 64 | hidl_string reply; |
| 65 | reply.setToExternal(os.str().c_str(), os.str().length()); |
| 66 | hidl_cb(reply); |
| 67 | return Void(); |
| 68 | } |
| 69 | |
| 70 | Return<void> QtiAllocator::allocate(const hidl_vec<uint32_t> &descriptor, uint32_t count, |
| 71 | allocate_cb hidl_cb) { |
| 72 | ALOGD_IF(DEBUG, "Allocating buffers count: %d", count); |
| 73 | gralloc::BufferDescriptor desc; |
| 74 | |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 75 | auto err = ::vendor::qti::hardware::display::mapper::V3_0::implementation::QtiMapper::Decode( |
| 76 | descriptor, &desc); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 77 | if (err != Error::NONE) { |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 78 | hidl_cb(static_cast<IMapper_3_0_Error>(err), 0, hidl_vec<hidl_handle>()); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 79 | return Void(); |
| 80 | } |
| 81 | |
| 82 | std::vector<hidl_handle> buffers; |
| 83 | buffers.reserve(count); |
| 84 | for (uint32_t i = 0; i < count; i++) { |
| 85 | buffer_handle_t buffer; |
| 86 | ALOGD_IF(DEBUG, "buffer: %p", &buffer); |
| 87 | err = buf_mgr_->AllocateBuffer(desc, &buffer); |
| 88 | if (err != Error::NONE) { |
| 89 | break; |
| 90 | } |
| 91 | buffers.emplace_back(hidl_handle(buffer)); |
| 92 | } |
| 93 | |
| 94 | uint32_t stride = 0; |
| 95 | hidl_vec<hidl_handle> hidl_buffers; |
| 96 | if (err == Error::NONE && buffers.size() > 0) { |
| 97 | stride = static_cast<uint32_t>(PRIV_HANDLE_CONST(buffers[0].getNativeHandle())->width); |
| 98 | hidl_buffers.setToExternal(buffers.data(), buffers.size()); |
| 99 | } |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 100 | hidl_cb(static_cast<IMapper_3_0_Error>(err), stride, hidl_buffers); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 101 | |
| 102 | for (const auto &b : buffers) { |
| 103 | buf_mgr_->ReleaseBuffer(PRIV_HANDLE_CONST(b.getNativeHandle())); |
| 104 | } |
| 105 | |
| 106 | return Void(); |
| 107 | } |
| 108 | |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 109 | } // namespace implementation |
| 110 | } // namespace V3_0 |
| 111 | } // namespace allocator |
| 112 | } // namespace display |
| 113 | } // namespace hardware |
| 114 | } // namespace qti |
| 115 | } // namespace vendor |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 116 | |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 117 | namespace vendor { |
| 118 | namespace qti { |
| 119 | namespace hardware { |
| 120 | namespace display { |
| 121 | namespace allocator { |
| 122 | namespace V4_0 { |
| 123 | namespace implementation { |
| 124 | |
| 125 | using android::hardware::hidl_handle; |
| 126 | using gralloc::BufferDescriptor; |
| 127 | using IMapper_4_0_Error = android::hardware::graphics::mapper::V4_0::Error; |
| 128 | using gralloc::Error; |
| 129 | |
| 130 | QtiAllocator::QtiAllocator() { |
| 131 | gralloc::GrallocProperties properties; |
| 132 | get_properties(&properties); |
| 133 | buf_mgr_ = BufferManager::GetInstance(); |
| 134 | buf_mgr_->SetGrallocDebugProperties(properties); |
| 135 | } |
| 136 | |
| 137 | Return<void> QtiAllocator::allocate(const hidl_vec<uint8_t> &descriptor, uint32_t count, |
| 138 | allocate_cb hidl_cb) { |
| 139 | ALOGD_IF(DEBUG, "Allocating buffers count: %d", count); |
| 140 | gralloc::BufferDescriptor desc; |
| 141 | |
| 142 | auto err = ::vendor::qti::hardware::display::mapper::V4_0::implementation::QtiMapper::Decode( |
| 143 | descriptor, &desc); |
| 144 | if (err != Error::NONE) { |
| 145 | hidl_cb(static_cast<IMapper_4_0_Error>(err), 0, hidl_vec<hidl_handle>()); |
| 146 | return Void(); |
| 147 | } |
| 148 | |
| 149 | std::vector<hidl_handle> buffers; |
| 150 | buffers.reserve(count); |
| 151 | for (uint32_t i = 0; i < count; i++) { |
| 152 | buffer_handle_t buffer; |
| 153 | ALOGD_IF(DEBUG, "buffer: %p", &buffer); |
| 154 | err = buf_mgr_->AllocateBuffer(desc, &buffer); |
| 155 | if (err != Error::NONE) { |
| 156 | break; |
| 157 | } |
| 158 | buffers.emplace_back(hidl_handle(buffer)); |
| 159 | } |
| 160 | |
| 161 | uint32_t stride = 0; |
| 162 | hidl_vec<hidl_handle> hidl_buffers; |
| 163 | if (err == Error::NONE && buffers.size() > 0) { |
| 164 | stride = static_cast<uint32_t>(PRIV_HANDLE_CONST(buffers[0].getNativeHandle())->width); |
| 165 | hidl_buffers.setToExternal(buffers.data(), buffers.size()); |
| 166 | } |
| 167 | hidl_cb(static_cast<IMapper_4_0_Error>(err), stride, hidl_buffers); |
| 168 | |
| 169 | for (const auto &b : buffers) { |
| 170 | buf_mgr_->ReleaseBuffer(PRIV_HANDLE_CONST(b.getNativeHandle())); |
| 171 | } |
| 172 | |
| 173 | return Void(); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | } // namespace implementation |
Tharaga Balachandran | 74ab111 | 2020-01-08 17:17:56 -0500 | [diff] [blame^] | 177 | } // namespace V4_0 |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 178 | } // namespace allocator |
| 179 | } // namespace display |
| 180 | } // namespace hardware |
| 181 | } // namespace qti |
| 182 | } // namespace vendor |