OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/display/display_util_x11.h" | 5 #include "ash/display/display_util_x11.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <X11/extensions/Xrandr.h> | |
10 | 9 |
11 #include "ash/display/display_info.h" | 10 #include "ash/display/display_info.h" |
12 #include "base/logging.h" | 11 #include "base/logging.h" |
13 #include "chromeos/display/output_util.h" | 12 #include "chromeos/display/output_util.h" |
14 | 13 |
14 using chromeos::OutputConfigurator; | |
15 | |
15 namespace ash { | 16 namespace ash { |
16 namespace internal { | 17 namespace internal { |
17 namespace { | 18 namespace { |
18 | 19 |
19 // A list of bogus sizes in mm that X detects that should be ignored. | 20 // A list of bogus sizes in mm that X detects that should be ignored. |
20 // See crbug.com/136533. The first element maintains the minimum | 21 // See crbug.com/136533. The first element maintains the minimum |
21 // size required to be valid size. | 22 // size required to be valid size. |
22 const unsigned long kInvalidDisplaySizeList[][2] = { | 23 const unsigned long kInvalidDisplaySizeList[][2] = { |
23 {40, 30}, | 24 {40, 30}, |
24 {50, 40}, | 25 {50, 40}, |
(...skipping 23 matching lines...) Expand all Loading... | |
48 if (mm_width == size[0] && mm_height == size[1]) { | 49 if (mm_width == size[0] && mm_height == size[1]) { |
49 LOG(WARNING) << "Black listed display size detected:" | 50 LOG(WARNING) << "Black listed display size detected:" |
50 << size[0] << "x" << size[1]; | 51 << size[0] << "x" << size[1]; |
51 return true; | 52 return true; |
52 } | 53 } |
53 } | 54 } |
54 return false; | 55 return false; |
55 } | 56 } |
56 | 57 |
57 std::vector<Resolution> GetResolutionList( | 58 std::vector<Resolution> GetResolutionList( |
58 XRRScreenResources* screen_resources, | 59 const OutputConfigurator::OutputSnapshot& output) { |
oshima
2013/08/16 23:13:05
isn't it better to get this in output_configurator
Daniel Erat
2013/08/16 23:35:36
You mean, move this method to OutputConfigurator?
oshima
2013/08/16 23:54:06
On second thought, no, but we should remove this t
| |
59 XRROutputInfo* output_info) { | |
60 typedef std::map<std::pair<int,int>, Resolution> ResolutionMap; | 60 typedef std::map<std::pair<int,int>, Resolution> ResolutionMap; |
61 | |
62 ResolutionMap resolution_map; | 61 ResolutionMap resolution_map; |
63 | 62 |
64 for (int i = 0; i < output_info->nmode; i++) { | 63 for (std::map<RRMode, OutputConfigurator::ModeInfo>::const_iterator it = |
65 RRMode mode = output_info->modes[i]; | 64 output.mode_infos.begin(); it != output.mode_infos.end(); ++it) { |
66 const XRRModeInfo* info = chromeos::FindXRRModeInfo(screen_resources, mode); | 65 const OutputConfigurator::ModeInfo& mode_info = it->second; |
67 DCHECK(info); | 66 const std::pair<int, int> size(mode_info.width, mode_info.height); |
68 // Just ignore bad entry on Release build. | 67 const Resolution resolution(gfx::Size(mode_info.width, mode_info.height), |
69 if (!info) | 68 mode_info.interlaced); |
70 continue; | |
71 ResolutionMap::key_type size = std::make_pair(info->width, info->height); | |
72 bool interlaced = (info->modeFlags & RR_Interlace) != 0; | |
73 | 69 |
74 ResolutionMap::iterator iter = resolution_map.find(size); | 70 // Add the resolution if it isn't already present and override interlaced |
75 | 71 // resolutions with non-interlaced ones. |
76 // Add new resolution if it's new size or override interlaced mode. | 72 ResolutionMap::iterator resolution_it = resolution_map.find(size); |
77 if (iter == resolution_map.end()) { | 73 if (resolution_it == resolution_map.end()) |
78 resolution_map.insert(ResolutionMap::value_type( | 74 resolution_map.insert(std::make_pair(size, resolution)); |
79 size, | 75 else if (resolution_it->second.interlaced && !resolution.interlaced) |
80 Resolution(gfx::Size(info->width, info->height), interlaced))); | 76 resolution_it->second = resolution; |
81 } else if (iter->second.interlaced && !interlaced) { | |
82 iter->second.interlaced = false; | |
83 } | |
84 } | 77 } |
85 | 78 |
86 std::vector<Resolution> resolution_list; | 79 std::vector<Resolution> resolution_list; |
87 for (ResolutionMap::const_iterator iter = resolution_map.begin(); | 80 for (ResolutionMap::const_iterator iter = resolution_map.begin(); |
88 iter != resolution_map.end(); | 81 iter != resolution_map.end(); |
89 ++iter) { | 82 ++iter) { |
90 resolution_list.push_back(iter->second); | 83 resolution_list.push_back(iter->second); |
91 } | 84 } |
92 std::sort(resolution_list.begin(), resolution_list.end(), ResolutionSorter()); | 85 std::sort(resolution_list.begin(), resolution_list.end(), ResolutionSorter()); |
93 return resolution_list; | 86 return resolution_list; |
94 } | 87 } |
95 | 88 |
96 } // namespace internal | 89 } // namespace internal |
97 } // namespace ash | 90 } // namespace ash |
OLD | NEW |