1 // Copyright 2016 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 GPU_IPC_COMMON_SURFACE_HANDLE_MOJOM_TRAITS_H_
6 #define GPU_IPC_COMMON_SURFACE_HANDLE_MOJOM_TRAITS_H_
7 
8 #include "gpu/ipc/common/surface_handle.h"
9 #include "gpu/ipc/common/surface_handle.mojom-shared.h"
10 
11 namespace mojo {
12 
13 template <>
14 struct StructTraits<gpu::mojom::SurfaceHandleDataView, gpu::SurfaceHandle> {
15   static uint64_t surface_handle(const gpu::SurfaceHandle& handle) {
16 #if defined(OS_WIN)
17     return reinterpret_cast<uint64_t>(handle);
18 #else
19     return static_cast<uint64_t>(handle);
20 #endif
21   }
22 
23   static bool Read(gpu::mojom::SurfaceHandleDataView data,
24                    gpu::SurfaceHandle* out) {
25     uint64_t handle = data.surface_handle();
26 #if defined(OS_WIN)
27     *out = reinterpret_cast<gpu::SurfaceHandle>(handle);
28 #else
29     *out = static_cast<gpu::SurfaceHandle>(handle);
30 #endif
31     return true;
32   }
33 };
34 
35 }  // namespace mojo
36 
37 #endif  // GPU_IPC_COMMON_SURFACE_HANDLE_MOJOM_TRAITS_H_
38