• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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       bool is_video);
25   virtual ~ScopedHardwareBufferFenceSync();
26 
buffer()27   AHardwareBuffer* buffer() const { return handle_.get(); }
28   ScopedHardwareBufferHandle TakeBuffer();
29   ScopedFD TakeFence();
30   ScopedFD TakeAvailableFence();
is_video()31   bool is_video() const { return is_video_; }
32 
33   // Provides fence which is signaled when the reads for this buffer are done
34   // and it can be reused. Must only be called once.
35   virtual void SetReadFence(base::ScopedFD fence_fd) = 0;
36 
37  private:
38   ScopedHardwareBufferHandle handle_;
39   ScopedFD fence_fd_;
40   ScopedFD available_fence_fd_;
41   const bool is_video_;
42 };
43 
44 }  // namespace android
45 }  // namespace base
46 
47 #endif  // BASE_ANDROID_SCOPED_HARDWARE_BUFFER_FENCE_SYNC_H_
48