blob: 757f20bcd27f777ab38f04f16b305d4373d90d8a [file] [log] [blame]
Chia-I Wu89d09dd2017-02-24 10:41:35 -08001/*
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 Wu79d13ff2017-03-31 12:48:11 -070020#include <unordered_set>
Chia-I Wu89d09dd2017-02-24 10:41:35 -080021
Chia-I Wu79d13ff2017-03-31 12:48:11 -070022#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
Chia-I Wu89d09dd2017-02-24 10:41:35 -080023#include <android/hardware/graphics/mapper/2.0/IMapper.h>
24#include <utils/StrongPointer.h>
25
Chia-I Wu89d09dd2017-02-24 10:41:35 -080026namespace android {
27namespace hardware {
28namespace graphics {
29namespace mapper {
30namespace V2_0 {
31namespace tests {
32
Chia-I Wu79d13ff2017-03-31 12:48:11 -070033using android::hardware::graphics::allocator::V2_0::IAllocator;
Chia-I Wu89d09dd2017-02-24 10:41:35 -080034
Chia-I Wu79d13ff2017-03-31 12:48:11 -070035// A wrapper to IAllocator and IMapper.
36class Gralloc {
37 public:
38 Gralloc();
39 ~Gralloc();
Chia-I Wu89d09dd2017-02-24 10:41:35 -080040
Chia-I Wu79d13ff2017-03-31 12:48:11 -070041 // IAllocator methods
Chia-I Wu89d09dd2017-02-24 10:41:35 -080042
Chia-I Wu79d13ff2017-03-31 12:48:11 -070043 sp<IAllocator> getAllocator() const;
Chia-I Wu89d09dd2017-02-24 10:41:35 -080044
Chia-I Wu79d13ff2017-03-31 12:48:11 -070045 std::string dumpDebugInfo();
Chia-I Wu89d09dd2017-02-24 10:41:35 -080046
Chia-I Wu79d13ff2017-03-31 12:48:11 -070047 // 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 Wu89d09dd2017-02-24 10:41:35 -080057
Chia-I Wu79d13ff2017-03-31 12:48:11 -070058 // IMapper methods
Chia-I Wu89d09dd2017-02-24 10:41:35 -080059
Chia-I Wu79d13ff2017-03-31 12:48:11 -070060 sp<IMapper> getMapper() const;
Chia-I Wu89d09dd2017-02-24 10:41:35 -080061
Chia-I Wu79d13ff2017-03-31 12:48:11 -070062 BufferDescriptor createDescriptor(
63 const IMapper::BufferDescriptorInfo& descriptorInfo);
Chia-I Wu89d09dd2017-02-24 10:41:35 -080064
Chia-I Wu79d13ff2017-03-31 12:48:11 -070065 const native_handle_t* importBuffer(const hidl_handle& rawHandle);
66 void freeBuffer(const native_handle_t* bufferHandle);
Chia-I Wu89d09dd2017-02-24 10:41:35 -080067
Chia-I Wu79d13ff2017-03-31 12:48:11 -070068 // 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 Wu89d09dd2017-02-24 10:41:35 -080089};
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