scoped_hardware_buffer_fence_sync.h 1.5 KB

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