Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 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 VTS_HAL_GRAPHICS_MAPPER_UTILS |
| 18 | #define VTS_HAL_GRAPHICS_MAPPER_UTILS |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <unordered_map> |
| 22 | |
| 23 | #include <android/hardware/graphics/mapper/2.0/IMapper.h> |
| 24 | #include <utils/StrongPointer.h> |
| 25 | |
| 26 | #include "VtsHalGraphicsAllocatorTestUtils.h" |
| 27 | |
| 28 | namespace android { |
| 29 | namespace hardware { |
| 30 | namespace graphics { |
| 31 | namespace mapper { |
| 32 | namespace V2_0 { |
| 33 | namespace tests { |
| 34 | |
| 35 | using android::hardware::graphics::common::V1_0::PixelFormat; |
| 36 | using android::hardware::graphics::allocator::V2_0::IAllocatorClient; |
| 37 | using android::hardware::graphics::allocator::V2_0::tests::AllocatorClient; |
| 38 | |
| 39 | // A wrapper to IMapper. |
| 40 | class Mapper { |
| 41 | public: |
| 42 | Mapper(); |
| 43 | ~Mapper(); |
| 44 | |
| 45 | sp<IMapper> getRaw() const; |
| 46 | |
| 47 | void retain(const native_handle_t* handle); |
| 48 | void release(const native_handle_t* handle); |
| 49 | |
| 50 | struct Dimensions { |
| 51 | uint32_t width; |
| 52 | uint32_t height; |
| 53 | }; |
| 54 | Dimensions getDimensions(const native_handle_t* handle); |
| 55 | |
| 56 | PixelFormat getFormat(const native_handle_t* handle); |
| 57 | uint32_t getLayerCount(const native_handle_t* handle); |
| 58 | uint64_t getProducerUsageMask(const native_handle_t* handle); |
| 59 | uint64_t getConsumerUsageMask(const native_handle_t* handle); |
| 60 | BackingStore getBackingStore(const native_handle_t* handle); |
| 61 | uint32_t getStride(const native_handle_t* handle); |
| 62 | |
| 63 | // We use fd instead of hidl_handle in these functions to pass fences |
| 64 | // in and out of the mapper. The ownership of the fd is always transferred |
| 65 | // with each of these functions. |
| 66 | void* lock(const native_handle_t* handle, uint64_t producerUsageMask, |
| 67 | uint64_t consumerUsageMask, const IMapper::Rect& accessRegion, |
| 68 | int acquireFence); |
| 69 | FlexLayout lockFlex(const native_handle_t* handle, uint64_t producerUsageMask, |
| 70 | uint64_t consumerUsageMask, |
| 71 | const IMapper::Rect& accessRegion, int acquireFence); |
| 72 | int unlock(const native_handle_t* handle); |
| 73 | |
| 74 | // Requests AllocatorClient to allocate a buffer, export the handle, and |
| 75 | // register the handle with mapper. |
| 76 | const native_handle_t* allocate( |
| 77 | std::unique_ptr<AllocatorClient>& allocatorClient, |
| 78 | const IAllocatorClient::BufferDescriptorInfo& info); |
| 79 | |
| 80 | private: |
| 81 | void init(); |
| 82 | |
| 83 | sp<IMapper> mMapper; |
| 84 | |
| 85 | // Keep track of all registered (retained) handles. When a test fails with |
| 86 | // ASSERT_*, the destructor will release the handles for the test. |
| 87 | std::unordered_map<const native_handle_t*, uint64_t> mHandles; |
| 88 | }; |
| 89 | |
| 90 | } // namespace tests |
| 91 | } // namespace V2_0 |
| 92 | } // namespace mapper |
| 93 | } // namespace graphics |
| 94 | } // namespace hardware |
| 95 | } // namespace android |
| 96 | |
| 97 | #endif // VTS_HAL_GRAPHICS_MAPPER_UTILS |