• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <utils/Mutex.h>
21 #include <android/hardware/graphics/mapper/2.0/IMapper.h>
22 #include <android/hardware/graphics/mapper/3.0/IMapper.h>
23 #include <cutils/native_handle.h>
24 
25 using android::hardware::graphics::mapper::V2_0::IMapper;
26 using android::hardware::graphics::mapper::V2_0::YCbCrLayout;
27 
28 namespace android {
29 namespace hardware {
30 namespace camera {
31 namespace common {
32 namespace V1_0 {
33 namespace helper {
34 
35 // Borrowed from graphics HAL. Use this until gralloc mapper HAL is working
36 class HandleImporter {
37 public:
38     HandleImporter();
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);
45     bool importFence(const native_handle_t* handle, int& fd) const;
46     void closeFence(int fd) const;
47 
48     // Assume caller has done waiting for acquire fences
49     void* lock(buffer_handle_t& buf, uint64_t cpuUsage, size_t size);
50 
51     // Assume caller has done waiting for acquire fences
52     YCbCrLayout lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
53                           const IMapper::Rect& accessRegion);
54 
55     int unlock(buffer_handle_t& buf); // returns release fence
56 
57 private:
58     void initializeLocked();
59     void cleanup();
60 
61     template<class M, class E>
62     bool importBufferInternal(const sp<M> mapper, buffer_handle_t& handle);
63     template<class M, class E>
64     YCbCrLayout lockYCbCrInternal(const sp<M> mapper, buffer_handle_t& buf, uint64_t cpuUsage,
65             const IMapper::Rect& accessRegion);
66     template<class M, class E>
67     int unlockInternal(const sp<M> mapper, buffer_handle_t& buf);
68 
69     Mutex mLock;
70     bool mInitialized;
71     sp<IMapper> mMapperV2;
72     sp<graphics::mapper::V3_0::IMapper> mMapperV3;
73 };
74 
75 } // namespace helper
76 } // namespace V1_0
77 } // namespace common
78 } // namespace camera
79 } // namespace hardware
80 } // namespace android
81 
82 #endif // CAMERA_COMMON_1_0_HANDLEIMPORTED_H
83