Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -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 CAMERA_COMMON_1_0_HANDLEIMPORTED_H |
| 18 | #define CAMERA_COMMON_1_0_HANDLEIMPORTED_H |
| 19 | |
Yin-Chia Yeh | 519c167 | 2017-04-21 14:59:31 -0700 | [diff] [blame] | 20 | #include <android/hardware/graphics/mapper/2.0/IMapper.h> |
Shuzhen Wang | 915115e | 2019-05-10 12:07:14 -0700 | [diff] [blame] | 21 | #include <android/hardware/graphics/mapper/3.0/IMapper.h> |
Marissa Wall | a51eb93 | 2019-06-21 09:13:35 -0700 | [diff] [blame] | 22 | #include <android/hardware/graphics/mapper/4.0/IMapper.h> |
Mathias Agopian | d8931ac | 2017-05-01 17:29:17 -0700 | [diff] [blame] | 23 | #include <cutils/native_handle.h> |
Marissa Wall | a51eb93 | 2019-06-21 09:13:35 -0700 | [diff] [blame] | 24 | #include <utils/Mutex.h> |
Yin-Chia Yeh | 519c167 | 2017-04-21 14:59:31 -0700 | [diff] [blame] | 25 | |
| 26 | using android::hardware::graphics::mapper::V2_0::IMapper; |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 27 | using android::hardware::graphics::mapper::V2_0::YCbCrLayout; |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace hardware { |
| 31 | namespace camera { |
| 32 | namespace common { |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 33 | namespace helper { |
| 34 | |
| 35 | // Borrowed from graphics HAL. Use this until gralloc mapper HAL is working |
| 36 | class HandleImporter { |
Avichal Rakesh | 0d2d8a4 | 2022-06-14 17:23:40 -0700 | [diff] [blame] | 37 | public: |
Yin-Chia Yeh | 519c167 | 2017-04-21 14:59:31 -0700 | [diff] [blame] | 38 | HandleImporter(); |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 39 | |
| 40 | // In IComposer, any buffer_handle_t is owned by the caller and we need to |
| 41 | // make a clone for hwcomposer2. We also need to translate empty handle |
| 42 | // to nullptr. This function does that, in-place. |
| 43 | bool importBuffer(buffer_handle_t& handle); |
| 44 | void freeBuffer(buffer_handle_t handle); |
Yin-Chia Yeh | 519c167 | 2017-04-21 14:59:31 -0700 | [diff] [blame] | 45 | bool importFence(const native_handle_t* handle, int& fd) const; |
| 46 | void closeFence(int fd) const; |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 47 | |
Jason Macnak | f2c9ed1 | 2020-04-20 14:43:58 -0700 | [diff] [blame] | 48 | // Locks 1-D buffer. Assumes caller has waited for acquire fences. |
Yuriy Romanenko | d0bd4f1 | 2018-01-19 16:00:00 -0800 | [diff] [blame] | 49 | void* lock(buffer_handle_t& buf, uint64_t cpuUsage, size_t size); |
| 50 | |
Jason Macnak | f2c9ed1 | 2020-04-20 14:43:58 -0700 | [diff] [blame] | 51 | // Locks 2-D buffer. Assumes caller has waited for acquire fences. |
| 52 | void* lock(buffer_handle_t& buf, uint64_t cpuUsage, const IMapper::Rect& accessRegion); |
| 53 | |
| 54 | // Assumes caller has waited for acquire fences. |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 55 | YCbCrLayout lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage, |
| 56 | const IMapper::Rect& accessRegion); |
| 57 | |
Emilian Peev | 6a2572b | 2021-05-24 16:51:17 -0700 | [diff] [blame] | 58 | // Query the stride of the first plane in bytes. |
| 59 | status_t getMonoPlanarStrideBytes(buffer_handle_t& buf, uint32_t* stride /*out*/); |
| 60 | |
Avichal Rakesh | 0d2d8a4 | 2022-06-14 17:23:40 -0700 | [diff] [blame] | 61 | int unlock(buffer_handle_t& buf); // returns release fence |
Yin-Chia Yeh | 1903059 | 2017-10-19 17:30:11 -0700 | [diff] [blame] | 62 | |
Emilian Peev | b5f634f | 2021-12-13 15:13:46 -0800 | [diff] [blame] | 63 | // Query Gralloc4 metadata |
| 64 | bool isSmpte2086Present(const buffer_handle_t& buf); |
| 65 | bool isSmpte2094_10Present(const buffer_handle_t& buf); |
| 66 | bool isSmpte2094_40Present(const buffer_handle_t& buf); |
| 67 | |
Avichal Rakesh | 0d2d8a4 | 2022-06-14 17:23:40 -0700 | [diff] [blame] | 68 | private: |
Yin-Chia Yeh | 519c167 | 2017-04-21 14:59:31 -0700 | [diff] [blame] | 69 | void initializeLocked(); |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 70 | void cleanup(); |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 71 | |
Avichal Rakesh | 0d2d8a4 | 2022-06-14 17:23:40 -0700 | [diff] [blame] | 72 | template <class M, class E> |
Shuzhen Wang | 915115e | 2019-05-10 12:07:14 -0700 | [diff] [blame] | 73 | bool importBufferInternal(const sp<M> mapper, buffer_handle_t& handle); |
Avichal Rakesh | 0d2d8a4 | 2022-06-14 17:23:40 -0700 | [diff] [blame] | 74 | template <class M, class E> |
Shuzhen Wang | 915115e | 2019-05-10 12:07:14 -0700 | [diff] [blame] | 75 | YCbCrLayout lockYCbCrInternal(const sp<M> mapper, buffer_handle_t& buf, uint64_t cpuUsage, |
Avichal Rakesh | 0d2d8a4 | 2022-06-14 17:23:40 -0700 | [diff] [blame] | 76 | const IMapper::Rect& accessRegion); |
| 77 | template <class M, class E> |
Shuzhen Wang | 915115e | 2019-05-10 12:07:14 -0700 | [diff] [blame] | 78 | int unlockInternal(const sp<M> mapper, buffer_handle_t& buf); |
| 79 | |
Yin-Chia Yeh | 519c167 | 2017-04-21 14:59:31 -0700 | [diff] [blame] | 80 | Mutex mLock; |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 81 | bool mInitialized; |
Shuzhen Wang | 915115e | 2019-05-10 12:07:14 -0700 | [diff] [blame] | 82 | sp<IMapper> mMapperV2; |
| 83 | sp<graphics::mapper::V3_0::IMapper> mMapperV3; |
Marissa Wall | a51eb93 | 2019-06-21 09:13:35 -0700 | [diff] [blame] | 84 | sp<graphics::mapper::V4_0::IMapper> mMapperV4; |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
Avichal Rakesh | 0d2d8a4 | 2022-06-14 17:23:40 -0700 | [diff] [blame] | 87 | } // namespace helper |
Yin-Chia Yeh | 248ed70 | 2017-01-23 17:27:26 -0800 | [diff] [blame] | 88 | |
Avichal Rakesh | 0d2d8a4 | 2022-06-14 17:23:40 -0700 | [diff] [blame] | 89 | // NOTE: Deprecated namespace. This namespace should no longer be used for the following symbols |
| 90 | namespace V1_0::helper { |
| 91 | // Export symbols to the old namespace to preserve compatibility |
| 92 | typedef android::hardware::camera::common::helper::HandleImporter HandleImporter; |
| 93 | } // namespace V1_0::helper |
| 94 | |
| 95 | } // namespace common |
| 96 | } // namespace camera |
| 97 | } // namespace hardware |
| 98 | } // namespace android |
| 99 | |
| 100 | #endif // CAMERA_COMMON_1_0_HANDLEIMPORTED_H |