• 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 <cutils/native_handle.h>
23 
24 using android::hardware::graphics::mapper::V2_0::IMapper;
25 
26 namespace android {
27 namespace hardware {
28 namespace camera {
29 namespace common {
30 namespace V1_0 {
31 namespace helper {
32 
33 // Borrowed from graphics HAL. Use this until gralloc mapper HAL is working
34 class HandleImporter {
35 public:
36     HandleImporter();
37 
38     // In IComposer, any buffer_handle_t is owned by the caller and we need to
39     // make a clone for hwcomposer2.  We also need to translate empty handle
40     // to nullptr.  This function does that, in-place.
41     bool importBuffer(buffer_handle_t& handle);
42     void freeBuffer(buffer_handle_t handle);
43     bool importFence(const native_handle_t* handle, int& fd) const;
44     void closeFence(int fd) const;
45 
46 private:
47     void initializeLocked();
48     void cleanup();
49 
50     Mutex mLock;
51     bool mInitialized;
52     sp<IMapper> mMapper;
53 
54 };
55 
56 } // namespace helper
57 } // namespace V1_0
58 } // namespace common
59 } // namespace camera
60 } // namespace hardware
61 } // namespace android
62 
63 #endif // CAMERA_COMMON_1_0_HANDLEIMPORTED_H