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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/ozone/common/display_util.cc
diff --git a/ui/ozone/common/display_util.cc b/ui/ozone/common/display_util.cc
index 432e85807e61ef752ca54d82604a5e3a7051cfea..ce2cb19ef42aa9b568812b69ab728292d0a8d808 100644
--- a/ui/ozone/common/display_util.cc
+++ b/ui/ozone/common/display_util.cc
@@ -5,8 +5,13 @@
#include "ui/ozone/common/display_util.h"
#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/threading/thread_restrictions.h"
#include "ui/display/types/display_mode.h"
#include "ui/display/types/display_snapshot.h"
+#include "ui/display/util/edid_parser.h"
+#include "ui/display/util/edid_parser.h"
#include "ui/ozone/public/ozone_switches.h"
namespace ui {
@@ -59,25 +64,19 @@ DisplaySnapshot_Params GetDisplaySnapshotParams(
return params;
}
-DisplaySnapshot_Params CreateSnapshotFromCommandLine() {
- DisplaySnapshot_Params display_param;
-
+bool CreateSnapshotFromCommandLine(DisplaySnapshot_Params* snapshot_out) {
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
std::string spec =
cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayBounds);
std::string physical_spec =
cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayPhysicalSizeMm);
- if (spec.empty())
- return display_param;
-
int width = 0;
int height = 0;
- if (sscanf(spec.c_str(), "%dx%d", &width, &height) < 2)
- return display_param;
-
- if (width == 0 || height == 0)
- return display_param;
+ if (spec.empty() || sscanf(spec.c_str(), "%dx%d", &width, &height) < 2 ||
+ width == 0 || height == 0) {
+ return false;
+ }
int physical_width = 0;
int physical_height = 0;
@@ -87,16 +86,67 @@ DisplaySnapshot_Params CreateSnapshotFromCommandLine() {
mode_param.size = gfx::Size(width, height);
mode_param.refresh_rate = 60;
- display_param.display_id = kDummyDisplayId;
- display_param.modes.push_back(mode_param);
- display_param.type = DISPLAY_CONNECTION_TYPE_INTERNAL;
- display_param.physical_size = gfx::Size(physical_width, physical_height);
- display_param.has_current_mode = true;
- display_param.current_mode = mode_param;
- display_param.has_native_mode = true;
- display_param.native_mode = mode_param;
+ snapshot_out->display_id = kDummyDisplayId;
+ snapshot_out->modes.push_back(mode_param);
+ snapshot_out->type = DISPLAY_CONNECTION_TYPE_INTERNAL;
+ snapshot_out->physical_size = gfx::Size(physical_width, physical_height);
+ snapshot_out->has_current_mode = true;
+ snapshot_out->current_mode = mode_param;
+ snapshot_out->has_native_mode = true;
+ snapshot_out->native_mode = mode_param;
+ return true;
+}
+
+bool CreateSnapshotFromEDID(bool internal,
+ const std::vector<uint8_t>& edid,
+ DisplaySnapshot_Params* snapshot_out) {
+ uint16_t manufacturer_id = 0;
+ gfx::Size resolution;
+
+ DisplayMode_Params mode_param;
+ mode_param.refresh_rate = 60.0f;
+
+ if (!ParseOutputDeviceData(edid, &manufacturer_id,
+ &snapshot_out->display_name, &mode_param.size,
+ &snapshot_out->physical_size) ||
+ !GetDisplayIdFromEDID(edid, 0, &snapshot_out->display_id)) {
+ return false;
+ }
+ ParseOutputOverscanFlag(edid, &snapshot_out->has_overscan);
+
+ snapshot_out->modes.push_back(mode_param);
+ // Use VGA for external display for now.
+ // TODO(oshima): frecon should set this value in the display_info.bin file.
+ snapshot_out->type =
+ internal ? DISPLAY_CONNECTION_TYPE_INTERNAL : DISPLAY_CONNECTION_TYPE_VGA;
+ snapshot_out->has_current_mode = true;
+ snapshot_out->current_mode = mode_param;
+ snapshot_out->has_native_mode = true;
+ snapshot_out->native_mode = mode_param;
+ return true;
+}
- return display_param;
+bool CreateSnapshotFromEDIDFile(const base::FilePath& file,
+ DisplaySnapshot_Params* snapshot_out) {
+ // const base::FilePath kDisplayInfoPath("/tmp/display_info.bin");
+ std::string raw_display_info;
+ {
+ const int kEDIDMaxSize = 128;
+ // Just read it on current thread as this is necessary information
+ // to start.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
spang 2015/01/22 02:25:26 This function is banned, see the red try run for c
+ if (!base::ReadFileToString(file, &raw_display_info, kEDIDMaxSize + 1) ||
+ raw_display_info.size() < 10) {
+ return false;
+ }
+ }
+ std::vector<uint8_t> edid;
+ // The head of the file contains one byte flag that indicates the type of
+ // display.
+ bool internal = raw_display_info[0] == 1;
+ edid.assign(raw_display_info.c_str() + 1,
+ raw_display_info.c_str() + raw_display_info.size());
+ return CreateSnapshotFromEDID(internal, edid, snapshot_out);
}
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698