| OLD | NEW |
| (Empty) | |
| 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 GPU_IPC_COMMON_MEMORY_STATS_STRUCT_TRAITS_H_ |
| 6 #define GPU_IPC_COMMON_MEMORY_STATS_STRUCT_TRAITS_H_ |
| 7 |
| 8 #include "gpu/ipc/common/memory_stats.h" |
| 9 #include "gpu/ipc/common/memory_stats.mojom-shared.h" |
| 10 |
| 11 namespace mojo { |
| 12 |
| 13 template <> |
| 14 struct StructTraits<gpu::mojom::VideoMemoryProcessStatsDataView, |
| 15 gpu::VideoMemoryUsageStats::ProcessStats> { |
| 16 static uint64_t video_memory_bytes( |
| 17 const gpu::VideoMemoryUsageStats::ProcessStats& state) { |
| 18 return state.video_memory; |
| 19 } |
| 20 |
| 21 static bool has_duplicates( |
| 22 const gpu::VideoMemoryUsageStats::ProcessStats& state) { |
| 23 return state.has_duplicates; |
| 24 } |
| 25 |
| 26 static bool Read(gpu::mojom::VideoMemoryProcessStatsDataView data, |
| 27 gpu::VideoMemoryUsageStats::ProcessStats* out) { |
| 28 out->video_memory = data.video_memory_bytes(); |
| 29 out->has_duplicates = data.has_duplicates(); |
| 30 return true; |
| 31 } |
| 32 }; |
| 33 |
| 34 template <> |
| 35 struct StructTraits<gpu::mojom::VideoMemoryUsageStatsDataView, |
| 36 gpu::VideoMemoryUsageStats> { |
| 37 static std::map<int32_t, gpu::VideoMemoryUsageStats::ProcessStats> |
| 38 process_map(const gpu::VideoMemoryUsageStats& stats) { |
| 39 #if defined(OS_WIN) |
| 40 std::map<int32_t, gpu::VideoMemoryUsageStats::ProcessStats> map; |
| 41 for (const auto& pair : stats.process_map) |
| 42 map[static_cast<int32_t>(pair.first)] = pair.second; |
| 43 return map; |
| 44 #else |
| 45 return stats.process_map; |
| 46 #endif |
| 47 } |
| 48 |
| 49 static uint64_t bytes_allocated(const gpu::VideoMemoryUsageStats& stats) { |
| 50 return stats.bytes_allocated; |
| 51 } |
| 52 |
| 53 static bool Read(gpu::mojom::VideoMemoryUsageStatsDataView data, |
| 54 gpu::VideoMemoryUsageStats* out) { |
| 55 #if defined(OS_WIN) |
| 56 std::map<int32_t, gpu::VideoMemoryUsageStats::ProcessStats> process_map; |
| 57 if (!data.ReadProcessMap(&process_map)) |
| 58 return false; |
| 59 for (const auto& pair : process_map) |
| 60 out->process_map[static_cast<base::ProcessId>(pair.first)] = pair.second; |
| 61 #else |
| 62 if (!data.ReadProcessMap(&out->process_map)) |
| 63 return false; |
| 64 #endif |
| 65 out->bytes_allocated = data.bytes_allocated(); |
| 66 return true; |
| 67 } |
| 68 }; |
| 69 |
| 70 } // namespace mojo |
| 71 |
| 72 #endif // GPU_IPC_COMMON_MEMORY_STATS_STRUCT_TRAITS_H_ |
| OLD | NEW |