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 
20 #include <cutils/native_handle.h>
21 #include <system/graphics.h>
22 #include <ui/Rect.h>
23 #include <utils/Mutex.h>
24 
25 namespace android {
26 namespace hardware {
27 namespace camera {
28 namespace common {
29 namespace helper {
30 
31 // Borrowed from graphics HAL. Use this until gralloc mapper HAL is working
32 class HandleImporter {
33   public:
34     HandleImporter();
35 
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);
41     bool importFence(const native_handle_t* handle, int& fd) const;
42     void closeFence(int fd) const;
43 
44     // Locks 1-D buffer. Assumes caller has waited for acquire fences.
45     void* lock(buffer_handle_t& buf, uint64_t cpuUsage, size_t size);
46 
47     // Locks 2-D buffer. Assumes caller has waited for acquire fences.
48     void* lock(buffer_handle_t& buf, uint64_t cpuUsage, const android::Rect& accessRegion);
49 
50     // Assumes caller has waited for acquire fences.
51     android_ycbcr lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
52                             const android::Rect& accessRegion);
53 
54     // Query the stride of the first plane in bytes.
55     status_t getMonoPlanarStrideBytes(buffer_handle_t& buf, uint32_t* stride /*out*/);
56 
57     int unlock(buffer_handle_t& buf);  // returns release fence
58 
59     // 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 
64   private:
65     void initializeLocked();
66     void cleanup();
67 
68     bool importBufferInternal(buffer_handle_t& handle);
69     int unlockInternal(buffer_handle_t& buf);
70 
71     Mutex mLock;
72     bool mInitialized;
73 };
74 
75 }  // namespace helper
76 
77 // NOTE: Deprecated namespace. This namespace should no longer be used for the following symbols
78 namespace V1_0::helper {
79 // Export symbols to the old namespace to preserve compatibility
80 typedef 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
89