Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: gpu/ipc/common/memory_stats_struct_traits.h

Issue 2717233003: gpu: Use mojom API for getting video memory usage. (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/ipc/common/memory_stats.typemap ('k') | gpu/ipc/common/typemaps.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « gpu/ipc/common/memory_stats.typemap ('k') | gpu/ipc/common/typemaps.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698