blob: 35145dc4b8f692e4f6c53970b4851e8330ec6e13 [file] [log] [blame]
Naseer Ahmede36f2242017-12-01 15:33:56 -05001/*
Tharaga Balachandran576571c2020-01-23 18:41:10 -05002 * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
Naseer Ahmede36f2242017-12-01 15:33:56 -05003 *
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 Balachandran576571c2020-01-23 18:41:10 -050033#include <cutils/properties.h>
Naseer Ahmede36f2242017-12-01 15:33:56 -050034#include <log/log.h>
Tharaga Balachandran74ab1112020-01-08 17:17:56 -050035#include <vendor/qti/hardware/display/mapper/3.0/IQtiMapper.h>
36#include <vendor/qti/hardware/display/mapper/4.0/IQtiMapper.h>
37
Naseer Ahmede36f2242017-12-01 15:33:56 -050038#include <vector>
39
Tharaga Balachandran74ab1112020-01-08 17:17:56 -050040#include "QtiMapper.h"
41#include "QtiMapper4.h"
Naseer Ahmede36f2242017-12-01 15:33:56 -050042#include "gr_utils.h"
43
Tharaga Balachandran576571c2020-01-23 18:41:10 -050044static void get_properties(gralloc::GrallocProperties *props) {
Yichi Chena8304132020-03-23 12:23:48 +080045 props->use_system_heap_for_sensors =
46 property_get_bool("vendor.gralloc.use_system_heap_for_sensors", 1);
Tharaga Balachandran576571c2020-01-23 18:41:10 -050047
Yichi Chena8304132020-03-23 12:23:48 +080048 props->ubwc_disable = property_get_bool("vendor.gralloc.disable_ubwc", 0);
Tharaga Balachandran576571c2020-01-23 18:41:10 -050049
Yichi Chena8304132020-03-23 12:23:48 +080050 props->ahardware_buffer_disable = property_get_bool("vendor.gralloc.disable_ahardware_buffer", 0);
Tharaga Balachandran576571c2020-01-23 18:41:10 -050051}
52
Naseer Ahmede36f2242017-12-01 15:33:56 -050053namespace vendor {
54namespace qti {
55namespace hardware {
56namespace display {
57namespace allocator {
Tharaga Balachandranab150ab2019-09-26 19:17:58 -040058namespace V3_0 {
Naseer Ahmede36f2242017-12-01 15:33:56 -050059namespace implementation {
60
61using android::hardware::hidl_handle;
62using gralloc::BufferDescriptor;
Tharaga Balachandran74ab1112020-01-08 17:17:56 -050063using IMapper_3_0_Error = android::hardware::graphics::mapper::V3_0::Error;
64using gralloc::Error;
Naseer Ahmede36f2242017-12-01 15:33:56 -050065
66QtiAllocator::QtiAllocator() {
Tharaga Balachandran576571c2020-01-23 18:41:10 -050067 gralloc::GrallocProperties properties;
68 get_properties(&properties);
Naseer Ahmede36f2242017-12-01 15:33:56 -050069 buf_mgr_ = BufferManager::GetInstance();
Tharaga Balachandran576571c2020-01-23 18:41:10 -050070 buf_mgr_->SetGrallocDebugProperties(properties);
Naseer Ahmede36f2242017-12-01 15:33:56 -050071}
72
73// Methods from ::android::hardware::graphics::allocator::V2_0::IAllocator follow.
74Return<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
83Return<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 Balachandran74ab1112020-01-08 17:17:56 -050088 auto err = ::vendor::qti::hardware::display::mapper::V3_0::implementation::QtiMapper::Decode(
89 descriptor, &desc);
Naseer Ahmede36f2242017-12-01 15:33:56 -050090 if (err != Error::NONE) {
Tharaga Balachandran74ab1112020-01-08 17:17:56 -050091 hidl_cb(static_cast<IMapper_3_0_Error>(err), 0, hidl_vec<hidl_handle>());
Naseer Ahmede36f2242017-12-01 15:33:56 -050092 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 Balachandran74ab1112020-01-08 17:17:56 -0500113 hidl_cb(static_cast<IMapper_3_0_Error>(err), stride, hidl_buffers);
Naseer Ahmede36f2242017-12-01 15:33:56 -0500114
115 for (const auto &b : buffers) {
116 buf_mgr_->ReleaseBuffer(PRIV_HANDLE_CONST(b.getNativeHandle()));
117 }
118
119 return Void();
120}
121
Tharaga Balachandran74ab1112020-01-08 17:17:56 -0500122} // namespace implementation
123} // namespace V3_0
124} // namespace allocator
125} // namespace display
126} // namespace hardware
127} // namespace qti
128} // namespace vendor
Naseer Ahmede36f2242017-12-01 15:33:56 -0500129
Tharaga Balachandran74ab1112020-01-08 17:17:56 -0500130namespace vendor {
131namespace qti {
132namespace hardware {
133namespace display {
134namespace allocator {
135namespace V4_0 {
136namespace implementation {
137
138using android::hardware::hidl_handle;
139using gralloc::BufferDescriptor;
140using IMapper_4_0_Error = android::hardware::graphics::mapper::V4_0::Error;
141using gralloc::Error;
142
143QtiAllocator::QtiAllocator() {
144 gralloc::GrallocProperties properties;
145 get_properties(&properties);
146 buf_mgr_ = BufferManager::GetInstance();
147 buf_mgr_->SetGrallocDebugProperties(properties);
148}
149
150Return<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 Ahmede36f2242017-12-01 15:33:56 -0500187}
188
189} // namespace implementation
Tharaga Balachandran74ab1112020-01-08 17:17:56 -0500190} // namespace V4_0
Naseer Ahmede36f2242017-12-01 15:33:56 -0500191} // namespace allocator
192} // namespace display
193} // namespace hardware
194} // namespace qti
195} // namespace vendor