OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/ozone/common/display_util.h" | 5 #include "ui/ozone/common/display_util.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" |
8 #include "ui/display/types/display_mode.h" | 10 #include "ui/display/types/display_mode.h" |
9 #include "ui/display/types/display_snapshot.h" | 11 #include "ui/display/types/display_snapshot.h" |
| 12 #include "ui/display/util/edid_parser.h" |
| 13 #include "ui/display/util/edid_parser.h" |
10 #include "ui/ozone/public/ozone_switches.h" | 14 #include "ui/ozone/public/ozone_switches.h" |
11 | 15 |
12 namespace ui { | 16 namespace ui { |
13 | 17 |
14 namespace { | 18 namespace { |
15 | 19 |
16 const int64_t kDummyDisplayId = 1; | 20 const int64_t kDummyDisplayId = 1; |
17 | 21 |
18 } // namespace | 22 } // namespace |
19 | 23 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 56 |
53 params.has_native_mode = display.native_mode() != NULL; | 57 params.has_native_mode = display.native_mode() != NULL; |
54 if (params.has_native_mode) | 58 if (params.has_native_mode) |
55 params.native_mode = GetDisplayModeParams(*display.native_mode()); | 59 params.native_mode = GetDisplayModeParams(*display.native_mode()); |
56 | 60 |
57 params.string_representation = display.ToString(); | 61 params.string_representation = display.ToString(); |
58 | 62 |
59 return params; | 63 return params; |
60 } | 64 } |
61 | 65 |
62 DisplaySnapshot_Params CreateSnapshotFromCommandLine() { | 66 bool CreateSnapshotFromCommandLine(DisplaySnapshot_Params* snapshot_out) { |
63 DisplaySnapshot_Params display_param; | |
64 | |
65 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 67 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
66 std::string spec = | 68 std::string spec = |
67 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayBounds); | 69 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayBounds); |
68 std::string physical_spec = | 70 std::string physical_spec = |
69 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayPhysicalSizeMm); | 71 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayPhysicalSizeMm); |
70 | 72 |
71 if (spec.empty()) | |
72 return display_param; | |
73 | |
74 int width = 0; | 73 int width = 0; |
75 int height = 0; | 74 int height = 0; |
76 if (sscanf(spec.c_str(), "%dx%d", &width, &height) < 2) | 75 if (spec.empty() || sscanf(spec.c_str(), "%dx%d", &width, &height) < 2 || |
77 return display_param; | 76 width == 0 || height == 0) { |
78 | 77 return false; |
79 if (width == 0 || height == 0) | 78 } |
80 return display_param; | |
81 | 79 |
82 int physical_width = 0; | 80 int physical_width = 0; |
83 int physical_height = 0; | 81 int physical_height = 0; |
84 sscanf(physical_spec.c_str(), "%dx%d", &physical_width, &physical_height); | 82 sscanf(physical_spec.c_str(), "%dx%d", &physical_width, &physical_height); |
85 | 83 |
86 DisplayMode_Params mode_param; | 84 DisplayMode_Params mode_param; |
87 mode_param.size = gfx::Size(width, height); | 85 mode_param.size = gfx::Size(width, height); |
88 mode_param.refresh_rate = 60; | 86 mode_param.refresh_rate = 60; |
89 | 87 |
90 display_param.display_id = kDummyDisplayId; | 88 snapshot_out->display_id = kDummyDisplayId; |
91 display_param.modes.push_back(mode_param); | 89 snapshot_out->modes.push_back(mode_param); |
92 display_param.type = DISPLAY_CONNECTION_TYPE_INTERNAL; | 90 snapshot_out->type = DISPLAY_CONNECTION_TYPE_INTERNAL; |
93 display_param.physical_size = gfx::Size(physical_width, physical_height); | 91 snapshot_out->physical_size = gfx::Size(physical_width, physical_height); |
94 display_param.has_current_mode = true; | 92 snapshot_out->has_current_mode = true; |
95 display_param.current_mode = mode_param; | 93 snapshot_out->current_mode = mode_param; |
96 display_param.has_native_mode = true; | 94 snapshot_out->has_native_mode = true; |
97 display_param.native_mode = mode_param; | 95 snapshot_out->native_mode = mode_param; |
| 96 return true; |
| 97 } |
98 | 98 |
99 return display_param; | 99 bool CreateSnapshotFromEDID(bool internal, |
| 100 const std::vector<uint8_t>& edid, |
| 101 DisplaySnapshot_Params* snapshot_out) { |
| 102 uint16_t manufacturer_id = 0; |
| 103 gfx::Size resolution; |
| 104 |
| 105 DisplayMode_Params mode_param; |
| 106 mode_param.refresh_rate = 60.0f; |
| 107 |
| 108 if (!ParseOutputDeviceData(edid, &manufacturer_id, |
| 109 &snapshot_out->display_name, &mode_param.size, |
| 110 &snapshot_out->physical_size) || |
| 111 !GetDisplayIdFromEDID(edid, 0, &snapshot_out->display_id)) { |
| 112 return false; |
| 113 } |
| 114 ParseOutputOverscanFlag(edid, &snapshot_out->has_overscan); |
| 115 |
| 116 snapshot_out->modes.push_back(mode_param); |
| 117 // Use VGA for external display for now. |
| 118 // TODO(oshima): frecon should set this value in the display_info.bin file. |
| 119 snapshot_out->type = |
| 120 internal ? DISPLAY_CONNECTION_TYPE_INTERNAL : DISPLAY_CONNECTION_TYPE_VGA; |
| 121 snapshot_out->has_current_mode = true; |
| 122 snapshot_out->current_mode = mode_param; |
| 123 snapshot_out->has_native_mode = true; |
| 124 snapshot_out->native_mode = mode_param; |
| 125 return true; |
| 126 } |
| 127 |
| 128 bool CreateSnapshotFromEDIDFile(const base::FilePath& file, |
| 129 DisplaySnapshot_Params* snapshot_out) { |
| 130 std::string raw_display_info; |
| 131 const int kEDIDMaxSize = 128; |
| 132 if (!base::ReadFileToString(file, &raw_display_info, kEDIDMaxSize + 1) || |
| 133 raw_display_info.size() < 10) { |
| 134 return false; |
| 135 } |
| 136 std::vector<uint8_t> edid; |
| 137 // The head of the file contains one byte flag that indicates the type of |
| 138 // display. |
| 139 bool internal = raw_display_info[0] == 1; |
| 140 edid.assign(raw_display_info.c_str() + 1, |
| 141 raw_display_info.c_str() + raw_display_info.size()); |
| 142 return CreateSnapshotFromEDID(internal, edid, snapshot_out); |
100 } | 143 } |
101 | 144 |
102 } // namespace ui | 145 } // namespace ui |
OLD | NEW |