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