1 // Copyright 2019 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_ANDROID_SCOPED_HARDWARE_BUFFER_FENCE_SYNC_H_ 6 #define BASE_ANDROID_SCOPED_HARDWARE_BUFFER_FENCE_SYNC_H_ 7 8 #include "base/android/scoped_hardware_buffer_handle.h" 9 #include "base/base_export.h" 10 #include "base/files/scoped_file.h" 11 12 namespace base { 13 namespace android { 14 15 // This class provides a ScopedHardwareBufferHandle and may include a fence 16 // which will be signaled when all pending work for the buffer has been finished 17 // and it can be safely read from. 18 class BASE_EXPORT ScopedHardwareBufferFenceSync { 19 public: 20 ScopedHardwareBufferFenceSync( 21 base::android::ScopedHardwareBufferHandle handle, 22 base::ScopedFD fence_fd, 23 base::ScopedFD available_fence_fd); 24 virtual ~ScopedHardwareBufferFenceSync(); 25 buffer()26 AHardwareBuffer* buffer() const { return handle_.get(); } 27 ScopedHardwareBufferHandle TakeBuffer(); 28 ScopedFD TakeFence(); 29 ScopedFD TakeAvailableFence(); 30 31 // Provides fence which is signaled when the reads for this buffer are done 32 // and it can be reused. Must only be called once. 33 virtual void SetReadFence(base::ScopedFD fence_fd) = 0; 34 35 private: 36 ScopedHardwareBufferHandle handle_; 37 ScopedFD fence_fd_; 38 ScopedFD available_fence_fd_; 39 }; 40 41 } // namespace android 42 } // namespace base 43 44 #endif // BASE_ANDROID_SCOPED_HARDWARE_BUFFER_FENCE_SYNC_H_ 45