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_GFX_GPU_FENCE_HANDLE_H_
6 #define UI_GFX_GPU_FENCE_HANDLE_H_
7 
8 #include "base/macros.h"
9 #include "build/build_config.h"
10 #include "ui/gfx/gfx_export.h"
11 
12 #if defined(OS_POSIX)
13 #include "base/files/scoped_file.h"
14 #endif
15 
16 #if defined(OS_FUCHSIA)
17 #include <lib/zx/event.h>
18 #endif
19 
20 #if defined(OS_WIN)
21 #include "base/win/scoped_handle.h"
22 #endif
23 
24 namespace gfx {
25 
26 struct GFX_EXPORT GpuFenceHandle {
27   GpuFenceHandle(const GpuFenceHandle&) = delete;
28   GpuFenceHandle& operator=(const GpuFenceHandle&) = delete;
29 
30   GpuFenceHandle();
31   GpuFenceHandle(GpuFenceHandle&& other);
32   GpuFenceHandle& operator=(GpuFenceHandle&& other);
33   ~GpuFenceHandle();
34 
35   bool is_null() const;
36 
37   // Returns an instance of |handle| which can be sent over IPC. This duplicates
38   // the handle so that IPC code can take ownership of it without invalidating
39   // |handle| itself.
40   GpuFenceHandle Clone() const;
41 
42   // TODO(crbug.com/1142962): Make this a class instead of struct.
43 #if defined(OS_POSIX)
44   base::ScopedFD owned_fd;
45 #elif defined(OS_FUCHSIA)
46   zx::event owned_event;
47 #elif defined(OS_WIN)
48   base::win::ScopedHandle owned_handle;
49 #endif
50 };
51 
52 }  // namespace gfx
53 
54 #endif  // UI_GFX_GPU_FENCE_HANDLE_H_
55