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 #ifndef UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_H_ | |
| 6 #define UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_H_ | |
| 7 | |
| 8 #include "ui/display/mojo/display_mode.mojom.h" | |
| 9 #include "ui/display/mojo/display_mode_struct_traits.h" | |
| 10 #include "ui/display/mojo/display_snapshot_mojo.mojom.h" | |
|
kylechar
2017/02/09 15:05:54
You are missing an import for DisplaySnapshotMojo.
thanhph1
2017/02/10 19:54:32
Done.
| |
| 11 | |
| 12 namespace mojo { | |
| 13 | |
| 14 template <> | |
| 15 struct EnumTraits<display::mojom::DisplayConnectionType, | |
|
kylechar
2017/02/09 15:05:54
Why is the defined twice?
thanhph1
2017/02/10 19:54:32
Removed.
| |
| 16 display::DisplayConnectionType> { | |
| 17 static display::mojom::DisplayConnectionType ToMojom( | |
| 18 display::DisplayConnectionType type); | |
| 19 static bool FromMojom(display::mojom::DisplayConnectionType type, | |
| 20 display::DisplayConnectionType* out); | |
| 21 }; | |
| 22 | |
| 23 template <> | |
| 24 struct StructTraits<display::mojom::DisplaySnapshotMojoDataView, | |
| 25 std::unique_ptr<display::DisplaySnapshotMojo>> { | |
| 26 static int64_t display_id( | |
| 27 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 28 return display_snapshot->display_id(); | |
| 29 } | |
| 30 | |
| 31 static gfx::Point origin( | |
| 32 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 33 return display_snapshot->origin(); | |
| 34 } | |
| 35 | |
| 36 static gfx::Size physical_size( | |
| 37 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 38 return display_snapshot->physical_size(); | |
| 39 } | |
| 40 | |
| 41 static display::DisplayConnectionType type( | |
| 42 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 43 return display_snapshot->type(); | |
| 44 } | |
| 45 | |
| 46 static bool is_aspect_preserving_scaling( | |
| 47 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 48 return display_snapshot->is_aspect_preserving_scaling(); | |
| 49 } | |
| 50 | |
| 51 static bool has_overscan( | |
| 52 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 53 return display_snapshot->has_overscan(); | |
| 54 } | |
| 55 | |
| 56 static bool has_color_correction_matrix( | |
| 57 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 58 return display_snapshot->has_color_correction_matrix(); | |
| 59 } | |
| 60 | |
| 61 static std::string display_name( | |
| 62 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 63 return display_snapshot->display_name(); | |
| 64 } | |
| 65 | |
| 66 static const base::FilePath::StringType sys_path( | |
|
kylechar
2017/02/09 15:05:54
I think you can just use FilePath in your mojom. T
thanhph1
2017/02/10 19:54:32
Nice, thanks. I didn't this exists. Updated!
| |
| 67 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 68 return display_snapshot->sys_path().value(); | |
| 69 } | |
| 70 | |
| 71 static bool compareDisplayMode(const display::DisplayMode* display_mode_a, | |
|
kylechar
2017/02/09 15:05:54
Many problems here.
1. This doesn't belong in the
thanhph1
2017/02/10 19:54:33
Nice, thanks. I use the name display_mode_lhs and
| |
| 72 const display::DisplayMode* display_mode_b) { | |
| 73 if ((display_mode_a->size() != display_mode_b->size()) || | |
|
kylechar
2017/02/09 15:05:54
return lhs.size() == rhs.size() && ...;
thanhph1
2017/02/10 19:54:32
Done.
| |
| 74 (display_mode_a->is_interlaced() != display_mode_b->is_interlaced()) || | |
| 75 (display_mode_a->refresh_rate() != display_mode_b->refresh_rate())) | |
| 76 return false; | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 static std::vector<uint8_t> edid( | |
| 81 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 82 return display_snapshot->edid(); | |
| 83 } | |
| 84 | |
| 85 static std::vector<std::unique_ptr<display::DisplayMode>> modes( | |
| 86 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 87 std::vector<std::unique_ptr<display::DisplayMode>> display_mode_list; | |
|
kylechar
2017/02/09 15:05:54
You know the size, tell the constructor so it can
thanhph1
2017/02/10 19:54:32
Done.
| |
| 88 for (const auto& display_mode : display_snapshot->modes()) | |
| 89 display_mode_list.push_back(display_mode->Clone()); | |
| 90 return display_mode_list; | |
| 91 } | |
| 92 | |
| 93 static int64_t current_mode_index( | |
| 94 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
|
kylechar
2017/02/09 15:05:54
Only one liner methods should go in the header. Mo
thanhph1
2017/02/10 19:54:32
Done.
| |
| 95 for (int i = 0; i < (int)display_snapshot->modes().size(); i++) { | |
|
kylechar
2017/02/09 15:05:54
You aren't allowed to use C style casts.
https://
thanhph1
2017/02/10 19:54:32
Cool, thanks!
| |
| 96 if (compareDisplayMode(display_snapshot->modes()[i].get(), | |
|
kylechar
2017/02/09 15:05:54
It would help for readability if you had done some
thanhph1
2017/02/10 19:54:33
nice, done!
| |
| 97 display_snapshot->current_mode())) | |
| 98 return i; | |
| 99 } | |
| 100 return -1; | |
| 101 } | |
| 102 | |
| 103 static int64_t native_mode_index( | |
| 104 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
|
kylechar
2017/02/09 15:05:54
Same as above.
thanhph1
2017/02/10 19:54:32
Done.
| |
| 105 for (int i = 0; i < (int)display_snapshot->modes().size(); i++) { | |
| 106 if (compareDisplayMode(display_snapshot->modes()[i].get(), | |
| 107 display_snapshot->native_mode())) | |
| 108 return i; | |
| 109 } | |
| 110 return -1; | |
| 111 } | |
| 112 | |
| 113 static int64_t product_id( | |
| 114 const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { | |
| 115 return display_snapshot->product_id(); | |
| 116 } | |
| 117 | |
| 118 static bool Read(display::mojom::DisplaySnapshotMojoDataView data, | |
| 119 std::unique_ptr<display::DisplaySnapshotMojo>* out); | |
| 120 }; | |
| 121 | |
| 122 } // namespace mojo | |
| 123 | |
| 124 #endif // UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_H_ | |
| OLD | NEW |