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