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

Side by Side Diff: ui/ozone/common/display_util.cc

Issue 854203002: Read EDID for the 1st display for startup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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"
10 #include "base/threading/thread_restrictions.h"
8 #include "ui/display/types/display_mode.h" 11 #include "ui/display/types/display_mode.h"
9 #include "ui/display/types/display_snapshot.h" 12 #include "ui/display/types/display_snapshot.h"
13 #include "ui/display/util/edid_parser.h"
14 #include "ui/display/util/edid_parser.h"
10 #include "ui/ozone/public/ozone_switches.h" 15 #include "ui/ozone/public/ozone_switches.h"
11 16
12 namespace ui { 17 namespace ui {
13 18
14 namespace { 19 namespace {
15 20
16 const int64_t kDummyDisplayId = 1; 21 const int64_t kDummyDisplayId = 1;
17 22
18 } // namespace 23 } // namespace
19 24
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 57
53 params.has_native_mode = display.native_mode() != NULL; 58 params.has_native_mode = display.native_mode() != NULL;
54 if (params.has_native_mode) 59 if (params.has_native_mode)
55 params.native_mode = GetDisplayModeParams(*display.native_mode()); 60 params.native_mode = GetDisplayModeParams(*display.native_mode());
56 61
57 params.string_representation = display.ToString(); 62 params.string_representation = display.ToString();
58 63
59 return params; 64 return params;
60 } 65 }
61 66
62 DisplaySnapshot_Params CreateSnapshotFromCommandLine() { 67 bool CreateSnapshotFromCommandLine(DisplaySnapshot_Params* snapshot_out) {
63 DisplaySnapshot_Params display_param;
64
65 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); 68 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
66 std::string spec = 69 std::string spec =
67 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayBounds); 70 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayBounds);
68 std::string physical_spec = 71 std::string physical_spec =
69 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayPhysicalSizeMm); 72 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayPhysicalSizeMm);
70 73
71 if (spec.empty())
72 return display_param;
73
74 int width = 0; 74 int width = 0;
75 int height = 0; 75 int height = 0;
76 if (sscanf(spec.c_str(), "%dx%d", &width, &height) < 2) 76 if (spec.empty() || sscanf(spec.c_str(), "%dx%d", &width, &height) < 2 ||
77 return display_param; 77 width == 0 || height == 0) {
78 78 return false;
79 if (width == 0 || height == 0) 79 }
80 return display_param;
81 80
82 int physical_width = 0; 81 int physical_width = 0;
83 int physical_height = 0; 82 int physical_height = 0;
84 sscanf(physical_spec.c_str(), "%dx%d", &physical_width, &physical_height); 83 sscanf(physical_spec.c_str(), "%dx%d", &physical_width, &physical_height);
85 84
86 DisplayMode_Params mode_param; 85 DisplayMode_Params mode_param;
87 mode_param.size = gfx::Size(width, height); 86 mode_param.size = gfx::Size(width, height);
88 mode_param.refresh_rate = 60; 87 mode_param.refresh_rate = 60;
89 88
90 display_param.display_id = kDummyDisplayId; 89 snapshot_out->display_id = kDummyDisplayId;
91 display_param.modes.push_back(mode_param); 90 snapshot_out->modes.push_back(mode_param);
92 display_param.type = DISPLAY_CONNECTION_TYPE_INTERNAL; 91 snapshot_out->type = DISPLAY_CONNECTION_TYPE_INTERNAL;
93 display_param.physical_size = gfx::Size(physical_width, physical_height); 92 snapshot_out->physical_size = gfx::Size(physical_width, physical_height);
94 display_param.has_current_mode = true; 93 snapshot_out->has_current_mode = true;
95 display_param.current_mode = mode_param; 94 snapshot_out->current_mode = mode_param;
96 display_param.has_native_mode = true; 95 snapshot_out->has_native_mode = true;
97 display_param.native_mode = mode_param; 96 snapshot_out->native_mode = mode_param;
97 return true;
98 }
98 99
99 return display_param; 100 bool CreateSnapshotFromEDID(bool internal,
101 std::vector<uint8_t> edid,
102 DisplaySnapshot_Params* snapshot_out) {
103 uint16_t manufacturer_id = 0;
104 gfx::Size resolution;
105
106 DisplayMode_Params mode_param;
107 mode_param.refresh_rate = 60.0f;
108
109 if (!ParseOutputDeviceData(edid, &manufacturer_id,
110 &snapshot_out->display_name, &mode_param.size,
111 &snapshot_out->physical_size) ||
112 !GetDisplayIdFromEDID(edid, 0, &snapshot_out->display_id)) {
113 return false;
114 }
115 ParseOutputOverscanFlag(edid, &snapshot_out->has_overscan);
116
117 snapshot_out->modes.push_back(mode_param);
118 // Use VGA for external display for now.
119 // TODO(oshima): frecon should set this value in the display_info.bin file.
120 snapshot_out->type =
121 internal ? DISPLAY_CONNECTION_TYPE_INTERNAL : DISPLAY_CONNECTION_TYPE_VGA;
122 snapshot_out->has_current_mode = true;
123 snapshot_out->current_mode = mode_param;
124 snapshot_out->has_native_mode = true;
125 snapshot_out->native_mode = mode_param;
126 return true;
127 }
128
129 bool CreateSnapshotFromEDIDFile(const base::FilePath& file,
130 DisplaySnapshot_Params* snapshot_out) {
131 // const base::FilePath kDisplayInfoPath("/tmp/display_info.bin");
132 std::string raw_display_info;
133 {
134 const int kEDIDMaxSize = 128;
135 // Just read it on current thread as this is necessary information
136 // to start.
137 base::ThreadRestrictions::ScopedAllowIO allow_io;
138 if (!base::ReadFileToString(file, &raw_display_info, kEDIDMaxSize + 1) ||
139 raw_display_info.size() < 10) {
140 return false;
141 }
142 }
143 std::vector<uint8_t> edid;
144 // The head of the file contains one byte flag that indicates the type of
145 // display.
146 bool internal = raw_display_info[0] == 1;
147 edid.assign(raw_display_info.c_str() + 1,
148 raw_display_info.c_str() + raw_display_info.size());
149 return CreateSnapshotFromEDID(internal, edid, snapshot_out);
100 } 150 }
101 151
102 } // namespace ui 152 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698