blob: 0c191f5a80922dcf160011fc9cf94bb84e0f885d [file] [log] [blame]
Naseer Ahmede36f2242017-12-01 15:33:56 -05001/*
Tharaga Balachandran74ab1112020-01-08 17:17:56 -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#ifndef __QTIMAPPER_H__
31#define __QTIMAPPER_H__
32
33#include <hidl/MQDescriptor.h>
34#include <hidl/Status.h>
Tharaga Balachandranab150ab2019-09-26 19:17:58 -040035#include <vendor/qti/hardware/display/mapper/3.0/IQtiMapper.h>
Naseer Ahmede36f2242017-12-01 15:33:56 -050036
Tharaga Balachandranf7e62a32019-06-06 11:33:29 -040037#include "QtiMapperExtensions.h"
Naseer Ahmede36f2242017-12-01 15:33:56 -050038#include "gr_buf_mgr.h"
Tharaga Balachandran74ab1112020-01-08 17:17:56 -050039#include "gr_utils.h"
40
Naseer Ahmede36f2242017-12-01 15:33:56 -050041namespace vendor {
42namespace qti {
43namespace hardware {
44namespace display {
45namespace mapper {
Tharaga Balachandran74ab1112020-01-08 17:17:56 -050046namespace V3_0 {
Naseer Ahmede36f2242017-12-01 15:33:56 -050047namespace implementation {
48
Tharaga Balachandranf7e62a32019-06-06 11:33:29 -040049using ::android::sp;
Naseer Ahmede36f2242017-12-01 15:33:56 -050050using ::android::hardware::hidl_array;
51using ::android::hardware::hidl_handle;
52using ::android::hardware::hidl_memory;
53using ::android::hardware::hidl_string;
54using ::android::hardware::hidl_vec;
Tharaga Balachandranf7e62a32019-06-06 11:33:29 -040055using ::android::hardware::Return;
56using ::android::hardware::Void;
Tharaga Balachandranab150ab2019-09-26 19:17:58 -040057using ::android::hardware::graphics::common::V1_2::PixelFormat;
58using ::android::hardware::graphics::mapper::V3_0::Error;
59using ::android::hardware::graphics::mapper::V3_0::IMapper;
60using ::android::hardware::graphics::mapper::V3_0::YCbCrLayout;
Naseer Ahmede36f2242017-12-01 15:33:56 -050061using ::android::hidl::base::V1_0::DebugInfo;
62using ::android::hidl::base::V1_0::IBase;
Naseer Ahmede36f2242017-12-01 15:33:56 -050063using gralloc::BufferManager;
Ashish Kumar25435772019-08-06 16:15:56 +053064using ::vendor::qti::hardware::display::mapperextensions::V1_1::IQtiMapperExtensions;
65using ::vendor::qti::hardware::display::mapperextensions::V1_1::implementation::QtiMapperExtensions;
Tharaga Balachandranab150ab2019-09-26 19:17:58 -040066using ::vendor::qti::hardware::display::mapper::V3_0::IQtiMapper;
Naseer Ahmede36f2242017-12-01 15:33:56 -050067
Tharaga Balachandranab150ab2019-09-26 19:17:58 -040068using IMapper_3_0 = android::hardware::graphics::mapper::V3_0::IMapper;
69using BufferDescriptorInfo_3_0 =
70 android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo;
71using IMapperBufferDescriptor = android::hardware::graphics::mapper::V3_0::BufferDescriptor;
Tharaga Balachandran74ab1112020-01-08 17:17:56 -050072using IMapper_3_0_Error = ::android::hardware::graphics::mapper::V3_0::Error;
Naseer Ahmed920d71b2018-03-08 16:54:28 -050073
Ashish Kumarf04c3de2018-08-01 14:45:14 +053074class QtiMapper : public IQtiMapper {
Naseer Ahmede36f2242017-12-01 15:33:56 -050075 public:
76 QtiMapper();
77 // Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
Tharaga Balachandranab150ab2019-09-26 19:17:58 -040078 Return<void> createDescriptor(const BufferDescriptorInfo_3_0 &descriptor_info,
Naseer Ahmede36f2242017-12-01 15:33:56 -050079 createDescriptor_cb hidl_cb) override;
80 Return<void> importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) override;
81 Return<Error> freeBuffer(void *buffer) override;
82 Return<void> lock(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region,
83 const hidl_handle &acquire_fence, lock_cb hidl_cb) override;
84 Return<void> lockYCbCr(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region,
85 const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) override;
86 Return<void> unlock(void *buffer, unlock_cb hidl_cb) override;
Naseer Ahmed036d57d2018-03-02 15:42:45 -050087
Naseer Ahmed920d71b2018-03-08 16:54:28 -050088 // Methods from ::android::hardware::graphics::mapper::V2_1::IMapper follow.
Tharaga Balachandranab150ab2019-09-26 19:17:58 -040089 Return<Error> validateBufferSize(void *buffer, const BufferDescriptorInfo_3_0 &descriptorInfo,
Naseer Ahmed920d71b2018-03-08 16:54:28 -050090 uint32_t stride) override;
Tharaga Balachandranab150ab2019-09-26 19:17:58 -040091 Return<void> getTransportSize(void *buffer, IMapper_3_0::getTransportSize_cb hidl_cb) override;
92
93 Return<void> isSupported(const BufferDescriptorInfo_3_0 &descriptor_info,
94 IMapper_3_0::isSupported_cb hidl_cb) override;
Naseer Ahmede36f2242017-12-01 15:33:56 -050095
Tharaga Balachandranf7e62a32019-06-06 11:33:29 -040096 Return<void> getMapperExtensions(getMapperExtensions_cb hidl_cb);
Ashish Kumar25435772019-08-06 16:15:56 +053097 sp<mapperextensions::V1_1::IQtiMapperExtensions> extensions_ = nullptr;
Tharaga Balachandran74ab1112020-01-08 17:17:56 -050098 hidl_vec<uint32_t> Encode(const IMapper_3_0::BufferDescriptorInfo &bd_info) {
99 hidl_vec<uint32_t> out;
100 out.resize(gralloc::kBufferDescriptorSize);
101 out[0] = gralloc::kMagicVersion;
102 out[1] = bd_info.width;
103 out[2] = bd_info.height;
104 out[3] = bd_info.layerCount;
105 out[4] = static_cast<uint32_t>(bd_info.format);
106 out[5] = static_cast<uint32_t>(bd_info.usage);
107 out[6] = static_cast<uint32_t>(bd_info.usage >> 32);
108 return out;
109 }
110 static gralloc::Error Decode(const hidl_vec<uint32_t> &in,
111 gralloc::BufferDescriptor *buf_descriptor) {
112 if (in.size() != gralloc::kBufferDescriptorSize || in[0] != gralloc::kMagicVersion) {
113 return gralloc::Error::BAD_DESCRIPTOR;
114 }
115 int32_t width = static_cast<int32_t>(in[1]);
116 int32_t height = static_cast<int32_t>(in[2]);
117 buf_descriptor->SetDimensions(width, height);
118 uint32_t layer_count = in[3];
119 buf_descriptor->SetLayerCount(layer_count);
120 int32_t format = static_cast<int32_t>(in[4]);
121 buf_descriptor->SetColorFormat(format);
122 uint64_t usage = static_cast<uint64_t>(in[6]) << 32 | in[5];
123 buf_descriptor->SetUsage(usage);
124 return gralloc::Error::NONE;
125 }
Ashish Kumar28fa16f2019-02-22 05:24:02 +0530126
Naseer Ahmede36f2242017-12-01 15:33:56 -0500127 private:
128 BufferManager *buf_mgr_ = nullptr;
Tharaga Balachandranab150ab2019-09-26 19:17:58 -0400129 Error CreateDescriptor(const BufferDescriptorInfo_3_0 &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 Ahmede36f2242017-12-01 15:33:56 -0500137} // namespace implementation
Tharaga Balachandran74ab1112020-01-08 17:17:56 -0500138} // namespace V3_0
Naseer Ahmede36f2242017-12-01 15:33:56 -0500139} // namespace mapper
140} // namespace display
141} // namespace hardware
142} // namespace qti
143} // namespace vendor
144
145#endif // __QTIMAPPER_H__