blob: df01202224557287f983a72ef66e03e80bb6204a [file] [log] [blame]
Yin-Chia Yeh248ed702017-01-23 17:27:26 -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 CAMERA_COMMON_1_0_HANDLEIMPORTED_H
18#define CAMERA_COMMON_1_0_HANDLEIMPORTED_H
19
Mathias Agopiand8931ac2017-05-01 17:29:17 -070020#include <cutils/native_handle.h>
Devin Moore523660c2023-10-02 15:55:11 +000021#include <system/graphics.h>
22#include <ui/Rect.h>
Marissa Walla51eb932019-06-21 09:13:35 -070023#include <utils/Mutex.h>
Yin-Chia Yeh519c1672017-04-21 14:59:31 -070024
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080025namespace android {
26namespace hardware {
27namespace camera {
28namespace common {
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080029namespace helper {
30
31// Borrowed from graphics HAL. Use this until gralloc mapper HAL is working
32class HandleImporter {
Avichal Rakesh0d2d8a42022-06-14 17:23:40 -070033 public:
Yin-Chia Yeh519c1672017-04-21 14:59:31 -070034 HandleImporter();
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080035
36 // In IComposer, any buffer_handle_t is owned by the caller and we need to
37 // make a clone for hwcomposer2. We also need to translate empty handle
38 // to nullptr. This function does that, in-place.
39 bool importBuffer(buffer_handle_t& handle);
40 void freeBuffer(buffer_handle_t handle);
Yin-Chia Yeh519c1672017-04-21 14:59:31 -070041 bool importFence(const native_handle_t* handle, int& fd) const;
42 void closeFence(int fd) const;
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080043
Jason Macnakf2c9ed12020-04-20 14:43:58 -070044 // Locks 1-D buffer. Assumes caller has waited for acquire fences.
Yuriy Romanenkod0bd4f12018-01-19 16:00:00 -080045 void* lock(buffer_handle_t& buf, uint64_t cpuUsage, size_t size);
46
Jason Macnakf2c9ed12020-04-20 14:43:58 -070047 // Locks 2-D buffer. Assumes caller has waited for acquire fences.
Devin Moore523660c2023-10-02 15:55:11 +000048 void* lock(buffer_handle_t& buf, uint64_t cpuUsage, const android::Rect& accessRegion);
Jason Macnakf2c9ed12020-04-20 14:43:58 -070049
50 // Assumes caller has waited for acquire fences.
Devin Moore523660c2023-10-02 15:55:11 +000051 android_ycbcr lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
52 const android::Rect& accessRegion);
Yin-Chia Yeh19030592017-10-19 17:30:11 -070053
Emilian Peev6a2572b2021-05-24 16:51:17 -070054 // Query the stride of the first plane in bytes.
55 status_t getMonoPlanarStrideBytes(buffer_handle_t& buf, uint32_t* stride /*out*/);
56
Avichal Rakesh0d2d8a42022-06-14 17:23:40 -070057 int unlock(buffer_handle_t& buf); // returns release fence
Yin-Chia Yeh19030592017-10-19 17:30:11 -070058
Emilian Peevb5f634f2021-12-13 15:13:46 -080059 // Query Gralloc4 metadata
60 bool isSmpte2086Present(const buffer_handle_t& buf);
61 bool isSmpte2094_10Present(const buffer_handle_t& buf);
62 bool isSmpte2094_40Present(const buffer_handle_t& buf);
63
Avichal Rakesh0d2d8a42022-06-14 17:23:40 -070064 private:
Yin-Chia Yeh519c1672017-04-21 14:59:31 -070065 void initializeLocked();
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080066 void cleanup();
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080067
Devin Moore523660c2023-10-02 15:55:11 +000068 bool importBufferInternal(buffer_handle_t& handle);
69 int unlockInternal(buffer_handle_t& buf);
Shuzhen Wang915115e2019-05-10 12:07:14 -070070
Yin-Chia Yeh519c1672017-04-21 14:59:31 -070071 Mutex mLock;
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080072 bool mInitialized;
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080073};
74
Avichal Rakesh0d2d8a42022-06-14 17:23:40 -070075} // namespace helper
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080076
Avichal Rakesh0d2d8a42022-06-14 17:23:40 -070077// NOTE: Deprecated namespace. This namespace should no longer be used for the following symbols
78namespace V1_0::helper {
79// Export symbols to the old namespace to preserve compatibility
80typedef android::hardware::camera::common::helper::HandleImporter HandleImporter;
81} // namespace V1_0::helper
82
83} // namespace common
84} // namespace camera
85} // namespace hardware
86} // namespace android
87
88#endif // CAMERA_COMMON_1_0_HANDLEIMPORTED_H