OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ui/ozone/common/display_util.h" |
| 6 |
| 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" |
| 15 |
| 16 namespace ui { |
| 17 |
| 18 namespace { |
| 19 |
| 20 const int64_t kDummyDisplayId = 1; |
| 21 const int64_t kDummyProductId = 1; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 FindDisplayById::FindDisplayById(int64_t display_id) : display_id_(display_id) { |
| 26 } |
| 27 |
| 28 bool FindDisplayById::operator()(const DisplaySnapshot_Params& display) const { |
| 29 return display.display_id == display_id_; |
| 30 } |
| 31 |
| 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(); |
| 37 |
| 38 return params; |
| 39 } |
| 40 |
| 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])); |
| 53 |
| 54 params.has_current_mode = display.current_mode() != NULL; |
| 55 if (params.has_current_mode) |
| 56 params.current_mode = GetDisplayModeParams(*display.current_mode()); |
| 57 |
| 58 params.has_native_mode = display.native_mode() != NULL; |
| 59 if (params.has_native_mode) |
| 60 params.native_mode = GetDisplayModeParams(*display.native_mode()); |
| 61 |
| 62 params.product_id = display.product_id(); |
| 63 params.string_representation = display.ToString(); |
| 64 |
| 65 return params; |
| 66 } |
| 67 |
| 68 bool CreateSnapshotFromCommandLine(DisplaySnapshot_Params* snapshot_out) { |
| 69 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 70 std::string spec = |
| 71 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayBounds); |
| 72 std::string physical_spec = |
| 73 cmd->GetSwitchValueASCII(switches::kOzoneInitialDisplayPhysicalSizeMm); |
| 74 |
| 75 int width = 0; |
| 76 int height = 0; |
| 77 if (spec.empty() || sscanf(spec.c_str(), "%dx%d", &width, &height) < 2 || |
| 78 width == 0 || height == 0) { |
| 79 return false; |
| 80 } |
| 81 |
| 82 int physical_width = 0; |
| 83 int physical_height = 0; |
| 84 sscanf(physical_spec.c_str(), "%dx%d", &physical_width, &physical_height); |
| 85 |
| 86 DisplayMode_Params mode_param; |
| 87 mode_param.size = gfx::Size(width, height); |
| 88 mode_param.refresh_rate = 60; |
| 89 |
| 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; |
| 99 return true; |
| 100 } |
| 101 |
| 102 } // namespace ui |
OLD | NEW |