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

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

Issue 2646213002: Write mojom and StructTraits for DisplaySnapshot. (Closed)
Patch Set: use FILE_PATH_LITERAL to create base::FilePath::StringType 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 #ifndef UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_CC_
kylechar 2017/02/09 15:05:54 Remove.
thanhph1 2017/02/10 19:54:32 Done.
6 #define UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_CC_
7
8 #include "ui/display/mojo/display_snapshot_mojo_struct_traits.h"
9
10 #include "ui/display/mojo/display_mode.mojom.h"
kylechar 2017/02/09 15:05:54 Please deduplicate header and source file includes
thanhph1 2017/02/10 19:54:32 Done. Removed a few.
11 #include "ui/display/mojo/display_mode_struct_traits.h"
12 #include "ui/display/mojo/display_snapshot_mojo.mojom.h"
13 #include "ui/display/types/display_constants.h"
14 #include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
15 #include "ui/gfx/geometry/size.h"
16
17 namespace mojo {
18
19 display::mojom::DisplayConnectionType EnumTraits<
kylechar 2017/02/09 15:05:54 Deduplicate.
thanhph1 2017/02/10 19:54:32 Removed.
20 display::mojom::DisplayConnectionType,
21 display::DisplayConnectionType>::ToMojom(display::DisplayConnectionType
22 type) {
23 switch (type) {
24 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE:
25 return display::mojom::DisplayConnectionType::
26 DISPLAY_CONNECTION_TYPE_NONE;
27
28 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_UNKNOWN:
29 return display::mojom::DisplayConnectionType::
30 DISPLAY_CONNECTION_TYPE_UNKNOWN;
31
32 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_INTERNAL:
33 return display::mojom::DisplayConnectionType::
34 DISPLAY_CONNECTION_TYPE_INTERNAL;
35
36 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VGA:
37 return display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VGA;
38
39 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_HDMI:
40 return display::mojom::DisplayConnectionType::
41 DISPLAY_CONNECTION_TYPE_HDMI;
42
43 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DVI:
44 return display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DVI;
45
46 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DISPLAYPORT:
47 return display::mojom::DisplayConnectionType::
48 DISPLAY_CONNECTION_TYPE_DISPLAYPORT;
49
50 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NETWORK:
51 return display::mojom::DisplayConnectionType::
52 DISPLAY_CONNECTION_TYPE_NETWORK;
53
54 case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VIRTUAL:
55 return display::mojom::DisplayConnectionType::
56 DISPLAY_CONNECTION_TYPE_VIRTUAL;
57 }
58 NOTREACHED();
59 return display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE;
60 }
61
62 // static
63 bool EnumTraits<display::mojom::DisplayConnectionType,
64 display::DisplayConnectionType>::
65 FromMojom(display::mojom::DisplayConnectionType type,
66 display::DisplayConnectionType* out) {
67 switch (type) {
68 case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE:
69 *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE;
70 return true;
71
72 case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_UNKNOWN:
73 *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_UNKNOWN;
74 return true;
75
76 case display::mojom::DisplayConnectionType::
77 DISPLAY_CONNECTION_TYPE_INTERNAL:
78 *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_INTERNAL;
79 return true;
80
81 case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VGA:
82 *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VGA;
83 return true;
84
85 case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_HDMI:
86 *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_HDMI;
87 return true;
88
89 case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DVI:
90 *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DVI;
91 return true;
92
93 case display::mojom::DisplayConnectionType::
94 DISPLAY_CONNECTION_TYPE_DISPLAYPORT:
95 *out =
96 display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DISPLAYPORT;
97 return true;
98
99 case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NETWORK:
100 *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NETWORK;
101 return true;
102
103 case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VIRTUAL:
104 *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VIRTUAL;
105 return true;
106 }
107 NOTREACHED();
108 return false;
109 }
110
111 // static
112 bool StructTraits<display::mojom::DisplaySnapshotMojoDataView,
113 std::unique_ptr<display::DisplaySnapshotMojo>>::
114 Read(display::mojom::DisplaySnapshotMojoDataView data,
115 std::unique_ptr<display::DisplaySnapshotMojo>* out) {
116 int64_t display_id = data.display_id();
kylechar 2017/02/09 15:05:54 You don't really need a temporary variable if ther
thanhph1 2017/02/10 19:54:32 Done.
117
118 gfx::Point origin;
119 if (!data.ReadOrigin(&origin))
120 return false;
121
122 gfx::Size physical_size;
123 if (!data.ReadPhysicalSize(&physical_size))
124 return false;
125
126 display::DisplayConnectionType type;
127 if (!data.ReadType(&type))
128 return false;
129
130 bool is_aspect_preserving_scaling = data.is_aspect_preserving_scaling();
131 bool has_overscan = data.has_overscan();
132 bool has_color_correction_matrix = data.has_color_correction_matrix();
133
134 std::string display_name;
135 if (!data.ReadDisplayName(&display_name))
136 return false;
137
138 base::FilePath::StringType string_path;
139 if (!data.ReadSysPath(&string_path))
140 return false;
141 const base::FilePath::StringPieceType sys_path(string_path);
142 const base::FilePath filePath(sys_path);
143
144 std::vector<std::unique_ptr<display::DisplayMode>> modes1;
145 if (!data.ReadModes(&modes1))
146 return false;
147
148 display::DisplaySnapshot::DisplayModeList modes;
149 for (int i = 0; i < (int)modes1.size(); i++) {
kylechar 2017/02/09 15:05:54 This would be clearer as a for each style loop. Al
thanhph1 2017/02/10 19:54:32 Cool, done!
kylechar 2017/02/10 21:43:30 Oh I see where you got the for_each thing for. Sor
150 std::unique_ptr<const display::DisplayMode> temp(modes1[i]->Clone());
151 modes.push_back(std::move(temp));
kylechar 2017/02/09 15:05:54 Why clone then move? Why not just clone?
thanhph1 2017/02/10 19:54:32 Done.
152 }
153
154 int current_mode_index = data.current_mode_index();
155 if ((current_mode_index < 0) || (current_mode_index >= (int)modes1.size()))
kylechar 2017/02/09 15:05:54 What happens if current_mode == null when you are
thanhph1 2017/02/10 19:54:32 Refactored. current_mode will be null if it doesn'
156 return false;
157 const display::DisplayMode* current_mode = modes[current_mode_index].get();
158
159 int native_mode_index = data.native_mode_index();
160 if ((native_mode_index < 0) || (native_mode_index >= (int)modes1.size()))
161 return false;
162 const display::DisplayMode* native_mode = modes[native_mode_index].get();
163
164 std::vector<uint8_t> edid;
165 if (!data.ReadEdid(&edid))
166 return false;
167 int64_t product_id = data.product_id();
168
169 *out = base::MakeUnique<display::DisplaySnapshotMojo>(
170 display_id, origin, physical_size, type, is_aspect_preserving_scaling,
171 has_overscan, has_color_correction_matrix, display_name, filePath,
172 product_id, std::move(modes), edid, current_mode, native_mode);
173 return true;
174 }
175
176 } // namespace mojo
177
178 #endif // UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_CC_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698