blob: c8d719bf0046f3d6afc95e7572b040a39ea2a7cf (
plain)
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
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/gpu_fence_handle.h"
#include "base/debug/alias.h"
#include "base/notreached.h"
#if defined(OS_POSIX)
#include <unistd.h>
#include "base/posix/eintr_wrapper.h"
#endif
#if defined(OS_FUCHSIA)
#include "base/fuchsia/fuchsia_logging.h"
#endif
#if defined(OS_WIN)
#include <windows.h>
#include "base/process/process_handle.h"
#endif
namespace gfx {
GpuFenceHandle::GpuFenceHandle() = default;
GpuFenceHandle::GpuFenceHandle(GpuFenceHandle&& other) = default;
GpuFenceHandle& GpuFenceHandle::operator=(GpuFenceHandle&& other) = default;
GpuFenceHandle::~GpuFenceHandle() = default;
bool GpuFenceHandle::is_null() const {
#if defined(OS_POSIX)
return !owned_fd.is_valid();
#elif defined(OS_FUCHSIA)
return !owned_event.is_valid();
#elif defined(OS_WIN)
return !owned_handle.IsValid();
#else
return true;
#endif
}
GpuFenceHandle GpuFenceHandle::Clone() const {
gfx::GpuFenceHandle handle;
#if defined(OS_POSIX)
const int duped_handle = HANDLE_EINTR(dup(owned_fd.get()));
if (duped_handle < 0)
return GpuFenceHandle();
handle.owned_fd = base::ScopedFD(duped_handle);
#elif defined(OS_FUCHSIA)
zx_status_t status =
owned_event.duplicate(ZX_RIGHT_SAME_RIGHTS, &handle.owned_event);
if (status != ZX_OK) {
ZX_DLOG(ERROR, status) << "zx_handle_duplicate";
return GpuFenceHandle();
}
#elif defined(OS_WIN)
const base::ProcessHandle process = ::GetCurrentProcess();
HANDLE duplicated_handle = INVALID_HANDLE_VALUE;
const BOOL result =
::DuplicateHandle(process, owned_handle.Get(), process,
&duplicated_handle, 0, FALSE, DUPLICATE_SAME_ACCESS);
if (!result) {
const DWORD last_error = ::GetLastError();
base::debug::Alias(&last_error);
CHECK(false);
}
handle.owned_handle.Set(duplicated_handle);
#else
NOTREACHED();
#endif
return handle;
}
} // namespace gfx
|