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; |
| 30 | using hardware::graphics::allocator::V2_0::PixelFormat; |
| 31 | using hardware::graphics::allocator::V2_0::ProducerUsage; |
| 32 | using hardware::graphics::allocator::V2_0::ConsumerUsage; |
| 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, |
| 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 | |
| 66 | Error getProducerUsageMask(buffer_handle_t handle, |
| 67 | uint64_t& usageMask) const |
| 68 | { |
| 69 | return mMapper->getProducerUsageMask(mDevice, handle, &usageMask); |
| 70 | } |
| 71 | |
| 72 | Error getConsumerUsageMask(buffer_handle_t handle, |
| 73 | uint64_t& usageMask) const |
| 74 | { |
| 75 | return mMapper->getConsumerUsageMask(mDevice, handle, &usageMask); |
| 76 | } |
| 77 | |
| 78 | Error getBackingStore(buffer_handle_t handle, |
| 79 | BackingStore& store) const |
| 80 | { |
| 81 | return mMapper->getBackingStore(mDevice, handle, &store); |
| 82 | } |
| 83 | |
| 84 | Error getStride(buffer_handle_t handle, uint32_t& stride) const |
| 85 | { |
| 86 | return mMapper->getStride(mDevice, handle, &stride); |
| 87 | } |
| 88 | |
| 89 | Error getNumFlexPlanes(buffer_handle_t handle, uint32_t& numPlanes) const |
| 90 | { |
| 91 | return mMapper->getNumFlexPlanes(mDevice, handle, &numPlanes); |
| 92 | } |
| 93 | |
| 94 | Error lock(buffer_handle_t handle, |
| 95 | uint64_t producerUsageMask, |
| 96 | uint64_t consumerUsageMask, |
| 97 | const Device::Rect& accessRegion, |
| 98 | int acquireFence, void*& data) const |
| 99 | { |
| 100 | return mMapper->lock(mDevice, handle, |
| 101 | producerUsageMask, consumerUsageMask, |
| 102 | &accessRegion, acquireFence, &data); |
| 103 | } |
| 104 | |
| 105 | Error lock(buffer_handle_t handle, |
| 106 | uint64_t producerUsageMask, |
| 107 | uint64_t consumerUsageMask, |
| 108 | const Device::Rect& accessRegion, |
| 109 | int acquireFence, FlexLayout& flexLayout) const |
| 110 | { |
| 111 | return mMapper->lockFlex(mDevice, handle, |
| 112 | producerUsageMask, consumerUsageMask, |
| 113 | &accessRegion, acquireFence, &flexLayout); |
| 114 | } |
| 115 | |
| 116 | int unlock(buffer_handle_t handle) const; |
| 117 | |
| 118 | private: |
| 119 | const IMapper* mMapper; |
| 120 | Device* mDevice; |
| 121 | }; |
| 122 | |
| 123 | } // namespace Gralloc2 |
| 124 | |
| 125 | } // namespace android |
| 126 | |
| 127 | #endif // ANDROID_UI_GRALLOC_MAPPER_H |