Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | namespace android { |
| 26 | |
| 27 | namespace Gralloc2 { |
| 28 | |
| 29 | using hardware::graphics::allocator::V2_0::Error; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 30 | using hardware::graphics::allocator::V2_0::ProducerUsage; |
| 31 | using hardware::graphics::allocator::V2_0::ConsumerUsage; |
Chia-I Wu | 5901fda | 2016-11-17 10:26:37 +0800 | [diff] [blame] | 32 | using hardware::graphics::common::V1_0::PixelFormat; |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 33 | using hardware::graphics::mapper::V2_0::FlexLayout; |
| 34 | using hardware::graphics::mapper::V2_0::BackingStore; |
| 35 | using hardware::graphics::mapper::V2_0::Device; |
| 36 | using hardware::graphics::mapper::V2_0::IMapper; |
| 37 | |
| 38 | // Mapper is a wrapper to IMapper, a client-side graphics buffer mapper. |
| 39 | class Mapper { |
| 40 | public: |
| 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 Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 55 | uint32_t* outWidth, uint32_t* outHeight) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 56 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 57 | return mMapper->getDimensions(mDevice, handle, outWidth, outHeight); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | Error getFormat(buffer_handle_t handle, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 61 | PixelFormat* outFormat) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 62 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 63 | return mMapper->getFormat(mDevice, handle, outFormat); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 66 | Error getLayerCount(buffer_handle_t handle, uint32_t* outLayerCount) const |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 67 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 68 | return mMapper->getLayerCount(mDevice, handle, outLayerCount); |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 71 | Error getProducerUsageMask(buffer_handle_t handle, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 72 | uint64_t* outUsageMask) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 73 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 74 | return mMapper->getProducerUsageMask(mDevice, handle, outUsageMask); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | Error getConsumerUsageMask(buffer_handle_t handle, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 78 | uint64_t* outUsageMask) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 79 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 80 | return mMapper->getConsumerUsageMask(mDevice, handle, outUsageMask); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | Error getBackingStore(buffer_handle_t handle, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 84 | BackingStore* outStore) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 85 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 86 | return mMapper->getBackingStore(mDevice, handle, outStore); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 87 | } |
| 88 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 89 | Error getStride(buffer_handle_t handle, uint32_t* outStride) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 90 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 91 | return mMapper->getStride(mDevice, handle, outStride); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 92 | } |
| 93 | |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 94 | Error getNumFlexPlanes(buffer_handle_t handle, |
| 95 | uint32_t* outNumPlanes) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 96 | { |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 97 | return mMapper->getNumFlexPlanes(mDevice, handle, outNumPlanes); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | Error lock(buffer_handle_t handle, |
| 101 | uint64_t producerUsageMask, |
| 102 | uint64_t consumerUsageMask, |
| 103 | const Device::Rect& accessRegion, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 104 | int acquireFence, void** outData) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 105 | { |
| 106 | return mMapper->lock(mDevice, handle, |
| 107 | producerUsageMask, consumerUsageMask, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 108 | &accessRegion, acquireFence, outData); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | Error lock(buffer_handle_t handle, |
| 112 | uint64_t producerUsageMask, |
| 113 | uint64_t consumerUsageMask, |
| 114 | const Device::Rect& accessRegion, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 115 | int acquireFence, FlexLayout* outFlexLayout) const |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 116 | { |
| 117 | return mMapper->lockFlex(mDevice, handle, |
| 118 | producerUsageMask, consumerUsageMask, |
Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame^] | 119 | &accessRegion, acquireFence, outFlexLayout); |
Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | int unlock(buffer_handle_t handle) const; |
| 123 | |
| 124 | private: |
| 125 | const IMapper* mMapper; |
| 126 | Device* mDevice; |
| 127 | }; |
| 128 | |
| 129 | } // namespace Gralloc2 |
| 130 | |
| 131 | } // namespace android |
| 132 | |
| 133 | #endif // ANDROID_UI_GRALLOC_MAPPER_H |