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

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 filepath mojom 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 // static
17 bool StructTraits<display::mojom::DisplaySnapshotMojoDataView,
18 std::unique_ptr<display::DisplaySnapshotMojo>>::
19 compare_display_mode(const display::DisplayMode& display_mode_lhs,
20 const display::DisplayMode& display_mode_rhs) {
21 return (display_mode_lhs.size() == display_mode_rhs.size()) &&
22 (display_mode_lhs.is_interlaced() ==
23 display_mode_rhs.is_interlaced()) &&
24 (display_mode_lhs.refresh_rate() == display_mode_rhs.refresh_rate());
25 }
26
27 // static
28 std::vector<std::unique_ptr<display::DisplayMode>>
29 StructTraits<display::mojom::DisplaySnapshotMojoDataView,
30 std::unique_ptr<display::DisplaySnapshotMojo>>::
31 modes(
32 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) {
33 std::vector<std::unique_ptr<display::DisplayMode>> display_mode_list;
34 display_mode_list.reserve(display_snapshot->modes().size());
kylechar 2017/02/10 21:40:29 You are creating a vector with the default size th
thanhph1 2017/02/13 20:09:11 Done.
35
36 for (const auto& display_mode : display_snapshot->modes())
37 display_mode_list.push_back(display_mode->Clone());
38 return display_mode_list;
39 }
40
41 // static
42 int64_t StructTraits<display::mojom::DisplaySnapshotMojoDataView,
43 std::unique_ptr<display::DisplaySnapshotMojo>>::
44 current_mode_index(
45 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) {
kylechar 2017/02/10 21:40:29 if (!display_snapshot->current_mode()) return ba
thanhph1 2017/02/13 20:09:11 Done, cool! Since we won't use base::Optional<uint
46 auto& modes = display_snapshot->modes();
47 for (size_t i = 0; i < modes.size(); ++i) {
48 if (compare_display_mode(*modes[i].get(),
49 *display_snapshot->current_mode()))
50 return i;
kylechar 2017/02/10 21:40:29 You'll need to change this to work with base::Opti
thanhph1 2017/02/13 20:09:11 As discussed, I'll use uint64_t and a bool to repl
51 }
52 return -1;
kylechar 2017/02/10 21:40:29 NOTREACHED(); return base::Optional<uint64_t>();
thanhph1 2017/02/13 20:09:11 Done.
53 }
54
55 // static
56 int64_t StructTraits<display::mojom::DisplaySnapshotMojoDataView,
57 std::unique_ptr<display::DisplaySnapshotMojo>>::
58 native_mode_index(
59 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) {
60 auto& modes = display_snapshot->modes();
kylechar 2017/02/10 21:40:29 Adding a helper function in an anonymous namespace
thanhph1 2017/02/13 20:09:11 Done.
61 for (size_t i = 0; i < modes.size(); ++i)
62 if (compare_display_mode(*modes[i].get(), *display_snapshot->native_mode()))
63 return i;
64 return -1;
65 }
66
67 // static
68 bool StructTraits<display::mojom::DisplaySnapshotMojoDataView,
69 std::unique_ptr<display::DisplaySnapshotMojo>>::
70 Read(display::mojom::DisplaySnapshotMojoDataView data,
71 std::unique_ptr<display::DisplaySnapshotMojo>* out) {
72 gfx::Point origin;
73 if (!data.ReadOrigin(&origin))
74 return false;
75
76 gfx::Size physical_size;
77 if (!data.ReadPhysicalSize(&physical_size))
78 return false;
79
80 display::DisplayConnectionType type;
81 if (!data.ReadType(&type))
82 return false;
83
84 std::string display_name;
85 if (!data.ReadDisplayName(&display_name))
86 return false;
87
88 base::FilePath filePath;
89 if (!data.ReadSysPath(&filePath))
90 return false;
91
92 std::vector<std::unique_ptr<display::DisplayMode>> modes1;
kylechar 2017/02/10 21:40:29 Please change the name, modes1 doesn't tell us any
thanhph1 2017/02/13 20:09:11 |modes1| contains non-const display::DisplayMode w
93 if (!data.ReadModes(&modes1))
94 return false;
95
96 display::DisplaySnapshot::DisplayModeList modes;
97 for_each(modes1.begin(), modes1.end(),
kylechar 2017/02/10 21:40:29 A few things: 1. Sometimes it makes sense to do th
thanhph1 2017/02/13 20:09:12 Thanks, cool! mojom doesn't allow to use const var
98 [&modes](std::unique_ptr<display::DisplayMode>& i) {
99 modes.push_back(i->Clone());
100 });
101
102 // Get current_mode pointer from modes1 array.
103 int current_mode_index = data.current_mode_index();
kylechar 2017/02/10 21:40:29 You are converting int64_t to int here which could
thanhph1 2017/02/13 20:09:11 Good catch, thanks! I'll change to int64_t instead
104 if (current_mode_index >= (int)modes1.size())
kylechar 2017/02/10 21:40:29 https://google.github.io/styleguide/cppguide.html#
thanhph1 2017/02/13 20:09:11 Removed this line.
105 return false;
106 const display::DisplayMode* current_mode = nullptr;
107 if (current_mode_index > 0)
108 current_mode = modes[current_mode_index].get();
109
110 // Get native_mode pointer from modes1 array.
kylechar 2017/02/10 21:40:30 Helper function again.
thanhph1 2017/02/13 20:09:12 Done.
111 int native_mode_index = data.native_mode_index();
112 if (native_mode_index >= (int)modes1.size())
113 return false;
114 const display::DisplayMode* native_mode = nullptr;
115 if (native_mode_index > 0)
116 native_mode = modes[native_mode_index].get();
117
118 std::vector<uint8_t> edid;
119 if (!data.ReadEdid(&edid))
120 return false;
121
122 *out = base::MakeUnique<display::DisplaySnapshotMojo>(
123 data.display_id(), origin, physical_size, type,
124 data.is_aspect_preserving_scaling(), data.has_overscan(),
125 data.has_color_correction_matrix(), display_name, filePath,
126 data.product_id(), std::move(modes), edid, current_mode, native_mode);
127 return true;
128 }
129
130 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698