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 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 20 | #include <unordered_set> |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 21 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 22 | #include <android/hardware/graphics/allocator/2.0/IAllocator.h> |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 23 | #include <android/hardware/graphics/mapper/2.0/IMapper.h> |
| 24 | #include <utils/StrongPointer.h> |
| 25 | |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace graphics { |
| 29 | namespace mapper { |
| 30 | namespace V2_0 { |
| 31 | namespace tests { |
| 32 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 33 | using android::hardware::graphics::allocator::V2_0::IAllocator; |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 34 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 35 | // A wrapper to IAllocator and IMapper. |
| 36 | class Gralloc { |
| 37 | public: |
| 38 | Gralloc(); |
| 39 | ~Gralloc(); |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 40 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 41 | // IAllocator methods |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 42 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 43 | sp<IAllocator> getAllocator() const; |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 44 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 45 | std::string dumpDebugInfo(); |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 46 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 47 | // When import is false, this simply calls IAllocator::allocate. When import |
| 48 | // is true, the returned buffers are also imported into the mapper. |
| 49 | // |
| 50 | // Either case, the returned buffers must be freed with freeBuffer. |
| 51 | std::vector<const native_handle_t*> allocate( |
| 52 | const BufferDescriptor& descriptor, uint32_t count, bool import = true, |
| 53 | uint32_t* outStride = nullptr); |
| 54 | const native_handle_t* allocate( |
| 55 | const IMapper::BufferDescriptorInfo& descriptorInfo, bool import = true, |
| 56 | uint32_t* outStride = nullptr); |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 57 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 58 | // IMapper methods |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 59 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 60 | sp<IMapper> getMapper() const; |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 61 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 62 | BufferDescriptor createDescriptor( |
| 63 | const IMapper::BufferDescriptorInfo& descriptorInfo); |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 64 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 65 | const native_handle_t* importBuffer(const hidl_handle& rawHandle); |
| 66 | void freeBuffer(const native_handle_t* bufferHandle); |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 67 | |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 68 | // We use fd instead of hidl_handle in these functions to pass fences |
| 69 | // in and out of the mapper. The ownership of the fd is always transferred |
| 70 | // with each of these functions. |
| 71 | void* lock(const native_handle_t* bufferHandle, uint64_t cpuUsage, |
| 72 | const IMapper::Rect& accessRegion, int acquireFence); |
| 73 | YCbCrLayout lockYCbCr(const native_handle_t* bufferHandle, |
| 74 | uint64_t cpuUsage, const IMapper::Rect& accessRegion, |
| 75 | int acquireFence); |
| 76 | int unlock(const native_handle_t* bufferHandle); |
| 77 | |
| 78 | private: |
| 79 | void init(); |
| 80 | const native_handle_t* cloneBuffer(const hidl_handle& rawHandle); |
| 81 | |
| 82 | sp<IAllocator> mAllocator; |
| 83 | sp<IMapper> mMapper; |
| 84 | |
| 85 | // Keep track of all cloned and imported handles. When a test fails with |
| 86 | // ASSERT_*, the destructor will free the handles for the test. |
| 87 | std::unordered_set<const native_handle_t*> mClonedBuffers; |
| 88 | std::unordered_set<const native_handle_t*> mImportedBuffers; |
Chia-I Wu | 89d09dd | 2017-02-24 10:41:35 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace tests |
| 92 | } // namespace V2_0 |
| 93 | } // namespace mapper |
| 94 | } // namespace graphics |
| 95 | } // namespace hardware |
| 96 | } // namespace android |
| 97 | |
| 98 | #endif // VTS_HAL_GRAPHICS_MAPPER_UTILS |