1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <android/hardware/graphics/mapper/2.1/IMapper.h>
20 #include <mapper-vts/2.0/MapperVts.h>
21 
22 namespace android {
23 namespace hardware {
24 namespace graphics {
25 namespace mapper {
26 namespace V2_1 {
27 namespace vts {
28 
29 using android::hardware::graphics::allocator::V2_0::IAllocator;
30 using V2_0::BufferDescriptor;
31 
32 // A wrapper to IAllocator and IMapper.
33 class Gralloc : public V2_0::vts::Gralloc {
34    public:
35      Gralloc(bool errOnFailure = true);
36      Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName,
37              bool errOnFailure = true);
38 
39      sp<IMapper> getMapper() const;
40 
41      bool validateBufferSize(const native_handle_t* bufferHandle,
42                              const IMapper::BufferDescriptorInfo& descriptorInfo, uint32_t stride);
43      void getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds,
44                            uint32_t* outNumInts);
45 
46      BufferDescriptor createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo);
47 
48      const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
49                                      bool import = true, uint32_t* outStride = nullptr);
50 
51    protected:
52      void init(bool errOnFailure = true);
53 
54      sp<IMapper> mMapperV2_1;
55 };
56 
57 }  // namespace vts
58 }  // namespace V2_1
59 }  // namespace mapper
60 }  // namespace graphics
61 }  // namespace hardware
62 }  // namespace android
63