1 // Copyright 2017 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 
5 #ifndef UI_GL_GPU_FENCE_H_
6 #define UI_GL_GPU_FENCE_H_
7 
8 #include "base/macros.h"
9 #include "build/build_config.h"
10 #include "ui/gfx/gfx_export.h"
11 #include "ui/gfx/gpu_fence_handle.h"
12 
13 extern "C" typedef struct _ClientGpuFence* ClientGpuFence;
14 
15 namespace base {
16 class TimeTicks;
17 }  // namespace base
18 
19 namespace gfx {
20 
21 // GpuFence objects own a GpuFenceHandle and release the resources in it when
22 // going out of scope as appropriate.
23 class GFX_EXPORT GpuFence {
24  public:
25   // Constructor takes ownership of the source handle's resources.
26   explicit GpuFence(GpuFenceHandle handle);
27   GpuFence() = delete;
28   GpuFence(GpuFence&& other);
29   GpuFence& operator=(GpuFence&& other);
30   ~GpuFence();
31 
32   // Returns a const reference to the underlying GpuFenceHandle
33   // owned by GpuFence. If you'd like a duplicated handle for use
34   // with IPC, call the Clone method on the returned handle.
35   const GpuFenceHandle& GetGpuFenceHandle() const;
36 
37   // Casts for use with the GLES interface.
38   ClientGpuFence AsClientGpuFence();
39   static GpuFence* FromClientGpuFence(ClientGpuFence gpu_fence);
40 
41   // Wait for the GpuFence to become ready.
42   void Wait();
43 
44   enum FenceStatus { kSignaled, kNotSignaled, kInvalid };
45   static FenceStatus GetStatusChangeTime(int fd, base::TimeTicks* time);
46 
47   base::TimeTicks GetMaxTimestamp() const;
48 
49  private:
50   gfx::GpuFenceHandle fence_handle_;
51 
52   DISALLOW_COPY_AND_ASSIGN(GpuFence);
53 };
54 
55 }  // namespace gfx
56 
57 #endif  // UI_GL_GPU_FENCE_H_
58