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 using android::hardware::graphics::mapper::V2_0::YCbCrLayout; 26 27 namespace android { 28 namespace hardware { 29 namespace camera { 30 namespace common { 31 namespace V1_0 { 32 namespace helper { 33 34 // Borrowed from graphics HAL. Use this until gralloc mapper HAL is working 35 class HandleImporter { 36 public: 37 HandleImporter(); 38 39 // In IComposer, any buffer_handle_t is owned by the caller and we need to 40 // make a clone for hwcomposer2. We also need to translate empty handle 41 // to nullptr. This function does that, in-place. 42 bool importBuffer(buffer_handle_t& handle); 43 void freeBuffer(buffer_handle_t handle); 44 bool importFence(const native_handle_t* handle, int& fd) const; 45 void closeFence(int fd) const; 46 47 // Assume caller has done waiting for acquire fences 48 void* lock(buffer_handle_t& buf, uint64_t cpuUsage, size_t size); 49 50 // Assume caller has done waiting for acquire fences 51 YCbCrLayout lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage, 52 const IMapper::Rect& accessRegion); 53 54 int unlock(buffer_handle_t& buf); // returns release fence 55 56 private: 57 void initializeLocked(); 58 void cleanup(); 59 60 Mutex mLock; 61 bool mInitialized; 62 sp<IMapper> mMapper; 63 64 }; 65 66 } // namespace helper 67 } // namespace V1_0 68 } // namespace common 69 } // namespace camera 70 } // namespace hardware 71 } // namespace android 72 73 #endif // CAMERA_COMMON_1_0_HANDLEIMPORTED_H 74