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

Side by Side Diff: ui/display/mojo/display_snapshot_mojo_struct_traits.cc

Issue 2646213002: Write mojom and StructTraits for DisplaySnapshot. (Closed)
Patch Set: fix format/comments. Refactor structure/code. Created 3 years, 10 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
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 #include "ui/display/mojo/display_snapshot_mojo_struct_traits.h"
6
7 #include "ipc/ipc_message_utils.h"
8 #include "ui/display/mojo/display_constants_struct_traits.h"
9 #include "ui/display/mojo/display_mode_struct_traits.h"
10 #include "ui/display/types/display_constants.h"
11 #include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
12 #include "ui/gfx/geometry/size.h"
13
14 namespace mojo {
15
16 namespace {
17
18 static int64_t get_mode_index(
kylechar 2017/02/13 22:01:23 https://google.github.io/styleguide/cppguide.html#
thanhph1 2017/02/14 20:20:53 Oh cool, thanks!
19 const display::DisplaySnapshot::DisplayModeList& modes,
20 const display::DisplayMode* mode) {
21 if (!mode)
22 return -1;
23
24 for (size_t i = 0; i < modes.size(); ++i)
kylechar 2017/02/13 22:01:23 The for loop body is more than one line so add {}.
thanhph1 2017/02/14 20:20:53 Done.
25 if (*modes[i].get() == *mode)
26 return i;
27
28 NOTREACHED();
29 return -1;
30 }
31
32 } // namespace
33
34 // static
35 std::vector<std::unique_ptr<display::DisplayMode>>
36 StructTraits<display::mojom::DisplaySnapshotMojoDataView,
37 std::unique_ptr<display::DisplaySnapshotMojo>>::
38 modes(
39 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) {
40 std::vector<std::unique_ptr<display::DisplayMode>> display_mode_list(
41 display_snapshot->modes().size());
42
43 for (const auto& display_mode : display_snapshot->modes())
44 display_mode_list.push_back(display_mode->Clone());
45 return display_mode_list;
46 }
47
48 // static
49 uint64_t StructTraits<display::mojom::DisplaySnapshotMojoDataView,
50 std::unique_ptr<display::DisplaySnapshotMojo>>::
51 current_mode_index(
52 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) {
53 return get_mode_index(display_snapshot->modes(),
kylechar 2017/02/13 22:01:24 get_mode_index returns an int64_t which you then r
thanhph1 2017/02/14 20:20:53 I change return value from int64_t to uint64_t in
54 display_snapshot->current_mode());
55 }
56
57 // static
58 uint64_t StructTraits<display::mojom::DisplaySnapshotMojoDataView,
59 std::unique_ptr<display::DisplaySnapshotMojo>>::
60 native_mode_index(
61 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) {
62 return get_mode_index(display_snapshot->modes(),
63 display_snapshot->native_mode());
64 }
65
66 // static
67 bool StructTraits<display::mojom::DisplaySnapshotMojoDataView,
68 std::unique_ptr<display::DisplaySnapshotMojo>>::
69 Read(display::mojom::DisplaySnapshotMojoDataView data,
70 std::unique_ptr<display::DisplaySnapshotMojo>* out) {
71 gfx::Point origin;
72 if (!data.ReadOrigin(&origin))
73 return false;
74
75 gfx::Size physical_size;
76 if (!data.ReadPhysicalSize(&physical_size))
77 return false;
78
79 display::DisplayConnectionType type;
80 if (!data.ReadType(&type))
81 return false;
82
83 std::string display_name;
84 if (!data.ReadDisplayName(&display_name))
85 return false;
86
87 base::FilePath filePath;
kylechar 2017/02/13 22:01:24 file_path
thanhph1 2017/02/14 20:20:53 Done.
88 if (!data.ReadSysPath(&filePath))
89 return false;
90
91 // mojom doesn't allow to use const variable so |modes1| contains non-const
kylechar 2017/02/13 22:01:24 Maybe this would be clearer? // There is a type m
thanhph1 2017/02/14 20:20:53 Done.
92 // unique pointers of DisplayMode which will be moved and auto-casted to const
93 // in |modes|
94 std::vector<std::unique_ptr<display::DisplayMode>> modes1;
kylechar 2017/02/13 22:01:24 The same comment as last time, |modes1| isn't a go
thanhph1 2017/02/14 20:20:53 Done. Changed to non_const_modes.
95 if (!data.ReadModes(&modes1))
96 return false;
97 display::DisplaySnapshot::DisplayModeList modes;
98 for (auto& it : modes1)
kylechar 2017/02/13 22:01:23 The variable |it| has nothing to do with an iterat
thanhph1 2017/02/14 20:20:53 Done, change to it |mode|.
99 modes.push_back(std::move(it));
100
101 // Get current_mode pointer from modes array.
102 bool current_mode_exist = data.current_mode_exist();
103 const display::DisplayMode* current_mode = nullptr;
104 if (current_mode_exist) {
kylechar 2017/02/13 22:01:24 Your DCHECK won't be there in release builds so th
thanhph1 2017/02/14 20:20:53 Good to know DCHECK won't be in release builds, th
105 uint64_t current_mode_index = data.current_mode_index();
106 DCHECK(current_mode_index < modes.size());
107 current_mode = modes[current_mode_index].get();
108 }
109
110 // Get native_mode pointer from modes array.
111 bool native_mode_exist = data.native_mode_exist();
112 const display::DisplayMode* native_mode = nullptr;
113 if (native_mode_exist) {
114 uint64_t native_mode_index = data.native_mode_index();
115 DCHECK(native_mode_index < modes.size());
116 native_mode = modes[native_mode_index].get();
117 }
118
119 std::vector<uint8_t> edid;
120 if (!data.ReadEdid(&edid))
121 return false;
122
123 gfx::Size maximum_cursor_size;
124 if (!data.ReadMaximumCursorSize(&maximum_cursor_size))
125 return false;
126
127 *out = base::MakeUnique<display::DisplaySnapshotMojo>(
128 data.display_id(), origin, physical_size, type,
129 data.is_aspect_preserving_scaling(), data.has_overscan(),
130 data.has_color_correction_matrix(), display_name, filePath,
131 data.product_id(), std::move(modes), edid, current_mode,
kylechar 2017/02/13 22:01:23 std::move(edid)
thanhph1 2017/02/14 20:20:53 Done.
132 current_mode_exist, native_mode, native_mode_exist, maximum_cursor_size);
133 return true;
134 }
135
136 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698