Chromium Code Reviews| 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 #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 // Returns the index of |mode| in |modes| or uint64_t max if |mode| is null. | |
|
Daniel Erat
2017/03/07 23:47:01
"... or not found."
thanhph
2017/03/08 00:19:23
Done.
| |
| 19 static uint64_t GetModeIndex( | |
| 20 const display::DisplaySnapshot::DisplayModeList& modes, | |
| 21 const display::DisplayMode* mode) { | |
| 22 if (!mode) | |
| 23 return std::numeric_limits<uint64_t>::max(); | |
| 24 | |
| 25 for (size_t i = 0; i < modes.size(); ++i) { | |
| 26 if (modes[i].get()->size() == mode->size() && | |
| 27 modes[i].get()->is_interlaced() == mode->is_interlaced() && | |
| 28 modes[i].get()->refresh_rate() == mode->refresh_rate()) | |
| 29 return i; | |
| 30 } | |
| 31 NOTREACHED(); | |
| 32 return std::numeric_limits<uint64_t>::max(); | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 // static | |
| 38 std::vector<std::unique_ptr<display::DisplayMode>> | |
| 39 StructTraits<display::mojom::DisplaySnapshotMojoDataView, | |
| 40 std::unique_ptr<display::DisplaySnapshotMojo>>:: | |
| 41 modes( | |
| 42 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 43 std::vector<std::unique_ptr<display::DisplayMode>> display_mode_list; | |
| 44 | |
| 45 for (const auto& display_mode : display_snapshot->modes()) | |
| 46 display_mode_list.push_back(display_mode->Clone()); | |
| 47 | |
| 48 return display_mode_list; | |
| 49 } | |
| 50 | |
| 51 // static | |
| 52 uint64_t StructTraits<display::mojom::DisplaySnapshotMojoDataView, | |
| 53 std::unique_ptr<display::DisplaySnapshotMojo>>:: | |
| 54 current_mode_index( | |
| 55 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 56 return GetModeIndex(display_snapshot->modes(), | |
| 57 display_snapshot->current_mode()); | |
| 58 } | |
| 59 | |
| 60 // static | |
| 61 uint64_t StructTraits<display::mojom::DisplaySnapshotMojoDataView, | |
| 62 std::unique_ptr<display::DisplaySnapshotMojo>>:: | |
| 63 native_mode_index( | |
| 64 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 65 return GetModeIndex(display_snapshot->modes(), | |
| 66 display_snapshot->native_mode()); | |
| 67 } | |
| 68 | |
| 69 // static | |
| 70 bool StructTraits<display::mojom::DisplaySnapshotMojoDataView, | |
| 71 std::unique_ptr<display::DisplaySnapshotMojo>>:: | |
| 72 Read(display::mojom::DisplaySnapshotMojoDataView data, | |
| 73 std::unique_ptr<display::DisplaySnapshotMojo>* out) { | |
| 74 gfx::Point origin; | |
| 75 if (!data.ReadOrigin(&origin)) | |
| 76 return false; | |
| 77 | |
| 78 gfx::Size physical_size; | |
| 79 if (!data.ReadPhysicalSize(&physical_size)) | |
| 80 return false; | |
| 81 | |
| 82 display::DisplayConnectionType type; | |
| 83 if (!data.ReadType(&type)) | |
| 84 return false; | |
| 85 | |
| 86 std::string display_name; | |
| 87 if (!data.ReadDisplayName(&display_name)) | |
| 88 return false; | |
| 89 | |
| 90 base::FilePath file_path; | |
| 91 if (!data.ReadSysPath(&file_path)) | |
| 92 return false; | |
| 93 | |
| 94 // There is a type mismatch between vectors containing unique_ptr<T> vs | |
| 95 // unique_ptr<const T>. We deserialize into a vector of unique_ptr<T> | |
| 96 // then create a vector of unique_ptr<const T> after. | |
| 97 std::vector<std::unique_ptr<display::DisplayMode>> non_const_modes; | |
| 98 if (!data.ReadModes(&non_const_modes)) | |
| 99 return false; | |
| 100 display::DisplaySnapshot::DisplayModeList modes; | |
| 101 for (auto& mode : non_const_modes) | |
| 102 modes.push_back(std::move(mode)); | |
| 103 | |
| 104 // Get current_mode pointer from modes array. | |
| 105 const display::DisplayMode* current_mode = nullptr; | |
| 106 if (data.has_current_mode()) { | |
| 107 size_t current_mode_index = data.current_mode_index(); | |
| 108 if (current_mode_index >= modes.size()) | |
| 109 return false; | |
| 110 current_mode = modes[current_mode_index].get(); | |
| 111 } | |
| 112 | |
| 113 // Get native_mode pointer from modes array. | |
| 114 const display::DisplayMode* native_mode = nullptr; | |
| 115 if (data.has_native_mode()) { | |
| 116 size_t native_mode_index = data.native_mode_index(); | |
| 117 if (native_mode_index >= modes.size()) | |
| 118 return false; | |
| 119 native_mode = modes[native_mode_index].get(); | |
| 120 } | |
| 121 | |
| 122 std::vector<uint8_t> edid; | |
| 123 if (!data.ReadEdid(&edid)) | |
| 124 return false; | |
| 125 | |
| 126 gfx::Size maximum_cursor_size; | |
| 127 if (!data.ReadMaximumCursorSize(&maximum_cursor_size)) | |
| 128 return false; | |
| 129 | |
| 130 *out = base::MakeUnique<display::DisplaySnapshotMojo>( | |
| 131 data.display_id(), origin, physical_size, type, | |
| 132 data.is_aspect_preserving_scaling(), data.has_overscan(), | |
| 133 data.has_color_correction_matrix(), display_name, file_path, | |
| 134 data.product_id(), std::move(modes), std::move(edid), current_mode, | |
| 135 native_mode, maximum_cursor_size); | |
| 136 return true; | |
| 137 } | |
| 138 | |
| 139 } // namespace mojo | |
| OLD | NEW |