blob: 509cb6e0547fe42e33677fe36d08ca45da0bc4a3 [file] [log] [blame]
Chia-I Wu9ba189d2016-09-22 17:13:08 +08001/*
2 * Copyright 2016 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#ifndef ANDROID_UI_GRALLOC_MAPPER_H
18#define ANDROID_UI_GRALLOC_MAPPER_H
19
20#include <memory>
21
22#include <android/hardware/graphics/mapper/2.0/IMapper.h>
23#include <system/window.h>
24
25namespace android {
26
27namespace Gralloc2 {
28
29using hardware::graphics::allocator::V2_0::Error;
Chia-I Wu9ba189d2016-09-22 17:13:08 +080030using hardware::graphics::allocator::V2_0::ProducerUsage;
31using hardware::graphics::allocator::V2_0::ConsumerUsage;
Chia-I Wu5901fda2016-11-17 10:26:37 +080032using hardware::graphics::common::V1_0::PixelFormat;
Chia-I Wu9ba189d2016-09-22 17:13:08 +080033using hardware::graphics::mapper::V2_0::FlexLayout;
34using hardware::graphics::mapper::V2_0::BackingStore;
35using hardware::graphics::mapper::V2_0::Device;
36using hardware::graphics::mapper::V2_0::IMapper;
37
38// Mapper is a wrapper to IMapper, a client-side graphics buffer mapper.
39class Mapper {
40public:
41 Mapper();
42 ~Mapper();
43
44 // this will be removed and Mapper will be always valid
45 bool valid() const { return (mMapper != nullptr); }
46
47 Error retain(buffer_handle_t handle) const
48 {
49 return mMapper->retain(mDevice, handle);
50 }
51
52 void release(buffer_handle_t handle) const;
53
54 Error getDimensions(buffer_handle_t handle,
Chia-I Wu67e376d2016-12-19 11:36:22 +080055 uint32_t* outWidth, uint32_t* outHeight) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +080056 {
Chia-I Wu67e376d2016-12-19 11:36:22 +080057 return mMapper->getDimensions(mDevice, handle, outWidth, outHeight);
Chia-I Wu9ba189d2016-09-22 17:13:08 +080058 }
59
60 Error getFormat(buffer_handle_t handle,
Chia-I Wu67e376d2016-12-19 11:36:22 +080061 PixelFormat* outFormat) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +080062 {
Chia-I Wu67e376d2016-12-19 11:36:22 +080063 return mMapper->getFormat(mDevice, handle, outFormat);
Chia-I Wu9ba189d2016-09-22 17:13:08 +080064 }
65
Chia-I Wu67e376d2016-12-19 11:36:22 +080066 Error getLayerCount(buffer_handle_t handle, uint32_t* outLayerCount) const
Craig Donner6ebc46a2016-10-21 15:23:44 -070067 {
Chia-I Wu67e376d2016-12-19 11:36:22 +080068 return mMapper->getLayerCount(mDevice, handle, outLayerCount);
Craig Donner6ebc46a2016-10-21 15:23:44 -070069 }
70
Chia-I Wu9ba189d2016-09-22 17:13:08 +080071 Error getProducerUsageMask(buffer_handle_t handle,
Chia-I Wu67e376d2016-12-19 11:36:22 +080072 uint64_t* outUsageMask) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +080073 {
Chia-I Wu67e376d2016-12-19 11:36:22 +080074 return mMapper->getProducerUsageMask(mDevice, handle, outUsageMask);
Chia-I Wu9ba189d2016-09-22 17:13:08 +080075 }
76
77 Error getConsumerUsageMask(buffer_handle_t handle,
Chia-I Wu67e376d2016-12-19 11:36:22 +080078 uint64_t* outUsageMask) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +080079 {
Chia-I Wu67e376d2016-12-19 11:36:22 +080080 return mMapper->getConsumerUsageMask(mDevice, handle, outUsageMask);
Chia-I Wu9ba189d2016-09-22 17:13:08 +080081 }
82
83 Error getBackingStore(buffer_handle_t handle,
Chia-I Wu67e376d2016-12-19 11:36:22 +080084 BackingStore* outStore) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +080085 {
Chia-I Wu67e376d2016-12-19 11:36:22 +080086 return mMapper->getBackingStore(mDevice, handle, outStore);
Chia-I Wu9ba189d2016-09-22 17:13:08 +080087 }
88
Chia-I Wu67e376d2016-12-19 11:36:22 +080089 Error getStride(buffer_handle_t handle, uint32_t* outStride) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +080090 {
Chia-I Wu67e376d2016-12-19 11:36:22 +080091 return mMapper->getStride(mDevice, handle, outStride);
Chia-I Wu9ba189d2016-09-22 17:13:08 +080092 }
93
Chia-I Wu67e376d2016-12-19 11:36:22 +080094 Error getNumFlexPlanes(buffer_handle_t handle,
95 uint32_t* outNumPlanes) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +080096 {
Chia-I Wu67e376d2016-12-19 11:36:22 +080097 return mMapper->getNumFlexPlanes(mDevice, handle, outNumPlanes);
Chia-I Wu9ba189d2016-09-22 17:13:08 +080098 }
99
100 Error lock(buffer_handle_t handle,
101 uint64_t producerUsageMask,
102 uint64_t consumerUsageMask,
103 const Device::Rect& accessRegion,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800104 int acquireFence, void** outData) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +0800105 {
106 return mMapper->lock(mDevice, handle,
107 producerUsageMask, consumerUsageMask,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800108 &accessRegion, acquireFence, outData);
Chia-I Wu9ba189d2016-09-22 17:13:08 +0800109 }
110
111 Error lock(buffer_handle_t handle,
112 uint64_t producerUsageMask,
113 uint64_t consumerUsageMask,
114 const Device::Rect& accessRegion,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800115 int acquireFence, FlexLayout* outFlexLayout) const
Chia-I Wu9ba189d2016-09-22 17:13:08 +0800116 {
117 return mMapper->lockFlex(mDevice, handle,
118 producerUsageMask, consumerUsageMask,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800119 &accessRegion, acquireFence, outFlexLayout);
Chia-I Wu9ba189d2016-09-22 17:13:08 +0800120 }
121
122 int unlock(buffer_handle_t handle) const;
123
124private:
125 const IMapper* mMapper;
126 Device* mDevice;
127};
128
129} // namespace Gralloc2
130
131} // namespace android
132
133#endif // ANDROID_UI_GRALLOC_MAPPER_H