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
3 // found in the LICENSE file.
5 #include "ui/ozone/common/display_util.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "ui/display/types/display_mode.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"
14 #include "ui/ozone/public/ozone_switches.h"
20 const int64_t kDummyDisplayId
= 1;
21 const int64_t kDummyProductId
= 1;
25 FindDisplayById::FindDisplayById(int64_t display_id
) : display_id_(display_id
) {
28 bool FindDisplayById::operator()(const DisplaySnapshot_Params
& display
) const {
29 return display
.display_id
== display_id_
;
32 DisplayMode_Params
GetDisplayModeParams(const DisplayMode
& mode
) {
33 DisplayMode_Params params
;
34 params
.size
= mode
.size();
35 params
.is_interlaced
= mode
.is_interlaced();
36 params
.refresh_rate
= mode
.refresh_rate();
41 DisplaySnapshot_Params
GetDisplaySnapshotParams(
42 const DisplaySnapshot
& display
) {
43 DisplaySnapshot_Params params
;
44 params
.display_id
= display
.display_id();
45 params
.origin
= display
.origin();
46 params
.physical_size
= display
.physical_size();
47 params
.type
= display
.type();
48 params
.is_aspect_preserving_scaling
= display
.is_aspect_preserving_scaling();
49 params
.has_overscan
= display
.has_overscan();
50 params
.display_name
= display
.display_name();
51 for (size_t i
= 0; i
< display
.modes().size(); ++i
)
52 params
.modes
.push_back(GetDisplayModeParams(*display
.modes()[i
]));
54 params
.has_current_mode
= display
.current_mode() != NULL
;
55 if (params
.has_current_mode
)
56 params
.current_mode
= GetDisplayModeParams(*display
.current_mode());
58 params
.has_native_mode
= display
.native_mode() != NULL
;
59 if (params
.has_native_mode
)
60 params
.native_mode
= GetDisplayModeParams(*display
.native_mode());
62 params
.product_id
= display
.product_id();
63 params
.string_representation
= display
.ToString();
68 bool CreateSnapshotFromCommandLine(DisplaySnapshot_Params
* snapshot_out
) {
69 base::CommandLine
* cmd
= base::CommandLine::ForCurrentProcess();
71 cmd
->GetSwitchValueASCII(switches::kOzoneInitialDisplayBounds
);
72 std::string physical_spec
=
73 cmd
->GetSwitchValueASCII(switches::kOzoneInitialDisplayPhysicalSizeMm
);
77 if (spec
.empty() || sscanf(spec
.c_str(), "%dx%d", &width
, &height
) < 2 ||
78 width
== 0 || height
== 0) {
82 int physical_width
= 0;
83 int physical_height
= 0;
84 sscanf(physical_spec
.c_str(), "%dx%d", &physical_width
, &physical_height
);
86 DisplayMode_Params mode_param
;
87 mode_param
.size
= gfx::Size(width
, height
);
88 mode_param
.refresh_rate
= 60;
90 snapshot_out
->display_id
= kDummyDisplayId
;
91 snapshot_out
->modes
.push_back(mode_param
);
92 snapshot_out
->type
= DISPLAY_CONNECTION_TYPE_INTERNAL
;
93 snapshot_out
->physical_size
= gfx::Size(physical_width
, physical_height
);
94 snapshot_out
->has_current_mode
= true;
95 snapshot_out
->current_mode
= mode_param
;
96 snapshot_out
->has_native_mode
= true;
97 snapshot_out
->native_mode
= mode_param
;
98 snapshot_out
->product_id
= kDummyProductId
;