File: gpu_fence_handle.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (94 lines) | stat: -rw-r--r-- 2,573 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_GPU_FENCE_HANDLE_H_
#define UI_GFX_GPU_FENCE_HANDLE_H_

#include "base/component_export.h"
#include "base/memory/ref_counted.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_POSIX)
#include "base/files/scoped_file.h"
#endif

#if BUILDFLAG(IS_FUCHSIA)
#include <lib/zx/event.h>
#endif

#if BUILDFLAG(IS_WIN)
#include "base/win/scoped_handle.h"
#endif

namespace gfx {

// TODO(crbug.com/40728014): Make this a class instead of struct.
struct COMPONENT_EXPORT(GFX) GpuFenceHandle {
#if BUILDFLAG(IS_POSIX)
  using ScopedPlatformFence = base::ScopedFD;
#elif BUILDFLAG(IS_FUCHSIA)
  using ScopedPlatformFence = zx::event;
#elif BUILDFLAG(IS_WIN)
  using ScopedPlatformFence = base::win::ScopedHandle;
#endif

  GpuFenceHandle(const GpuFenceHandle&) = delete;
  GpuFenceHandle& operator=(const GpuFenceHandle&) = delete;

  GpuFenceHandle();
  GpuFenceHandle(GpuFenceHandle&& other);
  GpuFenceHandle& operator=(GpuFenceHandle&& other);
  ~GpuFenceHandle();

  bool is_null() const;

  // Returns an instance of |handle| which can be sent over IPC. This duplicates
  // the handle so that IPC code can take ownership of it without invalidating
  // |handle| itself.
  GpuFenceHandle Clone() const;

  // Takes ownership of 'scoped_fence'. This likely comes from a move
  // operation.
  void Adopt(ScopedPlatformFence scoped_fence);

  // Internally clears out 'owned_fence' ownership.
  void Reset();

  // Returns a owned fence object (in scope) and 'Reset's the handle's fence
  // object.
  ScopedPlatformFence Release();

  // Helper functions for platforms with unscoped underlying fence
  // representations.
#if BUILDFLAG(IS_POSIX)
  // Returns fd but the returned fd is not owned.
  int Peek() const;
#elif BUILDFLAG(IS_WIN)
  // Returns HANDLE but the returned HANDLE is not owned.
  HANDLE Peek() const;
#endif

  // Returns global total number of clones since last call.
  static uint32_t GetAndClearNumberOfClones();

 private:
  struct RefCountedScopedFence
      : public base::RefCountedThreadSafe<RefCountedScopedFence> {
    explicit RefCountedScopedFence(ScopedPlatformFence scoped_fd);

   private:
    ~RefCountedScopedFence();

    friend class base::RefCountedThreadSafe<RefCountedScopedFence>;
    friend struct GpuFenceHandle;

    ScopedPlatformFence scoped_fence_;
  };

  scoped_refptr<RefCountedScopedFence> smart_fence_;
};

}  // namespace gfx

#endif  // UI_GFX_GPU_FENCE_HANDLE_H_