blob: 868fd144309cf274452049358b8540856c42de84 [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;
30using hardware::graphics::allocator::V2_0::PixelFormat;
31using hardware::graphics::allocator::V2_0::ProducerUsage;
32using hardware::graphics::allocator::V2_0::ConsumerUsage;
33using 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,
55 uint32_t& width, uint32_t& height) const
56 {
57 return mMapper->getDimensions(mDevice, handle, &width, &height);
58 }
59
60 Error getFormat(buffer_handle_t handle,
61 PixelFormat& format) const
62 {
63 return mMapper->getFormat(mDevice, handle, &format);
64 }
65
Craig Donner6ebc46a2016-10-21 15:23:44 -070066 Error getLayerCount(buffer_handle_t handle, uint32_t& layerCount) const
67 {
68 return mMapper->getLayerCount(mDevice, handle, &layerCount);
69 }
70
Chia-I Wu9ba189d2016-09-22 17:13:08 +080071 Error getProducerUsageMask(buffer_handle_t handle,
72 uint64_t& usageMask) const
73 {
74 return mMapper->getProducerUsageMask(mDevice, handle, &usageMask);
75 }
76
77 Error getConsumerUsageMask(buffer_handle_t handle,
78 uint64_t& usageMask) const
79 {
80 return mMapper->getConsumerUsageMask(mDevice, handle, &usageMask);
81 }
82
83 Error getBackingStore(buffer_handle_t handle,
84 BackingStore& store) const
85 {
86 return mMapper->getBackingStore(mDevice, handle, &store);
87 }
88
89 Error getStride(buffer_handle_t handle, uint32_t& stride) const
90 {
91 return mMapper->getStride(mDevice, handle, &stride);
92 }
93
94 Error getNumFlexPlanes(buffer_handle_t handle, uint32_t& numPlanes) const
95 {
96 return mMapper->getNumFlexPlanes(mDevice, handle, &numPlanes);
97 }
98
99 Error lock(buffer_handle_t handle,
100 uint64_t producerUsageMask,
101 uint64_t consumerUsageMask,
102 const Device::Rect& accessRegion,
103 int acquireFence, void*& data) const
104 {
105 return mMapper->lock(mDevice, handle,
106 producerUsageMask, consumerUsageMask,
107 &accessRegion, acquireFence, &data);
108 }
109
110 Error lock(buffer_handle_t handle,
111 uint64_t producerUsageMask,
112 uint64_t consumerUsageMask,
113 const Device::Rect& accessRegion,
114 int acquireFence, FlexLayout& flexLayout) const
115 {
116 return mMapper->lockFlex(mDevice, handle,
117 producerUsageMask, consumerUsageMask,
118 &accessRegion, acquireFence, &flexLayout);
119 }
120
121 int unlock(buffer_handle_t handle) const;
122
123private:
124 const IMapper* mMapper;
125 Device* mDevice;
126};
127
128} // namespace Gralloc2
129
130} // namespace android
131
132#endif // ANDROID_UI_GRALLOC_MAPPER_H