Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "ash/display/display_util_x11.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <map> | |
| 9 #include <X11/extensions/Xrandr.h> | |
| 10 | |
| 11 #include "ash/display/display_info.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "chromeos/display/output_util.h" | |
| 14 | |
| 15 namespace ash { | |
| 16 namespace internal { | |
| 17 namespace { | |
| 18 | |
| 19 // A list of bogus sizes in mm that X detects and should be ignored. | |
|
Daniel Erat
2013/07/31 17:34:05
nit: s/and should/and that should/
oshima
2013/07/31 21:59:49
Done.
| |
| 20 // See crbug.com/136533. | |
| 21 const unsigned long kInvalidDisplaySizeList[][2] = { | |
|
Daniel Erat
2013/07/31 17:34:05
add a comment stating that this needs to be sorted
oshima
2013/07/31 21:59:49
Only requirement is the 1st element is minimum siz
| |
| 22 {40, 30}, | |
| 23 {50, 40}, | |
| 24 {160, 90}, | |
| 25 {160, 100}, | |
| 26 }; | |
| 27 | |
| 28 // Resolution list are sorted by area and the larger one comes first. | |
| 29 struct ResolutionSorter { | |
| 30 bool operator()(const Resolution& a, const Resolution& b) { | |
| 31 return a.size.width() * a.size.height() > b.size.width() * b.size.height(); | |
| 32 } | |
| 33 }; | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 bool ShouldIgnoreSize(unsigned long mm_width, unsigned long mm_height) { | |
| 38 // Ignore if the reported display is smaller than minimum size. | |
| 39 if (mm_width <= kInvalidDisplaySizeList[0][0] || | |
| 40 mm_height <= kInvalidDisplaySizeList[0][1]) { | |
| 41 LOG(WARNING) << "Smaller than minimum display size"; | |
| 42 return true; | |
| 43 } | |
| 44 for (unsigned long i = 1 ; i < arraysize(kInvalidDisplaySizeList); ++i) { | |
| 45 const unsigned long* size = kInvalidDisplaySizeList[i]; | |
| 46 if (mm_width == size[0] && mm_height == size[1]) { | |
| 47 LOG(WARNING) << "Black listed display size detected:" | |
| 48 << size[0] << "x" << size[1]; | |
| 49 return true; | |
| 50 } | |
| 51 } | |
| 52 return false; | |
| 53 } | |
| 54 | |
| 55 std::vector<Resolution> GetResolutionList( | |
| 56 XRRScreenResources* screen_resources, | |
| 57 XRROutputInfo* output_info) { | |
| 58 typedef std::map<std::pair<int,int>, Resolution> ResolutionMap; | |
| 59 | |
| 60 ResolutionMap resolution_map; | |
| 61 | |
| 62 for (int i = 0; i < output_info->nmode; i++) { | |
| 63 RRMode mode = output_info->modes[i]; | |
| 64 const XRRModeInfo* info = chromeos::FindModeInfo(screen_resources, mode); | |
| 65 DCHECK(info); | |
| 66 // Just ignore bad entry on Release build. | |
| 67 if (!info) | |
| 68 continue; | |
| 69 ResolutionMap::key_type size = std::make_pair(info->width, info->height); | |
| 70 bool interlaced = (info->modeFlags & RR_Interlace) != 0; | |
| 71 | |
| 72 ResolutionMap::iterator iter = resolution_map.find(size); | |
| 73 | |
| 74 // Add new resolution if it's new size or override interlaced mode. | |
| 75 if (iter == resolution_map.end()) { | |
| 76 resolution_map.insert(ResolutionMap::value_type( | |
|
Daniel Erat
2013/07/31 17:34:05
why not just do:
resolution_map[size] = Resolut
oshima
2013/07/31 21:59:49
That didn't work because Resolution doesn't have d
Daniel Erat
2013/07/31 22:10:17
ah, makes sense. this seems fine
| |
| 77 size, | |
| 78 Resolution(gfx::Size(info->width, info->height), interlaced))); | |
| 79 } else if (iter->second.interlaced && !interlaced) { | |
| 80 iter->second.interlaced = false; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 std::vector<Resolution> resolution_list; | |
| 85 for (ResolutionMap::const_iterator iter = resolution_map.begin(); | |
| 86 iter != resolution_map.end(); | |
| 87 ++iter) { | |
| 88 resolution_list.push_back(iter->second); | |
| 89 } | |
| 90 std::sort(resolution_list.begin(), resolution_list.end(), ResolutionSorter()); | |
| 91 return resolution_list; | |
| 92 } | |
| 93 | |
| 94 } // namespace internal | |
| 95 } // namespace ash | |
| OLD | NEW |