• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 The Android Open Source Project
3  * * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <mapper-hal/2.1/MapperHal.h>
19 #include <mapper-passthrough/2.0/Gralloc0Hal.h>
20 
21 namespace android {
22 namespace hardware {
23 namespace graphics {
24 namespace mapper {
25 namespace V2_1 {
26 namespace passthrough {
27 
28 namespace detail {
29 
30 using V2_0::BufferDescriptor;
31 using V2_0::Error;
32 
33 // Gralloc0HalImpl implements V2_*::hal::MapperHal on top of gralloc0
34 template <typename Hal>
35 class Gralloc0HalImpl : public V2_0::passthrough::detail::Gralloc0HalImpl<Hal> {
36    public:
validateBufferSize(const native_handle_t * bufferHandle,const IMapper::BufferDescriptorInfo & descriptorInfo,uint32_t stride)37      Error validateBufferSize(const native_handle_t* bufferHandle,
38                               const IMapper::BufferDescriptorInfo& descriptorInfo,
39                               uint32_t stride) override {
40          if (!mModule->validateBufferSize) {
41              return Error::NONE;
42          }
43 
44          int32_t ret = mModule->validateBufferSize(
45                  mModule, bufferHandle, descriptorInfo.width, descriptorInfo.height,
46                  static_cast<int32_t>(descriptorInfo.format),
47                  static_cast<uint64_t>(descriptorInfo.usage), stride);
48          return static_cast<Error>(ret);
49      }
getTransportSize(const native_handle_t * bufferHandle,uint32_t * outNumFds,uint32_t * outNumInts)50      Error getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds,
51                             uint32_t* outNumInts) override {
52          if (!mModule->getTransportSize) {
53              *outNumFds = bufferHandle->numFds;
54              *outNumInts = bufferHandle->numInts;
55              return Error::NONE;
56          }
57 
58          int32_t ret = mModule->getTransportSize(mModule, bufferHandle, outNumFds, outNumInts);
59          return static_cast<Error>(ret);
60     }
61 
createDescriptor_2_1(const IMapper::BufferDescriptorInfo & descriptorInfo,BufferDescriptor * outDescriptor)62     Error createDescriptor_2_1(const IMapper::BufferDescriptorInfo& descriptorInfo,
63                                BufferDescriptor* outDescriptor) override {
64         return createDescriptor(
65                 V2_0::IMapper::BufferDescriptorInfo{
66                         descriptorInfo.width,
67                         descriptorInfo.height,
68                         descriptorInfo.layerCount,
69                         static_cast<common::V1_0::PixelFormat>(descriptorInfo.format),
70                         descriptorInfo.usage,
71                 },
72                 outDescriptor);
73     }
74 
75    private:
76     using BaseType2_0 = V2_0::passthrough::detail::Gralloc0HalImpl<Hal>;
77     using BaseType2_0::createDescriptor;
78     using BaseType2_0::mModule;
79 };
80 
81 }  // namespace detail
82 
83 using Gralloc0Hal = detail::Gralloc0HalImpl<hal::MapperHal>;
84 
85 }  // namespace passthrough
86 }  // namespace V2_1
87 }  // namespace mapper
88 }  // namespace graphics
89 }  // namespace hardware
90 }  // namespace android
91