blob: a17870c5ee170c7f936ba71cb144813b74e2856f [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#ifndef __QTIMAPPER_H__
31#define __QTIMAPPER_H__
32
33#include <hidl/MQDescriptor.h>
34#include <hidl/Status.h>
Ashish Kumar28fa16f2019-02-22 05:24:02 +053035#ifdef QTI_MAPPER_1_1
36#include <vendor/qti/hardware/display/mapper/1.1/IQtiMapper.h>
37#else
Ashish Kumarf04c3de2018-08-01 14:45:14 +053038#include <vendor/qti/hardware/display/mapper/1.0/IQtiMapper.h>
Ashish Kumar28fa16f2019-02-22 05:24:02 +053039#endif
Naseer Ahmede36f2242017-12-01 15:33:56 -050040
41#include "gr_buf_mgr.h"
42namespace vendor {
43namespace qti {
44namespace hardware {
45namespace display {
46namespace mapper {
Naseer Ahmede36f2242017-12-01 15:33:56 -050047namespace implementation {
48
49using ::android::hardware::Return;
50using ::android::hardware::Void;
Naseer Ahmede36f2242017-12-01 15:33:56 -050051using ::android::hardware::graphics::mapper::V2_0::IMapper;
Naseer Ahmed920d71b2018-03-08 16:54:28 -050052using ::android::hardware::graphics::mapper::V2_0::Error;
Naseer Ahmede36f2242017-12-01 15:33:56 -050053using ::android::hardware::graphics::mapper::V2_0::YCbCrLayout;
Naseer Ahmed920d71b2018-03-08 16:54:28 -050054using ::android::hardware::graphics::common::V1_1::PixelFormat;
Naseer Ahmede36f2242017-12-01 15:33:56 -050055using ::android::hardware::hidl_array;
56using ::android::hardware::hidl_handle;
57using ::android::hardware::hidl_memory;
58using ::android::hardware::hidl_string;
59using ::android::hardware::hidl_vec;
60using ::android::hidl::base::V1_0::DebugInfo;
61using ::android::hidl::base::V1_0::IBase;
62using ::android::sp;
Ashish Kumar28fa16f2019-02-22 05:24:02 +053063#ifdef QTI_MAPPER_1_1
64using ::vendor::qti::hardware::display::mapper::V1_1::IQtiMapper;
65#else
Ashish Kumarf04c3de2018-08-01 14:45:14 +053066using ::vendor::qti::hardware::display::mapper::V1_0::IQtiMapper;
Ashish Kumar28fa16f2019-02-22 05:24:02 +053067#endif
Naseer Ahmede36f2242017-12-01 15:33:56 -050068using gralloc::BufferManager;
69
Naseer Ahmed920d71b2018-03-08 16:54:28 -050070using IMapper_2_1 = android::hardware::graphics::mapper::V2_1::IMapper;
71using BufferDescriptorInfo_2_0 =
72android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo;
73using BufferDescriptorInfo_2_1 =
74android::hardware::graphics::mapper::V2_1::IMapper::BufferDescriptorInfo;
75using IMapperBufferDescriptor = android::hardware::graphics::mapper::V2_0::BufferDescriptor;
76
Ashish Kumarf04c3de2018-08-01 14:45:14 +053077class QtiMapper : public IQtiMapper {
Naseer Ahmede36f2242017-12-01 15:33:56 -050078 public:
79 QtiMapper();
80 // Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
Naseer Ahmed920d71b2018-03-08 16:54:28 -050081 Return<void> createDescriptor(const BufferDescriptorInfo_2_0 &descriptor_info,
Naseer Ahmede36f2242017-12-01 15:33:56 -050082 createDescriptor_cb hidl_cb) override;
83 Return<void> importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) override;
84 Return<Error> freeBuffer(void *buffer) override;
85 Return<void> lock(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region,
86 const hidl_handle &acquire_fence, lock_cb hidl_cb) override;
87 Return<void> lockYCbCr(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region,
88 const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) override;
89 Return<void> unlock(void *buffer, unlock_cb hidl_cb) override;
Naseer Ahmed036d57d2018-03-02 15:42:45 -050090
Naseer Ahmed920d71b2018-03-08 16:54:28 -050091 // Methods from ::android::hardware::graphics::mapper::V2_1::IMapper follow.
92 Return<Error> validateBufferSize(void* buffer,
93 const BufferDescriptorInfo_2_1& descriptorInfo,
94 uint32_t stride) override;
95 Return<void> getTransportSize(void* buffer, IMapper_2_1::getTransportSize_cb hidl_cb) override;
96 Return<void> createDescriptor_2_1(const BufferDescriptorInfo_2_1& descriptorInfo,
97 createDescriptor_2_1_cb _hidl_cb) override;
Naseer Ahmede36f2242017-12-01 15:33:56 -050098 Return<void> getMapSecureBufferFlag(void *buffer, getMapSecureBufferFlag_cb _hidl_cb) override;
99 Return<void> getInterlacedFlag(void *buffer, getInterlacedFlag_cb _hidl_cb) override;
100 Return<void> getCustomDimensions(void *buffer, getCustomDimensions_cb _hidl_cb) override;
101 Return<void> getRgbDataAddress(void *buffer, getRgbDataAddress_cb _hidl_cb) override;
102 Return<void> calculateBufferAttributes(int32_t width, int32_t height, int32_t format,
103 uint64_t usage,
104 calculateBufferAttributes_cb _hidl_cb) override;
Saurabh Dubey3bb11522018-05-24 17:10:24 +0530105 Return<void> getCustomFormatFlags(int32_t format, uint64_t usage,
106 getCustomFormatFlags_cb _hidl_cb) override;
Naseer Ahmede36f2242017-12-01 15:33:56 -0500107 Return<void> getColorSpace(void *buffer, getColorSpace_cb _hidl_cb) override;
108 Return<void> getYuvPlaneInfo(void *buffer, getYuvPlaneInfo_cb _hidl_cb) override;
109 Return<Error> setSingleBufferMode(void *buffer, bool enable) override;
110
Ashish Kumar28fa16f2019-02-22 05:24:02 +0530111#ifdef QTI_MAPPER_1_1
112 // Getters for fields present in private handle structure.
113 Return<void> getFd(void *buffer, getFd_cb _hidl_cb) override;
114 Return<void> getWidth(void *buffer, getWidth_cb _hidl_cb) override;
115 Return<void> getHeight(void *buffer, getHeight_cb _hidl_cb) override;
116 Return<void> getOffset(void *buffer, getOffset_cb _hidl_cb) override;
117 Return<void> getSize(void *buffer, getSize_cb _hidl_cb) override;
118 Return<void> getFormat(void *buffer, getFormat_cb _hidl_cb) override;
119 Return<void> getPrivateFlags(void *buffer, getPrivateFlags_cb _hidl_cb) override;
120 Return<void> getUnalignedWidth(void *buffer, getUnalignedWidth_cb _hidl_cb) override;
121 Return<void> getUnalignedHeight(void *buffer, getUnalignedHeight_cb _hidl_cb) override;
122 Return<void> getLayerCount(void *buffer, getLayerCount_cb _hidl_cb) override;
123 Return<void> getId(void *buffer, getId_cb _hidl_cb) override;
124 Return<void> getUsageFlags(void *buffer, getUsageFlags_cb _hidl_cb) override;
125#endif
126
Naseer Ahmede36f2242017-12-01 15:33:56 -0500127 private:
128 BufferManager *buf_mgr_ = nullptr;
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500129 Error CreateDescriptor(const BufferDescriptorInfo_2_1& descriptor_info,
130 IMapperBufferDescriptor * descriptor);
Naseer Ahmede36f2242017-12-01 15:33:56 -0500131 bool ValidDescriptor(const IMapper::BufferDescriptorInfo &bd);
132 bool GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd);
133 void WaitFenceFd(int fence_fd);
134 Error LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence);
135};
136
Naseer Ahmed920d71b2018-03-08 16:54:28 -0500137extern "C" IMapper_2_1 *HIDL_FETCH_IMapper(const char *name);
Ashish Kumarf04c3de2018-08-01 14:45:14 +0530138extern "C" IQtiMapper *HIDL_FETCH_IQtiMapper(const char *name);
139
Naseer Ahmede36f2242017-12-01 15:33:56 -0500140} // namespace implementation
Naseer Ahmede36f2242017-12-01 15:33:56 -0500141} // namespace mapper
142} // namespace display
143} // namespace hardware
144} // namespace qti
145} // namespace vendor
146
147#endif // __QTIMAPPER_H__