summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/gpu_fence.cc
blob: 888b236775fb94a9309e88c93a88fda0269c3456 (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
// Copyright 2014 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.h"

#include "base/logging.h"

namespace gfx {

GpuFence::GpuFence(const GpuFenceHandle& handle) : type_(handle.type) {
  switch (type_) {
    case GpuFenceHandleType::kEmpty:
      break;
    case GpuFenceHandleType::kAndroidNativeFenceSync:
#if defined(OS_POSIX)
      owned_fd_.reset(handle.native_fd.fd);
#else
      NOTREACHED();
#endif
      break;
  }
}

GpuFence::~GpuFence() = default;

GpuFenceHandle GpuFence::GetGpuFenceHandle() const {
  gfx::GpuFenceHandle handle;
  switch (type_) {
    case GpuFenceHandleType::kEmpty:
      break;
    case GpuFenceHandleType::kAndroidNativeFenceSync:
#if defined(OS_POSIX)
      handle.type = gfx::GpuFenceHandleType::kAndroidNativeFenceSync;
      handle.native_fd = base::FileDescriptor(owned_fd_.get(),
                                              /*auto_close=*/false);
#else
      NOTREACHED();
#endif
      break;
  }
  return handle;
}

ClientGpuFence GpuFence::AsClientGpuFence() {
  return reinterpret_cast<ClientGpuFence>(this);
}

// static
GpuFence* GpuFence::FromClientGpuFence(ClientGpuFence gpu_fence) {
  return reinterpret_cast<GpuFence*>(gpu_fence);
}

}  // namespace gfx