blob: dc1b40cc6d313715ca43047b414f3d4906d3552f [file] [log] [blame]
Naseer Ahmede36f2242017-12-01 15:33:56 -05001/*
Ashish Kumarf04c3de2018-08-01 14:45:14 +05302 * Copyright (c) 2018-2019 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 ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
31#define DEBUG 0
32#include "QtiMapper.h"
33#include <cutils/trace.h>
34#include <qdMetaData.h>
35#include <sync/sync.h>
36#include "gr_utils.h"
37
38namespace vendor {
39namespace qti {
40namespace hardware {
41namespace display {
42namespace mapper {
Naseer Ahmede36f2242017-12-01 15:33:56 -050043namespace implementation {
44
45using gralloc::BufferInfo;
46
47QtiMapper::QtiMapper() {
48 buf_mgr_ = BufferManager::GetInstance();
49 ALOGD_IF(DEBUG, "Created QtiMapper instance");
50}
51
Naseer Ahmed920d71b2018-03-08 16:54:28 -050052bool QtiMapper::ValidDescriptor(const BufferDescriptorInfo_2_1 &bd) {
Naseer Ahmede36f2242017-12-01 15:33:56 -050053 if (bd.width == 0 || bd.height == 0 || (static_cast<int32_t>(bd.format) <= 0) ||
Ramakant Singh8f929ff2018-04-26 19:53:50 +053054 bd.layerCount <= 0) {
Naseer Ahmede36f2242017-12-01 15:33:56 -050055 return false;
56 }
57
58 return true;
59}
60
Naseer Ahmed920d71b2018-03-08 16:54:28 -050061Error QtiMapper::CreateDescriptor(const BufferDescriptorInfo_2_1& descriptor_info,
62 IMapperBufferDescriptor *descriptor) {
Naseer Ahmede36f2242017-12-01 15:33:56 -050063 ALOGD_IF(DEBUG,
64 "BufferDescriptorInfo: wxh: %dx%d usage: 0x%" PRIu64 " format: %d layer_count: %d",
65 descriptor_info.width, descriptor_info.height, descriptor_info.usage,
66 static_cast<uint32_t>(descriptor_info.format), descriptor_info.layerCount);
67
68 if (ValidDescriptor(descriptor_info)) {
69 auto vec = gralloc::BufferDescriptor::Encode(descriptor_info);
Naseer Ahmed920d71b2018-03-08 16:54:28 -050070 *descriptor = vec;
71 return Error::NONE;
Naseer Ahmede36f2242017-12-01 15:33:56 -050072 } else {
Naseer Ahmed920d71b2018-03-08 16:54:28 -050073 return Error::BAD_VALUE;
Naseer Ahmede36f2242017-12-01 15:33:56 -050074 }
Naseer Ahmed920d71b2018-03-08 16:54:28 -050075}
76
77// Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
78Return<void> QtiMapper::createDescriptor(const BufferDescriptorInfo_2_0 &descriptor_info,
79 createDescriptor_cb hidl_cb) {
80 IMapperBufferDescriptor descriptor;
81 auto info_2_1 = BufferDescriptorInfo_2_1 {
82 descriptor_info.width,
83 descriptor_info.height,
84 descriptor_info.layerCount,
85 static_cast<PixelFormat>(descriptor_info.format),
86 descriptor_info.usage,
87 };
88 auto err = CreateDescriptor(info_2_1, &descriptor);
89 hidl_cb(err, descriptor);
Naseer Ahmede36f2242017-12-01 15:33:56 -050090 return Void();
91}
92
93Return<void> QtiMapper::importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) {
94 if (!raw_handle.getNativeHandle()) {
95 ALOGE("%s: Unable to import handle", __FUNCTION__);
96 hidl_cb(Error::BAD_BUFFER, nullptr);
97 return Void();
98 }
99
100 native_handle_t *buffer_handle = native_handle_clone(raw_handle.getNativeHandle());
101 if (!buffer_handle) {
102 ALOGE("%s: Unable to clone handle", __FUNCTION__);
103 hidl_cb(Error::NO_RESOURCES, nullptr);
104 return Void();
105 }
106
107 auto error = buf_mgr_->RetainBuffer(PRIV_HANDLE_CONST(buffer_handle));
108 if (error != Error::NONE) {
109 ALOGE("%s: Unable to retain handle: %p", __FUNCTION__, buffer_handle);
110 native_handle_close(buffer_handle);
111 native_handle_delete(buffer_handle);
112
113 hidl_cb(error, nullptr);
114 return Void();
115 }
116 ALOGD_IF(DEBUG, "Imported handle: %p id: %" PRIu64, buffer_handle,
117 PRIV_HANDLE_CONST(buffer_handle)->id);
118 hidl_cb(Error::NONE, buffer_handle);
119 return Void();
120}
121
122Return<Error> QtiMapper::freeBuffer(void *buffer) {
123 if (!buffer) {
124 return Error::BAD_BUFFER;
125 }
126 return buf_mgr_->ReleaseBuffer(PRIV_HANDLE_CONST(buffer));
127}
128
129bool QtiMapper::GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd) {
130 auto handle = fence_handle.getNativeHandle();
131 if (handle && handle->numFds > 1) {
132 ALOGE("invalid fence handle with %d fds", handle->numFds);
133 return false;
134 }
135
136 *outFenceFd = (handle && handle->numFds == 1) ? handle->data[0] : -1;
137 return true;
138}
139
140void QtiMapper::WaitFenceFd(int fence_fd) {
141 if (fence_fd < 0) {
142 return;
143 }
144
145 const int timeout = 3000;
146 ATRACE_BEGIN("fence wait");
147 const int error = sync_wait(fence_fd, timeout);
148 ATRACE_END();
149 if (error < 0) {
150 ALOGE("QtiMapper: lock fence %d didn't signal in %u ms - error: %s", fence_fd, timeout,
151 strerror(errno));
152 }
153}
154
155Error QtiMapper::LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence) {
156 if (!buffer) {
157 return Error::BAD_BUFFER;
158 }
159
160 int fence_fd;
161 if (!GetFenceFd(acquire_fence, &fence_fd)) {
162 return Error::BAD_VALUE;
163 }
164
165 if (fence_fd > 0) {
166 WaitFenceFd(fence_fd);
167 }
168
169 auto hnd = PRIV_HANDLE_CONST(buffer);
170
171 return buf_mgr_->LockBuffer(hnd, usage);
172}
173
174Return<void> QtiMapper::lock(void *buffer, uint64_t cpu_usage,
175 const IMapper::Rect & /*access_region*/,
176 const hidl_handle &acquire_fence, lock_cb hidl_cb) {
177 auto err = LockBuffer(buffer, cpu_usage, acquire_fence);
178 if (err != Error::NONE) {
179 hidl_cb(err, nullptr);
180 return Void();
181 }
182
183 auto hnd = PRIV_HANDLE_CONST(buffer);
184 auto *out_data = reinterpret_cast<void *>(hnd->base);
185 hidl_cb(Error::NONE, out_data);
186 return Void();
187}
188
189Return<void> QtiMapper::lockYCbCr(void *buffer, uint64_t cpu_usage,
190 const IMapper::Rect & /*access_region*/,
191 const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) {
192 YCbCrLayout layout = {};
193 auto err = LockBuffer(buffer, cpu_usage, acquire_fence);
194 if (err != Error::NONE) {
195 hidl_cb(err, layout);
196 return Void();
197 }
198
199 auto hnd = PRIV_HANDLE_CONST(buffer);
200 android_ycbcr yuv_plane_info[2];
201 if (gralloc::GetYUVPlaneInfo(hnd, yuv_plane_info) != 0) {
202 hidl_cb(Error::BAD_VALUE, layout);
203 }
204 layout.y = yuv_plane_info[0].y;
205 layout.cr = yuv_plane_info[0].cr;
206 layout.cb = yuv_plane_info[0].cb;
207 layout.yStride = static_cast<uint32_t>(yuv_plane_info[0].ystride);
208 layout.cStride = static_cast<uint32_t>(yuv_plane_info[0].cstride);
209 layout.chromaStep = static_cast<uint32_t>(yuv_plane_info[0].chroma_step);
210 hidl_cb(Error::NONE, layout);
211 return Void();
212}
213
214Return<void> QtiMapper::unlock(void *buffer, unlock_cb hidl_cb) {
215 auto err = Error::BAD_BUFFER;
216 if (buffer != nullptr) {
217 err = buf_mgr_->UnlockBuffer(PRIV_HANDLE_CONST(buffer));
218 }
219 // We don't have a release fence
220 hidl_cb(err, hidl_handle(nullptr));
221 return Void();
222}
223
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500224Return<Error> QtiMapper::validateBufferSize(void* buffer,
225 const BufferDescriptorInfo_2_1& descriptor_info,
226 uint32_t /*stride*/) {
227 auto err = Error::BAD_BUFFER;
228 auto hnd = static_cast<private_handle_t *>(buffer);
229 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
230 if (buf_mgr_->IsBufferImported(hnd) != Error::NONE) {
231 return Error::BAD_BUFFER;
232 }
233 auto info = gralloc::BufferInfo(descriptor_info.width, descriptor_info.height,
234 static_cast<uint32_t>(descriptor_info.format),
235 static_cast<uint64_t>(descriptor_info.usage));
236 info.layer_count = descriptor_info.layerCount;
237 err = buf_mgr_->ValidateBufferSize(hnd, info);
238 }
239 return err;
240}
241
242Return<void> QtiMapper::getTransportSize(void *buffer,
243 IMapper_2_1::getTransportSize_cb hidl_cb) {
244 auto err = Error::BAD_BUFFER;
245 auto hnd = static_cast<private_handle_t *>(buffer);
246 uint32_t num_fds = 0, num_ints = 0;
247 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
248 num_fds = 2;
249 // TODO(user): reduce to transported values;
250 num_ints = static_cast<uint32_t >(hnd->numInts);
251 err = Error::NONE;
252 }
253 ALOGD_IF(DEBUG, "GetTransportSize: num fds: %d num ints: %d err:%d", num_fds, num_ints, err);
254 hidl_cb(err, num_fds, num_ints);
255 return Void();
256}
257
258Return<void> QtiMapper::createDescriptor_2_1(const BufferDescriptorInfo_2_1& descriptor_info,
259 IMapper_2_1::createDescriptor_2_1_cb hidl_cb) {
260 IMapperBufferDescriptor descriptor;
261 auto err = CreateDescriptor(descriptor_info, &descriptor);
262 hidl_cb(err, descriptor);
263 return Void();
264}
265
Naseer Ahmede36f2242017-12-01 15:33:56 -0500266Return<void> QtiMapper::getMapSecureBufferFlag(void *buffer, getMapSecureBufferFlag_cb hidl_cb) {
267 auto err = Error::BAD_BUFFER;
268 auto hnd = static_cast<private_handle_t *>(buffer);
269 int *map_secure_buffer = 0;
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500270 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
Naseer Ahmede36f2242017-12-01 15:33:56 -0500271 if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) {
272 *map_secure_buffer = 0;
273 } else {
274 err = Error::NONE;
275 }
276 }
277 hidl_cb(err, *map_secure_buffer != 0);
278 return Void();
279}
280
281Return<void> QtiMapper::getInterlacedFlag(void *buffer, getInterlacedFlag_cb hidl_cb) {
282 auto err = Error::BAD_BUFFER;
283 auto hnd = static_cast<private_handle_t *>(buffer);
284 int *interlaced_flag = nullptr;
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500285 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
Naseer Ahmede36f2242017-12-01 15:33:56 -0500286 if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, interlaced_flag) != 0) {
287 *interlaced_flag = 0;
288 } else {
289 err = Error::NONE;
290 }
291 }
292 hidl_cb(err, *interlaced_flag != 0);
293 return Void();
294}
295
296Return<void> QtiMapper::getCustomDimensions(void *buffer, getCustomDimensions_cb hidl_cb) {
297 auto err = Error::BAD_BUFFER;
298 auto hnd = static_cast<private_handle_t *>(buffer);
299 int stride = 0;
300 int height = 0;
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500301 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
Naseer Ahmede36f2242017-12-01 15:33:56 -0500302 stride = hnd->width;
303 height = hnd->height;
304 gralloc::GetCustomDimensions(hnd, &stride, &height);
305 err = Error::NONE;
306 }
307 hidl_cb(err, stride, height);
308 return Void();
309}
310
311Return<void> QtiMapper::getRgbDataAddress(void *buffer, getRgbDataAddress_cb hidl_cb) {
312 auto err = Error::BAD_BUFFER;
313 auto hnd = static_cast<private_handle_t *>(buffer);
314 void *rgb_data = nullptr;
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500315 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
Naseer Ahmede36f2242017-12-01 15:33:56 -0500316 if (gralloc::GetRgbDataAddress(hnd, &rgb_data) == 0) {
317 err = Error::NONE;
318 }
319 }
320 hidl_cb(err, rgb_data);
321 return Void();
322}
323
324Return<void> QtiMapper::calculateBufferAttributes(int32_t width, int32_t height, int32_t format,
325 uint64_t usage,
326 calculateBufferAttributes_cb hidl_cb) {
327 unsigned int alignedw, alignedh;
328 BufferInfo info(width, height, format, usage);
329 gralloc::GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
330 bool ubwc_enabled = gralloc::IsUBwcEnabled(format, usage);
331 hidl_cb(Error::NONE, alignedw, alignedh, ubwc_enabled);
332 return Void();
333}
334
Saurabh Dubey3bb11522018-05-24 17:10:24 +0530335Return<void> QtiMapper::getCustomFormatFlags(int32_t format, uint64_t usage,
336 getCustomFormatFlags_cb hidl_cb) {
337 uint64_t priv_flags = 0;
Saurabh Dubey48b757d2018-05-24 19:13:53 +0530338 auto err = Error::NONE;
339 int32_t custom_format = format;
340 if (gralloc::GetCustomFormatFlags(format, usage, &custom_format, &priv_flags) != 0) {
341 err = Error::UNSUPPORTED;
342 }
343 hidl_cb(err, custom_format, priv_flags);
Saurabh Dubey3bb11522018-05-24 17:10:24 +0530344 return Void();
345}
346
Naseer Ahmede36f2242017-12-01 15:33:56 -0500347Return<void> QtiMapper::getColorSpace(void *buffer, getColorSpace_cb hidl_cb) {
348 auto err = Error::BAD_BUFFER;
349 auto hnd = static_cast<private_handle_t *>(buffer);
350 int color_space = 0;
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500351 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
Naseer Ahmede36f2242017-12-01 15:33:56 -0500352 gralloc::GetColorSpaceFromMetadata(hnd, &color_space);
353 err = Error::NONE;
354 }
355 hidl_cb(err, color_space);
356 return Void();
357}
358
359Return<void> QtiMapper::getYuvPlaneInfo(void *buffer, getYuvPlaneInfo_cb hidl_cb) {
360 auto err = Error::BAD_BUFFER;
361 auto hnd = static_cast<private_handle_t *>(buffer);
362 hidl_vec<YCbCrLayout> layout;
363 layout.resize(2);
364 android_ycbcr yuv_plane_info[2];
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500365 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
Naseer Ahmede36f2242017-12-01 15:33:56 -0500366 if (gralloc::GetYUVPlaneInfo(hnd, yuv_plane_info) == 0) {
367 err = Error::NONE;
368 for (int i=0; i < 2; i++) {
369 layout[i].y = yuv_plane_info[i].y;
370 layout[i].cr = yuv_plane_info[i].cr;
371 layout[i].cb = yuv_plane_info[i].cb;
372 layout[i].yStride = static_cast<uint32_t>(yuv_plane_info[i].ystride);
373 layout[i].cStride = static_cast<uint32_t>(yuv_plane_info[i].cstride);
374 layout[i].chromaStep = static_cast<uint32_t>(yuv_plane_info[i].chroma_step);
375 }
376 }
377 }
378 hidl_cb(err, layout);
379 return Void();
380}
381
382Return<Error> QtiMapper::setSingleBufferMode(void *buffer, bool enable) {
383 auto err = Error::BAD_BUFFER;
384 auto hnd = static_cast<private_handle_t *>(buffer);
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500385 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
Naseer Ahmede36f2242017-12-01 15:33:56 -0500386 if (setMetaData(hnd, SET_SINGLE_BUFFER_MODE, &enable) != 0) {
387 err = Error::UNSUPPORTED;
388 } else {
389 err = Error::NONE;
390 }
391 }
392 return err;
393}
394
Ashish Kumar28fa16f2019-02-22 05:24:02 +0530395#ifdef QTI_MAPPER_1_1
396Return<void> QtiMapper::getFd(void *buffer, getFd_cb hidl_cb) {
397 auto err = Error::BAD_BUFFER;
398 int fd = 0;
399 auto hnd = static_cast<private_handle_t *>(buffer);
400 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
401 err = Error::NONE;
402 fd = hnd->fd;
403 }
404 hidl_cb(err, fd);
405 return Void();
406}
407
408Return<void> QtiMapper::getWidth(void *buffer, getWidth_cb hidl_cb) {
409 auto err = Error::BAD_BUFFER;
410 int width = 0;
411 auto hnd = static_cast<private_handle_t *>(buffer);
412 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
413 err = Error::NONE;
414 width = hnd->width;
415 }
416 hidl_cb(err, width);
417 return Void();
418}
419
420Return<void> QtiMapper::getHeight(void *buffer, getHeight_cb hidl_cb) {
421 auto err = Error::BAD_BUFFER;
422 int height = 0;
423 auto hnd = static_cast<private_handle_t *>(buffer);
424 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
425 err = Error::NONE;
426 height = hnd->height;
427 }
428 hidl_cb(err, height);
429 return Void();
430}
431
432Return<void> QtiMapper::getFormat(void *buffer, getFormat_cb hidl_cb) {
433 auto err = Error::BAD_BUFFER;
434 int format = 0;
435 auto hnd = static_cast<private_handle_t *>(buffer);
436 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
437 err = Error::NONE;
438 format = hnd->format;
439 }
440 hidl_cb(err, format);
441 return Void();
442}
443
444Return<void> QtiMapper::getPrivateFlags(void *buffer, getPrivateFlags_cb hidl_cb) {
445 auto err = Error::BAD_BUFFER;
446 int flags = 0;
447 auto hnd = static_cast<private_handle_t *>(buffer);
448 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
449 err = Error::NONE;
450 flags = hnd->flags;
451 }
452 hidl_cb(err, flags);
453 return Void();
454}
455
456Return<void> QtiMapper::getUnalignedWidth(void *buffer, getUnalignedWidth_cb hidl_cb) {
457 auto err = Error::BAD_BUFFER;
458 int unaligned_width = 0;
459 auto hnd = static_cast<private_handle_t *>(buffer);
460 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
461 err = Error::NONE;
462 unaligned_width = hnd->unaligned_width;
463 }
464 hidl_cb(err, unaligned_width);
465 return Void();
466}
467
468Return<void> QtiMapper::getUnalignedHeight(void *buffer, getUnalignedHeight_cb hidl_cb) {
469 auto err = Error::BAD_BUFFER;
470 int unaligned_height = 0;
471 auto hnd = static_cast<private_handle_t *>(buffer);
472 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
473 err = Error::NONE;
474 unaligned_height = hnd->unaligned_height;
475 }
476 hidl_cb(err, unaligned_height);
477 return Void();
478}
479
480Return<void> QtiMapper::getLayerCount(void *buffer, getLayerCount_cb hidl_cb) {
481 auto err = Error::BAD_BUFFER;
482 unsigned int layer_count = 0;
483 auto hnd = static_cast<private_handle_t *>(buffer);
484 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
485 err = Error::NONE;
486 layer_count = hnd->layer_count;
487 }
488 hidl_cb(err, layer_count);
489 return Void();
490}
491
492Return<void> QtiMapper::getId(void *buffer, getId_cb hidl_cb) {
493 auto err = Error::BAD_BUFFER;
494 uint64_t id = 0;
495 auto hnd = static_cast<private_handle_t *>(buffer);
496 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
497 err = Error::NONE;
498 id = hnd->id;
499 }
500 hidl_cb(err, id);
501 return Void();
502}
503
504Return<void> QtiMapper::getUsageFlags(void *buffer, getUsageFlags_cb hidl_cb) {
505 auto err = Error::BAD_BUFFER;
506 uint64_t usage = 0;
507 auto hnd = static_cast<private_handle_t *>(buffer);
508 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
509 err = Error::NONE;
510 usage = hnd->usage;
511 }
512 hidl_cb(err, usage);
513 return Void();
514}
515
516Return<void> QtiMapper::getSize(void *buffer, getSize_cb hidl_cb) {
517 auto err = Error::BAD_BUFFER;
518 unsigned int size = 0;
519 auto hnd = static_cast<private_handle_t *>(buffer);
520 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
521 err = Error::NONE;
522 size = hnd->size;
523 }
524 hidl_cb(err, size);
525 return Void();
526}
527
528Return<void> QtiMapper::getOffset(void *buffer, getOffset_cb hidl_cb) {
529 auto err = Error::BAD_BUFFER;
530 unsigned int offset = 0;
531 auto hnd = static_cast<private_handle_t *>(buffer);
532 if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
533 err = Error::NONE;
534 offset = hnd->offset;
535 }
536 hidl_cb(err, offset);
537 return Void();
538}
539#endif
540
Naseer Ahmede36f2242017-12-01 15:33:56 -0500541// Methods from ::android::hidl::base::V1_0::IBase follow.
542
543// When we are in passthrough mode, this method is used
544// by hidl to obtain the SP HAL object
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500545IMapper_2_1 *HIDL_FETCH_IMapper(const char * /* name */) {
Naseer Ahmede36f2242017-12-01 15:33:56 -0500546 ALOGD_IF(DEBUG, "Fetching IMapper from QtiMapper");
547 auto mapper = new QtiMapper();
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500548 return static_cast<IMapper_2_1 *>(mapper);
Naseer Ahmede36f2242017-12-01 15:33:56 -0500549}
550
Ashish Kumarf04c3de2018-08-01 14:45:14 +0530551IQtiMapper *HIDL_FETCH_IQtiMapper(const char * /* name */) {
552 ALOGD_IF(DEBUG, "Fetching QtiMapper");
553 return new QtiMapper();
554}
555
Naseer Ahmede36f2242017-12-01 15:33:56 -0500556} // namespace implementation
Naseer Ahmede36f2242017-12-01 15:33:56 -0500557} // namespace mapper
558} // namespace display
559} // namespace hardware
560} // namespace qti
561} // namespace vendor